	function formvalidation(thisform)
	{
		test = validatePriceAvailForm(thisform);
		if(test==true){
		thisform.submit();
						}
	}

	function setStyle(objId, style)
	{
		if (navigator.userAgent.indexOf("Opera") != -1)
		{ //Opera
			styleObj = eval('document.all.' + objId);
			styleObj.style.display = style;
		}
		else if (document.getElementById)
		{ //Netscape 6 & IE 5
			myObj = document.getElementById(objId);
			myObj.style.display = style;
		}
		else
		{
			alert('This website uses DHTML. We recommend you upgrade your browser.');
		}
	}
function validatePriceAvailForm(form)
	{
		if (form.numRooms.value == "")
		{
			alert('Please specify the Number of Rooms');
			return false;
		}

		if ( form.numRooms.value != 1 )
		{
			var sameOccupancy = 'true';

			for (var i = 1 ; i <= 5 ; i++)
			{
				if (document.getElementById('room' + i + 'b').style.display == 'block')
				{
					if( i > 1 )
					{
						var numAdults = document.getElementById('numAdults' + i).selectedIndex;
						var lastRoomNumAdults = document.getElementById('numAdults' + (i-1)).selectedIndex;

						if( numAdults != lastRoomNumAdults )
						{
							sameOccupancy = 'false';
						}
					}
				}

				if (document.getElementById('room' + i + 'c').style.display == 'block')
				{

					if( i > 1 )
					{
						var numChildren = 0;
						var numChildrenBox = document.getElementById('numChildren' + i);
						if (numChildrenBox != null)
						{
							numChildren = numChildrenBox.selectedIndex;
						}
						var lastRoomNumChildren = 0;
						numChildrenBox = document.getElementById('numChildren' + (i-1));
						if (numChildrenBox != null)
						{
							lastRoomNumChildren = numChildrenBox.selectedIndex;
						}

						if( numChildren != lastRoomNumChildren )
						{
							sameOccupancy = 'false';
						}
					}
				}
				if (document.getElementById('room' + i + 'd').style.display == 'block')
				{

					if(i > 1)
					{
						var ratePlan = null;
						var ratePlanBox = document.getElementById('ratePlan' + i);
						if (ratePlanBox != null)
						{
							ratePlan = ratePlanBox.selectedIndex;

						}

						var lastRatePlan= null ;
						ratePlanBox = document.getElementById('ratePlan' + (i-1));

						if (ratePlanBox != null)
						{
							lastRatePlan = ratePlanBox.selectedIndex;

						}


						if( ratePlan != lastRatePlan )
						{
							sameOccupancy = 'false';
						}

					}
				}

			}

		}

		for (var i = 1 ; i <= 5 ; i++)
		{
			if (document.getElementById('room' + i + 'b').style.display == 'block')
			{
				if (document.getElementById('numAdults' + i).selectedIndex < 0)
				{
					alert('Please Enter Your Guest Room Occupancy');
					return false;
				}
			}
		}

		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);
			//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;
		}
		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


		if (validateAscii(form.corporateId) == false){
			return false;
		}

		if (validateAscii(form.promotionalCode) == false){
			return false;
		}


		if (preventDoubleClick())
		{
			if( sameOccupancy == 'true' )
			{
				form.allRoomsSame.value = confirm('Would you like all the Room/rates to be the same? Click OK if all the same and Cancel if you wish to select different Rooms/rates for each Room.');
			}
		}
		else
		{
			return false;
		}
		 return true;
	}

		function validDate(form) {

		var arrMY = form.arrivalMonthYear.value;
		var depMY = form.departureMonthYear.value;
		var arrDY = form.arrivalDay.value;
		var depDY = form.departureDay.value;
		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) {
                    var leap = (arrYearTemp % 4 == 0 &&
                               (arrYearTemp % 100 != 0 || arrYearTemp % 400 == 0));
                    if (arrDY >29 || (arrDY == 29 && !leap)) {
                        alert('Please Enter a Valid Date');
						return false;
                    }
				}
                if (depMonthTemp == 1) {
                    var leap = (depYearTemp % 4 == 0 &&
                               (depYearTemp % 100 != 0 || depYearTemp % 400 == 0));
                    if (depDY >29 || (depDY == 29 && !leap)) {
                        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;
            }

	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;


    //return Math.round(difference_ms/ONE_DAY)
    diff=Math.round(difference_ms/ONE_DAY);

    return diff;
   }
   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;
   }
   // function to open help window
	function MM_openBrWindow(theURL,winName,features) {


			if(ie4){
			xMousePos = window.event.x+document.body.scrollLeft;
			yMousePos = window.event.y+document.body.scrollTop - 100;
			}else {
			// document.captureEvents(Event.MOUSEUP);
			// xMousePos = window.event.pageX;
			// yMousePos = window.event.pageY - 100;
			}
		features=features+",left="+xMousePos+",top="+yMousePos;
		helpPopup=window.open(theURL,winName,features);
		//helpPopup.moveTo(xMousePos,yMousePos);
	}

	
   var doubleClick;



//***********************************************************************************
//PLEASE REMOVE THE CODE BELOW FOR WEB UI REDESIGN DELIVERY FOR ADVANCE SEARCH.
//THIS WAS REQUIRED FOR PROPERTYSEARCHFORM
//***********************************************************************************


function validatePropertySearchFormAll(form) {
      var passed = true;

      // the Struts-Validator dynamically generated validation
      passed = validatePropertySearchForm(form);
      // the 'custom' validations below
     if (passed)
      {
         passed = validateCapacityRequest(form);
      }
      if (passed)
      {
         passed = validateCountryState(form);
      }
      if (passed)
      {
         passed = validateAddressSearch(form);
      }
      if (passed)
      {
         passed = validateReferencePointSearch(form);
      }
      if (passed)
      {
         passed = preventDoubleClick();
      }
      return passed;
   }

  /**
    * Called on form submit to ensure that either none or all of the input elements that would
    * trigger an availability have been selected (arrival date, departure date)
    */
   function validateCapacityPropertySearchRequest(form) {

      if (hasAStayElementPropertySearch(form) && !hasAllStayElementsPropertySearch(form)) {

         var msg = "If you would like to check Room Availability for a Stay, you must provide:\n  - Your Arrival Date and Month-Year\n  - Your Departure Date and Month-Year\n\nIf you do not wish to check Room Availability and are just searching for a hotel,\nplease deselect all of these fields.";

         window.alert(msg);

         try
         {
            if (form.arrivalMonthYear.selectedIndex == 0) {
               form.arrivalMonthYear.focus();
               return false;
            }
            else if (form.arrivalDay.selectedIndex == 0) {
               form.arrivalDay.focus();
               return false;
            }
            else if (form.departureMonthYear.selectedIndex == 0) {
               form.departureMonthYear.focus();
               return false;
            }
            else if (form.departureDay.selectedIndex == 0) {
               form.departureDay.focus();
               return false;
            }
            return false;
         }
         catch (e)
         {
            //Must've come from a page that doesn't have this property.
         }
      }
      else if (hasAllStayElements(form)) {
         return validateArrivalDate(form);
      }

      return true;
   }


   /**
    * 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 = 26;
      var currentMonth = 8;
      var currentYear = 2006;

      // Set maximum allowable consumption date (e.g. today + 350)
      
      var maxDay = 11;
      var maxMonth = 8;
      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
//***********************************************************************************


   /**
    ****************************************************************************
    * the main validation methods
    ****************************************************************************
    */

   /**
    * wrapper function that calls all post-submit validation functions
    */
   function validateSelectHotelFormAll(form) {
      var passed = true;

      // the Struts-Validator dynamically generated validation
      	

		

		
		
		


      // the 'custom' validations below
     if (passed)
      {
         passed = validateCapacityRequest(form);
      }
      
	      if (passed)
    	  {
        	 passed = validateCountryState(form);
	      }
	  
      if (passed)
      {
         passed = validateAddressSearch(form);
      }
      if (passed)
      {
         passed = validateReferencePointSearch(form);
      }
      if (passed)
      {
         passed = preventDoubleClick();
      }
      return passed;
   }


   /**
    * wrapper function that calls all post-submit validation functions
    */
   function validatePropertyPriceAvailFormAll(form) {
      var passed = true;

      // the Struts-Validator dynamically generated validation
      passed = validatePropertyPriceAvailForm(form);

      // the 'custom' validations below
      if (passed) {
         passed = validateArrivalDate(form);
      }
      if (passed)
      {
         passed = preventDoubleClick();
      }
      return passed;
   }

	/**
    * wrapper function that calls all post-submit validation functions
    */
   function validateAddBillingFormAll(form)
   {
      var passed = true;

      if(form.memberId.value != "" ^ form.webPassword.value != "")
      {
      window.alert("Both Username and Password fields are mandatory to login as a GCCI customer");
      return false;
      }

      else if(form.memberId.value == "" && form.webPassword.value == "")
      {
      if(form.gcciSignupFlag.checked)
      {
      if(form.newUserPassword.value == "" || form.newUserConfirmPassword.value == "")
      {
      window.alert("Please enter the password in both the password fields.");
      return false;
      }
      else if((form.newUserPassword.value.length < 6 || form.newUserPassword.value.length >8) ||
       		  (form.newUserConfirmPassword.value.length < 6 || form.newUserConfirmPassword.value.length >8))
      {
      window.alert("Both the password fields should have 6 - 8 characters");
	  return false;
      }
      else if(form.newUserPassword.value != form.newUserConfirmPassword.value)
      {
      window.alert("Please enter the same password in both the password fields.");
      return false;
      }
      }

      // the Struts-Validator dynamically generated validation
      passed = validateAddBillingForm(form);

      // Go validate the customer information
      if (passed)
      {
         passed = validateCustomerInfo(form);
      }

      if (passed)
      {
         passed = validateBillingGuestAddress(form);
      }

      if (passed)
      {
         if(!form.useGuestAddress[0].checked)
         {
            passed = validateBillingAddress(form);
         }
      }

      // the 'custom' validations below
      if (passed)
      {
         passed = validateEmailAddresses(form);
      }

/*
	  if (passed)
      {
         passed = validateCreditCardExpiryDate(form);
      }
*/
      if (passed)
      {
         passed = validateResSummary(form);
      }
      if (passed)
      {
         passed = preventDoubleClick();
      }

      }
      if (form.iataNumber.value == "Enter IATA/ARC/TIDS #")
      {
         form.iataNumber.value = "";
      }

      return passed;
   }

	/**
    * function to validate comments entered by user on ReviewAndReserve page
    */
	function validateResSummary(form)
	{
		// ok, could have more than one comment here,
		// loop over all the comment i's and check em
		var elements = form.elements;
		var str = '';
		str += elements.length + '<BR>';
		for (var i=0;i<elements.length;i++){
			if(elements[i].name.indexOf('comment') != -1){
				if (validateAscii(elements[i]) == false){
					return false;
				}
			}
		}
		return true;
	}


   /**
    * wrapper function that calls all post-submit validation functions
    */
function validateReservationRetrieveFormAll(form)
   {

      var passed = true;

      // the Struts-Validator dynamically generated validation
      //passed = validateReservationRetrieveForm(form);

      if ((form.creditCardNumber.value == "") && (form.confirmationNumber.value == ""))
      {
         window.alert("Please enter either a Credit Card Number or a Reservation Confirmation Number");
         return false;
      }

      if (form.firstName.value == "" && form.newFirstName.value =="" )
      {
         window.alert("Please enter your First Name");

         form.firstName.focus();
         return false;
      }

      if (form.lastName.value == "" && form.newLastName.value =="")
      {
         window.alert("Please enter your Last Name");
         form.lastName.focus();
         return false;
      }

      if (passed)
      {
         passed = preventDoubleClick();
      }


      return passed;
   }


/*
   function validateCreditCardExpiryDate(form)
   {
      var passed = true;
      var month = [form.creditCardExpMonth.selectedIndex].value;
      var year = [form.creditCardExpYear.selectedIndex].value;
      if (month < 11)
      {
         month++;
      }
      else
      {
         month = 0;
         year++;
      }
      var now = new Date();
      var expiry = new Date(year, month, 1);

      if (expiry < now)
      {
         passed = false;
         window.alert("The Credit Card you have entered has expired, please check the expiry month and year."+expiry);
      }

      return passed;
   }
*/
   function validateEmailAddresses(form)
   {
      var email1 = form.email.value;
      var email2 = form.confirmEmail.value;

      if (email1 != email2)
      {
         window.alert("Email and confirm email addresses do not match. Please correct and submit again.");
         return false;
      }
      return true;
   }

   function validateBillingGuestAddress(form)
   {
      if ((form.country.value == "US" || form.country.value == "CA" || form.country.value == "AU"))
      {
         if (form.state.value == "")
         {
            window.alert("Please enter a state for guest address.");
            form.state.focus();
            return false;
         }
      }
      if ((form.country.value == "US" || form.country.value == "CA"))
      {
         if (form.postalCode.value == "")
         {
            window.alert("Please enter a postal code for guest address.");
            form.postalCode.focus();
            return false;
         }
      }
      return true;
   }

   function validateCustomerInfo(form)
   {
      if (form.firstName.value == "")
      {
         window.alert("Please enter the guest first name.");
         form.firstName.focus();
         return false;
      }
      else if(!validateAscii(form.firstName)){
         return false;
      }
      if (form.lastName.value == "")
      {
         window.alert("Please enter the guest last name.");
         form.lastName.focus();
         return false;
      }
      else if(!validateAscii(form.lastName)){
         return false;
      }
      if (form.address1.value == "")
      {
         window.alert("Please enter address line 1 for guest address.");
         form.address1.focus();
         return false;
      }
      else if(!validateAscii(form.address1)){
         return false;
      }
      if (Trim(form.city.value) == "")
      {
         window.alert("Please enter a city for guest address.");
         form.city.focus();
         return false;
      }
      else if(!validateAscii(form.city)){
         return false;
      }

      if (form.country.value == "")
      {
         window.alert("Please enter a country for guest address.");
         form.country.focus();
         return false;
      }

      if (form.email.value == "")
      {
         window.alert("Please enter a valid email address.");
         form.email.focus();
         return false;
      }
      else if(!validateAscii(form.email)){
         return false;
      }

      if (form.confirmEmail.value == "")
      {
         window.alert("Please enter a valid confirmation email address.");
         form.confirmEmail.focus();
         return false;
      }
      else if(!validateAscii(form.confirmEmail)){
         return false;
      }

      if (form.telephone.value == "")
      {
         window.alert("Please enter a valid telephone number for guest.");
         form.telephone.focus();
         return false;
      }
      else
      {
         result = validateTelephoneNumber(form.telephone.value);
         if(result == false)
         {
            window.alert("Please enter a valid telephone number for guest.");
            form.telephone.focus();
            return false;
         }
      }

      if (form.creditCardType.value == "")
      {
         window.alert("Please enter a credit card type.");
         form.creditCardType.focus();
         return false;
      }

      if (form.creditCardNumber.value == "")
      {
         window.alert("Please enter your credit card number");
         form.creditCardNumber.focus();
         return false;
      }

      if (form.creditCardExpMonth.value == "")
      {
         window.alert("Please enter a credit card expiry month.");
         form.creditCardExpMonth.focus();
         return false;
      }

      if (form.creditCardExpYear.value == "-1")
      {
         window.alert("Please enter a credit card expiry year.");
         form.creditCardExpYear.focus();
         return false;
      }
      return true;
   }

   function validateBillingAddress(form)
   {
      if (form.billingFirstName.value == "")
      {
         window.alert("Please enter the credit card holders first name.");
         form.billingFirstName.focus();
         return false;
      }
      else if(!validateAscii(form.billingFirstName)){
         return false;
      }
      if (form.billingLastName.value == "")
      {
         window.alert("Please enter the credit card holders last name.");
         form.billingLastName.focus();
         return false;
      }
      else if(!validateAscii(form.billingLastName)){
         return false;
      }
      if (form.billingAddress1.value == "")
      {
         window.alert("Please enter address line 1 for billing address.");
         form.billingAddress1.focus();
         return false;
      }
      else if(!validateAscii(form.billingAddress1)){
         return false;
      }
      if (form.billingCity.value == "")
      {
         window.alert("Please enter a city for billing address.");
         form.billingCity.focus();
         return false;
      }
      else if(!validateAscii(form.billingFirstName)){
         return false;
      }

      if ((form.billingCountry.value == "US" || form.billingCountry.value == "CA" || form.billingCountry.value == "AU"))
      {
         if (form.billingState.value == "")
         {
            window.alert("Please enter a state for billing address.");
            form.billingState.focus();
            return false;
         }
      }
      if ((form.billingCountry.value == "US" || form.billingCountry.value == "CA"))
      {
         if (form.billingPostalCode.value == "")
         {
            window.alert("Please enter a postal code for billing address.");
            form.billingPostalCode.focus();
            return false;
         }
      }
      if (form.billingCountry.value == "")
      {
         window.alert("Please enter a country for billing address.");
         form.billingCountry.focus();
         return false;
      }
      return true;
   }


   /**
    * Called on form submit to ensure that asian users only enter valid
    * ascii (includes extended). DANSHAW
   */
   function validateAscii(item){
      
      return true;
   }

   /**
    * Called on form submit to ensure that the telephone number only contains valid
    * characters (dec ascii 32-64 and 91-96). WT593
    */
   function validateTelephoneNumber(telephoneNumber)
   {
      for (i = 0; i < telephoneNumber.length; i++)
      {
         if (telephoneNumber.charCodeAt(i) > 96)
         {
            return false;
         }
         if (telephoneNumber.charCodeAt(i) < 32)
         {
            return false;
         }
         if (telephoneNumber.charCodeAt(i) > 64 && telephoneNumber.charCodeAt(i) < 91)
         {
            return false;
         }
      }
      return true;
   }

   /**
    * Called on form submit to ensure that either none or all of the input elements that would
    * trigger an availability have been selected (arrival date, departure date)
    */
   function validateCapacityRequest(form) {
      if (hasAStayElement(form) && !hasAllStayElements(form)) {
     	if(form.arrivalMonthYear.selectedIndex > 0 &&
     		form.arrivalDay.selectedIndex > 0 &&
     			form.departureMonthYear.selectedIndex == 0 &&
     				form.departureDay.selectedIndex == 0){
     		changeDep(form);
     		return true;
     	}
     	else {
        	 var msg = "If you would like to check Room Availability for a Stay, you must provide:\n  - Your Arrival Date and Month-Year\n  - Your Departure Date and Month-Year\n\nIf you do not wish to check Room Availability and are just searching for a hotel,\nplease deselect all of these fields.";

	         window.alert(msg);

    	     try
        	 {
            	if (form.arrivalMonthYear.selectedIndex == 0) {
	               form.arrivalMonthYear.focus();
    	           return false;
        	    }
            	else if (form.arrivalDay.selectedIndex == 0) {
	               form.arrivalDay.focus();
    	           return false;
        	    }
            	else if (form.departureMonthYear.selectedIndex == 0) {
	               form.departureMonthYear.focus();
    	           return false;
        	    }
            	else if (form.departureDay.selectedIndex == 0) {
	               form.departureDay.focus();
    	           return false;
        	    }
            	return false;
	         }

        	 catch (e)
	         {
    	        //Must've come from a page that doesn't have this property.
        	 }
        }
      }
      else if (hasAllStayElements(form)) {
         return validateArrivalAndDepDate(form);
      }

      return true;
   }


   function validateReferencePointSearch(form)
   {
      if ((form.referencePoint != null) && (form.referencePointType != null))
      {
         if ((form.referencePoint.value == "") && (form.referencePointType.value != ""))
         {
            window.alert("Please enter a reference point.");
            return false;
         }

         if ((form.referencePointType.value == "") && (form.referencePoint.value != ""))
         {
            window.alert("Please select a reference point type from the drop down list.");
            return false;
         }
         return true;
      }
      return true;
   }

   /**
    * this method ensures that the Stay Date provided occurs in the future; this
    * is called inside validateCapacityRequest
    */
   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));
		
		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;
   }

   /**
    * If the Guest has input a Street Address in attempting to perform a Street Address Search,
    * this method ensures that at least a City or Postal Code has been specified in addition
    * to the basic Country or Country/State requirement
    */
   function validateAddressSearch(form) {
      if (form.nearStreetAddress != null && form.nearStreetAddress.value != "") {
         if (form.nearCity.value == "" && form.nearPostalCode.value == "") {
            window.alert("When performing a Street Address search,\n you must provide either a City or a Postal Code");
            form.nearCity.focus();
            return false;
         }
      }
      return true;
   }

   /**
    * If the Guest wishes to reserve 6-9 rooms (US/Canada) or 4-9 rooms (non US/Canada),
    * or 10+ rooms, this method causes a popup window to open providing a link and/or
    * instructions for reserving rooms under such situations, as these types of
    * reservations cannot be booked online
    */
   function validateNumRooms(aSelect) {
      var form = aSelect.form;
      var countryCode;
      try
      {
         countryCode = form.countryCode[form.countryCode.selectedIndex].value;
      }
      catch (e)
      {
         countryCode = "XX";
      }
      var numRooms = aSelect.options[aSelect.selectedIndex].value;
      var numRoomsLabel = aSelect.options[aSelect.selectedIndex].text;
      if (countryCode == "" || countryCode == "none")
      {
         alert("You must select a country before choosing the number of rooms");
         aSelect.selectedIndex = 0;
         return false;
      }
      
         
            if (numRooms == 9) {
               aSelect.selectedIndex=0;
               aSelect.focus();
               
               var url = "messageGroup.do?msgKey=search.group_request_msg&arg1=http%3A%2F%2Fwww.bestwestern.com";
               
               url += "&arg0=" + numRoomsLabel;
               validationPopupMessage(url,"msgWindow", 300,200);
               return false;
            }
            if (numRooms == 10) {
               aSelect.selectedIndex=0;
               aSelect.focus();
               var url = "messageGroup.do?msgKey=search.group_online_msg&arg0=http%3A%2F%2Fwww.bestwestern.com";
               validationPopupMessage(url,"msgWindow", 300,200);
               return false;
            }
         
         
      
      return true;
   }

  function validateReservationChangeFormAll(form)
   {
      var cancel = "";
      var modifyRoom = "";
      var modifyBestExtra = "";
      var found = false;
      var comp_id = "";

      if (document.forms['reservationChangeForm'].elements["changesSelected"] != null)
      {
         // if you only have a one hotel reservation, we must assign the comp id value into the form as an array so we can access the other elements
         if(document.forms['reservationChangeForm'].elements['COMP_ID'].value != null && !document.forms['reservationChangeForm'].elements['COMP_ID'].length){


            comp_id = document.forms['reservationChangeForm'].elements['COMP_ID'].value;
           for (var i=1; i<20; i++)
            {
               cancel = "CANCEL_ROOM" + i + "_" + comp_id;
               modifyRoom = "MODIFY_ROOM" + i + "_" + comp_id;
               modifyBestExtra = "MODIFY_BEST_EXTRA" + i + "_" + comp_id;

               if ( (document.forms['reservationChangeForm'].elements[cancel] != null && document.forms['reservationChangeForm'].elements[cancel].checked) ||
                   (document.forms['reservationChangeForm'].elements[modifyRoom] != null && document.forms['reservationChangeForm'].elements[modifyRoom].checked) ||
                       (document.forms['reservationChangeForm'].elements[modifyBestExtra] != null && document.forms['reservationChangeForm'].elements[modifyBestExtra].checked) )
               {
                  found = true;
               }
	}



         }else{

	// start logic to handle muliple room
	for(var j=0; j < document.forms['reservationChangeForm'].elements['COMP_ID'].length; j++){
            comp_id = document.forms['reservationChangeForm'].elements['COMP_ID'][j].value;
            for (var i=1; i<20; i++)
            {
               cancel = "CANCEL_ROOM" + i + "_" + comp_id;
               modifyRoom = "MODIFY_ROOM" + i + "_" + comp_id;
               modifyBestExtra = "MODIFY_BEST_EXTRA" + i + "_" + comp_id;

               if ( (document.forms['reservationChangeForm'].elements[cancel] != null && document.forms['reservationChangeForm'].elements[cancel].checked) ||
                   (document.forms['reservationChangeForm'].elements[modifyRoom] != null && document.forms['reservationChangeForm'].elements[modifyRoom].checked) ||
                       (document.forms['reservationChangeForm'].elements[modifyBestExtra] != null && document.forms['reservationChangeForm'].elements[modifyBestExtra].checked) )
               {
                  found = true;
                  break;
               }
            }
         }
	// end logic to handle muliple room

	}

         if (found == false)
         {
           window.alert("There are no modify options selected, please reselect.");

            return false;
         }
         for(var j=0; j < document.forms['reservationChangeForm'].elements['COMP_ID'].length; j++){
            comp_id = document.forms['reservationChangeForm'].elements['COMP_ID'][j].value;

            for (var i=1; i<20; i++)
            {
               cancel = "CANCEL_ROOM" + i + "_" + comp_id;
               modifyRoom = "MODIFY_ROOM" + i + "_" + comp_id;
               modifyBestExtra = "MODIFY_BEST_EXTRA" + i + "_" + comp_id;

               if (document.forms['reservationChangeForm'].elements[cancel] != null && document.forms['reservationChangeForm'].elements[cancel].checked)
               {
                  if ( (document.forms['reservationChangeForm'].elements[modifyRoom] != null && document.forms['reservationChangeForm'].elements[modifyRoom].checked) ||
                      (document.forms['reservationChangeForm'].elements[modifyBestExtra] != null && document.forms['reservationChangeForm'].elements[modifyBestExtra].checked))
                  {
                      window.alert("Cancel Room cannot be combined with the other modify options, please reselect.");

                     return false;
                  }
               }
            }
         }
      }
      return true;
   }

   function changeOfBillingState(aSelect, fieldName)
   {
      var val = new String(aSelect.options[aSelect.selectedIndex].value);
      var form = aSelect.form;

      // synch any existing state dropdown
      if (fieldName == "state")
      {
         form.state.selectedIndex = aSelect.selectedIndex;
      }

      else if (fieldName == "billingState")
      {
         form.billingState.selectedIndex = aSelect.selectedIndex;
      }

      // change the country dropdown(s) to the proper value
      displayBillingCountry(aSelect, fieldName);

      // if the Guest selected one of the country headers in the state drop-down, complain
      if (val == "US" || val == "CA" || val == "AU")
      {
         window.alert("For Canada, the United States and Australia,\n please select a City or a State");
         aSelect.focus();
      }
      return;
   }

   function changeOfBillingCountry(aSelect, fieldName)
   {
      refreshBillingStates(aSelect, fieldName);
      var form = aSelect.form;

      // synch any existing country dropdowns
      if (fieldName == "country")
      {
         form.country.selectedIndex = aSelect.selectedIndex;
      }
      else if (fieldName == "")
      {
         form.billingCountry.selectedIndex = aSelect.selectedIndex;
      }
   }

   function changeOfShortenStay(aSelect, bSelectName)
   {
      document.forms['reservationChangeForm'].elements[bSelectName].selectedIndex = aSelect.selectedIndex;
      return;
   }

   /** Displays the proper country depending on a state */
   function displayBillingCountry(aSelect, fieldName)
   {
      var val  = aSelect.options[aSelect.selectedIndex].value;
      var form = aSelect.form;
      var idx = 0;

      if (val.indexOf("US_") == 0)
      {
         idx = getIndex(form.billingCountry, "US");
      }
      else if (val.indexOf("CA_") == 0)
      {
         idx = getIndex(form.billingCountry, "CA");
      }
      else if (val.indexOf("AU_") == 0)
      {
         idx = getIndex(form.billingCountry, "AU");
      }

      if (idx > 0)
      {
         if (fieldName == "state")
         {
            form.country.selectedIndex = idx;
         }
         else if (fieldName == "billingState")
         {
            form.billingCountry.selectedIndex = idx;
         }
      }
   }

   function refreshBillingStates(aSelect, fieldName)
   {
      var stateCodes = new Array();
      var val = aSelect.options[aSelect.selectedIndex].value;
      var form = aSelect.form;

      if (val == "US")
      {
         stateCodes = US_states_withoutAll;
      }
      else if (val == "CA")
      {
         stateCodes = CA_states_withoutAll;
      }
      else if (val == "AU")
      {
         stateCodes = AU_states_withoutAll;
      }
      else if (val != "")
      {
         stateCodes = new Array(new Option("",""));
      }

      if (fieldName == "country")
      {
         setOptions(form.state, stateCodes);
      }
      else if (fieldName == "billingCountry")
      {
         setOptions(form.billingState, stateCodes);
      }
   }

   /**
    * When a guest selects a state, we synch the other state box, if any, we change
    * the country to the appropriate country, and we changed the number of rooms
    * drop-down according to the country
    */
   function changeOfState(aSelect) {
      var val = new String(aSelect.options[aSelect.selectedIndex].value);
      var form = aSelect.form;

      // synch any existing state dropdown
      if (form.stateCode != null) {
         form.stateCode.selectedIndex = aSelect.selectedIndex;
      }

      if (form.nearState!= null) {
         form.nearState.selectedIndex = aSelect.selectedIndex;
      }

      // change the country dropdown(s) to the proper value
      displayCountry(aSelect);

      // refresh the number of rooms dropdown based on country
      refreshNumRoomsDropdown(form.countryCode);

      // if the Guest selected one of the country headers in the state drop-down, complain
      if (val == "US" || val == "CA" || val == "AU") {
         window.alert("For Canada, the United States and Australia,\n please select a City or a State");
         aSelect.focus();
      }
      return;
   }

   /**
    * When a guest selects a country, we synch the other state box, if any,
    * we display the appropriate list of states, and we display the
    * number of rooms drop-down appropriate to the country
    */
   function changeOfCountry(aSelect) {
      refreshStates(aSelect);
      refreshNumRoomsDropdown(aSelect);
      var form = aSelect.form;

      // synch any existing country dropdowns
      if (form.countryCode != null) {
         form.countryCode.selectedIndex = aSelect.selectedIndex;
      }

      if (form.nearCountry != null) {
         form.nearCountry.selectedIndex = aSelect.selectedIndex;
      }
   }

    /**
     * called to keep the city fields the same
     */
    function synchCity(aTextbox)
    {
         var form = aTextbox.form;
         if (form.city != null) {
            form.city.value = aTextbox.value;
         }
         if (form.nearCity != null) {
            form.nearCity.value = aTextbox.value;
         }
         return true;
    }

   /**
    * When a Guest selects a month, refresh the ArrivalDay drop-down;
    * also called when a year changes, to account for the possibility
    * that a leap year was selecte/unselected
    */
   function changeOfMonth(aSelect) {
      var month = aSelect.value;
      var day   = aSelect.form.arrivalDay.value;
      var year  = aSelect.form.arrivalYear.value;
      var numDays = getNumDaysInMonth(month,year);
      var aryDays = new Array();
      
   
   
      day --;
   
     

      for (var i=1; i <= numDays; i++) {
         aryDays[i] = new Option(i,i);
      }

      setOptions(aSelect.form.arrivalDay, aryDays);
      // restore the date, if one was selected and is valid
      if (day > 0 && day < numDays) {
         aSelect.form.arrivalDay.options[day].selected = true;
      }
   }


   /**
    ****************************************************************************
    * functions supporting the main validation methods above
    ****************************************************************************
    */

   /* Displays the proper state drop-downs based on a country */
   function refreshStates(aSelect) {
      var stateCodes = new Array();
      var val = aSelect.options[aSelect.selectedIndex].value;
      var form = aSelect.form;

      if (val == "US") {
         stateCodes = US_states;
      }
      else if (val == "CA") {
         stateCodes = CA_states;
      }
      else if (val == "AU") {
         stateCodes = AU_states;
      }
      else if (val != ""){
         stateCodes = new Array(new Option("All",""));
      }

      setOptions(form.stateCode, stateCodes);

      if (form.nearState != null) {
         setOptions(form.nearState, stateCodes);
      }
   }

   /** Displays the proper country depending on a state */
   function displayCountry(aSelect) {
      var val  = aSelect.options[aSelect.selectedIndex].value;
      var form = aSelect.form;
      var idx = 0;

      if (val.indexOf("US_") == 0) {
      //if (isValueInOptionArray(val, US_states)) {
         idx = getIndex(form.countryCode, "US");
      }
      else if (val.indexOf("CA_") == 0) {
      // else if (isValueInOptionArray(val, CA_states)) {
         idx = getIndex(form.countryCode, "CA");
      }
      else if (val.indexOf("AU_") == 0) {
      //else if (isValueInOptionArray(val, AU_states)) {
         idx = getIndex(form.countryCode, "AU");
      }

      if (idx > 0)
      {
         form.countryCode.selectedIndex = idx;
         if (form.nearCountry != null) {
            form.nearCountry.selectedIndex = idx;
         }
      }
   }


   /** refreshes the numRooms dropdown according to the country selected */
   function refreshNumRoomsDropdown(aSelect) {
      var form = aSelect.form;
      if (form.numRooms != null) {
         var opt = new Array();
         var val = aSelect.options[aSelect.selectedIndex].value;
         var numRoomsSelect = form.numRooms;
         var currentSelect = form.numRooms.selectedIndex;
         if (val == "" || val == "none")
         {
            setOptions(form.numRooms, numRooms_noCountry);
            form.numRooms.selectedIndex = 0;
         }
         
         else if (val == "CA")
         {
            removeAllData(numRoomsSelect);
            numRoomsSelect.options[numRoomsSelect.length] = new Option("", "0");
             
               
                  numRoomsSelect.options[numRoomsSelect.length] = new Option("1", "1");
               
                  numRoomsSelect.options[numRoomsSelect.length] = new Option("2", "2");
               
                  numRoomsSelect.options[numRoomsSelect.length] = new Option("3", "3");
               
               numRoomsSelect[numRoomsSelect.length] = new Option("4-9", "9");
               numRoomsSelect[numRoomsSelect.length] = new Option("10+", "10");
            
         }
         
         else if (val == "IT")
         {
            removeAllData(numRoomsSelect);
            numRoomsSelect.options[numRoomsSelect.length] = new Option("", "0");
             
               
                  numRoomsSelect.options[numRoomsSelect.length] = new Option("1", "1");
               
                  numRoomsSelect.options[numRoomsSelect.length] = new Option("2", "2");
               
                  numRoomsSelect.options[numRoomsSelect.length] = new Option("3", "3");
               
               numRoomsSelect[numRoomsSelect.length] = new Option("4-9", "9");
               numRoomsSelect[numRoomsSelect.length] = new Option("10+", "10");
            
         }
         
         else if (val == "US")
         {
            removeAllData(numRoomsSelect);
            numRoomsSelect.options[numRoomsSelect.length] = new Option("", "0");
             
               
                  numRoomsSelect.options[numRoomsSelect.length] = new Option("1", "1");
               
                  numRoomsSelect.options[numRoomsSelect.length] = new Option("2", "2");
               
                  numRoomsSelect.options[numRoomsSelect.length] = new Option("3", "3");
               
               numRoomsSelect[numRoomsSelect.length] = new Option("4-9", "9");
               numRoomsSelect[numRoomsSelect.length] = new Option("10+", "10");
            
         }
         
         else if (val == "policy")
         {
            removeAllData(numRoomsSelect);
            numRoomsSelect.options[numRoomsSelect.length] = new Option("", "0");
             
               
         }
         
         else
         {
            setOptions(form.numRooms, numRooms_max3);
         }
         if (form.numRooms.length > (currentSelect + 2) && !(val == "" || val == "none"))
         {
            form.numRooms.selectedIndex = currentSelect;
         }
      }
   }

   /**
    * This method returns true if any 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 hasAStayElement(form) {
      try
      {
         return (
            form.arrivalMonthYear.selectedIndex > 0 ||
         	form.arrivalDay.selectedIndex > 0 ||
         	form.departureMonthYear.selectedIndex > 0 ||
         	form.departureDay.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 hasAllStayElements(form) {
      try
      {

      return (
         	form.arrivalMonthYear.selectedIndex > 0 &&
         	form.arrivalDay.selectedIndex > 0 &&
         	form.departureMonthYear.selectedIndex > 0 &&
         	form.departureDay.selectedIndex > 0  );
      }
      catch (e)
      {
         return false;
      }
   }


   /**
    ****************************************************************************
    * 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 validationPopupMessage(url, winName, aWidth, aHeight, X, Y)
   {
      // if Height and Width are passed, but no X and Y coordinates passed,
      // center the window on the screen
      if ( aHeight != null && aWidth != null && X == null && Y == null ) {
         X = Math.round((window.screen.availWidth - aWidth) / 2);
         Y = Math.round((window.screen.availHeight - aHeight) / 2);
      }

      var features= "height="+aHeight +", width="+aWidth +
            ", screenX="+X +", screenY="+Y +", left="+X +", top="+Y
            +", location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no";

      var popup = window.open(url,winName, features);
      popup.focus();
   }

   function preventDoubleClick()
   {
      if (doubleClick)
      {
         alert('Your request is being processed, please wait.');
         return false;
      }
      else
      {
         doubleClick = true;
         return true;
      }
   }

   function validateOtherEmail(form)
   {
   	  var passed;
   	  if (form.newEmailAddress.value == "")
      {
         window.alert("Please enter a valid email address.");
         form.newEmailAddress.focus();
         passed = false;
      }
      else if(!validateAscii(form.newEmailAddress)){
         form.newEmailAddress.focus();
         passed = false;
      }
      else
      {
      	 passed = validateReservationRetrieveForm(form);
      }
      return passed;
   }
/**
* 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;

}
