      var count=0;

    function Onlyone()
   {
        if (count == 0)
         {
         count++;
         return true;
         }
      else
     {
   alert('Please wait, your request is being processed.');
         return false;
     }
   }

// dates stuff
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
//Function to get day of week for arrival
function getArrDayOfWeek()
{
	var y = document.myForm.arrival_year.options[document.myForm.arrival_year.selectedIndex].value;
	var m = document.myForm.arrival_month.options[document.myForm.arrival_month.selectedIndex].value;
	var d = document.myForm.arrival_day.options[document.myForm.arrival_day.selectedIndex].value;
	var c = new Date(y,m-1,d,0,0,0);
	var dayOfWeek = c.getDay();
	document.myForm.arrivaldow.value = days[dayOfWeek];
	getDepDayOfWeek();
}
//Function to get day of week for departure
function getDepDayOfWeek()
{
	var y = document.myForm.departure_year.options[document.myForm.departure_year.selectedIndex].value;
	var m = document.myForm.departure_month.options[document.myForm.departure_month.selectedIndex].value;
	var d = document.myForm.departure_day.options[document.myForm.departure_day.selectedIndex].value;
	var c = new Date(y,m-1,d,0,0,0);
	var dayOfWeek = c.getDay();
	document.myForm.departuredow.value = days[dayOfWeek];
}

      // quadYear
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; }
}
//Function called on check in date. Used to set departure date = arrival date + 1
function changeDates()
{
  theForm = document.myForm;
  var indate;
   var outdate;
  yearOffset = parseInt(theForm.arrival_year.options[0].value,10);
  
  var inMonth=theForm.arrival_month.selectedIndex;
 
  var inYear=parseInt(theForm.arrival_year.options[theForm.arrival_year.selectedIndex].value,10);
 
  
	
  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 inMonthVal = theForm.arrival_month.options[theForm.arrival_month.selectedIndex].value;
 
  var inDay=parseInt(theForm.arrival_day.options[theForm.arrival_day.selectedIndex].value,10);
 
  	indate=inDay+"-"+inMonthVal+"-"+inYear;
	document.cookie="homepageADates="+escape(indate)+';path=/';

  if(inDay >= days[inMonth]) { inDay = days[inMonth]; }
  else { inDay = inDay%days[inMonth]; }
  theForm.arrival_day.options[inDay-1].selected=true;
 
  outMonth=inMonth;
  outDay = inDay%days[inMonth];
  //alert(outDay);
  outYear=inYear;
  if(outDay == 0) { outMonth = (inMonth + 1) % 12; }
  if(outDay == 0 && inMonth == 11) { outYear++; }

  theForm.departure_month.options[outMonth].selected=true;
  theForm.departure_day.options[outDay].selected=true;
  theForm.departure_year.options[(outYear-yearOffset)].selected=true;
	var outDay=parseInt(theForm.departure_day.options[theForm.departure_day.selectedIndex].value,10);
	var outMonthVal = theForm.departure_month.options[theForm.departure_month.selectedIndex].value;
	outdate=outDay+"-"+outMonthVal+"-"+outYear;
	document.cookie="homepageDDates="+escape(outdate)+';path=/';

  getArrDayOfWeek();
}
//function called on check out date .
function checkOutDate()
{
//  if (cal != "")
//	  alert("in checkoutdate");
  theForm = document.myForm;
  var outdate;
  yearOffset = parseInt(theForm.arrival_year.options[0].value,10);
  var outMonth=theForm.departure_month.selectedIndex;
  var outYear=parseInt(theForm.departure_year.options[theForm.departure_year.selectedIndex].value,10);
	
  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.departure_day.options[theForm.departure_day.selectedIndex].value,10);
  var outMonthVal = theForm.departure_month.options[theForm.departure_month.selectedIndex].value;
	outdate=outDay+"-"+outMonthVal+"-"+outYear;
	document.cookie="homepageDDates="+escape(outdate)+';path=/';

  if(outDay >= days[outMonth]) { outDay = days[outMonth]; }
  else { outDay = outDay%days[outMonth]; }
  theForm.departure_day.options[outDay-1].selected=true;
   //code to fill out nights field if departure date changes.
    var inDay = parseInt(theForm.arrival_day.options[theForm.arrival_day.selectedIndex].value,10);
	var inMonth=theForm.arrival_month.selectedIndex;
	var inYear = parseInt(theForm.arrival_year.options[theForm.arrival_year.selectedIndex].value,10);
    var depDate = new Date(outYear,outMonth,outDay);
	//alert(depDate);
    var arrDate = new Date(inYear,inMonth,inDay);
	//alert(arrDate);
	var depMiliSeconds = depDate.getTime();
	var arrMiliSeconds = arrDate.getTime();
	
	if ((depMiliSeconds - arrMiliSeconds) > 0 )
	{
		var diffDays = Math.floor((depMiliSeconds - arrMiliSeconds)/(1000*60*60*24));
		theForm.nights.value = diffDays;
		//alert(diffDays);
	} 
  getDepDayOfWeek();
}

function changeNights()
{
    theForm = document.myForm;
    var outdate;
    yearOffset = parseInt(theForm.arrival_year.options[0].value,10);
    var outMonth=theForm.departure_month.selectedIndex;
    var outYear=parseInt(theForm.departure_year.options[theForm.departure_year.selectedIndex].value,10);
        
    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.departure_day.options[theForm.departure_day.selectedIndex].value,10);
  
    //code to fill out nights field if departure date changes.
    var inDay = parseInt(theForm.arrival_day.options[theForm.arrival_day.selectedIndex].value,10);
    var inMonth=theForm.arrival_month.selectedIndex;
    var inYear = parseInt(theForm.arrival_year.options[theForm.arrival_year.selectedIndex].value,10);
    var depDate = new Date(outYear,outMonth,outDay);
    //alert(depDate);
    var arrDate = new Date(inYear,inMonth,inDay);
    //alert(arrDate);
    var depMiliSeconds = depDate.getTime();
    var arrMiliSeconds = arrDate.getTime();
    
    if ((depMiliSeconds - arrMiliSeconds) > 0 )
    {
        var diffDays = Math.floor((depMiliSeconds - arrMiliSeconds)/(1000*60*60*24));
        theForm.nights.value = diffDays;
        //alert(diffDays);
    }
    getArrDayOfWeek();
}

function changeByDays()
{
  theForm = document.myForm;
  if(!(theForm.nights.value)){
	 changeDates();
	  return false;
  }
  if( parseInt(theForm.nights.value) < 0){
	   	   return false;
   }
   var indate;
   var outdate;
  yearOffset = parseInt(theForm.arrival_year.options[0].value,10);

  var inMonth=theForm.arrival_month.selectedIndex;
  //alert("inMonth"+inMonth);
 
  var inYear=parseInt(theForm.arrival_year.options[theForm.arrival_year.selectedIndex].value,10);
  	
  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 inMonthVal = theForm.arrival_month.options[theForm.arrival_month.selectedIndex].value;
   var inDay=parseInt(theForm.arrival_day.options[theForm.arrival_day.selectedIndex].value,10);
  
  	indate=inDay+"-"+inMonthVal+"-"+inYear;
	document.cookie="homepageADates="+escape(indate)+';path=/';
 
  if(inDay >= days[inMonth]) { inDay = days[inMonth]; }
  else { inDay = inDay%days[inMonth]; }
 
  theForm.arrival_day.options[inDay-1].selected=true;
  //alert("inDay"+inDay);
 
  outMonth=inMonth;
  outYear=inYear;
 //alert(theForm.nights.value);
  
  var addDays = theForm.nights.value;
  addDays++;
  //alert(addDays);
  for(i=0;i < addDays;i++){
   outDay = inDay + i;
  }
 //alert("outDay"+outDay);
  if(outDay > days[outMonth]) 
	{ 
	  monthIncrement = Math.floor(parseInt(outDay)/parseInt(days[outMonth]));
	  outDay = outDay%days[outMonth];
	  //alert(days[outMonth]);
	  //alert("monthIncrement"+monthIncrement);
      outMonth = (inMonth + monthIncrement)%12;
	  //alert("outMonth"+outMonth);
	  if(inMonth + monthIncrement > 11) { outYear++; }

	}
 
  //alert("outDay"+outDay);
  //alert("outMonth"+outMonth);
  //alert("outYear"+outYear);
 
  theForm.departure_month.options[outMonth].selected=true;
  theForm.departure_day.options[outDay-1].selected=true;
  theForm.departure_year.options[(outYear-yearOffset)].selected=true;
	var outDay=parseInt(theForm.departure_day.options[theForm.departure_day.selectedIndex].value,10);
	var outMonthVal = theForm.departure_month.options[theForm.departure_month.selectedIndex].value;
	outdate=outDay+"-"+outMonthVal+"-"+outYear;
	document.cookie="homepageDDates="+escape(outdate)+';path=/';

  getArrDayOfWeek();
}
