function LoadDates(){
	var yourserial = getCookie("SerialC"); 
	if (yourserial != null){
   		setDateToCookie(yourserial);
   	}
	else{
		yourserial=defaultInOut();
	 	register(yourserial, "SerialC");	   
	 }  

}


function setCookieToUser() {
  theForm = document.mainForm;
  var currInMonth = parseInt(theForm.outmonth.options[theForm.inmonth.selectedIndex].value,10);
  var currInDay = parseInt(theForm.outday.options[theForm.inday.selectedIndex].value,10);
  var currInYear = parseInt(theForm.outyear.options[theForm.inyear.selectedIndex].value,10); 
  var currOutMonth = parseInt(theForm.outmonth.options[theForm.outmonth.selectedIndex].value,10);
  var currOutDay = parseInt(theForm.outday.options[theForm.outday.selectedIndex].value,10);
  var currOutYear = parseInt(theForm.outyear.options[theForm.outyear.selectedIndex].value,10);

  var CurrPickupTime=parseInt(theForm.pickuptime.options[theForm.pickuptime.selectedIndex].value,10);
  var CurrDropoffTime=parseInt(theForm.dropofftime.options[theForm.dropofftime.selectedIndex].value,10);

//  var CurrVehicleClass=parseInt(theForm.vehicleclass.options[theForm.vehicleclass.selectedIndex].value,10);
var CurrVehicleClass=1

  register(currInDay+"-"+currInMonth+"-"+currInYear+"-"+currOutDay+"-"+currOutMonth+"-"+currOutYear+"-"+CurrPickupTime+"-"+CurrDropoffTime+"-"+CurrVehicleClass, "SerialC");  
  return(currInDay+"-"+currInMonth+"-"+currInYear+"-"+currOutDay+"-"+currOutMonth+"-"+currOutYear+"-"+CurrPickupTime+"-"+CurrDropoffTime+"-"+CurrVehicleClass);
}

function setDateToCookie(inSerial){
	var yourserial_array=inSerial.split("-");
	var theinyear=yourserial_array[2]
	var theinmonth=yourserial_array[1]
	var theintoday=yourserial_array[0]
	var theoutyear=yourserial_array[5]
	var theoutmonth=yourserial_array[4]
	var theouttoday=yourserial_array[3]

	var thepickuptime=yourserial_array[6]
	var thedropofftime=yourserial_array[7]

	var thevehicleclass=yourserial_array[8]

	theForm = document.mainForm;
	theForm.inday.options[theintoday-1].selected=true;
	theForm.inmonth.options[theinmonth-1].selected=true;
	theForm.inyear.options[(theinyear-2005)].selected=true;
	theForm.outday.options[theouttoday-1].selected=true;
	theForm.outmonth.options[theoutmonth-1].selected=true;
	theForm.outyear.options[(theoutyear-2005)].selected=true;

	theForm.pickuptime.options[thepickuptime].selected=true;
	theForm.dropofftime.options[thedropofftime].selected=true;

//	theForm.vehicleclass.options[thevehicleclass].selected=true;	
}

function defaultInOut() {
	var now = new Date();
	var serial = now.valueOf();
	var futuredate = new Date(serial + 14 * 24 * 60 * 60 * 1000);
	var futureout = new Date(serial + 16 *24 * 60 * 60 * 1000);
	var theinyear=futuredate.getFullYear();
	var theinmonth=futuredate.getMonth()+1;
	var theintoday=futuredate.getDate();
	var theoutyear=futureout.getFullYear();
	var theoutmonth=futureout.getMonth()+1;
	var theouttoday=futureout.getDate();

	theForm = document.mainForm;
	theForm.inday.options[theintoday-1].selected=true;
	theForm.inmonth.options[theinmonth-1].selected=true;
	theForm.inyear.options[(theinyear-2005)].selected=true;
	theForm.outday.options[theouttoday-1].selected=true;
	theForm.outmonth.options[theoutmonth-1].selected=true;
	theForm.outyear.options[(theoutyear-2005)].selected=true;

	theForm.pickuptime.options[8].selected=true;
	theForm.dropofftime.options[8].selected=true;

//	theForm.vehicleclass.options[1].selected=true;
  	
	return(theintoday+"-"+theinmonth+"-"+theinyear+"-"+theouttoday+"-"+theoutmonth+"-"+theinyear+"-8-8-1");
}

function y2k(number){return (number < 1000) ? number + 1900 : number;}

function isLeapYear(yr)
{
  if (((yr % 4 == 0) && (yr % 100 != 0)) || (yr % 400 == 0)) { return true; }
  else { return false; } 
}

var today = new Date(new Date().valueOf());
function changeDates()
{
  theForm = document.mainForm;
  yearOffset = parseInt(theForm.inyear.options[0].value,10);
  var inMonth=parseInt(theForm.inmonth.options[theForm.inmonth.selectedIndex].value,10)-1;
  var inYear=parseInt(theForm.inyear.options[theForm.inyear.selectedIndex].value,10);
  var baseMonth=today.getMonth();
  var baseDay=today.getDate();
  var baseYear=y2k(today.getYear());
  
  if(isLeapYear(inYear)) { var days = new Array(31,29,31,30,31,30,31,31,30,31,30,31); }
  else { var days = new Array(31,28,31,30,31,30,31,31,30,31,30,31); }

  var inDay=parseInt(theForm.inday.options[theForm.inday.selectedIndex].value,10);
  
  if(inDay >= days[inMonth]) { inDay = days[inMonth]; }
  else { inDay = inDay%days[inMonth]; }
  theForm.inday.options[inDay-1].selected=true;

  var currOutMonth = parseInt(theForm.outmonth.options[theForm.outmonth.selectedIndex].value,10)-1;
  var currOutDay = parseInt(theForm.outday.options[theForm.outday.selectedIndex].value,10);
  var currOutYear = parseInt(theForm.outyear.options[theForm.outyear.selectedIndex].value,10);
 
   if((currOutYear < inYear) || (currOutYear == inYear && currOutMonth < inMonth) ||
    (currOutYear == inYear && currOutMonth == inMonth && currOutDay <= inDay))
  {
    outMonth=inMonth;
    outDay = inDay%days[inMonth];
    outYear=inYear;
    if(outDay == 0) { outMonth = (inMonth + 1) % 12; }
    if(outDay == 0 && inMonth == 11) { outYear++; }
  
    theForm.outmonth.options[outMonth].selected=true;
    theForm.outday.options[outDay].selected=true;
    theForm.outyear.options[(outYear-yearOffset)].selected=true;

    currOutMonth=outMonth
	currOutYear=outYear
	
  }
  

if (inMonth < baseMonth){
theForm.inyear.options[baseYear-yearOffset+1].selected=true;
	if(currOutMonth > baseMonth){theForm.outyear.options[baseYear-yearOffset+1].selected=true;}
}

if (inMonth >= baseMonth){
theForm.inyear.options[baseYear-yearOffset].selected=true;
    if(currOutMonth >= baseMonth){theForm.outyear.options[baseYear-yearOffset].selected=true;}
}

if (inYear < baseYear){
   theForm.inyear.options[baseYear-yearOffset].selected=true;
}  
  
}


function checkOutDate()
{
  theForm = document.mainForm;
  yearOffset = parseInt(theForm.inyear.options[0].value,10);
  var outMonth=theForm.outmonth.selectedIndex;
  var outYear=parseInt(theForm.outyear.options[theForm.outyear.selectedIndex].value,10);
  
  var currInMonth = parseInt(theForm.inmonth.options[theForm.inmonth.selectedIndex].value,10)-1;
  var currInYear = parseInt(theForm.inyear.options[theForm.inyear.selectedIndex].value,10);
  
  var baseMonth=today.getMonth();
  var baseDay=today.getDate();
  var baseYear=y2k(today.getYear());
    
  if(isLeapYear(outYear)) { var days = new Array(31,29,31,30,31,30,31,31,30,31,30,31); }
  else { var days = new Array(31,28,31,30,31,30,31,31,30,31,30,31); }

  var outDay=parseInt(theForm.outday.options[theForm.outday.selectedIndex].value,10);
  
  if(outDay >= days[outMonth]) { outDay = days[outMonth]; }
  else { outDay = outDay%days[outMonth]; }
  theForm.outday.options[outDay-1].selected=true;

if (outMonth < baseMonth){
theForm.outyear.options[baseYear-yearOffset+1].selected=true;
}

if (outMonth >= baseMonth){
theForm.outyear.options[baseYear-yearOffset].selected=true;
  outYear=parseInt(theForm.outyear.options[theForm.outyear.selectedIndex].value,10);														   
  if (outYear < currInYear){
  theForm.inyear.options[baseYear-yearOffset].selected=true;
  theForm.inmonth.options[baseMonth].selected=true;
  theForm.inday.options[baseDay+1].selected=true;

  }
}



}
          