﻿String.prototype.ellipsisString = function(length) {

    var result = this;
    if (this.length > length + 1) {
        result = result.substring(0, length);
        result = result.substring(0, result.lastIndexOf(' '));
        var lastChar = result.charAt(result.length - 1);
        if (lastChar == "." || lastChar == "," || lastChar == "-") {
            if (result.length > 1) {
                result = result.substring(0, result.length - 1);
            }
        }
        return result + "...";
    } else {
        return this;
    }

    return this + length;
}


function slideDate()
	{

	}



function isDate(dateStr) {

	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var datePat = /^(\d{4})(\-)(\d{1,2})(\-)(\d{1,2})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) {
		//alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
		return false;
	}
	year = matchArray[1];
	month = matchArray[3]; // p@rse date into variables
	day = matchArray[5];
	
	if (month < 1 || month > 12) { // check month range
		//alert("Month must be between 1 and 12.");
		return false;
	}

	if (day < 1 || day > 31) {
		//alert("Day must be between 1 and 31.");
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		//alert("Month "+month+" doesn`t have 31 days!")
		return false;
	}

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			//alert("February " + year + " doesn`t have " + day + " days!");
			return false;
		}
	}
	return true; // date is valid
}


//Yahoo Calendar
 function setupCal(checkin, checkout, checkinId, checkoutId, checkinCalId, checkoutCalId, numOfCal)
 {
    var theMindate = new Date();    
    var min_date = theMindate.getDate();  
    var min_month = theMindate.getMonth();
    min_month++;
    var min_year = theMindate.getFullYear();
    theMindate = min_month + "/" + min_date + "/" + min_year;    
    var theMaxdate = min_month + "/" + min_date + "/" + (min_year + 1);     
    
    //make yesterday selectable for checkin calendar(due to time zone differnce)
    var earlyMindate = new Date();
    earlyMindate.setDate(min_date -1);
    var early_month = earlyMindate.getMonth();
    early_month++;
    earlyMindate = early_month + "/" + earlyMindate.getDate() + "/" + earlyMindate.getFullYear();
    
    if (checkin == null || checkout == null)
    {
        checkin = dateFormat(min_month) + "/" + dateFormat(min_date) + "/" + min_year;
        checkout = checkin;
    }
    
    //get calendar selected date
    var checkinSelection = document.getElementById(checkinId).value == 0? checkout : reFormatDate(document.getElementById(checkinId).value);
    var checkoutSelection = document.getElementById(checkoutId).value == 0? checkout : reFormatDate(document.getElementById(checkoutId).value);    
    
    //get calendar seleted month
    var checkinCalPage =  checkin.substr(0,2) + checkin.substr(5,5);
    var checkoutCalPage =  checkout.substr(0,2) + checkout.substr(5,5);
    
    // setup checkin calendar
    var checkinCal = new YAHOO.widget.CalendarGroup("checkinCal",checkinCalId, 
                                                { pages:numOfCal, 
                                                  mindate:earlyMindate, 
                                                  maxdate:theMaxdate, 
                                                  navigator:true
                                                });                     
    checkinCal.cfg.setProperty("pagedate",checkinCalPage,false);  
    checkinCal.cfg.setProperty("selected", checkinSelection + ", " + checkoutSelection, false); 
    
    //add international features
    checkinCal.cfg.setProperty("MONTHS_LONG", monthsLong);                                             
    checkinCal.cfg.setProperty("WEEKDAYS_SHORT", weekdaysShort);         
    checkinCal.cfg.setProperty("MY_LABEL_YEAR_POSITION", myLabelYearPosition); 
    checkinCal.cfg.setProperty("MY_LABEL_MONTH_POSITION", myLabelMonthPosition);
    checkinCal.cfg.setProperty("MY_LABEL_YEAR_SUFFIX",  myLabelYearSuffix); 
    checkinCal.cfg.setProperty("MY_LABEL_MONTH_SUFFIX",  myLabelMonthSuffix); 
    checkinCal.render();     
       
    //set the input field as the calendar trigger        
    var checkinShow = document.getElementById(checkinId);
    YAHOO.util.Event.addListener(checkinShow, "click", checkinCal.show, checkinCal, true); 
    
    //handle calendar select event
    checkinCal.selectEvent.subscribe(checkinHandleSelect, checkinCal, true);
	checkinCal.hide();		     
    	
    function checkinHandleSelect(type,args,obj) {
        var dates = args[0];
        var date = dates[0];
        var year = date[0], month = dateFormat(date[1]), day = dateFormat(date[2]);
        var checkinDate = year + "-" + month + "-" + day;
        checkinSelection = month + "/" + day + "/" + year;
        document.getElementById(checkinId).value = checkinDate;        
        document.getElementById("checkinValue").value = checkinDate;
        document.getElementById("checkoutValue").value = document.getElementById(checkoutId).value;
        checkinCal.hide();
        
        //update checkout calendar start month according to checkin date
        checkinCalPage = date[1] + "/" + year;
        checkoutCal.cfg.setProperty("pagedate",checkinCalPage,false);    
        
        //update checkout calendar highlight dates
        if (document.getElementById(checkoutId).value != 0)
        {
            checkoutSelection = reFormatDate(document.getElementById(checkoutId).value);
        }         
        checkinCal.cfg.setProperty("selected", checkinSelection + ", " + checkoutSelection, false); 
        checkoutCal.cfg.setProperty("selected", checkinSelection + ", " + checkoutSelection, false);         
	    checkinCal.render();
	    checkoutCal.render();
    }
    
    // setup checkout calendar    
    var checkoutCal = new YAHOO.widget.CalendarGroup("checkoutCal",checkoutCalId, 
                                                { pages:numOfCal, 
                                                  mindate:theMindate, 
                                                  maxdate:theMaxdate, 
                                                  navigator:true
                                                });
    checkoutCal.cfg.setProperty("pagedate",checkoutCalPage,false);     
    checkoutCal.cfg.setProperty("selected", checkinSelection + ", " + checkoutSelection, false);
    
    //add international features 
    checkoutCal.cfg.setProperty("MONTHS_LONG", monthsLong);                                             
    checkoutCal.cfg.setProperty("WEEKDAYS_SHORT", weekdaysShort);    
    checkoutCal.cfg.setProperty("MY_LABEL_YEAR_POSITION", myLabelYearPosition); 
    checkoutCal.cfg.setProperty("MY_LABEL_MONTH_POSITION", myLabelMonthPosition);
    checkoutCal.cfg.setProperty("MY_LABEL_YEAR_SUFFIX",  myLabelYearSuffix); 
    checkoutCal.cfg.setProperty("MY_LABEL_MONTH_SUFFIX",  myLabelMonthSuffix);                                         
    checkoutCal.render();     
    
    //set the input field as the calendar trigger
    var checkoutShow = document.getElementById(checkoutId);
    YAHOO.util.Event.addListener(checkoutShow, "click", checkoutCal.show, checkoutCal, true); 
    
    //handle calendar select event
    checkoutCal.selectEvent.subscribe(checkoutHandleSelect, checkoutCal, true);
	checkoutCal.hide();
		
    function checkoutHandleSelect(type,args,obj) {
        var dates = args[0];
        var date = dates[0];
        var year = date[0], month = dateFormat(date[1]), day = dateFormat(date[2]);
        var checkoutDate = year + "-" + month + "-" + day;
        checkoutSelection = month + "/" + day + "/" + year;
        document.getElementById(checkoutId).value = checkoutDate;
        document.getElementById("checkinValue").value = document.getElementById(checkinId).value;
        document.getElementById("checkoutValue").value = checkoutDate;
        
        //update checkout calendar highlight dates
        if (document.getElementById(checkinId).value != 0)
        {
            checkinSelection = reFormatDate(document.getElementById(checkinId).value);
        }
	    checkinCal.cfg.setProperty("selected", checkinSelection + ", " + checkoutSelection, false); 
        checkoutCal.cfg.setProperty("selected", checkinSelection + ", " + checkoutSelection, false);         
	    checkinCal.render();
	    checkoutCal.render();   
	    
        checkoutCal.hide();    
    }    
    
    //hide calendar when user click anywhere outside the calendar
    function hideDiv(e){
        var target=(e?e.target:event.srcElement);
        var checkinCalDiv =document.getElementById(checkinCalId);
        var checkinDiv =document.getElementById(checkinId);
        var checkoutCalDiv =document.getElementById(checkoutCalId);
        var checkoutDiv =document.getElementById(checkoutId);
        if(checkinCalDiv != null && checkinDiv != null && checkoutCalDiv != null && checkoutDiv != null)
        {
            (isChild(target,checkinCalDiv) || target == checkinDiv) ? null : checkinCalDiv.style.display='none';
            (isChild(target,checkoutCalDiv) || target == checkoutDiv) ? null : checkoutCalDiv.style.display='none';
        }
        
        //if it is hotel page, set additional visibility control for the calendars on rate tab
        if (document.getElementById("detailTabCheckin") != null || document.getElementById("rateTabCheckin") != null)
        {
            hideHotelDiv(e)
            hideRateDiv(e)
        }
    }
    document.onclick=hideDiv
}

//change date format from yyyy-mm-dd to mm/dd/yyyy
function reFormatDate(date)
{
    var year = date.substr(0,4);
    var month = date.substr(5,2);
    var day = date.substr(8,2);
    return month + "/" + day + "/" + year;
}

function dateFormat(date)
{
    return date.toString().length == 1? "0" + date: date;
}

//check if child is a childNode of parent
function isChild(child, parent) {
	while(child) {
		if (child == parent) 
			return true;
		child = child.parentNode;
	}
	return false;
}

// visibility control for hotel.aspx page rate tab first calendar
function hideHotelDiv(e){
    var target=(e?e.target:event.srcElement);
    var checkinCalDiv =document.getElementById("CheckinCalContainer");
    var checkinDiv =document.getElementById("hotelCheckin");
    var checkoutCalDiv =document.getElementById("CheckoutCalContainer");
    var checkoutDiv =document.getElementById("hotelCheckout");
    if(checkinCalDiv != null && checkinDiv != null && checkoutCalDiv != null && checkoutDiv != null)
    {
        (isChild(target,checkinCalDiv) || target == checkinDiv) ? null : checkinCalDiv.style.display='none';
        (isChild(target,checkoutCalDiv) || target == checkoutDiv) ? null : checkoutCalDiv.style.display='none';
    }
}
// visibility control for hotel.aspx page rate tab second calendar.
function hideRateDiv(e){
    var target=(e?e.target:event.srcElement);
    var checkinCalDiv =document.getElementById("rateTabCheckinCalContainer");
    var checkinDiv =document.getElementById("rateTabCheckin");
    var checkoutCalDiv =document.getElementById("rateTabCheckoutCalContainer");
    var checkoutDiv =document.getElementById("rateTabCheckout");
    if(checkinCalDiv != null && checkinDiv != null && checkoutCalDiv != null && checkoutDiv != null)
    {
        (isChild(target,checkinCalDiv) || target == checkinDiv) ? null : checkinCalDiv.style.display='none';
        (isChild(target,checkoutCalDiv) || target == checkoutDiv) ? null : checkoutCalDiv.style.display='none';
    }
}

function DoSearch(languageCode, target, affiliateId, city, domain, brandId, customData) {

    var redirection;
    var affiliateParam;
    var brandParam;
    var host;
    if (document.getElementById("defaultCityName") != null) {
        city = document.getElementById("defaultCityName").value;
    }
    if (document.getElementById('hotelCheckin') != null)
    {
        if (document.getElementById('hotelCheckin').value == 0 ||
            document.getElementById('hotelCheckout').value == 0 ||
            document.getElementById('hotelCheckin').value == 'Check-in' ||
            document.getElementById('hotelCheckout').value == 'Check-out' ||
            document.getElementById('hotelCheckin').value == 'Check in' || 
            document.getElementById('hotelCheckout').value == 'Check out')
        {
		    alert(typeof(JavaScriptEnterCheckinCheckout) == 'undefined' ? 'Please enter your checkin and checkout date.' : JavaScriptEnterCheckinCheckout)
            return false
        }
        else
        {
			document.getElementById("checkinValue").value = document.getElementById("hotelCheckin").value;
			document.getElementById("checkoutValue").value = document.getElementById("hotelCheckout").value;
        }
    }

    document.getElementById("checkinValue").value = document.getElementById("hotelCheckin").value;
    document.getElementById("checkoutValue").value = document.getElementById("hotelCheckout").value;

    if (!ValidateDates()) {
        return false;
    }



    city = escape(city);
    if (typeof(brandId) == 'undefined' || brandId == "0" || brandId == "")
    {
		brandParam = '';
    }
    else
    {
        brandParam = '&brandId=' + brandId;
    }
    if (affiliateId == null || affiliateId == '')
    {
        affiliateParam = '';
        host = '';
    }
    else
    {
        affiliateParam = '&a_aid=' + affiliateId;
    }
	// backwards compatability for existing affiliate scripts
	if (typeof(domain) == 'undefined' || domain == '')
	{
		host = 'http://www.hotelscombined.com'	
	}
	else
	{
		host = 'http://' + domain;
	}
    
    var defaultSort = GetQSVal("sort");
    if (defaultSort.length > 0)
    {
		defaultSort = "&sort=" + defaultSort;
    }

    //if come from home page or come from city/searchResult pages with a new city name entered in the 'City' textbox
    //if ((document.getElementById("citySearchRadio") != null && document.getElementById("citySearchRadio").checked) || document.getElementById("M_C_SearchResultCity") != null) {
    if (document.getElementById("selectedFileName").value == null || document.getElementById("selectedFileName").value == ""){




        if (city == null || city.length < 3 || city.toLowerCase().indexOf(escape('city name')) >= 0) {
            alert(typeof(JavaScriptEnterCityName) == 'undefined' ? 'Please enter a city name that is at least 3 characters in length' : JavaScriptEnterCityName);
            return false;
        }
        redirection = "/Search.aspx?search=" + city + "&checkin=" + document.getElementById("checkinValue").value + "&checkout=" + document.getElementById("checkoutValue").value + "&languageCode=" + languageCode + affiliateParam + brandParam + defaultSort;
        
        //if come from city or search result pages, add query info
        if (document.getElementById("M_C_SearchResultCity") != null)
        {        
            var currency = document.getElementById("M_C_currencies");
            redirection += currency == null? "":"&currencyCode=" + currency.options[currency.selectedIndex].id;               
	
	        if (document.getElementById("M_C_LowRate") != null)
            {
                if(document.getElementById("M_C_LowRate").value != null && document.getElementById("M_C_LowRate").value != 0)
                {
                    redirection += "&lowRate=" + escape(document.getElementById("M_C_LowRate").value);                
                }            
            }
            if (document.getElementById("M_C_HighRate") != null)
            {
                if(document.getElementById("M_C_HighRate").value != null && document.getElementById("M_C_HighRate").value != 0)
                {
                    redirection += "&highRate=" + escape(document.getElementById("M_C_HighRate").value);               
                }            
            }            
                      
            redirection += GetStarValue(redirection, document.getElementById("M_C_Star5"), "star5");
            redirection += GetStarValue(redirection, document.getElementById("M_C_Star4"), "star4");
            redirection += GetStarValue(redirection, document.getElementById("M_C_Star3"), "star3");
            redirection += GetStarValue(redirection, document.getElementById("M_C_Star2"), "star2");
            redirection += GetStarValue(redirection, document.getElementById("M_C_Star1"), "star1");
            redirection += "&cityName=" + city; 
            
            if (document.getElementById("M_C_HotelName") != null)
            {
                if(document.getElementById("M_C_HotelName").value != null && document.getElementById("M_C_HotelName").value != 0)
                {
                    redirection += "&hotelName=" + escape(document.getElementById("M_C_HotelName").value);                
                }            
            }      
            
            if (document.getElementById("M_C_ShowSoldOut") != null) {
                redirection += document.getElementById("M_C_ShowSoldOut").checked? "":"&showSoldOut=false"; 
            }        
	         
	        if(document.getElementById("M_C_ShowOnRequest") != null){
	            redirection += document.getElementById("M_C_ShowOnRequest").checked? "":"&showOnRequest=false"; 
	        }	        
        }        
    } else {
        redirection = "/SearchResults.aspx?fileName=" + document.getElementById("selectedFileName").value + "&checkin=" + document.getElementById("checkinValue").value + "&checkout=" + document.getElementById("checkoutValue").value + "&languageCode=" + languageCode + affiliateParam + brandParam + defaultSort;
    }
        
    redirection += document.getElementById("guestValue") == null? "":"&Adults=" + document.getElementById("guestValue").value;
    redirection += document.getElementById("roomValue") == null ? "" : "&Rooms=" + document.getElementById("roomValue").value;

    redirection += document.getElementById("searchCountryCode") == null ? "" : "&countryCode=" + document.getElementById("searchCountryCode").value;
    redirection += document.getElementById("searchStateCode") == null ? "" : "&stateCode=" + document.getElementById("searchStateCode").value;

    if (document.getElementById("M_C_HotelFacility1") != null) {
        var facility = "";
        for (var i=1; i<=11; i++){
            if(document.getElementById("M_C_HotelFacility"+ i).checked){
                facility += i + ',';
            }
        }	
        if(facility != ""){
            var strLen = facility.length;
            facility = facility.slice(0,strLen-1);
            redirection += "&facilities="+ facility;
        }

    }
    if (customData != "") {
        if (customData.indexOf("label=") >= 0) {
            //The label parameter has already been added
            customData = customData.replace("?label=", "&label=");
        }
        else {
            customData = "&label=" + customData;
        }
        
    }
    redirection = host + redirection + customData;
    switch (target)
    {
        case "_blank":
            window.open(redirection).focus();
            break;
        case "_parent":
            window.parent.location = redirection;
            break;
        case "_top":
            window.top.location = redirection;
            break;
        default:
            window.location = redirection; // _self
    }
    
    return false;
}

function DoHotelSearch(languageCode, target, affiliateId, hotelFileName, domain, brandId, customData) {
    var affiliateParam;
    var host;
    var brandParam;
    
    if (document.getElementById('hotelCheckin') != null)
    {
        if(document.getElementById('hotelCheckin').value == 0 || document.getElementById('hotelCheckout').value == 0 )
        {
		    alert(typeof(JavaScriptEnterCheckinCheckout) == 'undefined' ? 'Please enter your checkin and checkout date.' : JavaScriptEnterCheckinCheckout)
            return false
        }
        else
        {
			document.getElementById("checkinValue").value = document.getElementById("hotelCheckin").value;
			document.getElementById("checkoutValue").value = document.getElementById("hotelCheckout").value;
        }
    }
    
    if (typeof(brandId) == 'undefined' || brandId == "0" || brandId == "")
    {
		brandParam = '';
    }
    else
    {
		brandParam = '&brandId=' + brandId
}

    if (customData != "") {
        customData = "&label=" + customData;
    }
    
    if (affiliateId == null || affiliateId == '')
    {
        affiliateParam = '';
        host = '';
    }
    else
    {
        affiliateParam = '&a_aid=' + affiliateId;   
		// backwards compatability for existing affiliate scripts
    }
    
    if (typeof (domain) == 'undefined' || domain == '') {
        host = 'http://www.hotelscombined.com'
    }
    else {
        host = 'http://' + domain;
    }
    
    var guest = document.getElementById('guestValue') == null? "":"&Adults=" + document.getElementById("guestValue").value;
    var room  = document.getElementById('roomValue') == null? "" :"&Rooms=" + document.getElementById('roomValue').value;
    
    var redirection = host + "/Hotel.aspx?tabId=Rates&fileName=" + hotelFileName + "&checkin=" + document.getElementById("checkinValue").value + "&checkout=" + document.getElementById("checkoutValue").value + "&languageCode=" + languageCode + affiliateParam + brandParam + guest + room + customData;
    
    switch (target)
    {
        case "_blank":
            window.open(redirection).focus();
            break;
        case "_parent":
            window.parent.location = redirection;
            break;
        case "_top":
            window.top.location = redirection;
            break;
        default:
            window.location = redirection; // _self
    }
    
    return false;
}

function GetStarValue (qString, starElement, starName)
{
	if (starElement == null || starElement.checked)
	{	    
	    return "";        
	}else
	{
	    return "&" + starName + "=false" ;
	}
}

// validate dates
function ValidateDates() {

    var inDate = getDate(document.getElementById("checkinValue").value);
    var outDate = getDate(document.getElementById("checkoutValue").value);
    var currentDate = new Date();
    
	//validate checkin - checkout difference (date range too big)
	if ((outDate - inDate)/86400000 >= 31) {  //86400000 is one days in milliseconds
		alert(typeof(JavaScriptPeriodOfStay) == 'undefined' ? 'Your period of stay should be no longer than 30 nights.' : JavaScriptPeriodOfStay)
		return false
	}

    // validate checkout <= checkin
	if (outDate - inDate <= 0) {
		alert(typeof(JavaScriptEnsureCheckoutAfterCheckin) == 'undefined' ? 'Please ensure that the check-out date is after the check-in date.' : JavaScriptEnsureCheckoutAfterCheckin)
		return false
	}

    //validate checkin/checkout is less than one year in advance
    if((outDate - currentDate)/86400000 >= 363) {
		alert(typeof(JavaScriptBookWithinOneYear) == 'undefined' ? 'You cannot book more than 1 year in advance.' : JavaScriptBookWithinOneYear)
        return false;
    }
    
	return true
}

function getDate(dateString) {
    var year = dateString.substr(0,4)
    var month = dateString.substr(5,2) - 1 // 0 - 11
    var day = dateString.substr(8, 2)
    return new Date(year,month,day)
}

//extract (first!) value from querystring for the passed name
function GetQSVal(qsName) {
	try
	{
		var qsPair
		var i
		var qString = location.search.substr(1)
		
		if (qString == null || qString.length == 0)
			qString = query;
		    
		var arrNameVal = qString.split('&')
		//for (i in arrNameVal) {	
		for(i=0; i<arrNameVal.length; i++){
			qsPair = arrNameVal[i].split('=')
			if (URLDecode(qsPair[0]).toLowerCase() == qsName.toLowerCase()) return URLDecode(qsPair[1])
		}
	}
	catch(e)
	{
	}
	return ""
}

function setRoomValue(select, isAffiliate)
{
    if(select.value == "5" && isAffiliate == false)
    {
        select.selectedIndex = 0;
        var r = confirm(typeof(JavaScriptSearchMoreRoom) == 'undefined' ? 'We only support searching for up to four rooms at once, would you like to use our partner site Hotelplanner.com to search for more rooms?' : JavaScriptSearchMoreRoom);
        if (r== true)
        {
            var qString =  "?sc=HotelsCombined"; 
                city = "",
                checkin = "",
                checkout = "";
            
            //if on city or searchResults page
            if ( document.getElementById("M_C_SearchResultCity") != null && document.getElementById("M_C_SearchResultCity").value != 0) 
            {
                city = document.getElementById("M_C_SearchResultCity").value;
            }
            else
            {
                //if on hotel page
                if ( document.getElementById("cityNameValue") != null && document.getElementById("cityNameValue").value != 0) 
                {
                    city = document.getElementById("cityNameValue").value;
                }
            }
            
            //get user selected checkin and ckeckout value
            if (( document.getElementById("hotelCheckin") != null && document.getElementById("hotelCheckin").value != 0) ||
                ( document.getElementById("detailTabCheckin") != null && document.getElementById("detailTabCheckin").value != 0) ||
                ( document.getElementById("rateTabCheckin") != null && document.getElementById("rateTabCheckin").value != 0))
            {
                var checkinDom = document.getElementById("checkinValue");
                checkin = checkinDom == null? "" : checkinDom.value == 0? "" : reFormatDate (checkinDom.value);
            }              
            if (( document.getElementById("hotelCheckout") != null && document.getElementById("hotelCheckout").value != 0) ||
                ( document.getElementById("detailTabCheckout") != null && document.getElementById("detailTabCheckout").value != 0) ||
                ( document.getElementById("rateTabCheckout") != null && document.getElementById("rateTabCheckout").value != 0))
            {
                var checkoutDom = document.getElementById("checkoutValue");
                checkout = checkoutDom == null? "" : checkoutDom.value == 0? "" : reFormatDate (checkoutDom.value);
            }  
            
            qString += city == ""? "" : "&City=" + city;
            qString += checkin == ""? "" : "&Checkin=" + checkin;
            qString += checkout == ""? "" : "&Checkout=" + checkout;
            window.open("/ProviderRedirect.aspx?key=2.HPL.EN.USD.0.0.0&url=" + escape("http://www.hotelplanner.com" + qString), "_self");
            return false;
        }
    }
    else
    {
        document.getElementById('roomValue').value = select.options[select.selectedIndex].value;       
    }
     return false;
}

function setGuestValue(select)
{
    document.getElementById('guestValue').value = select.options[select.selectedIndex].value;
    return false;
}

/* --- Swazz Javascript Calendar ---
/* --- v 1.0 3rd November 2006
By Oliver Bryant
http://calendar.swazz.org */


/*
The task is to create a globally customizeable calendar, almost like a class, with ptoperties;
*/

//Seperator
//Enable Date From
//Enable Date To
//Visible Date From
//Visible Date To (ability to display like 3 month at once)
//Have highlights for "current day" - optional
//Have highlights for "selected day" - optional
var seperator = '-';

var enableDateFrom = new Date();
var enableDateTo = new Date();
//enableDateTo.setMonth(enableDateTo.getMonth() + 1);
//enableDateTo.setDate(enableDateTo.getDate() - 1);
enableDateFrom.setDate(enableDateFrom.getDate() - 1);
enableDateTo.setFullYear(enableDateTo.getFullYear() + 1);

function getObj(objID)
{
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}

function checkClick(e) {
	e?evt=e:evt=event;
	CSE=evt.target?evt.target:evt.srcElement;
	if (getObj('fc'))
		if (!isChild(CSE,getObj('fc')))
			getObj('fc').style.display='none';
}

function isChild(s,d) {
	while(s) {
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}

function Left(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
	
document.write('<table id="fc" style="position:absolute;top:10px;left:100px;border-collapse:collapse;background:#FFFFFF;border:1px solid #ABABAB;z-index:99999;display:none" cellpadding=2>');
document.write('<tr><td style="cursor:pointer" onclick="csubm()"><img src="http://affiliates.hotelscombined.com/StyleImages/arrowleftmonth.gif"></td><td colspan=5 id="mns" align="center" style="font:bold 13px Arial"></td><td align="right" style="cursor:pointer" onclick="caddm()"><img src="http://affiliates.hotelscombined.com/StyleImages/arrowrightmonth.gif"></td></tr>');
document.write('<tr><td align=center style="background:#ABABAB;font:12px Arial">S</td><td align=center style="background:#ABABAB;font:12px Arial">M</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">W</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">F</td><td align=center style="background:#ABABAB;font:12px Arial">S</td></tr>');
for(var kk=1;kk<=6;kk++) {
	document.write('<tr>');
	for(var tt=1;tt<=7;tt++) {
		num=7 * (kk-1) - (-tt);
		document.write('<td id="v' + num + '" style="width:18px;height:18px">&nbsp;</td>');
	}
	document.write('</tr>');
}
document.write('</table>');

document.all?document.attachEvent('onclick',checkClick):document.addEventListener('click',checkClick,false);


// Calendar script
var now = new Date;
var sccm=now.getMonth();
var sccy=now.getFullYear();
var ccm=now.getMonth();
var ccy=now.getFullYear();

var updobj;
function lcs(ielem) {
	updobj=ielem;
	var calendarTable = document.getElementById("fc");
	//alert(calendarTable.offsetTop);
	calendarTable.style.top = parseInt((Top(ielem) + 22)) + "px";
	calendarTable.style.left = Left(ielem) + "px";
	getObj('fc').style.left=Left(ielem);
	getObj('fc').style.top=Top(ielem)+ielem.offsetHeight;
	getObj('fc').style.display='';
	
	// First check date is valid
	curdt=ielem.value;
	curdtarr=curdt.split(seperator);
	isdt=true;
	for(var k=0;k<curdtarr.length;k++) {
		if (isNaN(curdtarr[k]))
			isdt=false;
	}
	if (isdt&(curdtarr.length==3)) {
		ccm=curdtarr[1]-1;
		ccy=curdtarr[0];
		prepcalendar(curdtarr[2],curdtarr[1]-1,curdtarr[0]);
		//prepcalendar(curdtarr[0],curdtarr[1]-1,curdtarr[2]);
	}
	
}

function evtTgt(e)
{
	var el;
	if(e.target)el=e.target;
	else if(e.srcElement)el=e.srcElement;
	if(el.nodeType==3)el=el.parentNode; // defeat Safari bug
	return el;
}
function EvtObj(e){if(!e)e=window.event;return e;}
function cs_over(e) {
	evtTgt(EvtObj(e)).style.background='#FFCC66';
}
function cs_out(e) {
	evtTgt(EvtObj(e)).style.background='#C4D3EA';
}
function cs_click(e) {
    updobj.value = calvalarr[evtTgt(EvtObj(e)).id.substring(1, evtTgt(EvtObj(e)).id.length)];
	getObj('fc').style.display='none';
	
}

var mn=new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
var mnn=new Array('31','28','31','30','31','30','31','31','30','31','30','31');
var mnl=new Array('31','29','31','30','31','30','31','31','30','31','30','31');
var calvalarr=new Array(42);

function f_cps(obj) {
	obj.style.background='#C4D3EA';
	obj.style.font='10px Arial';
	obj.style.color='#333333';
	obj.style.textAlign='center';
	obj.style.textDecoration='none';
	obj.style.border='1px solid #6487AE';
	obj.style.cursor='pointer';
}

function f_cpps(obj) {
	obj.style.background='#C4D3EA';
	obj.style.font='10px Arial';
	obj.style.color='#ABABAB';
	obj.style.textAlign='center';
	obj.style.textDecoration='line-through';
	obj.style.border='1px solid #6487AE';
	obj.style.cursor='default';
}

function f_hds(obj) {
	obj.style.background='#FFF799';
	obj.style.font='bold 10px Arial';
	obj.style.color='#333333';
	obj.style.textAlign='center';
	obj.style.border='1px solid #6487AE';
	obj.style.cursor='pointer';
}



// day selected
function prepcalendar(hd,cm,cy) {
	now=new Date();
	sd=now.getDate();
	td=new Date();
	td.setDate(1);
	td.setFullYear(cy);
	td.setMonth(cm);
	cd=td.getDay();
	getObj('mns').innerHTML=mn[cm]+ ' ' + cy;
	marr=((cy%4)==0)?mnl:mnn;
		for(var d=1;d<=calvalarr.length;d++) {
		f_cps(getObj('v'+parseInt(d)));
		if ((d >= (cd -(-1))) && (d<=cd-(-marr[cm]))) {
			var currentDate = new Date(cy, cm, d-cd);
			dip = !((currentDate >= enableDateFrom) && (currentDate <= enableDateTo));
			
			//dip=((d-cd < sd)&&(cm==sccm)&&(cy==sccy));
			htd=((hd!='')&&(d-cd==hd));
			if (dip)
			{
				f_cpps(getObj('v'+parseInt(d)));
			}
			else if (htd)
			{
				f_hds(getObj('v'+parseInt(d)));
			}
			else
			{
				f_cps(getObj('v'+parseInt(d)));
			}

			getObj('v'+parseInt(d)).onmouseover=(dip)?null:cs_over;
			getObj('v'+parseInt(d)).onmouseout=(dip)?null:cs_out;
			getObj('v'+parseInt(d)).onclick=(dip)?null:cs_click;

			getObj('v' + parseInt(d)).innerHTML = d - cd;

			var currentMonth = (cm - (-1));
			var currentMonthString = "";
			if (currentMonth < 10) {
			    currentMonthString = "0" + currentMonth;
			}
			else {
			    currentMonthString = currentMonth;
			}
			calvalarr[d]=''+cy+seperator+currentMonthString+seperator+(d-cd);
		}
		else {
			getObj('v'+d).innerHTML='&nbsp;';
			getObj('v'+parseInt(d)).onmouseover=null;
			getObj('v'+parseInt(d)).onmouseout=null;
			getObj('v'+parseInt(d)).style.cursor='default';
			}
	}
}

prepcalendar('',ccm,ccy);
//getObj('fc'+cc).style.visibility='hidden';

function caddm() {

	marr=((ccy%4)==0)?mnl:mnn;
	
	ccm+=1;
	if (ccm>=12) {
		ccm=0;
		ccy++;
	}
	//cdayf();
	prepcalendar(0,ccm,ccy);
}

function csubm() {
	marr=((ccy%4)==0)?mnl:mnn;
	
	ccm-=1;
	if (ccm<0) {
		ccm=11;
		ccy--;
	}
	//cdayf();
	prepcalendar(0,ccm,ccy);
}

function cdayf() {
if ((ccy>sccy)|((ccy==sccy)&&(ccm>=sccm)))
	return;
else {
	ccy=sccy;
	ccm=sccm;
	cfd=scfd;
	}
}
