var currDateTime = new Date();
var movieShowDate;
var cinemaShowTime = new Array();
var arrCinemaSession= new Array();
var arrCinemaSessionCode = new Array();
var arrCinema = new Array();
var strBookCinema="";
var strBookSession="";
var alertCounter=0;
var movieDateList;
var rowColorClass1 = "class=\"altRowGrey\"";
var weekday=new Array(7);
var monthName=new Array(13);
weekday[0]="Sun";
weekday[1]="Mon";
weekday[2]="Tue";
weekday[3]="Wed";
weekday[4]="Thu";
weekday[5]="Fri";
weekday[6]="Sat";
monthName[1] = "Jan";
monthName[2] = "Feb";
monthName[3] = "Mar";
monthName[4] = "Apr";
monthName[5] = "May";
monthName[6] = "Jun";
monthName[7] = "Jul";
monthName[8] = "Aug";
monthName[9] = "Sep";
monthName[10] = "Oct";
monthName[11] = "Nov";
monthName[12] = "Dec";
//var arrCinemaSession = new Array();
function setShowListingByMovie(inCinemaCode, inDate){
	var procDate;
	var movieName;
	var cinemaName;
	var currentDate;
	var tempString;
	var h,i,j,k;
	var tempArray;
	var day1, dayLast;
	var curMovie;
	var tempMovieArray;
	var tempAP;
	var alertCounter = 0;
	var firstDay="";
	var today = new Date();
	if (inDate!=null && inDate != "")
		currentDate = new Date(inDate);
	else
		currentDate = new Date();
tempString = currentDate.getFullYear() + "/" + (parseInt(currentDate.getMonth())+1) + "/" + currentDate.getDate();	
	tempArray = sessionByMovie[0].split(" ");
	if (tempArray.length == 2){
		tempArray = tempArray[0].split(",");
		if (tempArray.length == 4)
			day1 = new Date(tempArray[3]);
	}
	tempArray = sessionByMovie[(sessionByMovie.length - 1)].split(" ");
	if (tempArray.length == 2){
		tempArray = tempArray[0].split(",");
		if (tempArray.length == 4)
			dayLast = new Date(tempArray[3]);
	}

	if (currentDate < day1 || currentDate > dayLast){
	;//currentDate = new Date();
	}

	curMovie = "";
	j = -1;
	var currentShowTime="";
	var skipThis = false;
	for (i=0;i<sessionByMovie.length;i++){
	if (sessionByMovie[i].indexOf(inCinemaCode+",") >= 0){
		skipThis = false;
			if (curMovie != sessionByMovie[i].split(",").slice(1,2)+""){
			j = j + 1;
			arrCinemaSession[j] = new Array();
			curMovie = sessionByMovie[i].split(",").slice(1,2)+"";
			arrCinemaSession[j][0] = curMovie;
			}
		}
	}
var tempClass = "";
	for (k=0;k<arrCinemaSession.length;k++){
		if (movieDateList != ""){
		document.write("<tr valign=\"top\" "+tempClass+">");
		document.write("<td width=\"2\">&nbsp;</td>");
		document.write("<td ><strong class=\"cinemaLocation\"><a href=\"movies.asp?mID="+arrCinemaSession[k][0]+"\">"+getdbMovieName(arrCinemaSession[k][0])+"</a>"+"</strong></td>");	
		document.write("<td valign=\"top\"><div class=\"date\" id=\"divD"+arrCinemaSession[k][0]+inCinemaCode+"\"></div><div  class=\"time\" id=\"div"+arrCinemaSession[k][0]+inCinemaCode+"\"></div></td>");
//	document.write("<td valign=\"top\" colspan=\"2\" ></td>");
	
	
		if (tempClass =="")
			tempClass = rowColorClass1;
		else
			tempClass ="";
		getTimeLayerbyMovie(currentDate.getFullYear()+"/"+(parseInt(currentDate.getMonth())+1)+"/"+currentDate.getDate(), arrCinemaSession[k][0], inCinemaCode);
		}

	}
//document.write("</table>");
}

function setShowListingByCinema(inMovieCode, inDate){
	var procDate;
	var movieName;
	var cinemaName;
	var currentDate;
	var tempString;
	var h,i,j,k;
	var tempArray;
	var day1, dayLast;
	var curCinema;
	var tempMovieArray;
	var tempAP;
	var today = new Date();
	var firstDay = "";

	
	if (inDate!=null && inDate!="")
		currentDate = new Date(inDate);
	else
		currentDate = new Date();
	tempString = currentDate.getFullYear() + "/" + (parseInt(currentDate.getMonth())+1) + "/" + currentDate.getDate();	
	tempArray = sessionByCinema[0].split(" ");
	if (tempArray.length == 2){
		tempArray = tempArray[0].split(",");
		if (tempArray.length == 4)
			day1 = new Date(tempArray[3]);
	}
	tempArray = sessionByCinema[(sessionByCinema.length - 1)].split(" ");
	if (tempArray.length == 2){
		tempArray = tempArray[0].split(",");
		if (tempArray.length == 4)
			dayLast = new Date(tempArray[3]);
	}
	
	if (currentDate < day1 || currentDate > dayLast){
	currentDate = new Date();
	}
	curCinema = "";
	j = -1;
	var currentShowTime="";
	var tempShowTime;
	var skipThis = false;
	for (i=0;i<sessionByCinema.length;i++){
		if (sessionByCinema[i].indexOf(","+inMovieCode+",") > 0){
			if (curCinema != sessionByCinema[i].slice(0,3)){
				j = j + 1;
				arrCinemaSession[j] = new Array();;
				curCinema = sessionByCinema[i].slice(0,3)
				arrCinemaSession[j][0] = curCinema;
			}
		}
	}
	
var tempClass = "";
	for (k=0;k<arrCinemaSession.length;k++){
		if (movieDateList != ""){
		document.write("<tr valign=\"top\" "+tempClass+">");
		document.write("<td width=\"2\">&nbsp;</td>");
		document.write("<td style=\" border-right: solid 0px #cccccc;\"><div class=\"cinemaLocation\"><a href=\"cinema.asp?c="+arrCinemaSession[k][0]+"\">"+getCinemaName(arrCinemaSession[k][0])+"</a>"+"</div></td>");	
		
		
			document.write("<td  style=\" border-right: solid 0px #cccccc;\"><div class=\"date\" id=\"divD"+inMovieCode+arrCinemaSession[k][0]+"\"></div><div  class=\"time\"  id=\"div"+inMovieCode+arrCinemaSession[k][0]+"\"></div></td>");	
		
		
//		document.write("<td colspan=\"2\"  style=\" border-right: solid 0px #cccccc;\"></td>");
		

	
		if (tempClass =="")
			tempClass = rowColorClass1;
		else
			tempClass ="";
		getTimeLayerbyCinema("", inMovieCode, arrCinemaSession[k][0]);
		}

	}
}

function getMovieName(inVal){
	if ((inVal+"").length > 0){
		
	}
	else
		return "Invalid Data";
	
}
function getCinemaName(inVal){
	var i, returnVal;
	for(i=0;i<cinemaList.length; i++){
		if (inVal == cinemaList[i].split(",")[0])
			return cinemaList[i].split(",")[1];
	}
	return "";	
}
function bookSession(inCin,inCode){
var xmlHttp;
strBookCinema = inCin;
strBookSession = inCode;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      if (xmlHttp.responseText=="PASS")
	  window.location.href="../include/asp/bookticket.asp?c="+ strBookCinema +"&s="+ strBookSession;
	  else
	  generateLogin('');	  
      }
    }

  xmlHttp.open("GET","../include/asp/chkLogin.asp");
  xmlHttp.send(null);
}

function doLogin(frm){
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      if (xmlHttp.responseText == "PASS")
	  	window.location.href="../include/asp/bookticket.asp?c="+ strBookCinema +"&s="+ strBookSession;
	  else if (xmlHttp.responseText == "PENDING")
	  	generateLogin("<div class=\"loginContent\">We found your login in information but it seem like it is not activated yet.<br>Please <a href=\"../SignUp/ResendActivation.asp\">click here</a> if you have forgotten or did not receive your activation code. System will send the activation code to your email account again.</div>");
	  else
	  	generateLogin("<div class=\"loginContent\">Invalid User Name or Password.<br/>Please <a href=\"../SignUp/ForgotPassword.asp\">click here</a> if you have forgotten your password. The system will generate a password and send it to your email account.</div>");
      }
    }

  xmlHttp.open("GET","../include/asp/getLoginDetail.asp?user="+getElement("txtUserName").value+"&pass="+getElement("txtPassword").value);
  xmlHttp.send(null);	
}
function getdbMovieName(inCode){
	var i;
	var tempMovieNameArray = new Array()
	inCode = inCode+"";
	
	if (inCode != ""){
		if (inCode.length <= 4){
			for (i = 0;i<movieNameList.length;i++){
				if(movieNameList[i].indexOf(inCode+",")==0){
					tempMovieNameArray = movieNameList[i].split(",");
					return (tempMovieNameArray.slice(1));
				}			
			}			
		}
	}
	return ("Data temporary unavailable.");
}
function getDateCinema(inVal,cinemaCode,movieCode){
	var nowDateVal = currentDate.getFullYear() + "/" + (parseInt(currentDate.getMonth())+1) + "/" + currentDate.getDate();		
	var i;
	var newDateVal = "";
	var returnVal ="";
	var d1 = new Date(nowDateVal);
	var d2="";
	for(i=0;i<sessionByMovie.length;i++){
		if (sessionByMovie[i].indexOf(cinemaCode+",")==0 && sessionByMovie[i].indexOf(movieCode) > 0){
			if (newDateVal!=sessionByMovie[i].split(",").slice(3).split(" ")[0])	{
				newDateVal = sessionByMovie[i].split(",").slice(3).split(" ")[0];
				d2=new Date(newDateVal);
				if (d2-d1 >=0){
					if (newDateVal==inVal+"")
					returnVal = returnVal + "&nbsp; | &nbsp;" + "<strong><a href=\"javascript:setMovieTime('"+newDateVal+"','"+cinemaCode+"');\" >"+d2+"</a></strong>";		
					else
					returnVal = returnVal + "&nbsp; | &nbsp;" + "<a href=\"javascript:setMovieTime('"+newDateVal+"','"+cinemaCode+"');\">"+d2+"</a>";	
				}
			}
		}
	}
	return returnVal;
}
function getDateMovie(inVal){
	var nowDate = currentDate.getFullYear() + "/" + (parseInt(currentDate.getMonth())+1) + "/" + currentDate.getDate();		
	
	
}
function genDateListbyMovie(movCode, cinCode, sDate){
	var toDay = new Date();
	var nowDate = toDay.getFullYear()+"/"+parseInt(toDay.getMonth()+1)+"/"+toDay.getDate();
	var i, j=0;
	var arrDateList = new Array;
	var k;
	var tempCurrDate="";
	var tempCurrDateM="";
	var returnVal="";
	for(i=0;i<sessionByMovie.length;i++){
		if (sessionByMovie[i].indexOf(","+movCode+",")>=0 && sessionByMovie[i].indexOf(cinCode)>=0){
			if (tempCurrDate == "" || sessionByMovie[i].indexOf(tempCurrDate)<0){
				tempCurrDate = sessionByMovie[i].split(" ")[0].split(",")[3].toString();
				if (Date.parse(tempCurrDate) >= Date.parse(nowDate)){
					if (tempCurrDate == sDate) 
						tempCurrDateM = "<b style=\"color:#004681;\">"+ weekday[(new Date(tempCurrDate)).getDay()] + " "+tempCurrDate.split("/")[2]+" "+monthName[parseInt(tempCurrDate.split("/")[1])]+"</b>";
					else
						tempCurrDateM = weekday[(new Date(tempCurrDate)).getDay()] + " "+tempCurrDate.split("/")[2]+" "+monthName[parseInt(tempCurrDate.split("/")[1])];
					arrDateList[j]="<a href=\"javascript:getTimeLayerbyMovie('"+tempCurrDate+"','"+movCode+"','"+cinCode+"')\">"+tempCurrDateM+"</a>";
					j = j + 1;
				}
			}
		}
	}
	if (arrDateList.length>0){
		for(k=0;k<arrDateList.length;k++){
			if(k==0)
				returnVal = arrDateList[k];
			else
				returnVal = returnVal + " |   " + arrDateList[k];
		}
	}else
		returnVal = "";
	return returnVal;
}

function genDateListbyCinema(movCode, cinCode, sDate){
	var toDay = new Date();
	var nowDate = toDay.getFullYear()+"/"+parseInt(toDay.getMonth()+1)+"/"+toDay.getDate();
	var i, j=0;
	var arrDateList = new Array;
	var k;
	var tempCurrDate="";
	var tempCurrDateM="";
	var returnVal="";
	for(i=0;i<sessionByCinema.length;i++){
		if (sessionByCinema[i].indexOf(","+movCode+",")>=0 && sessionByCinema[i].indexOf(cinCode)>=0){
			if (tempCurrDate == "" || sessionByCinema[i].indexOf(tempCurrDate)<0){
				tempCurrDate = sessionByCinema[i].split(" ")[0].split(",")[3].toString();
				if (Date.parse(tempCurrDate) >= Date.parse(nowDate)){
					if (tempCurrDate == sDate)
						tempCurrDateM = "<b style=\"color:#950066;\">"+weekday[(new Date(tempCurrDate)).getDay()] + " "+tempCurrDate.split("/")[2]+" "+monthName[parseInt(tempCurrDate.split("/")[1])]+"</b>";
					else
						tempCurrDateM = weekday[(new Date(tempCurrDate)).getDay()] + " "+tempCurrDate.split("/")[2]+" "+monthName[parseInt(tempCurrDate.split("/")[1])];
					arrDateList[j]="<a href=\"javascript:getTimeLayerbyCinema('"+tempCurrDate+"','"+movCode+"','"+cinCode+"')\">"+tempCurrDateM+"</a>";
					j = j + 1;
				}
			}
		}
	}
	if (arrDateList.length>0){
		for(k=0;k<arrDateList.length;k++){
			if(k==0)
				returnVal = arrDateList[k];
			else
				returnVal = returnVal + " |   " + arrDateList[k];
		}
	}else
		returnVal = "";
	return returnVal;
}
function getTimeLayerbyMovie(dateVal, movCode, cinCode){
	if(document.getElementById("div"+movCode+cinCode)){
	var j = 0;
	var currentShowTime="";
	var skipThis = false;
	var fCondent="";
	var thisDate;
	var toDay = new Date();
	var toDayCheck;
	var dateChecker = true;
	var dateLoop;
	var dateLoopMax = 7;
	var tempDateList="";
	var isToday =	toDay.getFullYear()+"/"+(toDay.getMonth()+1)+"/"+toDay.getDate()+"";
	if (dateVal != "")	
	dateVal = (Date.parse(dateVal) >= Date.parse(isToday))?dateVal:isToday;
	else
	dateVal = isToday;
			
		var arrCinemaSession = new Array();
		for (i=0;i<sessionByMovie.length;i++){
			if (sessionByMovie[i].indexOf(cinCode+",") >= 0 && sessionByMovie[i].indexOf(","+movCode+",")>=0 ){
					if (dateChecker){
						if(Date.parse(dateVal) <= Date.parse(sessionByMovie[i].split(" ")[0].split(",")[3])){
							dateVal = sessionByMovie[i].split(" ")[0].split(",")[3];
							dateChecker = false;
						}
						tempDateList = dateVal;
					}

					if (dateChecker==false){
						if (tempDateList.indexOf(dateVal) < 0)
							tempDateList = tempDateList + "," + dateVal;

						if (Date.parse(sessionByMovie[i].split(" ")[0].split(",")[3]) == Date.parse(dateVal)){
							skipThis = false;
							toDayCheck = Date.parse(isToday) == Date.parse(sessionByMovie[i].split(" ")[0].split(",")[3])?true:false;	
							tempMovieArray = sessionByMovie[i].split(" ");
							if (toDayCheck) 
								if ((parseInt(tempMovieArray[1].replace(":",""))<= parseInt(toDay.getHours()+""+toDay.getMinutes())))		
									skipThis = true;
						if (skipThis != true){
						if (tempMovieArray[1]+"" != currentShowTime){
							currentShowTime = tempMovieArray[1];
							tempAP = (parseInt(tempMovieArray[1].replace(":",""))<1200)?"am":"pm"
							tempShowTime = (parseInt(tempMovieArray[1].replace(":",""))<1300)?tempMovieArray[1]:(parseInt(tempMovieArray[1].split(":")[0])-12)+":"+tempMovieArray[1].split(":")[1];
						//	if (parseInt(tempMovieArray[1].replace(":","")) < 1800){
								if (arrCinemaSession[1])
									arrCinemaSession[1]	= arrCinemaSession[1] + " &nbsp; |   &nbsp; " + "<a href='javascript:bookSession(\""+ cinCode +"\","+ sessionByMovie[i].split(",")[2] +")'>"+tempShowTime+tempAP+"</a>";
								else
									arrCinemaSession[1]	= "<a href='javascript:bookSession(\""+ cinCode +"\","+ sessionByMovie[i].split(",")[2] +")'>"+tempShowTime+tempAP+"</a>";
					/*		}
							else{
								if (arrCinemaSession[2])
								arrCinemaSession[2]	= arrCinemaSession[2] + " &nbsp; |   &nbsp; " + "<a href='javascript:bookSession(\""+ cinCode +"\","+ sessionByMovie[i].split(",")[2] +")'>"+tempShowTime+tempAP+"</a>";
								else
								arrCinemaSession[2]	= "<a href='javascript:bookSession(\""+ cinCode +"\","+ sessionByMovie[i].split(",")[2] +")'>"+tempShowTime+tempAP+"</a>";
							}
							*/
						}
						}
					}
					}
				}
			}
			
			}
	if (arrCinemaSession[1])// || arrCinemaSession[2])
	{
		fCondent="<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr width=\"100%\" valign=\" top\"><td  align=\"left\">";
		if (arrCinemaSession[1])
			fCondent=fCondent+arrCinemaSession[1]+"</td>";
		else
			fCondent=fCondent+"</td>";
		fCondent=fCondent+"</td>";/*<td width=\"160\" align=\"left\">";	
		if (arrCinemaSession[2])
			fCondent=fCondent+arrCinemaSession[2]+"</td>";
		else
			fCondent=fCondent+"&nbsp;</td>";*/
		fCondent = fCondent + "</tr></table>";	
	}
	if (fCondent=="")
		fCondent = "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr width=\"100%\" valign=\"top\"><td>No sessions are available for the selected item.</td></tr></table>"
//call date func
	document.getElementById("divD"+movCode+cinCode).innerHTML = genDateListbyMovie(movCode, cinCode, dateVal);
	if (document.getElementById("divD"+movCode+cinCode).innerHTML != "")
		document.getElementById("div"+movCode+cinCode).innerHTML = fCondent;
	else
		document.getElementById("div"+movCode+cinCode).innerHTML = "No movie date available.";
}

function getTimeLayerbyCinema(dateVal, movCode, cinCode){
	if(document.getElementById("div"+movCode+cinCode)){
//
	var j = 0;
	var currentShowTime="";
	var skipThis = false;
	var fCondent="";
	var thisDate;
	var toDay = new Date();
	var dateChecker = true;
	var isToday =	toDay.getFullYear()+"/"+(toDay.getMonth()+1)+"/"+toDay.getDate()+"";
	var toDayCheck;
	if (dateVal != "")	
	dateVal = (Date.parse(dateVal) >= Date.parse(isToday))?dateVal:isToday;
	else
	dateVal = isToday;

	var arrCinemaSession = new Array();
	for (i=0;i<sessionByCinema.length;i++){
		if (sessionByCinema[i].indexOf(cinCode+",") >= 0 && sessionByCinema[i].indexOf(","+movCode+",")>=0){
			if (dateChecker){
				if(Date.parse(dateVal) <= Date.parse(sessionByCinema[i].split(" ")[0].split(",")[3])){
					dateVal = sessionByCinema[i].split(" ")[0].split(",")[3];
					dateChecker = false;
				}
			}
			if (dateChecker==false){	
				if (Date.parse(sessionByCinema[i].split(" ")[0].split(",")[3]) == Date.parse(dateVal)){
					skipThis = false;
					toDayCheck = Date.parse(isToday) == Date.parse(sessionByCinema[i].split(" ")[0].split(",")[3])?true:false;	
					tempMovieArray = sessionByCinema[i].split(" ");
					if (toDayCheck) 
						if ((parseInt(tempMovieArray[1].replace(":",""))<= parseInt(toDay.getHours()+""+toDay.getMinutes())))		
							skipThis = true;
					if (skipThis != true){
						if (tempMovieArray[1]+"" != currentShowTime){
							currentShowTime = tempMovieArray[1];
							tempAP = (parseInt(tempMovieArray[1].replace(":",""))<1200)?"am":"pm"
							tempShowTime = (parseInt(tempMovieArray[1].replace(":",""))<1300)?tempMovieArray[1]:(parseInt(tempMovieArray[1].split(":")[0])-12)+":"+tempMovieArray[1].split(":")[1];
								if (arrCinemaSession[1])
									arrCinemaSession[1]	= arrCinemaSession[1] + " &nbsp; |   &nbsp; " + "<a href='javascript:bookSession(\""+ cinCode +"\","+ sessionByCinema[i].split(",")[2] +")'>"+tempShowTime+tempAP+"</a>";
								else
									arrCinemaSession[1]	= "<a href='javascript:bookSession(\""+ cinCode +"\","+ sessionByCinema[i].split(",")[2] +")'>"+tempShowTime+tempAP+"</a>";
							
						}
					}
				}
			}
		}
			if (arrCinemaSession[1])// || arrCinemaSession[2])
			{
			fCondent="<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr valign=\"top\"><td width=\"100%\" align=\"left\" style=\" border-right: solid 0px #cccccc;\" >";
			if (arrCinemaSession[1])
				fCondent=fCondent+arrCinemaSession[1]+"</td>";
			else
				fCondent=fCondent+"</td>";

			/*if (arrCinemaSession[2])
				fCondent=fCondent+arrCinemaSession[2]+"</td>";
			else
				fCondent=fCondent+"</td>";*/
			fCondent = fCondent + "</tr></table>";	
			}
		}
	}
	if (fCondent=="")
		fCondent = "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr width=\"100%\" valign=\"top\"><td>No sessions are available for the selected item.</td></tr></table>"
//call date func
	document.getElementById("divD"+movCode+cinCode).innerHTML = genDateListbyCinema(movCode, cinCode, dateVal);
	if (document.getElementById("divD"+movCode+cinCode).innerHTML != "")
		document.getElementById("div"+movCode+cinCode).innerHTML = fCondent;
	else
		document.getElementById("div"+movCode+cinCode).innerHTML = "No movie date available.";
}
function listByCinema(){
var toDay = currDateTime.getFullYear() + "/" + (parseInt(currDateTime.getMonth()) + 1) + "/" + currDateTime.getDate();	
var i,j,k,l,q;
var currCinema = "NOCINEMA";
var tempArray = new Array();
var arrCinema = new Array();
var arrCinemaDate = new Array();
var tempClass = " class=\"altRowGrey\"";
var CinemaContent = "";
var tempCinemaDate = new Array();
j = -1;
for (i = 0; i < sessionByCinema.length;i++){
	tempArray = sessionByCinema[i].split(",");
		if (sessionByCinema[i].indexOf(currCinema+",") < 0)
		{
			j = j + 1;
			arrCinema[j] = tempArray[0];
			currCinema = tempArray[0];
		}
		if (Date.parse(tempArray[3].split(" ")[0]) >= Date.parse(toDay)){
				if (arrCinemaDate[j]){
					if (arrCinemaDate[j].indexOf(tempArray[3].split(" ")[0]) == -1)
					arrCinemaDate[j] = arrCinemaDate[j] + "," + tempArray[3].split(" ")[0];
				}else{
					arrCinemaDate[j] = tempArray[3].split(" ")[0];
				}
		}	
}

for(q=0;q<arrCinemaDate.length;q++){
arrCinemaDate[q] = dateSort(arrCinemaDate[q]);	
//document.write("DayLast : " + arrCinemaDate[q] +"<br />");
}

var tempDate;
var contentClass=tempClass;
for (k=0; k < arrCinema.length;k++){
	if (contentClass =="")
		contentClass = tempClass;
	else
		contentClass = "";
	CinemaContent = "<tr valign=\"top\""+contentClass+"><td width=\"8\">&nbsp;</td><td width=\"160\"><strong>"+ "<a href=\"cinema.asp?c="+arrCinema[k]+"\">"+getCinemaName(arrCinema[k])+"</a></strong></td><td>";
if (arrCinemaDate[k]){	
tempCinemaDate = arrCinemaDate[k].split(",");
	for(l=0;l<tempCinemaDate.length;l++){
		tempDate = new Date(tempCinemaDate[l]);
		if (l != 0)
		CinemaContent = CinemaContent + " | ";	
		CinemaContent = CinemaContent + "<a href=\"cinema.asp?c="+arrCinema[k]+"&mDate="+tempDate.getFullYear()+"/"+(parseInt(tempDate.getMonth())+1)+"/"+tempDate.getDate()+"\">"+weekday[tempDate.getDay()]+ " " + tempDate.getDate()+" "+monthName[parseInt(tempDate.getMonth())+1]+"</a>";
	}
}else
CinemaContent = CinemaContent + "No Showing Date Available";
	CinemaContent+="</td></tr>"
document.write(CinemaContent);
}
}

function dateSort(inString){
	var tempArray;
	var i,j;
	var tempDate;
	var returnArray;
	tempArray = inString.split(",");
	if (isArray(tempArray)){
		for (i = 0; i < tempArray.length;i++){
			tempDate = new Date(tempArray[i]);
			tempArray[i] = "" + tempDate.getFullYear()+set2Digit((tempDate.getMonth()+1).toString())+set2Digit(""+tempDate.getDate());
		}
		tempArray.sort();
		i = 0;
		for (i = 0; i < tempArray.length;i++){
			tempArray[i] = tempArray[i].substr(0,4)+"/"+tempArray[i].substr(4,2)+"/"+tempArray[i].substr(6,2);
		}
		return (tempArray.join(","));
	}
	else
		return inString;
}

function isArray(obj) {
    return obj.constructor == Array;
}

function set2Digit(inVal){
	if (inVal.length <2)
		return ("0" + inVal);
	else
		return inVal;
}

function getElement (id) {

if (document.getElementById) {
	if (document.getElementById(id))
		return document.getElementById(id);
	else
		return eval("document.frmLLogin." + id);
}
else if (document.all) {
return window.document.all[id];
}
else if (document.layers) {
return window.document.layers[id];
}
} 