/******************************************
 Common Functions
*******************************************/

function submitViaEnter(pEvent, pForm) 
{
	if (pEvent.keyCode == 13) 
  	{
    	pForm.submit();
  	}
}

function OpenPopupWindow(pBodyUri, pWindowTitle, pScrollOption, pFrameOption, pWidth, pHeight, pResizable)
{
  	var undefined = void 0;	// IE 5 doesn't have 'undefined'
  	var lWidth = (pWidth == undefined) ? 351 : pWidth;
  	var lHeight = (pHeight == undefined) ? 275 : pHeight;
  	var lResizable = (pResizable == undefined) ? "no" : pResizable;
  	var lProtocol = document.location.protocol;
  	var lWindowOptions = "width=" + lWidth + ",height=" + lHeight + ",toolbar=no,menubar=no,scrollbars=no,resizable=" + lResizable;
  	var lPopupPath = (lProtocol == "https:" && pFrameOption == "N") ? "/common/secure/popup.jsp" : "/common/popup.jsp";
  	var lWindowPath = lPopupPath + "?bodyUri=" + escape(pBodyUri) + "&title=" + escape(pWindowTitle) + "&scroll=" + pScrollOption + "&frames=" + pFrameOption;
  	var lWindowName = "";
  	for (i=0; i<pWindowTitle.length; i++)
  	{
    	var lChar = pWindowTitle.charAt(i);
    	if (lChar != ' ' && lChar != '-' && lChar != '&')
    	{
      		lWindowName += lChar;
    	}
  	}
  	var lWindowTitle = pWindowTitle;
  	window.open(lWindowPath, lWindowName, lWindowOptions);
}

function OpenGenericPopupWindow(pBodyUri, pWindowTitle, pScrollOption, pFrameOption, pWidth, pHeight, pResizable)
{
  	var undefined = void 0;	// IE 5 doesn't have 'undefined'
  	var lWidth = (pWidth == undefined) ? 351 : pWidth;
  	var lHeight = (pHeight == undefined) ? 275 : pHeight;
  	var lResizable = (pResizable == undefined) ? "no" : pResizable;
  	var lProtocol = document.location.protocol;
  	var lWindowOptions = "width=" + lWidth + ",height=" + lHeight + ",toolbar=no,menubar=no,scrollbars=no,resizable=" + lResizable;
  	var lPopupPath = (lProtocol == "https:" && pFrameOption == "N") ? "/common/secure/genericpopup.jsp" : "/common/genericpopup.jsp";
  	var lWindowPath = lPopupPath + "?bodyUri=" + escape(pBodyUri) + "&title=" + escape(pWindowTitle) + "&scroll=" + pScrollOption + "&frames=" + pFrameOption;
  	var lWindowName = "";
  	for (i=0;i<pWindowTitle.length;i++)
  	{
    	var lChar = pWindowTitle.charAt(i);
    	if (lChar != ' ' && lChar != '-' && lChar != '&')
    	{
      		lWindowName += lChar;
    	}
  	}
  	var lWindowTitle = pWindowTitle;
  	window.open(lWindowPath, lWindowName, lWindowOptions).focus();
}

var sPanelName = '';

function hidePanelPopup()
{	
	$(sPanelName).style.display = 'none';
	sPanelName = '';
}

/**
  * String pPanelName - The Name of the div wrapper
  * int pXPos - The X Coordinate you wish to show the div at in pixels.
  * int pYPos - The Y Coordinate you wish to show the div at.
  *
  * If either pXPos or pYPos are missing, they will be assigned a value of 300;
  */
function showPanelPopup(pPanelName, pXPos, pYPos)
{
	var lPanel = $(pPanelName);
	var lXPos = (pXPos) ? pXPos : 300;
	var lYPos = (pYPos) ? pYPos : 300;
	var lScrollAmount = document.body.scrollTop;

	lYPos = (lYPos + lScrollAmount);
	
	lPanel.style.position = 'absolute';
	lPanel.style.left = lXPos;
	lPanel.style.top = lYPos;
	lPanel.style.display = 'block';
	sPanelName = pPanelName;
}

function OpenHotelMap (pBrandUrl, pHotelCode)
{
  	var lWindowOptions = "width=800,height=550,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";
  	var lWindowPath = "http://" + pBrandUrl + "/hoteldirectory/nav/map.jsp?hotelcode=" + pHotelCode + "&type=hotel.map";
  	window.open(lWindowPath, "Map", lWindowOptions);
}

function OpenDynamicMap (pHotelCode, pHotelBrandCode)
{
  	var lWindowOptions = "width=800,height=550,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";
  	var lWindowPath = "/hoteldirectory/nav/map.jsp?hotelcode=" + pHotelCode + "&hotelBrandCode=" + pHotelBrandCode + "&type=hotel.map";
  	window.open(lWindowPath, "Map", lWindowOptions);
}

function OpenStaticMap (pHotelImage)
{
	var lWindowOptions = "width=800,height=550,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";
	window.open(pHotelImage, "Map", lWindowOptions);
}

function OpenCityMap (pCity, pState, pCountry, pShowCrossBrandMap)
{
    var lWindowOptions = "width=600,height=528,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";
    var lWindowPath = "/hoteldirectory/nav/map.jsp?type=city.map&city=" + pCity + "&state=" + pState + "&country=" + pCountry;
    if (pShowCrossBrandMap)
    {
    	lWindowPath += "&crossbrand=true";
	}
    window.open(lWindowPath, "Map", lWindowOptions);
}

function popEmail(pPageLink)
{
    pPageLink = encodeURIComponent(pPageLink);
  	window.open("/popupemailafriend.do?title=Email+a+Friend&pageLink="+pPageLink, 'email', 'dependent, toolbar=no,width=400,height=597').focus();  
}

function goToLink(pSelect)
{
  	if (pSelect[pSelect.selectedIndex].value.substring(0, 4) == "http")
  	{
    	window.open(pSelect[pSelect.selectedIndex].value,'_blank');
  	}
  	else if (pSelect[pSelect.selectedIndex].value.substring(0, 3) == "www")
  	{
    	window.open("http://" + pSelect[pSelect.selectedIndex].value, '_top');
  	}
  	else
  	{
    	window.open(pSelect[pSelect.selectedIndex].value, '_top');
  	}
}

function handleLanguageChange(pEnglish)
{
  	var lLanguageOptions = document.localeform.language.options;
  	var lSelectedOption = lLanguageOptions[lLanguageOptions.selectedIndex];
  	if (lSelectedOption.value == pEnglish)
  	{
    	document.localeform.onlyTranslatedPromos.value = 'true';
    	document.localeform.submit();
  	}
  	else
  	{
    	window.open('/common/languageoptions.jsp?language=' + lSelectedOption.value, 'languageoptions','width=400,height=300,scrollbars=1');
  	}
}

function submitLanguageOptions()
{
  	window.close();
  	if (opener && !opener.closed)
  	{
    	var lLocaleForm = opener.document.localeform;
    	var lPromoVisibility = window.document.optionsForm.promoVisibility;

    	lLocaleForm.onlyTranslatedPromos.value = (lPromoVisibility[1].checked) ? 'true' : 'false';
    	lLocaleForm.submit();
  	}
}

function assignCountryCode(pCountryCode, pCountryPrefix)
{
  	if (pCountryCode.value == '')
  	{
		pCountryPrefix.value = '';
  	}
  	else
  	{
		pCountryPrefix.value = countryCodes[pCountryCode.value];
  	}
  	pCountryCode.focus();
}

function RemoveInvalidPostalCodeCharacters(pPostalCode, pCountry)
{
	// The postal code for United States or Mexico contains only numbers
	var lValidUsMxChar = /[0-9]/;
	// The postal code for other countries including Canada can contain numbers and letters
	var lValidOtherChar = /[a-zA-Z0-9]/;
	var lCounter;
	var lPostalCode = "";

	if (pPostalCode != "")
	{
		for (lCounter = 0; lCounter < pPostalCode.length; lCounter++)
	  	{
	    	lTemp = pPostalCode.charAt(lCounter);
			
			if (pCountry == "US" || pCountry == "MX")
			{
	    		if (lValidUsMxChar.test(lTemp))
	    		{
	    			lPostalCode += lTemp;
	    		}
	    	}
	    	else
	    	{
	    		if (lValidOtherChar.test(lTemp))
	    		{
	    			lPostalCode += lTemp;
	    		}
	    	}
	    }
	}
    
    return lPostalCode;
}

function RemoveInvalidPhoneCharacters(pNumber)
{
  	var lValidChars = "0123456789";
  	var lCounter;
  	var lValidNumber = "";

  	if (pNumber != "")
  	{
		for (lCounter=0; lCounter < pNumber.length; lCounter++)
    	{
	  		lTemp = pNumber.charAt(lCounter);
	  		if (lValidChars.indexOf(lTemp) != "-1")
	  		{
        		lValidNumber += lTemp;
	  		}
		}
  	}

  	return lValidNumber;
}

function IsValidateEmailConstruction(pEmail)
{
  	var validEmail = false;
  	var filter  = /^([a-zA-Z0-9_\.\-\'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  	if (filter.test(pEmail))
  	{
		validEmail = true;
  	}
  
  	return(validEmail);
}

function isAllDigit(pStr)
{
    if (pStr.value != "")
    {
        for (i = 0; i < pStr.length; i++)
        {
            if (!isDigit(pStr.charAt(i)))
            {
                return false;
            }
        }
        return true;
    }
    return false;
}

// This will retrieve the cookie by name, if the cookie does not exist, it will return false.
function getCookie(pName)
{
  	var start = document.cookie.indexOf(pName + "=");
  	var len = start + pName.length + 1;
  	if (!start && pName != document.cookie.substring(0, pName.length ))
  	{
    	return null;
  	}
  	if (start == -1)
  	{
    	return null;
  	}
  	var end = document.cookie.indexOf(";", len);
  	if (end == -1)
  	{
    	end = document.cookie.length;
  	}
  	return unescape(document.cookie.substring(len, end));
}

function setCookie(pName, pValue, pExpires, pPath) 
{
  	// set time, it's in milliseconds
  	var today = new Date();
  	today.setTime(today.getTime());
  	var expires_date = new Date( today.getTime() + pExpires);

  	document.cookie = pName + "=" + escape(pValue) +
            (pExpires ? ";expires=" + expires_date.toGMTString() : "") + 
            (pPath ? ";path=" + pPath : "");
}
	
/**
* Returns true if pDate is 10 digits long and can be parsed as a Date().
*/
function isValidDate(pDate)
{
	var lLength = pDate.length;
	var lMilliseconds = Date.parse(pDate);
	
	if ((lLength != 10) && (isNaN(lMilliseconds)))
	{
		return false;
	}
	
	return true;
}

function handleArriveChanged(pArriveField, pDepartField)
{
	var lArriveValid = isValidDate(pArriveField.value);
	var lDepartValid = isValidDate(pDepartField.value);
	
	if (lArriveValid && lDepartValid)
	{
		var lArriveMillis = Date.parse(pArriveField.value);
		var lDepartMillis = Date.parse(pDepartField.value);
		
		if (lArriveMillis > lDepartMillis)
		{
			pDepartField.value = "";
		}
	}
}

function handleDepartChanged(pArriveField, pDepartField)
{
	var lArriveValid = isValidDate(pArriveField.value);
	var lDepartValid = isValidDate(pDepartField.value);
	
	if (lArriveValid && lDepartValid)
	{
		var lArriveMillis = Date.parse(pArriveField.value);
		var lDepartMillis = Date.parse(pDepartField.value);
		
		if (lDepartMillis < lArriveMillis)
		{
			pArriveField.value = "";
		}
	}
}

/******************************************
 My Account
*******************************************/

function submitResForm(pConfNo, pResNo, pHotelBrandCode, pSubmitAction)
{
	document.myAccountForm.confNo.value = pConfNo;
  	document.myAccountForm.resNo.value = pResNo;
  	document.myAccountForm.submitAction.value = pSubmitAction;
  	document.myAccountForm.hotelBrandCode.value = pHotelBrandCode; 

  	document.myAccountForm.action = "/myaccount/secure/myReservationsAction.do";
    	
  	document.myAccountForm.submit(); 
}

function checkin(pConfNo, pResNo, pBrandVariantCode, pCheckInUrl)
{
  	if (pCheckInUrl == "")
  	{
    	submitResForm(pConfNo, pResNo, pBrandVariantCode, 'checkin');
  	}
  	else
  	{
  		document.location = pCheckInUrl;
  	}
}

function editReservation(pConfNo, pResNo, pHotelBrandCode)
{
	submitResForm(pConfNo, pResNo, pHotelBrandCode, "edit");
}

function cancelReservation(pConfNo, pResNo, pHotelBrandCode)
{
	submitResForm(pConfNo, pResNo, pHotelBrandCode, "cancel");
}

function confirmDeleteHotel(pHotelID, pPanelName)
{
	showPanelPopup(pPanelName, 350, 300);
	
 	document.myAccountForm.submitAction.value = "delete";
  	document.myAccountForm.hotelID.value = pHotelID;
}

function deleteHotel()
{
 	document.myAccountForm.action = "/myaccount/secure/myFavoriteHotelAction.do";
  	document.myAccountForm.submit();
}

function printReceipt(pResNo)
{
  	var lLink = "/myaccount/secure/printReceipt.do?action=print&resNo=" + pResNo;
  	window.open(lLink, "", "width=620, height=600, left=0, top=0, menubar=no, status=yes, location=no, toolbar=no, scrollbars=yes, resizable=no");
}

function HandleEYCancel()
{
	document.eyPreferencesForm.action.value="cancel";
	document.eyPreferencesForm.submit();
}	

function switchTab(pBrand)
{
	$('tabRAD').className = 'inactive';
    $('tabCHI').className = 'inactive';
    $('tabPII').className = 'inactive';
    $('tabPKP').className = 'inactive';
    $('panelRAD').className = 'inactivePanel';
    $('panelCHI').className = 'inactivePanel';
    $('panelPII').className = 'inactivePanel';
    $('panelPKP').className = 'inactivePanel';
      
    $('tab' + pBrand).className = 'active';
    $('panel' + pBrand).className = 'activePanel';
}

function updateMyNewsletterForm()
{
	var lForm = document.myNewsletterForm;
	lForm.submitAction.value="update";
	lForm.submit();
}

function updateMyInterestsForm()
{
    var lForm = document.myInterestForm;
	lForm.submitAction.value="update";
	lForm.submit();
}

/******************************************
 Login
*******************************************/
function handlePasswordKeypress(pEvent)
{
  	var lEvent = (pEvent) ? pEvent : event;
  	var lCharCode = (lEvent.charCode) ? lEvent.charCode : ((lEvent.which) ? lEvent.which : lEvent.keyCode);
  	if (lCharCode == 13 || lCharCode == 3)
  	{
      	document.loginForm.submit();
      	return false;
  	}
  	return true;
}

function handleConfOrCCKeypress(pEvent, pForm)
{
  var lEvent = (pEvent) ? pEvent : event;
  var lCharCode = (lEvent.charCode) ? lEvent.charCode : ((lEvent.which) ? lEvent.which : lEvent.keyCode);
  if (lCharCode == 13 || lCharCode == 3)
  {
      pForm.submit();
      return false;
  }
  return true;
}

/******************************************
 Express Yourself
*******************************************/

function toggleShuttleSelection(pEnabled)
{
  	var lForm = document.checkInForm;
  	if (pEnabled == 'true')
  	{
    	lForm.shuttleUni.disabled = false;
		lForm.shuttleUni.className = '';
		lForm.airlineName.disabled = false;
		lForm.airlineName.className = '';
		lForm.flightNumber.disabled = false;
		lForm.flightNumber.className = '';
  	}
  	else
  	{
		lForm.shuttleUni.disabled = true;
		lForm.shuttleUni.className = 'disabled';
		lForm.airlineName.disabled = true;
		lForm.airlineName.className = 'disabled';
		lForm.flightNumber.disabled = true;
		lForm.flightNumber.className = 'disabled';
  	}	
}	

function toggleParkingSelection(pEnabled)
{
  	var lForm = document.checkInForm;	
  	if (pEnabled == 'true')
  	{
		lForm.vehicleType.disabled = false;
		lForm.vehicleType.className = '';
		lForm.vehicleType.options[1].selected = true;
		if (lForm.parkingType)
		{
	  		lForm.parkingType.disabled = false;
	  		lForm.parkingType.className = '';
		}
  	}
  	else
  	{
		lForm.vehicleType.disabled = true;
		lForm.vehicleType.className = 'disabled';
		lForm.vehicleType.options[0].selected = true;
		if (lForm.parkingType)
		{
	  		lForm.parkingType.disabled = true;
	  		lForm.parkingType.className = 'disabled';
	  		lForm.parkingType.options[0].selected = true;
		}
  	}	
}

function autoSelectWakeUpCall()
{
  	document.checkInForm.wakeUpCall.checked = true;
}

function setWakeUpCallTime(pFormField)
{
	var lValidMinuteDelimiters = new Array(" ", ":", ",", "-", "/", ".", ";", "|");
	var lTimeString = pFormField.value;
	var lHours = lTimeString;
	var lMinutes = "00";

	for (var i = 0; i < lValidMinuteDelimiters.length; i++)
	{
		var lIndex = lTimeString.indexOf(lValidMinuteDelimiters[i]);
		
		if (lIndex > 0)
		{
			lHours = lTimeString.substring(0, lIndex);
			lMinutes = lTimeString.substring(lIndex + 1, lTimeString.length);

			if (lMinutes == "")
			{
				lMinutes = "00";
			}
			else if (lMinutes.length < 2)
			{
				lMinutes = "0" + lMinutes;
			}

			break;
		}
	}

	// If there is no delimeter in the time field...
	if (lHours == lTimeString)
	{
		// See if it is 800
		if (lTimeString.length == 3)
		{
			lHours = lTimeString.substring(0, 1);
			lMinutes = lTimeString.substring(1,3);
		}
		// or maybe 1200
		else if (lTimeString.length == 4)
		{
			lHours = lTimeString.substring(0, 2);
			lMinutes = lTimeString.substring(2, 4);
		}
	}
	
	var lValidTimeString = lHours + ":" + lMinutes;
	var lTime = new Date("3/20/1963 " + lValidTimeString);

	pFormField.value = lValidTimeString;
	return true;
}

function performCheckin()
{
  	if (document.checkInForm.wakeUpCall.checked)
  	{
  		setWakeUpCallTime(document.checkInForm.wakeUpCallTime);
  	}
  	document.getElementById("checkinButtons").style.visibility='hidden';
  	document.checkInForm.submit();
}

function cancelEnrollment()
{
	document.createAccountForm.action.value = "cancel";
	document.createAccountForm.submit();
}

function createAccount()
{
	var lForm = document.createAccountForm;
	
	if (lForm.postal)
	{
		lForm.postal.value = RemoveInvalidPostalCodeCharacters(lForm.postal.value, lForm.country.options[lForm.country.selectedIndex].value);
	}
	if (lForm.countryPrefix)
	{
		lForm.countryPrefix.value = RemoveInvalidPhoneCharacters(lForm.countryPrefix.value);
	}
	if (lForm.areaCode)
	{
		lForm.areaCode.value = RemoveInvalidPhoneCharacters(lForm.areaCode.value);
	}
	if (lForm.phoneNumber)
	{
		lForm.phoneNumber.value = RemoveInvalidPhoneCharacters(lForm.phoneNumber.value);
	}
	if (lForm.GPNumber)
	{
		lForm.GPNumber.value = RemoveInvalidPhoneCharacters(lForm.GPNumber.value);
	}
	
	if (!isDblClick())
	{
		document.createAccountForm.submit();
	}
}

/******************************************
 GPP
*******************************************/

var lLastClickDate;
function isDblClick()
{
  	var lStatus = false;
  	var lThisClickDate = new Date();

  	if (lLastClickDate != null)
  	{
    	if ((lThisClickDate.getTime() - lLastClickDate.getTime()) < 2000)
		{
	  		lStatus = true;
		}
  	}

  	lLastClickDate = lThisClickDate;

  	return lStatus;
}

function goToFooterLink(pSelect)
{
	var lUrl = pSelect[pSelect.selectedIndex].value;
	var lTarget = "_blank";

	if (lUrl.indexOf("crossBrandEntry") > 0)
	{
		lTarget = "_top";
	}
			
	if (lUrl.substring(0,4) == "http")
	{
		window.open(lUrl, lTarget);
	}
	else if (lUrl.substring(0,3) == "www")
	{
		window.open("http://" + lUrl, lTarget);
	}
	else
	{
		window.open(lUrl, lTarget);
	}
}

function handleCarlsonSiteSelect()
{
	var lSiteOptions = document.carlsonSiteSelectForm.carlsonSiteSelect.options;
	var lSelectedOption = lSiteOptions[lSiteOptions.selectedIndex];
	if (lSelectedOption.value)
	{
		goToFooterLink(lSiteOptions);
	}
}

function moreOptions(pForm, pActionPath)
{
    var lForm = document.forms[pForm];
    lForm.action = pActionPath;
    lForm.submit();
}

function changeCountry()
{
  	var lForm = document.hotelSearchForm;
  	if (lForm.country.value != "" &&
  	    lForm.country.value != "US" &&
  	    lForm.country.value != "CA" &&
  	    lForm.country.value != "MX")
  	{
    	document.getElementById("stateprovince").style.display = "none";
    	document.getElementById("stateprovincelabel").style.display = "none";
  	}
  	else
  	{
    	document.getElementById("stateprovince").style.display = "";
    	document.getElementById("stateprovincelabel").style.display = "";
  	}
}

function toggleTabHighlight(pTabId, pInitialClassName)
{
    if (pInitialClassName == "inactivetab")
    {
    	var lClassName = document.getElementById(pTabId).className;
					
      	if (lClassName == pInitialClassName)
      	{
        	document.getElementById(pTabId).className = "activetab";
      	}
      	else
      	{
        	document.getElementById(pTabId).className = pInitialClassName;
      	}
    }
}
	
/******************************************
 Promo
*******************************************/

function showAllPromos()
{
  	document.localeform.onlyTranslatedPromos.value = "false";
  	document.localeform.submit();
}

/******************************************
 Booking Panel Functions
*******************************************/

function switchTabs(pSelectedElement, pEyFlag, pSetGppPromo)
{
  	if (pSelectedElement == "fah")
  	{
      	Element.show("fah");
      	Element.hide("res");
      
      	$("fahtd").className = "selected";
      	$("fahtd2").className = "selected";
      	$("vwrestd").className = "unselected";
      	$("vwrestd2").className = "";
      	if (pEyFlag == true)
      	{
      		if (pSetGppPromo == undefined)
      		{
      	    Element.hide("ey");
      	   }
        	$("eytd").className = "unselected";
        	$("eytd2").className = "";
      	}
    }
    if (pSelectedElement == "ey")
    { 	
      	if (pSetGppPromo == true)
      	{
	      	Element.show("fah");
	      	Element.hide("res");
      		$("promotionalCode").value = "redeemgp";
      	}
      	else
      	{
	      	Element.hide("fah");
	      	Element.show("ey");
	      	Element.hide("res");
      		$("promotionalCode").value = "";
      		document.eyBorgResForm.firstName.focus();
      	}

      	$("eytd").className = "selected";
      	$("fahtd").className = "unselected";
      	$("vwrestd").className = "unselected";
      	$("eytd2").className = "selected";
      	$("fahtd2").className = "";
      	$("vwrestd2").className = "";
    }
    if (pSelectedElement == "res")
    {
      	Element.hide("fah");
      	Element.show("res");

      	$("vwrestd").className = "selected";
      	$("fahtd").className = "unselected";
      	$("vwrestd2").className = "selected";
      	$("fahtd2").className = "";
      	if (pEyFlag == true)
      	{
      		if (pSetGppPromo == undefined)
      		{
      	    Element.hide("ey");
      	   }
        	$("eytd").className = "unselected";
        	$("eytd2").className = "";
      	}
      	document.findResForm.firstName.focus();
    }
}

/******************************************
 Multiple Room Functionality
*******************************************/

totalRooms = 9;
roomPrefix = "room";
function changeRooms(pNumRooms)
{
  	roomsSelected = new Number(pNumRooms.value);
  	for (i = 1; i <= totalRooms; i++)
  	{
    	if (i <= roomsSelected)
    	{
	  		document.getElementById(roomPrefix + i).style.display = "";
    	}
    	else
    	{
      		document.getElementById(roomPrefix + i).style.display = "none";
		}
  	}
}

/******************************************
 Reservation
*******************************************/

function selectGuaranteeMethod()
{
    var lForm = document.guestInfoForm;
    var lSelectedMethod = lForm.deposit.options[lForm.deposit.selectedIndex].value;

    lForm.cardType.selectedIndex = 0;
    lForm.cardNumber.value = "";
    lForm.cardExpireMonth.selectedIndex = 0;
    lForm.cardExpireYear.selectedIndex = 0;
    lForm.updateCards.checked = false;

    if (lSelectedMethod == "CO")
    {
        lForm.cardType.disabled = true;
        lForm.cardNumber.disabled = true;
        lForm.cardExpireMonth.disabled = true;
        lForm.cardExpireYear.disabled = true;
        lForm.updateCards.disabled = true;

        if (lForm.cardType.style)
        { 
        	// Check to see if browser supports styles
            lForm.cardType.style.backgroundColor="#cccccc";
            lForm.cardNumber.style.backgroundColor="#cccccc";
            lForm.cardExpireMonth.style.backgroundColor="#cccccc";
            lForm.cardExpireYear.style.backgroundColor="#cccccc";
            lForm.updateCards.style.backgroundColor="#cccccc";
        }
    }
    else
    {
        lForm.cardType.disabled = false;
        lForm.cardNumber.disabled = false;
        lForm.cardExpireMonth.disabled = false;
        lForm.cardExpireYear.disabled = false;
        lForm.updateCards.disabled = false;

         if (lForm.cardType.style)
         {  
            // Check to see if browser supports styles
            lForm.cardType.style.backgroundColor="#ffffff";
            lForm.cardNumber.style.backgroundColor="#ffffff";
            lForm.cardExpireMonth.style.backgroundColor="#ffffff";
            lForm.cardExpireYear.style.backgroundColor="#ffffff";
            lForm.updateCards.style.backgroundColor="#ffffff";
        }

        // Set the values back to their defaults on change
        for (ii=0; ii < lForm.cardType.length; ii++)
        {
            if (lForm.cardType.options[ii].defaultSelected)
            {
                lForm.cardType.selectedIndex = ii;
                break;
            }
        }

        lForm.cardNumber.value = lForm.cardNumber.defaultValue;

        for (ii=0; ii < lForm.cardExpireMonth.length; ii++)
        {
            if (lForm.cardExpireMonth.options[ii].defaultSelected)
            {
                lForm.cardExpireMonth.selectedIndex = ii;
                break;
            }
        }

        for (ii=0; ii < lForm.cardExpireYear.length; ii++)
        {
            if (lForm.cardExpireYear.options[ii].defaultSelected)
            {
                lForm.cardExpireYear.selectedIndex = ii;
                break;
            }
        }
    }
}

function submitHotelSearchForm(pShowInterimSearchPage)
{
	// a hack to make the animation gif works properly in IE is to submit the form first
	$('hotelSearchForm').submit();
	if (pShowInterimSearchPage)
	{
    	document.getElementById("bodydiv").style.display = "none";
      	document.getElementById("waitdiv").style.display = "";
      	document.getElementsByTagName("body")[0].className = "waitpage";
	}
}

function submitHotelSelectForm(pShowInterimSearchPage)
{
	// a hack to make the animation gif works properly in IE is to submit the form first
	$('hotelSelectForm').submit();
	if (pShowInterimSearchPage)
	{
    	document.getElementById("bodydiv").style.display = "none";
      	document.getElementById("waitdiv").style.display = "";
      	document.getElementsByTagName("body")[0].className = "waitpage";
	}
}

/********************************************
 WebExtra
*********************************************/

function processSideItinForm()
{
    if (document.resInfoForm.numberAdults)
    {
      	var lNumAdults = document.resInfoForm.numberAdults.options[document.resInfoForm.numberAdults.selectedIndex].value;
      	if (parseInt(lNumAdults) == 0)
      	{
        	lNumAdults = 1;
        	document.resInfoForm.numberAdults.options[1].selected = true;
      	}
    }
    	
    document.resInfoForm.submit();
}

function changeImage(pNewImage)
{
 	document.mainImage.src = pNewImage;
}

/********************************************
 Hot Deals
*********************************************/

function hotdealPopup(pForm)
{
	var lURL = "/hotdeals/currentavailability.do?nights=" + pForm.nights.value + "&hotelCode=" + pForm.hotelCode.value +
	           "&adultCount=" + pForm.adultCount.value + "&childCount=" + pForm.childCount.value +
			   "&startDate=" + pForm.startDate.value;
    OpenPopupWindow(lURL, "CurrentAvailability", 'no', 'Y', 621, 390, 'yes');
	//This delay here will allow it to work with Mozilla
	window.setTimeout("window.parent.close();", 500);
}

function makeReservation()
{
	window.setTimeout("window.parent.close();", 500);
    document.makeResEntranceForm.submit();
}

function updateCityList()
{
	var lForm = document.hotDealsRegionSearchForm;
	var lRegion = lForm.region.options[lForm.region.selectedIndex].value;
	lForm.cities.options.length = 0;
	for (bill = 0; bill < citiesRegionArray.length; bill++)
	{
		if (citiesRegionArray[bill] == lRegion)
		{
			lForm.cities.options[lForm.cities.options.length] = new Option(citiesDescriptionArray[bill], citiesValueArray[bill], 0, 0);
		}
	}
	return;
}

var citiesRegionArray = new Array();
var citiesValueArray = new Array();
var citiesDescriptionArray = new Array();
function createRegionArray(vRegion, vCity, vFixedCity, vState, vCountry, vCountryName, vStateName)
{
	var lCityNumber = citiesRegionArray.length;
	var lValue = vCity + "|" + vState + "|" + vCountry;
	var lDescription;

	if (vStateName == "")
	{
		lDescription = vCity + ", " + vCountryName;
	}
	else
	{
		lDescription = vCity + ", " + vStateName;
	}

	citiesRegionArray[lCityNumber] = vRegion;
	citiesValueArray[lCityNumber] = lValue;
	citiesDescriptionArray[lCityNumber] = lDescription;
}

/********************************************
 CCW Functions
*********************************************/

function brandChange()
{
  	document.brandForm.submit();
  	return true;
}

function returnHotelCode(pHotlcode)
{
  	parent.opener.document.resLookupForm.hotelCode.value = pHotlcode;
  	parent.close();
}

function returnPCRNumber(pCorpid)
{
  	parent.opener.document.hotelSearchForm.corporateAccountID.value = pCorpid;
  	parent.close();
}

/********************************************
 Omniture Tracking
*********************************************/

function omnitureCustomLink(pBrandName, pSuiteId)
{
    s_linkType='o';
    s_linkName='Referral to ' + pBrandName;
    s_eVar9=pBrandName;
    s_lnk=s_co(this);
    s_gs(pSuiteId);
}

/********************************************
 Plan an Event
*********************************************/

function changeEventResDate (pFormObj)
{
	var intEventSelected, intEventDate, intArriveSelected, intDepartSelected, intArriveDate, intDepartDate, intArriveMonth, intDepartMonth;
	var strEventMonth, strDepartMonth, strMonth, strYear, intCount;

	intEventSelected = pFormObj.eventDay.selectedIndex;
	intEventDate = pFormObj.eventDay[intEventSelected].value;
    intArriveSelected = pFormObj.checkinDay.selectedIndex;
	intArriveDate = pFormObj.checkinDay[intArriveSelected].value;
    intDepartSelected = pFormObj.checkoutDay.selectedIndex;
    intDepartDate = pFormObj.checkoutDay[intDepartSelected].value;

	if (intEventDate != "")
    {
        if (intArriveDate != intEventDate)
        {
            intArriveDate = intEventDate;
        }
        if (intDepartDate <= intArriveDate)
        {
            intDepartDate = intArriveDate;
            intDepartDate++;
        }

		intEventSelected = pFormObj.eventMonthYear.selectedIndex;
		strEventMonth	= pFormObj.eventMonthYear[intEventSelected].value;

		/* Get the arrive month name and loop over the month days array to match the value. */
		if (strEventMonth.length == 8)
		{
			strMonth = strEventMonth.substring(0, 3);
			intArriveYear = strEventMonth.substring(4, 8);

			for (intCount = 0; intCount < 12; intCount++)
			{
				if (strMonth == strMonthArray[intCount])
				{
					intArriveMonth = intCount;
				}
			}
		}

		intDepartMonth	= intArriveMonth;
		intDepartYear	= intArriveYear;

		/* Check to see if the new depart date is greater than the amount of available days. */
		if (intDepartDate > intDaysArray[intArriveMonth])
		{
			intDepartDate = 1;
			intDepartMonth++;

			if (intDepartMonth > 11)
			{
				intDepartMonth = 0;
				intDepartYear++;
			}
		}

		/* Select the dates according to the passed data. */
		pFormObj.checkinDay[intArriveDate].selected = true;
		strMonthDisplay = strMonthArray[intArriveMonth] + " " + intArriveYear;
		for (intCount = 0; intCount < pFormObj.checkinMonthYear.options.length; intCount++)
		{
			if (strMonthDisplay == pFormObj.checkinMonthYear[intCount].value)
			{
				pFormObj.checkinMonthYear[intCount].selected = true;
			}
		}
		
		pFormObj.checkoutDay[intDepartDate].selected = true;
        strMonthDisplay = strMonthArray[intDepartMonth] + " " + intDepartYear;
		for (intCount = 0; intCount < pFormObj.checkoutMonthYear.options.length; intCount++)
		{
			if (strMonthDisplay == pFormObj.checkoutMonthYear[intCount].value)
			{
				pFormObj.checkoutMonthYear[intCount].selected = true;
			}
		}
	}

	return;
}

/********************************************
 EDW
*********************************************/

function handleHotelCodeChange()
{
    var lHotelCodeSelect = $('hotelSelectForm').hotelCode;
    var lSelectedOption = lHotelCodeSelect[lHotelCodeSelect.selectedIndex];

    if (lSelectedOption.value == 'other-locations')
    {
      	window.location='/reservation/clearReservation.do';
    }
}

/********************************************
 Obsolet Functions
*********************************************/

function changeDepartDate (formObj)
{
  	var intSelected, intDepartSelected, intArriveDate, intDepartDate, intArriveMonth, intDepartMonth;
  	var strArriveMonth, strDepartMonth, strMonth, strYear, intCount;

  	intSelected = formObj.checkinDay.selectedIndex;
  	intArriveDate = formObj.checkinDay[intSelected].value;
  	intDepartSelected = formObj.checkoutDay.selectedIndex;
  	intDepartDate = formObj.checkoutDay[intDepartSelected].value;

  	if (intArriveDate != "")
  	{
    	if (intDepartDate <= intArriveDate)
    	{
        	intDepartDate = intArriveDate;
        	intDepartDate++;
    	}

		intSelected = formObj.checkinMonthYear.selectedIndex;
		strArriveMonth = formObj.checkinMonthYear[intSelected].value;

		/* Get the arrive month name and loop over the month days array to match the value. */
		if (strArriveMonth.length == 8)
		{
	  		strMonth = strArriveMonth.substring(0, 3);
	  		intArriveYear	= strArriveMonth.substring(4, 8);
	  
	  		for (intCount = 0; intCount < 12; intCount++)
	  		{
	    		if (strMonth == strMonthArray[intCount])
	    		{
		  			intArriveMonth = intCount;
	    		}
	  		}
		}
		else
		{
	  		intArriveYear	= strArriveMonth.substring(2, 6);
	  		intArriveMonth = Number(strArriveMonth.substring(0, 2)) - 1;
		}

		intDepartMonth = intArriveMonth;
		intDepartYear = intArriveYear;

		/* Check to see if the new depart date is greater than the amount of available days. */
		if (intDepartDate > intDaysArray[intArriveMonth])
		{
	  		intDepartDate = 1;
	  		intDepartMonth++;

	  		if (intDepartMonth > 11)
	  		{
				intDepartMonth = 0;
				intDepartYear++;
	  		}
		}

		/* Select the dates according to the passed data. */
		/* the values for customer service and reservations day option boxes are different */
		if (formObj.name == 'frmFeedback' || formObj.name == 'meetingRequestForm')
		{
			formObj.checkoutDay[intDepartDate].selected = true;
		}
		else
		{
	  		formObj.checkoutDay[intDepartDate-1].selected = true;
		}

		if (formObj.name == 'frmFeedback')
		{
	  		strMonthDisplay = strCSMonthArray[intDepartMonth] + intDepartYear;
		}
		else
		{
	  		strMonthDisplay = strMonthArray[intDepartMonth] + " " + intDepartYear;
		}

		for (intCount = 0; intCount < formObj.checkoutMonthYear.options.length; intCount++)
		{
	  		if (strMonthDisplay == formObj.checkoutMonthYear[intCount].value)
	  		{
				formObj.checkoutMonthYear[intCount].selected = true;
	  		}
		}
  	}
  
  	return;
}

function showCalendar(formObj, strType, strDirection)
{
  	var strMonth, intMonth, intYear, calWindow;
  	var loopCount, strURL;

  	if (strType == "event")
  	{
		strMonth = formObj.eventMonthYear[formObj.eventMonthYear.selectedIndex].value;
  	}
  	else if (strType == "altEvent")
  	{
		strMonth = formObj.altEventMonthYear[formObj.altEventMonthYear.selectedIndex].value;
  	}
  	else if (strType == "arrive")
  	{
		strMonth = formObj.checkinMonthYear[formObj.checkinMonthYear.selectedIndex].value;
  	}
  	else if (formObj.checkoutMonthYear)
  	{
		strMonth = formObj.checkoutMonthYear[formObj.checkoutMonthYear.selectedIndex].value;
  	}

  	if (strMonth != "")
  	{
		if (strMonth.length == 8)
		{
	  		intYear = strMonth.substring(4, 8);
	  		strMonth = strMonth.substring(0, 3);
      		for (i = 0; i < 12; i++)
	  		{
	    		if (strMonth == strMonthArray[i])
				{
		  			intMonth = i + 1;
				}
	  		}
		}
		else
		{
	  		intYear = strMonth.substring(2, 6);
	  		intMonth = Number(strMonth.substring(0, 2));
		}
		strURL = "/reservation/calendar.jsp?direction=" + strDirection + "&field=" + strType + "&month=" + intMonth + "&year=" + intYear + "&formName=document." + formObj.name;
  	}
  	else
  	{
		strURL = "/reservation/calendar.jsp?direction=" + strDirection + "&field=" + strType + "&formName=document." + formObj.name;
  	}

  	OpenPopupWindow(strURL, "Calendar", "no", "N");
  
  	return;
}

function getCalendarValues (fieldName, intDay, intMonth, intYear, formObj)
{
  	var arriveDate, arriveMonth, arriveYear;
  	var departDate, departMonth, departYear;
  
  	if (fieldName == "arrive")
  	{
    	arriveDate = intDay;
		arriveMonth	= intMonth - 1;
		arriveYear = intYear;
    
    	if (formObj.checkoutDay && formObj.checkoutMonthYear)
    	{
	  		departDate = Number(formObj.checkoutDay[formObj.checkoutDay.selectedIndex].value);
	  		departMonth = formObj.checkoutMonthYear[formObj.checkoutMonthYear.selectedIndex].value;
	  		if (departMonth.length == 8)
	  		{
	    		departYear = departMonth.substring(0, 3);
				departMonth = departMonth.substring(4, 8);
	  		}
	  		else
	  		{
	    		departYear = departMonth.substring(2, 6);
				departMonth = Number(departMonth.substring(0, 2)) - 1;
	  		}
		}
  	}
  	else
  	{
    	departDate = intDay;
		departMonth	= intMonth - 1;
		departYear = intYear;
    
    	arriveDate = Number(formObj.checkinDay[formObj.checkinDay.selectedIndex].value);
		arriveMonth	= formObj.checkinMonthYear[formObj.checkinMonthYear.selectedIndex].value;

    	if (arriveMonth.length == 8)
    	{
	  		arriveYear = arriveMonth.substring(0, 3);
	  		arriveMonth = arriveMonth.substring(4, 8);
		}
		else
		{
	  		arriveYear = arriveMonth.substring(2, 6);
	  		arriveMonth = Number(arriveMonth.substring(0, 2)) - 1;
		}
  	}
  
  	selectDates(formObj, arriveDate, departDate, arriveMonth, departMonth, arriveYear, departYear);
  
  	if (fieldName == "arrive" && formObj.checkoutDay && formObj.checkoutMonthYear)
  	{
		changeDepartDate(formObj);
  	}
  
  	return;
}

function selectDates (formObj, intArriveDate, intDepartDate, intArriveMonth, intDepartMonth, intArriveYear, intDepartYear)
{
  	var intCount, strMonthDisplay;
  	/* Select the dates according to the passed data. */
  	/* the values for customer service and reservations day option boxes are different */

  	if (formObj.name == 'frmFeedback' || formObj.name == 'meetingRequestForm')
  	{
		formObj.checkinDay.options[intArriveDate].selected = true;
		if (formObj.checkoutDay)
		{
	  		formObj.checkoutDay.options[intDepartDate].selected = true;
		}
  	}
  	else
  	{
		formObj.checkinDay.options[intArriveDate-1].selected = true;
		if (formObj.checkoutDay)
		{
	  		formObj.checkoutDay.options[intDepartDate-1].selected = true;
		}
  	}
  
  	/* Select the months according to the passed data. */
  	/* Loop through the options and find the matching one. */
  	if (formObj.name == 'frmFeedback')
  	{
		strMonthDisplay = strCSMonthArray[intArriveMonth] + intArriveYear;
  	}
  	else
  	{
		strMonthDisplay = strMonthArray[intArriveMonth] + " " + intArriveYear;
  	}

  	for (intCount = 0; intCount < formObj.checkinMonthYear.options.length; intCount++)
  	{
    	if (strMonthDisplay == formObj.checkinMonthYear[intCount].value)
		{
	  		formObj.checkinMonthYear[intCount].selected = true;
		}
  	}
  
  	if (formObj.name == 'frmFeedback')
  	{
    	strMonthDisplay = strCSMonthArray[intDepartMonth] + intDepartYear;
  	}
  	else
  	{
		strMonthDisplay = strMonthArray[intDepartMonth] + " " + intDepartYear;
  	}

  	if (formObj.checkoutMonthYear)
  	{
    	for (intCount = 0; intCount < formObj.checkoutMonthYear.options.length; intCount++)
    	{
	  		if (strMonthDisplay == formObj.checkoutMonthYear[intCount].value)
	  		{
				formObj.checkoutMonthYear[intCount].selected = true;
	  		}
		}
  	}
  
  	return;
}

function selectCity(formObj, pPrompt)
{
  	if (formObj.city.value == pPrompt)
  	{
		formObj.city.select();
  	}
}

function setAnonymous(pForm)
{
  	if (pForm.anonymousRequest.checked == true)
  	{
    	pForm.firstName.value = ""; pForm.firstName.disabled = true;
    	pForm.lastName.value = ""; pForm.lastName.disabled = true;
    	pForm.addressLine1.value = ""; pForm.addressLine1.disabled = true;
    	pForm.addressLine2.value = ""; pForm.addressLine2.disabled = true;
    	pForm.addressLine3.value = ""; pForm.addressLine3.disabled = true;
    	pForm.city.value = ""; pForm.city.disabled = true;
    	pForm.state.value = ""; pForm.state.disabled = true;
   	 	pForm.zipCode.value = ""; pForm.zipCode.disabled = true;
    	pForm.country.value = ""; pForm.country.disabled = true;
	    pForm.phoneCountryCode.value = ""; pForm.phoneCountryCode.disabled = true;
	    pForm.phoneAreaCode.value = ""; pForm.phoneAreaCode.disabled = true;
	    pForm.phoneNumber.value = ""; pForm.phoneNumber.disabled = true;
	    pForm.phoneExtension.value = ""; pForm.phoneExtension.disabled = true;
	    pForm.emailAddress.value = ""; pForm.emailAddress.disabled = true;
	    pForm.contactRequested[0].disabled = true;
	    pForm.contactRequested[1].disabled = true;
	    pForm.contactRequested[1].checked = true;
	    pForm.goldRewardsNumber.value = ""; pForm.goldRewardsNumber.disabled = true;
	}
	else
	{
	    pForm.firstName.disabled = false;
	    pForm.lastName.disabled = false;
	    pForm.addressLine1.disabled = false;
	    pForm.addressLine2.disabled = false;
	    pForm.addressLine3.disabled = false;
	    pForm.city.disabled = false;
	    pForm.state.disabled = false;
	    pForm.zipCode.disabled = false;
	    pForm.country.disabled = false;
	    pForm.phoneCountryCode.disabled = false;
	    pForm.phoneAreaCode.disabled = false;
	    pForm.phoneNumber.disabled = false;
	    pForm.phoneExtension.disabled = false;
	    pForm.emailAddress.disabled = false;
	    pForm.contactRequested[0].disabled = false;
	    pForm.contactRequested[1].disabled = false;
	    pForm.goldRewardsNumber.disabled = false;
	}
}

function showForecast(pShow)
{
    if (pShow)
    {
        Effect.SlideDown('forecast2');
        Effect.SlideDown('forecast3');
        Effect.Fade('showForecastLink');
        Effect.Appear('hideForecastLink');
    }
    else
    {
        Effect.SlideUp('forecast2');
        Effect.SlideUp('forecast3');
        Effect.Fade('hideForecastLink');
        Effect.Appear('showForecastLink');
    }
}

function addHotel()
{
	document.myAccountForm[1].action.value = "add";
    document.myAccountForm[1].submit();
}

function showStaticDetailDiv(pElementId)
{
    toggleSelects(true);    
    new Effect.BlindDown(pElementId);
}

function hideStaticDetailDiv(pElementId)
{
    toggleSelects(false);
    new Effect.BlindUp(pElementId);
}

function toggleSelects(pMakeHidden)
{
    var lSelectElements = document.body.getElementsByTagName("SELECT");
    var lVisible = pMakeHidden ? "hidden" : "visible";
    
    for(i = 0; i < lSelectElements.length; i++)
    {
    	var lSelect = lSelectElements[i];
    	lSelect.style.visibility = lVisible;
    }
}

function showDetailDiv(pElementId, pDataElementId, pUri, pParams)
{
    toggleSelects(true);    
    new Effect.BlindDown(pElementId);
    var myAjax = new Ajax.Updater(
             pDataElementId,
             pUri,
             {
                method: 'get',
                parameters: pParams
             })
}

function hideDetailDiv(pElementId, pDataElementId, pText)
{
    toggleSelects(false);
    new Effect.BlindUp(pElementId);
    setTimeout('$(\'' + pDataElementId + '\').innerHTML = \'' + pText + '\'', 2000);
}

function submitSpecialRates()
{
 $('specialRatesForm').submit();
}