//Comment out lines 526 and 528 to disable link to official movie site
//Comment out lines 61 and 640 to stop showtimes from hiding
//Change line 36 to match folder that contains schedule.xml
//Load the schedule.xml file, cross browser
var remotePurchaseURL="https://www.retrievertickets.com/purchase.php";//Where they can buy tickets
var sidVar="osses";//the variable name for the showing ID at the purchasing site
var tidVar="ostk";//the variable name for the Theater ID at the purchasing site
var midVar="movieID";//the variable name for the Movie ID at the purchasing site.
var movieInfoURL="http://www.retriever-tickets.com/functions/moviedisplay.cfm?movieid=<movieID>&KeepThis=true&TB_iframe=true&height=400&width=600";

//server side directories and files
//var imgDir="assets/Lansing/images/";//local directory for movie images
var xmlSchedulePath="./";//directory and file name for the schedule.xml file
var mainPageElementId="writeroot";//the div element ID to output the created table to
var dayStartTime="035900"; //The time on a particular day to start including movies showing that day
var dayEndTime="040000"; //The latest time, on the following day, to include movies that are showing
var matEndHour="18"; //The Hour that matinee shows end
var matEndMin="00"; //The Minute during the above hour that matinee shows end
//CSS Classes
var tableClass="movTbl";//the table
var curDateClass="curDateRow";//table row that displays the current and selected date
var movieRowClass="movNameRow"; //movie row element
var movieCellClass="movNameCell";//movie name cell
var movieRatingSpan="movRatingSpan";//span for movie ratings
var movieRatingRSpan="movRatingRSpan";//possible different style for R-rated movies
var movieDescriptionCell="movDescCell";//description text
var movieTimesCell="movTimesCell";//movie times cell
var movieTimeLink="movShowTimeLink";//movie time link
var movePastTime="movShowTimePast";//movies that have already shown
var gridTable="gridTable";
var gridTd="gridTd";

//Other variables
var shortDescLength=500;//number of characters to use for shortened movie description
var movieImageWidth="100";//width to display the movie image at
var movieImageHeight="150";//height to display the movie image at

//Theater Names Array, needs to match folder names within the scripts directory
var theaterList=new Array("");
var theaterLabel=new Array("Click a time to Buy Tickets");
var scheduleList=new Array();
var movImgArray=new Array();

var y = 0;
var leftrightslide=new Array();
for (var x in movImgArray) {
	leftrightslide[y]='<a href="#" onclick="showMovieListing(' + x + ');"><img src="' + movImgArray[x] + '" border=1></a>';
	y++;
}

for (x in theaterList) {
	scheduleList[x]=loadDoc(xmlSchedulePath + theaterList[x] + "/schedule.xml");
}

function loadDoc(schedPath){
	try
	{
		if (window.ActiveXObject)
		{
			var errorHappendHere = "Check Browser and security settings";
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async=false;
			xmlDoc.load(schedPath);
			xmlDoc=xmlDoc.documentElement;
		}
		else if(window.XMLHttpRequest)
		{
			var errorHappendHere = "Error handling XMLHttpRequest request";
			var d = new XMLHttpRequest();
			d.open("GET", schedPath, false);
			d.send(null);
			xmlDoc=d.responseXML;
		} else {
			var errorHappendHere = "Error.";
			xmlDoc = document.implementation.createDocument("","",null);
			xmlDoc.async=false;
			xmlDoc.load(schedPath);
		}
	}	
	catch(e)
	{
		alert(errorHappendHere);
	}
	return xmlDoc;
}

//Cross browser extraction of text in a node
function retText(node){
	if(window.ActiveXObject){
		return node.text;
	} else {
		return node.textContent;
	}
}

function addShow(vtime,vitem){
	this.time=vtime;
	this.item=vitem;
}

function timeSort(a,b){
	var x = a.time;
	var y = b.time;
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
//Fill in the select list with dates ranging from today to the max date in the xml file
function populateSelect(xmlDoc, elSel){
	var dmindate=new Date();
	var showings=xmlDoc.getElementsByTagName('Session');
	fmaxdate="";
	for (var showing=0;showing<showings.length; showing++){
		if(retText(showings[showing].getElementsByTagName('Date_time')[0]) > fmaxdate) {
			fmaxdate=retText(showings[showing].getElementsByTagName('Date_time')[0]);//get the Max Date
		}
		
	}
	var dmaxdate=new Date.parseString(fmaxdate, "yyyyMMddHHmmss");
	while(dmindate <=dmaxdate){//Fill in the Select List
		var elOptNew = document.createElement('option');
		elOptNew.text = dmindate.format("EE NNN d, yyyy");
		elOptNew.value = dmindate.format("MM/dd/yyyy");
		dmindate.setDate(dmindate.getDate()+1);
		try {
			elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
			elSel.add(elOptNew); // IE only
		}
	}
}

function setDisplayDate(newDate){
	dateArr=newDate.split("/");
	document.getElementById('curyear').value=dateArr[2];
	document.getElementById('curmonth').value=dateArr[0];
	document.getElementById('curday').value=dateArr[1];
}

function moviesort(a,b){
	if (retText(a.getElementsByTagName('Movie_Name')[0]) > retText(b.getElementsByTagName('Movie_Name')[0])) {
		return 1;
	} else if(retText(a.getElementsByTagName('Movie_Name')[0]) < retText(b.getElementsByTagName('Movie_Name')[0])) {
		return -1;
	} else {
		return 0;
	}
}

