
// films
var test = 0;
var submittable = true;

var imgArray = new Array();
imgArray[0] = new Image();
imgArray[0] = imgDir + "/common/loader_macish.gif"

imgArray[1] = new Image();
imgArray[1] = imgDir + "/films/ppv/bttn_complete_purchase_disabled.gif"

imgArray[2] = new Image();
imgArray[2] = imgDir + "/films/bg_about_page.jpg"

imgArray[3] = new Image();
imgArray[3] = imgDir + "/films/ppv/bg_thickbox_blue_gradient.jpg"

var loadingGraphic2 = '<img src="' + imgDir + '/common/loader_macish.gif" />';


film = new Object();

film.loadFilmSummary = loadFilmSummary;

/**
*
*	Refreshes the currently selected film via ajax
*
*/
function loadFilmSummary(code){

	xmlHttp=getXmlHttpObject()

	xmlHttp.onreadystatechange = function(){

  	if(xmlHttp.readyState == 4){

			if (typeof(pageTracker) != 'undefined') {
				pageTracker._trackPageview('/films/preview/' + code);
			}

      document.getElementById('filmSummary').innerHTML = xmlHttp.responseText;
    }else{
			document.getElementById('filmSummary').innerHTML = loadingGraphic;
		}
  }

	var url = siteURL

	url=url+'/films/'+code+'/summary';

	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);

}



//film.switchFilmView = switchFilmView;

/**
*
*	switches the film browse view via ajax
*
*/
/*
function switchFilmView(type){

	switch(type){
		case "b":
			// change images
			document.getElementById('browseViewButton').src=imgDir+'/icon_browse_view_down.gif'
			document.getElementById('listViewButton').src=imgDir+'/icon_list_view_up.gif'

			xmlHttp=getXmlHttpObject()

			xmlHttp.onreadystatechange = function(){

				if(xmlHttp.readyState == 4){
					document.getElementById('filmView').innerHTML = xmlHttp.responseText;
					document.getElementById('browseSort').style.display='block'
				}else{
					document.getElementById('filmView').innerHTML = loadingGraphic;
				}
			}

			var url = siteURL

			url=url+'/films/browse';

			xmlHttp.open("POST",url,true);
			xmlHttp.send(null);

		break;
		case "l":
			// change images
			document.getElementById('browseViewButton').src=imgDir+'/icon_browse_view_up.gif'
			document.getElementById('listViewButton').src=imgDir+'/icon_list_view_down.gif'

			xmlHttp=getXmlHttpObject()

			xmlHttp.onreadystatechange = function(){

				if(xmlHttp.readyState == 4){
					document.getElementById('browseSort').style.display='none'
					document.getElementById('filmView').innerHTML = xmlHttp.responseText;
				}else{
					document.getElementById('filmView').innerHTML = loadingGraphic;
				}
			}

			var url = siteURL

			url=url+'/films/list';

			xmlHttp.open("POST",url,true);
			xmlHttp.send(null);

		break;
	}
}
*/

/**
*
*
*
*/
function setSelectedRow(el, sc){
	divs = document.getElementById('filmsList').getElementsByTagName('div');

	for(i=0;i<divs.length;i++){
		if(divs[i].className=='filmTDOn'){
			divs[i].className='filmTD'
		}
	}
	window.selectedCode = sc;
	el.className='filmTDOn';
}

/**
*
*
*
*/
function ajaxCommentsList(page, code){

	xmlHttp=getXmlHttpObject()

	xmlHttp.onreadystatechange=function(){

  	if(xmlHttp.readyState==4){
      document.getElementById('discussion').innerHTML=xmlHttp.responseText;
    }else{
      document.getElementById('discussion').innerHTML=loadingGraphic;
    }
  }

	//var sortBy = document.getElementById('sortBy').value
	//+"&sortBy="+sortBy;
	var url = siteURL+"/films/"+code+"/commentslist?ajax=1&page="+page

	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);

}

/**
*
*
*
*/
function processOrder(code){

	xmlHttp=getXmlHttpObject()

	xmlHttp.onreadystatechange = function(){

  	if(xmlHttp.readyState == 4){

			if(test == 1){
				document.getElementById('orderProcessing').innerHTML = xmlHttp.responseText;
				processError(xmlHttp.responseText);
			}else{
				if(xmlHttp.responseText == 'success'){

					//tb_remove();
					//submittable = true
					//reloadPlayer(code);
					document.location = siteURLLocked+"/films/"+code
				}else{
					submittable = true
					processError(xmlHttp.responseText);
					document.getElementById('orderProcessing').innerHTML = '';
					document.getElementById('completeImg').src = imgDir + '/films/ppv/bttn_complete_purchase.gif';
				}
			}

    }else{
			submittable = false
			document.getElementById('completeImg').src = imgDir + '/films/ppv/bttn_complete_purchase_disabled.gif';
			document.getElementById('orderProcessing').innerHTML = loadingGraphic2;
		}
  }

	if(submittable == true){
		form = document.getElementById('ppvPayment');

		var send = Array();

		send[0] = 'step';
		send[1] = 'existing';
		send[2] = 'filmID';
		send[3] = 'billingEmail';
		send[4] = 'billingName';
		send[5] = 'cardNum';
		send[6] = 'cardType';
		send[7] = 'expMon';
		send[8] = 'expYear';
		send[9] = 'securityCode';
		send[10] = 'billingAddress';
		/*send[10] = 'billingAddress2';*/
		send[11] = 'billingCity';
		send[12] = 'billingCountry';
		send[13] = 'billingState';
		send[14] = 'billingProvince';
		send[15] = 'billingZip';
		send[16] = 'promoCode';

		//send['billingCountry'] = form.billingCountry.value

		var url = siteURL+'/films/ppv/process?';


		for(i=0;i<send.length;i++){
			if (document.getElementById(send[i])) {
				// clear any old errors
				if(document.getElementById(send[i]+'_error')){
					document.getElementById(send[i]+'_error').innerHTML = '';
				}

				url += send[i]+'='+document.getElementById(send[i]).value+'&' ;
			}
		}

		document.getElementById('iAgree_error').innerHTML = ''
		url += (document.getElementById('iAgree').checked==true) ? 'iAgree=1&': 'iAgree=&';

		if(document.getElementById('an_error')){
				document.getElementById('an_error').innerHTML=''
		}

		if(document.getElementById('saveCCInfo')){ // not avaliable for non-members
		url += (document.getElementById('saveCCInfo').checked==true) ? 'saveCCInfo=1&': 'saveMyInfo=&';
		}

		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
	}else{
		// do nothing
	}
}

function processError(responseString){

	errors = responseString.split('&')

	for(i=0;i<errors.length;i++){

		pair = errors[i].split('=');

		if (pair[0] == 'billingProvince') {
			pair[0] = 'billingState';
		}

		if(document.getElementById(pair[0]+'_error')){
			document.getElementById(pair[0]+'_error').innerHTML = pair[1];
		}
	}
}

function ajaxFilmsList(p){

	xmlHttp=getXmlHttpObject()

	xmlHttp.onreadystatechange = function(){

		if(xmlHttp.readyState == 4){
			document.getElementById('filmsLayout').innerHTML = xmlHttp.responseText;
		}else{
			document.getElementById('filmsLayout').innerHTML = loadingGraphic;
		}
	}

	var url = siteURL

	url=url+'/films/list?page='+p+'&';

	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);

}

function toggleAboutThisPage(){

	if(document.getElementById('aboutThisPage').style.display=='block'){
		document.getElementById('aboutThisPage').style.display='none'
		document.getElementById('aboutThisPageBttn').src=imgDir+'/films/bttn_films_about_page_open.gif'
	}else{
		document.getElementById('aboutThisPage').style.display='block'
		document.getElementById('aboutThisPageBttn').src=imgDir+'/films/bttn_films_about_page_close.gif'
	}

}

function reloadPlayer(code){

	xmlHttp=getXmlHttpObject()

	xmlHttp.onreadystatechange = function(){

  	if(xmlHttp.readyState == 4){
			document.getElementById('player').innerHTML = xmlHttp.responseText;
    }else{
			document.getElementById('player').innerHTML = loadingGraphic2;
		}
  }

	var url = siteURL+'/films/'+code+'/player';

	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);
}

function toggleMoreCredits(){
	if(document.getElementById("allCredits").style.display == 'none'){
		document.getElementById("allCredits").style.display = 'block'
		document.getElementById("toggleLink").innerHTML='show fewer(-)';
	}else{
		document.getElementById("allCredits").style.display = 'none'
		document.getElementById("toggleLink").innerHTML='show all(+)';
	}
}

