var moviepicked=0
var datepicked=0
var Days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var Months = new Array('Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');

function populateDates(dd1)
{

  moviepicked=1;
  var idx = dd1.selectedIndex;
  var val = dd1[idx].value;
  // alert("val"+val);
  var par = document.forms["movieSelection"];
  var parelmts = par.elements;
  var timingssel = parelmts["timings"];
  var moviename = val;
  //alert("a"+moviepicked+"b"+datepicked+"c");
  if (datepicked == 0 && moviename != "Select a movie" && moviename != "allmovies")
  {
   var directory = ""+document.location;
   directory = directory.substr(0, directory.lastIndexOf('/'));

   Http.get({
		//url: "http://"+document.domain+"/libs/services.asp?type=dates&moviename="+moviename,
		url: "http://"+document.domain+"/libs/services.asp?type=dates&moviename="+moviename,
		callback: fillTimings,
		cache: Http.Cache.Get
	}, [timingssel]);
  }
 // timingssel.selectedIndex=1;
  datepicked=0;
}
function fillTimings(xmlreply, timingselmt)
{

  if (xmlreply.status == Http.Status.OK)
  {
  //alert("reloading times");
   var timingsresponse = xmlreply.responseText;
   var timingsar = timingsresponse.split("|");
   timingselmt.length = 1;
   timingselmt.length = timingsar.length+1;
   for (o=0; o < timingsar.length; o++)
   {   
   		//alert(timingsar[o])
   		var mydate= new Date(timingsar[o])
		var theyear=mydate.getFullYear()
		var themonth=mydate.getMonth()+1
		var thetoday=mydate.getDate()

   		//timingselmt[o].text = theyear+"-"+themonth+"-"+thetoday;
	 	//timingselmt[o].text = Days[mydate.getDay()]+" "+Months[themonth-1]+". "+thetoday;
		timingselmt[o].text = Days[mydate.getDay()]+ " "+Months[themonth-1]+". " +thetoday;
	 //alert(timingselmt[o].value)
	 	timingselmt[o].value = theyear+"-"+themonth+"-"+thetoday;
	  //timingselmt.options[o].value = theyear+"-"+themonth+"-"+thetoday;
   }
   timingselmt[o].text = "All Days";
   timingselmt[o].value="alldays";
  }
  else
  {
   alert("Cannot handle the Ajax call.");
  }
}


function populateMovies(dd1)
{
  datepicked = 1;
  var idx = dd1.selectedIndex;
  var val = dd1[idx].value;
  var par = document.forms["movieSelection"];
  var parelmts = par.elements;
  var moviessel = parelmts["movies"];
  var date = val;
  //alert("x"+moviepicked+"y"+datepicked+"z");
  if (moviepicked == 0 && date != "Select date" && date != "alldays")
  {
   var directory = ""+document.location;
   directory = directory.substr(0, directory.lastIndexOf('/'));
   Http.get({
		url: "http://"+document.domain+"/libs/services.asp?type=moviesbydate&date="+date,
		callback: fillMovies,
		cache: Http.Cache.Get
	}, [moviessel]);
  }
  //moviepicked=0;
}
function fillMovies(xmlreply, movieselmt)
{
  if (xmlreply.status == Http.Status.OK)
  {
  //alert("reloading movie list");
   var moviesresponse = xmlreply.responseText;
   var moviesar = moviesresponse.split("|");
   movieselmt.length = 1;
   movieselmt.length = moviesar.length+1;
   for (o=0; o < moviesar.length; o++)
   {
	 movieselmt[o].text = moviesar[o];
   }
   movieselmt[o].text = "All Movies";
   movieselmt[o].value = "allmovies";
  }
  else
  {
   alert("Cannot handle the Ajax call.");
  }
}

