
	var doubleClick;

		function submitForm(){
		    var pass=true;
		    var searchType = "Location";		    
		    if(searchType!="Location"){
		      pass = validateAdvSearch(document.selectHotelForm,searchType);
		    }		    
		    if(pass==true){		   
			    if(document.selectHotelForm.pageNumber.value=="")
			      document.selectHotelForm.pageNumber.value=1;

			    if(validateSelectHotelFormOld(document.selectHotelForm))		      
			      document.selectHotelForm.submit();
		    }
		}

		

		
		function validateSelectHotelFormOld(form){
		
		if(form.countryCode==""){
		  alert("Please select a country.");
		  return false;
		}	
		
		if(document.selectHotelForm.groupVar.value=="")
		{
			if(! validDate(document.selectHotelForm)){
				
				return false;
			}
			//new validation for date
			var arrMY = form.arrivalMonthYear.value;
			var depMY = form.departureMonthYear.value;
			var arrDY = form.arrivalDay.value;
			var depDY =form.departureDay.value;
			arrDate = new Date();
			depDate = new Date();
			arrDate.setYear(arrMY.substring(0,4));
			arrDate.setMonth(arrMY.substring(6,4));
			arrDate.setDate(arrDY);	
			depDate.setYear(depMY.substring(0,4));
			depDate.setMonth(depMY.substring(6,4));
			depDate.setDate(depDY);
			
			
			if(days_between(depDate, arrDate)< 0){
				
				alert('Your Check-out date must occur after your Check-in date.  Please revise your dates and try again.');
				changeDep(form);
				return false;
			}
			if(days_between(depDate, arrDate)== 0){
				
				alert('Check-in date is equal to the Check-out date. Please enter a valid date.');
				changeDep(form);
				return false;
			}
		}
		return true;
		
		}// End of validate selectHotelForm.
		
		
		
		
		
			
function compareCheckInCheckOutDate()
{
    var ddf=getObj("arrivalDay").value;
    
    var ddt=getObj("departureDay").value;
     //mm=if((mm-1)<10)?("0"+(mm-1)):(mm-1);
   
 if ((ddf)<10)
    {
        ddf=("0"+ddf);
    }
    if ((ddt)<10)
    {
        ddt=("0"+ddt);
    }

	var dt1=getObj("arrivalMonthYear").value.substring(4,6) + "/" + ddf + "/20" + getObj("arrivalMonthYear").value.substring(2,4);
	var dt2=getObj("departureMonthYear").value.substring(4,6) + "/" + ddt + "/20" + getObj("departureMonthYear").value.substring(2,4);
    //alert (getObj("arrivalMonthYear").value);
    //alert (getObj("month").value);
//	var dt1=getObj("txtDateFr").value;
//	var dt2=getObj("txtDateTo").value;

	dtStartDate = new Date(dt1); 
	dtEndDate = new Date(dt2); 
	
	var today = new Date();
	


	if (dtEndDate.getTime() <= dtStartDate.getTime())
		{
		alert('Check Out Date must be after Check In Date.');
		return false;
		}
	if (dtStartDate.getTime() < (today.getTime() - 86400000))
		{
		alert('Check In Date cannot be earlier than Today.');
		return false;
		}
	
	if (dt1 == '')
		{
		alert('Please specify a Check In Date.');
		return false;
		}
	if (dt2 == '')
		{
		alert('You must enter a Check Out Date');
		return false;
		}
	
		
		return true;

	
}
	
	
		
		
		
		
		function goToSelectOccupancy(avilableStatus,propertyCode,pageNumber){
//			if (compareCheckInCheckOutDate())
 //   {

		    document.selectHotelForm.availStatus.value=avilableStatus;			
		    document.selectHotelForm.propertyCode.value=propertyCode;			
		    document.selectHotelForm.pageNumber.value=0;            		
		    document.selectHotelForm.action="http://book.bestwestern.com/bestwestern/priceAvail.do?propertyCode=05523&disablenav=true&sob=P535";		 
//		   }    		
		}
	
	 	
	

   /**
    * this method ensures that the Stay Date provided occurs in the future; this
    * is called inside validateCapacityRequest
    */
   function validateArrivalDate(form)
   {
      var day   = parseInt(form.arrivalDay.value);
      var month = parseInt(form.arrivalMonth.value);
      var year  = parseInt(form.arrivalYear.value);
      var numNights = parseInt(form.numNights.value);
      //alert("month: " + month + " day: " + day + " year: " + year);

      // Make sure we have valid date values
      //if (!isDateValid(day, month, year)) {
        // window.alert("The Arrival Date that you entered is invalid.\n Please enter a valid Date");
        // form.arrivalDay.focus();
        // return false;
      //}
      

      // Set todays date
      
      var currentDay = 13;
      var currentMonth = 6;
      var currentYear = 2006;

      // Set maximum allowable consumption date (e.g. today + 350)
      
      var maxDay = 26;
      var maxMonth = 5;
      var maxYear = 2007;

      // See if the date is in the past
      //if (year < currentYear || (year == currentYear && month < currentMonth) || (year == currentYear && month == currentMonth && day < currentDay))
      //{
        // window.alert("The Arrival Date that you provided has already passed");
        // form.arrivalYear.focus();



        // return false;
      //}

      var checkDay = getDay(day, month, year);
      var startDay = getDay(currentDay, currentMonth, currentYear);
      //alert ("checkDay: " + checkDay + " startDay: " + startDay);
      try





      {
         // Calculate how many number of days into the future the consumption date is
        // var c = compare(startDay, checkDay, currentYear, year);
        // if ( (c + numNights) > 350)



        // {
        //    window.alert("The Arrival Date that you entered is too far in the future.\nPlease enter a valid Date.");
         //   form.arrivalYear.focus();
         //   return false;
        // }


      }
      catch (e)
      {
         alert(e);
         return false;
      }
      return true;
   }

 function hasAStayElementPropertySearch(form) {
      try
      {
         return (
            form.arrivalMonth.selectedIndex > 0 ||
            form.arrivalDay.selectedIndex > 0 ||
            form.arrivalYear.selectedIndex > 0 ||
            form.numNights.value > 0 ||
            form.numRooms.selectedIndex > 0);
      }
      catch (e)
      {
         return false;
      }
   }

   /**
    * This method returns true if all one of the input elements
    * that would trigger an availability (arrival date, numNights or numRooms)
    * has been selected - used by validateCapacityRequest to display the proper
    * alert if not all needed elements have been input
    */
   function hasAllStayElementsPropertySearch(form) {
      try
      {

      return (
         form.arrivalMonth.selectedIndex > 0 &&
         form.arrivalDay.selectedIndex > 0 &&
         form.arrivalYear.selectedIndex > 0 &&
         form.numNights.value > 0 &&
         form.numRooms.selectedIndex > 0);
      }
      catch (e)
      {
         return false;
      }
   }
//***********************************************************************************
//PLEASE REMOVE THE CODE ABOVE FOR WEB UI REDESIGN DELIVERY FOR ADVANCE SEARCH.
//THIS WAS REQUIRED FOR PROPERTYSEARCHFORM
//***********************************************************************************


   function validateArrivalAndDepDate(form)
   {
	  try {

      	if(! validDate(form)){

			return false;
		}

		//new validation for date
		var arrMY = form.arrivalMonthYear.value;
		var depMY = form.departureMonthYear.value;
		var arrDY = form.arrivalDay.value;
		var depDY = form.departureDay.value;

		arrDate = new Date(0);
		depDate = new Date(0);

		arrDate.setYear(arrMY.substring(0,4));
		arrDate.setDate(arrDY);
		arrDate.setMonth(arrMY.substring(6,4));
		

		depDate.setYear(depMY.substring(0,4));
		depDate.setDate(depDY);
		depDate.setMonth(depMY.substring(6,4));
		

		if(days_between(depDate, arrDate)< 0){

			//alert('Your Check-out date must occur after your Check-in date.  Please revise your dates and try again.');
			changeDep(form);
				depMY = form.departureMonthYear.value;
				depDY = form.departureDay.value;
				depDate.setYear(depMY.substring(0,4));
				depDate.setDate(depDY);
				depDate.setMonth(depMY.substring(6,4));
				
			//return false;
		}

		if(days_between(depDate, arrDate)== 0){

			//alert('Check-in date is equal to the Check-out date. Please enter a valid date.');
			changeDep(form);
				depMY = form.departureMonthYear.value;
				depDY = form.departureDay.value;
				depDate.setYear(depMY.substring(0,4));
				depDate.setDate(depDY);
				depDate.setMonth(depMY.substring(6,4));
				
			//return false;
		}

		var nights = Math.abs(days_between(arrDate, depDate));
		if( nights > 30)
		{
			alert('Bestwestern.com cannot process a hotel reservation that exceeds 30 days in length. Please revise your reservation Check In or Check Out dates.');
			return false;
		}

		//var istooFar = Math.abs(days_between(arrDate, new Date()));
		//if( istooFar > 350)
		//{
		//	alert('The Arrival Date that you entered is too far in the future. Please enter a valid Date.');
		//	return false;
		//}

		//var istooFarCheckOutDate = Math.abs(days_between(depDate, new Date()));
		//if( istooFarCheckOutDate > 350)
		//{
		//	alert('The Departure Date that you entered is too far in the future. Please enter a valid Date.');
		//	return false;
		//}


		//end validation
	  }
      catch (e)
      {
         alert(e);
         return false;
      }
      return true;
   }

   /**
    * this method ensures that the Stay Date provided is valid; this
    * is called inside validateArrivalAndDepDate
    */
	function validDate(form) {
		var arrMY = form.arrivalMonthYear.value;
		var depMY = form.departureMonthYear.value;
		var arrDY = form.arrivalDay.value;
		var depDY = form.departureDay.value;
		//when user blank out all the dates
		if(arrDY == "" && arrMY == "" && depDY == "" && depMY == ""){
			return true;
		}


		arrMonthTemp = arrMY.substring(6,4);
		arrYearTemp = arrMY.substring(0,4);
		depMonthTemp = depMY.substring(6,4);
		depYearTemp = depMY.substring(0,4);

		arrDate = new Date(0);
		depDate = new Date(0);
		
		arrDate.setYear(arrMY.substring(0,4));
		arrDate.setDate(arrDY);
		arrDate.setMonth(arrMY.substring(6,4));
		

		depDate.setYear(depMY.substring(0,4));
		depDate.setDate(depDY);
		depDate.setMonth(depMY.substring(6,4));
		

		if ((arrDate.getMonth() < 0 || arrDate.getMonth() > 11)||(depDate.getMonth() < 0 || depDate.getMonth() > 11)) {
		    alert('Please Enter a Valid Date');
				return false;
		}
		if ((arrDate.getDate() < 1 || arrDate.getDate() > 31)||(depDate.getDate() < 1 || depDate.getDate() > 31)) {
		    alert('Please Enter a Valid Date');
				return false;
		}
		if ((arrMonthTemp == 3 || arrMonthTemp == 5 || arrMonthTemp == 8 || arrMonthTemp == 10) &&
		    (arrDY == 31)) {
		    alert('Please Enter a Valid Date');
				return false;
		}
		if ((depMonthTemp == 3 || depMonthTemp == 5 || depMonthTemp == 8 || depMonthTemp == 10) &&
		    (depDY == 31)) {
		    alert('Please Enter a Valid Date');
				return false;
		}
		if (arrMonthTemp == 1) {
		    if (arrDY > 29 || (arrDY == 29 && !isLeapYear(arrYearTemp))) {
				alert('Please Enter a Valid Date');
					return false;
		    }
		}
		if (depMonthTemp == 1) {
		    if (depDY > 29 || (depDY == 29 && !isLeapYear(arrYearTemp))) {
				alert('Please Enter a Valid Date');
					return false;
			}
		}
        compDate = new Date();
        compDate.setHours(0,0,0,0);
		//if (arrDate < (compDate)|| depDate < (compDate) ){
		//	alert('The arrival or departure date you have provided has already passed, please provide valid dates.');
		//		return false;
		//}

		return true;
	}


	/**
    * Returns the difference between two dates.
    */
	function days_between(date1, date2)
	{
    	// The number of milliseconds in one day
	    var ONE_DAY = 1000 * 60 * 60 * 24;

    	// Convert both dates to milliseconds
	    var date1_ms = date1.getTime();
    	var date2_ms = date2.getTime();

	    // Calculate the difference in milliseconds
    	var difference_ms = date1_ms - date2_ms;

	    diff=Math.round(difference_ms/ONE_DAY);

    	return diff;
   }

   /**
    * Changes the departure date equal to increment of
    * arrival date to one day.
    */
    
       function changeDep(form)
   {
   		var arrMY = form.arrivalMonthYear.value;
		var arrDY = form.arrivalDay.value;

		arrDate = new Date(0);

		arrDate.setYear(arrMY.substring(0,4));
		arrDate.setDate(arrDY);
		arrDate.setMonth(arrMY.substring(6,4));
		
		form.departureMonthYear.value =form.arrivalMonthYear.value;
		
	
   }
  // function changeDep(form)
   //{
   	//	var arrMY = form.arrivalMonthYear.value;
	//	var arrDY = form.arrivalDay.value;

	//	arrDate = new Date(0);

//		arrDate.setYear(arrMY.substring(0,4));
//		arrDate.setDate(arrDY);
//		arrDate.setMonth(arrMY.substring(6,4));
		
//		temp_date = new Date(arrDate.getTime() +(24*60*60*1000)); //Incrementing the arrival date to one day
//		form.departureDay.value = temp_date.getDate();

//		if(temp_date.getMonth() < 10){
//			tempMY= temp_date.getYear() + "0" + temp_date.getMonth();

//		}else{
//			tempMY= temp_date.getYear() + '' + temp_date.getMonth();

//		}
//		form.departureMonthYear.value = tempMY;
//   }
   /* END - Changes for HotelSearchForm */

   function getDay(day,month,year)
   {
      var days = new Array(12);
      var retVal = 0;
      days[0] = 0;   // place holder
      days[1] = 31;  // January
      days[2] = 28;  // February
      days[3] = 31;  // March
      days[4] = 30;  // April
      days[5] = 31;  // May
      days[6] = 30;  // June
      days[7] = 31;  // July
      days[8] = 31;  // August
      days[9] = 30;  // September
      days[10] = 31; // October
      days[11] = 30; // November
      days[12] = 31; // December

      for (var i = 0 ; i < month; i++)
      {
         retVal += days[i];
      }

      if (month > 1 && isLeapYear(year))
      {
         retVal++;
      }

      retVal = retVal + day;
      //alert("getDay::retVal: " + retVal);
      return retVal;
   }

   function isLeapYear(year)
   {
      if ((year % 100 != 0 && year % 4 == 0) || (year % 400 == 0))
      {
         return true;
      }
      else
      {
         return false;
      }
   }

   function compare(day1, day2, year1, year2)
   {
      //alert ("compare::day1: " + day1 + " compare::day2: " + day2 + " compare::year1: " + year1 + " compare::year2: " + year2);
      if (year1 != year2)
      {
         day2 += (year2 - year1) * 365;
         //alert ("compare::(new)day2: " + day2);
         if (day1 < 59 && isLeapYear(year1))
         {
            day2++;
         }
      }

      var ret = day2 - day1;
      //alert("compare::returning: " + ret);

      return ret;
   }

   /**
    * Called on form submit to ensure that the Guest has selected a state in the event
    * that they selected the US, Canada, or Australia as the country, and did not select
    * a city
    */
   function validateCountryState(form)
   {
      if ((form.referencePoint == null || form.referencePoint.value == "") &&
         (form.hotelName == null || form.hotelName.value == "") )
      {
         var country = form.countryCode.options[form.countryCode.selectedIndex].value;
         if (country == "")
         {
            window.alert("Please select a country.");
            if ( (form.nearStreetAddress != null && form.nearStreetAddress.value != "") ||
                (form.nearPostalCode != null && form.nearPostalCode.value != ""))
            {
               form.nearCountry.focus();
            }
            else
            {
               form.countryCode.focus();
            }
            return false;
         }
         var state    = form.stateCode.options[form.stateCode.selectedIndex].value;
         /*
         if ((country == "US" || country == "CA" || country == "AU") && form.stateCode.selectedIndex == 0)
         */
         if ((country == "US" || country == "CA" || country == "AU") && form.stateCode.selectedIndex == 0 && Trim(form.city.value) == "")
         {
            window.alert("For Canada, the United States and Australia,\n please select a City or a State");
            // if the Guest is doing a 'near address' search, bring the focus there
            if ( (form.nearStreetAddress != null && form.nearStreetAddress.value != "") ||
                (form.nearPostalCode != null && form.nearPostalCode.value != "") )
            {
               form.nearState.focus();
            }
            else
            {
               form.stateCode.focus();
            }
            return false;
         }
         result = validateAscii(form.city);
         if(result == false){
            return false;
         }
      }
      return true;
   }

   


   
   /**
    ****************************************************************************
    * Generic helper functions not specific to the validation that we are performing
    ****************************************************************************
    */

   /**
    * given a select value, return its index within the select element;
    * if not found return the first element in the select
    */
   function getIndex(aSelect, aValue) {
      for (var i=0; i < aSelect.length; i++) {
         if (aSelect.options[i].value == aValue) {
            return i;
         }
      }
      return 0;
   }

   /**
    * given an array of Select Option objects, this function returns
    * true if the passed value is contained in the array; this function
    * is used to determine the Country to which a selected state belongs
    */
   function isValueInOptionArray(aValue, aryOption) {
      if (aryOption.length > 0) {
         for (var i=0; i < aryOption.length; i++) {
            if (aryOption[i].value == aValue) {
               return true;
            }
         }
      }
      return false;
   }

   function removeAllData(options)
   {
      var element = options.firstChild;
      while (element != null)
      {
         var nextChild = element.nextSibling;
         options.removeChild(element);
         element = nextChild;
      }
      options.length = 0;
   }

   /**
    * given a select input and an array of Options,
    * set the options of the select to the Options provided
    */
   function setOptions(aSelect, aryOptions) {
      if (aryOptions.length > 0) {
         removeAllData(aSelect);
         for (var i=0; i < aryOptions.length; i++) {
            // if we do not assign a new Option, running this method twice
            // over the same array will yield a pointer error
            if(aryOptions[i] != null)
               aSelect.options[aSelect.length] = new Option(aryOptions[i].text, aryOptions[i].value);
         }
      }
   }

   /**
    * checks validity of date, copied from validator-rules.xml;
    * but modified to use a 0-based month index (i.e. jan=0)
    */
   function isDateValid(day, month, year) {
      if (month < 0 || month > 11) {
         return false;
      }
      if (day < 1 || day > 31) {
         return false;
      }
      if ((month == 3 || month == 5 || month == 8 || month == 10) &&
         (day == 31)) {
         return false;
      }
      if (month == 1) {
         var leap = (year % 4 == 0 &&
               (year % 100 != 0 || year % 400 == 0));
         if (day>29 || (day == 29 && !leap)) {
            return false;
         }
      }
      return true;
   }


   /**
    * Given a month represented by an integer (jan=0) and a year,
    * return the number of days in that month; if the year is null,
    * return 29 days for February
    */
   function getNumDaysInMonth(month,year) {
      if (month == 3 || month == 5 || month == 8 || month == 10) {
         return 30;
      }
      else if (month == 1) {
         var leapOrNull = (year < 0) || (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
         if (leapOrNull)
            return 29;
         else
            return 28;
      }
      else {
         return 31;
      }
   }


   /**
    * wrapper around window.open used for opening a non-resizable no-thrills popup message windows
    */
  

   function preventDoubleClick()
   {
      if (doubleClick)
      {
         alert('Your request is being processed, please wait.');
         return false;
      }
      else
      {
         doubleClick = true;
         return true;
      }
   }

   
/**
* function for check password for gcci membership on review and reservation page
*/

function validatePassword(form)
{
	if(form.newUserPassword.value.length==0)
		{
			alert("Please enter 6 and 8 characters in Password field");
			form.newUserPassword.focus();
			return false;
		}

		if(form.newUserPassword.value.length<6 || form.newUserPassword.value.length>8 )
		{
			alert("Please enter 6 and 8 characters in Password field");
			form.newUserPassword.focus();
			return false;
		}

		if(form.newUserConfirmPassword.value.length==0)
		{
			alert("You did not validate password. Please re-enter");
			form.newUserConfirmPassword.focus();
			return false;
		}

		if (form.newUserPassword.value != form.newUserConfirmPassword.value)
		{
			alert("The Passwords you Entered Do Not Match. Please re-enter them");
			form.newUserPassword.focus();
			return false;
		}
		return true;
}

function pressEscapeKey()
{
	if (window.event.keyCode == 27)
		doubleClick = false;
}

function getDoubleClickValue(val)
{
	doubleClick= val;
}


function checkCheckOutDate(form)
{
  try {
//alert(form.arrivalMonthYear.selectedIndex);

	if(form.arrivalMonthYear.selectedIndex >= 0 && form.arrivalDay.selectedIndex >= 0 )  {
  
		
	if(! validDate(form))
	{
	   return false;
	}
	
	//new validation for date
	var arrMY = form.arrivalMonthYear.value;
	var depMY = form.departureMonthYear.value;
	var arrDY = form.arrivalDay.value;
	var depDY = form.departureDay.value;

	arrDate = new Date(0);
	depDate = new Date(0);

	arrDate.setYear(arrMY.substring(0,4));
	arrDate.setDate(arrDY);
	arrDate.setMonth(arrMY.substring(6,4));
	

	depDate.setYear(depMY.substring(0,4));
	depDate.setDate(depDY);
	depDate.setMonth(depMY.substring(6,4));
	

		//var istooFarCheckInDate = Math.abs(days_between(arrDate, new Date()));
		//if( istooFarCheckInDate > 350)
		//{
		//	alert('The Arrival Date that you entered is too far in the future. Please enter a valid Date.');
		//	return false;
		//}
		if(days_between(depDate, arrDate)< 0){

			changeDep(form);
				depMY = form.departureMonthYear.value;
				depDY = form.departureDay.value;
				depDate.setYear(depMY.substring(0,4));
				depDate.setDate(depDY);
				depDate.setMonth(depMY.substring(6,4));
			
		}
		if(days_between(depDate, arrDate)== 0){
			changeDep(form);
				depMY = form.departureMonthYear.value;
				depDY = form.departureDay.value;
				depDate.setYear(depMY.substring(0,4));
				depDate.setDate(depDY);
				depDate.setMonth(depMY.substring(6,4));
				
		}

		//var istooFarCheckOutDate = Math.abs(days_between(depDate, new Date()));
		//if( istooFarCheckOutDate > 350)
		//{
		//	alert('The Departure Date that you entered is too far in the future. Please enter a valid Date.');
		//	return false;
		//}
	 
	 }
  }
 catch (e)
     {
		 alert(e);
         return false;
     }
return true;

}


