﻿var currentTabId = 0;
var chinc=0;
var ckout=0;
function setInVlue(bb)
{
	chinc=bb;
}
function setOutVlue(pv)
{	
	ckout=pv;
}
function TabTabs(tabId) {
    currentTabId = tabId;

    for (i = 0; i < tabCount; i++)
    {
        if (i == currentTabId)
        {
            document.getElementById("tabCell1-" + i).className = "dark";
            document.getElementById("tabCell2-" + i).className = "dark";
            document.getElementById("tabCell3-" + i).className = "dark";
            
            var temp1 = document.getElementById("tabImageLeft-" + i); // null for whitelabel
            if (temp1 != null)
            {
                temp1.src = "/Images/c_b_tl.gif";
            }
            var temp2 = document.getElementById("tabImageRight-" + i);
            if (temp2 != null)
            {
                temp2.src = "/Images/c_b_tr.gif";
            }
            document.getElementById("tabData" + i).style.display = "";
            document.getElementById("tabLink" + i).className = "tabSelected";
        }
        else
        {
            document.getElementById("tabCell1-" + i).className = "light";
            document.getElementById("tabCell2-" + i).className = "light";
            document.getElementById("tabCell3-" + i).className = "light";
            
            var temp3 = document.getElementById("tabImageLeft-" + i);
            if (temp3 != null)
            {
                temp3.src = "/Images/c_p_tl.gif";
            }
            var temp4 = document.getElementById("tabImageRight-" + i)
            if (temp4 != null)
            {
                temp4.src = "/Images/c_p_tr.gif";
            }
            document.getElementById("tabData" + i).style.display = "none";
            document.getElementById("tabLink" + i).className = "tabUnSelected";
        }
    }
    
    if (tabId == 4 && mapSource.length > 0) // && !mapAlreadyShown
    {		
		setTimeout("HideMapLoading()", 3000);		
		document.getElementById("mapFrame").src = mapSource;
		mapAlreadyShown = true;
    }
    
}
function TabTabsNew(tabId) {
    currentTabId = tabId;

    for (i = 0; i < tabCount; i++)
    {
        if (i == currentTabId)
        {
			document.getElementById("tab" + i).className = "active";
			document.getElementById("tab" + i).blur();
			document.getElementById("tabData" + i).style.display = "";
        }
        else
        {
			document.getElementById("tab" + i).className = "";
			document.getElementById("tabData" + i).style.display = "none";
        }
    }
    
    if (tabId == 4 && mapSource.length > 0) // && !mapAlreadyShown
    {
		setTimeout("HideMapLoading()", 3000);
		document.getElementById("mapFrame").src = mapSource;
		mapAlreadyShown = true;
    }
    
}
function HideMapLoading()
{
	document.getElementById("LoadingMaps").style.display = "none";
}

function ChangeDates() {

    if (!ValidateDates())
        return false
    
	var qString = location.search.substr(1)
	
	if (qString == null || qString.length == 0 || qString.indexOf("gclid=") >= 0)
	    qString = query;

	qString = setQStringName(qString, 'checkin', new Array(document.getElementById("checkinValue").value))
	qString = setQStringName(qString, 'checkout', new Array(document.getElementById("checkoutValue").value))
    var page = GetQSVal("pageIndex")
	if (page != "0" && page != "") qString = setQStringName(qString, "pageIndex", new Array("0"))	
	
	if (path != null && path.length > 0)
	    location = path + "?" + qString
	else	
	    location = location.pathname + "?" + qString
	
	return 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 SetupCalendars() {
	var currentYear = new Date().getFullYear();
	
    var nextYear = currentYear +  1;

    // checkin calendar
    Calendar.setup({
        inputField     : "checkinValue",
        ifFormat       : "%Y-%m-%d",
        button         : "checkinTrigger",
        weekNumbers    : false,
        onUpdate       : checkinCalendarUpdated,
       // dateStatusFunc : disabledStatus,
        range          : [currentYear, nextYear]
    });
    
    // checkout calendar
    Calendar.setup({
        inputField     : "checkoutValue",
        ifFormat       : "%Y-%m-%d",
        button         : "checkoutTrigger",
        weekNumbers    : false,
        onUpdate       : checkoutCalendarUpdated,
       // dateStatusFunc : disabledStatus,
        range          : [currentYear, nextYear]
    });
}

function disabledStatus (calDate) {
    if (calDate - new Date()  < 0)
        return true;    
    return false;
}

function checkinCalendarUpdated(cal) {
    if (cal.dateClicked) {
        document.getElementById("checkinMonth").selectedIndex = cal.date.getMonth();
        document.getElementById("checkinDay").selectedIndex = (cal.date.getDate() - 1);
        cal.hide();
        checkinUpdated();
    }
}

function checkoutCalendarUpdated(cal) {
    if (cal.dateClicked) {
        document.getElementById("checkoutMonth").selectedIndex = cal.date.getMonth();
        document.getElementById("checkoutDay").selectedIndex = (cal.date.getDate() - 1);
        cal.hide();
        checkoutUpdated();
    }
}


//changes departure month when arrival month is changed

function checkinUpdated() {
	inM = document.getElementById("checkinMonth");
	inD = document.getElementById("checkinDay");
	outM = document.getElementById("checkoutMonth");
	outD = document.getElementById("checkoutDay");
	//alert(inM)
	var res = adjustDate( inM.options.selectedIndex, inD );
	if( res != 0 ) 
		{
		outD.options.selectedIndex = 0;
if ( inM.options.selectedIndex == 11 ) 
	{ outM.options.selectedIndex = 0 }
      else if( res == 4 ) 
		  {
		  outM.options.selectedIndex=inM.options.selectedIndex + 1;
           outD.options.selectedIndex = 0;
		   } else { 
			   outM.options.selectedIndex=inM.options.selectedIndex + 1;
			   outD.options.selectedIndex = 1;           }
			   } else{outM.options.selectedIndex = inM.options.selectedIndex;     
	if (outD.options.selectedIndex <= inD.options.selectedIndex) {
	outD.options.selectedIndex = inD.options.selectedIndex + 2; }    }
	var checkinMonth = inM.options[inM.selectedIndex].value * 1;
    var checkinDay = inD.options[inD.selectedIndex].value * 1;
    var checkoutMonth = outM.options[outM.selectedIndex].value * 1;
    var checkoutDay = outD.options[outD.selectedIndex].value * 1;
	
    document.getElementById("checkinValue").value = getYear(inM.selectedIndex) + "-" + checkinMonth + "-" + checkinDay;
	alert(getYear(inM.selectedIndex) + "-" + checkinMonth + "-" + checkinDay);
    document.getElementById("checkoutValue").value = getYear(outM.selectedIndex) + "-" + checkoutMonth + "-" + checkoutDay;
	return;
	}
	
	function checkoutUpdated() {   
	outM = document.getElementById("checkoutMonth");
	outD = document.getElementById("checkoutDay");
	inM = document.getElementById("checkinMonth");
	inD = document.getElementById("checkinDay");
	adjustDate( outM.options.selectedIndex, outD );
    var checkinMonth = inM.options[inM.selectedIndex].value * 1;
    var checkinDay = inD.options[inD.selectedIndex].value * 1;
    var checkoutMonth = outM.options[outM.selectedIndex].value * 1;
    var checkoutDay = outD.options[outD.selectedIndex].value * 1;
	//alert(getYear(inM.selectedIndex) + "-" + checkinMonth + "-" + checkinDay)
	document.getElementById("checkinValue").value = getYear(inM.selectedIndex) + "-" + checkinMonth + "-" + checkinDay;	
    alert(getYear(outM.selectedIndex) + "-" + checkoutMonth + "-" + checkoutDay)
	document.getElementById("checkoutValue").value = getYear(outM.selectedIndex) + "-" + checkoutMonth + "-" + checkoutDay;
	
	return;
	}

function isLeapYear( yrStr ) {
    var leapYear = false;
    var year = parseInt( yrStr, 10 );
    // every fourth year is a leap year
    if ( year % 4 == 0 ) {
        leapYear = true;
        // unless it's a multiple of 100
        if( year % 100 == 0 ) {
            leapYear = false;
            // unless it's a multiple of 400
            if( year % 400 == 0 ) {
                leapYear=true;
            }
        }
    }
    return leapYear;
}


function getDaysInMonth( mthIdx, YrStr ) {
    // all the rest have 31
    var maxDays = 31
    // expect Feb. (of course)
    if( mthIdx == 1 ) {
        if( isLeapYear( YrStr ) ) {
            maxDays=29;
        } else {
            maxDays=28;
        }
    }

    // thirty days hath...
    if( mthIdx == 3 || mthIdx == 5 || mthIdx == 8 || mthIdx == 10 ) {
        maxDays=30;
    }
    return maxDays;
}

function getYear(mthIdx) {
    var today = new Date()
    var theYear = parseInt(today.getFullYear())
    
    if( mthIdx < today.getMonth() ) {
        theYear = ( parseInt(today.getFullYear()) + 1 )
    }

    return theYear    
}

// do not allow selection of days that are not valid
// return non-zero if it is the last day of the month
function adjustDate( mthIdx, Dt ) {
    var value = 0;
    var theYear = getYear(mthIdx)
    var numDays = getDaysInMonth( mthIdx, theYear );
    
    if( mthIdx == 1 ) {
        if( Dt.options.selectedIndex + 2 < numDays ) {
            return 0;
        } else {
            if( Dt.options.selectedIndex + 1 > numDays) {
                Dt.options.selectedIndex=numDays - 1;
            }
            //check for leap year
            if( (Dt.options.selectedIndex + 1) == numDays ) {
                return 1;
            } else {
                return 4;
            }
        }
    }

    if( Dt.options.selectedIndex + 2 < numDays ) {
        value = 0;
    } else {
        if ( Dt.options.selectedIndex + 1 > numDays ) {
            Dt.options.selectedIndex--;
            value = 3;
        } else if ( Dt.options.selectedIndex + 1 == numDays ) {
            //index is 31 or 30
            value = 2;
        } else {
            value = 4;
        }
    }
    return value;
}

function over(o) {
    o.className = "list listMouseover";
}

function out(o) {
    o.className = "list";
}

function ConvertCurrency(displayLowRate, displayHighRate, displayToAUD, desiredToAUD) {
    document.getElementById("M_C_LowRate").value = Math.floor(displayLowRate / displayToAUD * desiredToAUD);
    document.getElementById("M_C_HighRate").value = Math.ceil(displayHighRate / displayToAUD * desiredToAUD);
}

function RefineSearchShowAll() {
    
	var qString = location.search.substr(1)
	
	if (qString == null || qString.length == 0 || qString.indexOf("gclid=") >= 0)
	    qString = query;
	
	qString = SetStarValue(qString, document.getElementById("M_C_Star5"), 'star5');
	qString = SetStarValue(qString, document.getElementById("M_C_Star4"), 'star4');
	qString = SetStarValue(qString, document.getElementById("M_C_Star3"), 'star3');
	qString = SetStarValue(qString, document.getElementById("M_C_Star2"), 'star2');
	qString = SetStarValue(qString, document.getElementById("M_C_Star1"), 'star1');
	
	qString = remQStringName(qString, 'star5');
	qString = remQStringName(qString, 'star4');
	qString = remQStringName(qString, 'star3');
	qString = remQStringName(qString, 'star2');
	qString = remQStringName(qString, 'star1');
	
	qString = remQStringName(qString, 'lowRate');
	qString = remQStringName(qString, 'highRate');
    qString = setQStringName(qString, "pageIndex", new Array("0"))
    
    qString = setQStringName(qString, "availableOnly", new Array("false"));
	
	if (path != null && path.length > 0)
	    location = path + "?" + qString
	else	
	    location = location.pathname + "?" + qString
	
	return false;
}

function ChangeCurrency(element) {
	var qString = location.search.substr(1)
	
	if (qString == null || qString.length == 0 || qString.indexOf("gclid=") >= 0)
	    qString = query;
	    
    qString = qString = remQStringName(qString, "lowRate");
    qString = qString = remQStringName(qString, "highRate");
    qString = setQStringName(qString, 'currencyCode', new Array(element.value))
    
	if (path != null && path.length > 0)
	    location = path + "?" + qString
	else	
	    location = location.pathname + "?" + qString
	
	return false;    
}

function ReloadSearch() {
    if (!ValidateDates())
        return false
    
	var qString = location.search.substr(1)
	
	if (qString == null || qString.length == 0 || qString.indexOf("gclid=") >= 0)
	    qString = query;

	qString = setQStringName(qString, 'checkin', new Array(document.getElementById("checkinValue").value))
	qString = setQStringName(qString, 'checkout', new Array(document.getElementById("checkoutValue").value))
		
	qString = SetStarValue(qString, document.getElementById("M_C_Star5"), 'star5');
	qString = SetStarValue(qString, document.getElementById("M_C_Star4"), 'star4');
	qString = SetStarValue(qString, document.getElementById("M_C_Star3"), 'star3');
	qString = SetStarValue(qString, document.getElementById("M_C_Star2"), 'star2');
	qString = SetStarValue(qString, document.getElementById("M_C_Star1"), 'star1');
	qString = SetStarValue(qString, document.getElementById("M_C_Star0"), 'star0');
	qString = setQStringName(qString, "sort", new Array(document.getElementById("sortBy").options[document.getElementById("sortBy").selectedIndex].value));
	    
	var currency = document.getElementById("M_C_currencies");    
	if (currency != null)
	{
	    qString = setQStringName(qString, 'currencyCode', new Array(currency.options[currency.selectedIndex].text))    
	}
	
	var lowRate = document.getElementById("M_C_LowRate");
	var highRate = document.getElementById("M_C_HighRate");
	
	if (lowRate == null || lowRate.value == null || lowRate.value == 0)
	{
	    qString = remQStringName(qString, "lowRate");
	}
	else
	{
	    qString = setQStringName(qString, "lowRate", new Array(lowRate.value))
	}
	
	if (highRate == null || highRate.value == null || highRate.value == 0)
	{
	    qString = remQStringName(qString, "highRate");
	}
	else
	{
	    qString = setQStringName(qString, "highRate", new Array(highRate.value))
	}
	
	if (document.getElementById("M_C_AvailableOnly").checked)
	{
	    qString = remQStringName(qString, "availableOnly");
	}
	else
	{
	    qString = setQStringName(qString, "availableOnly", new Array("false"));
	}
	
    var page = GetQSVal("pageIndex")
	if (page != "0" && page != "") qString = setQStringName(qString, "pageIndex", new Array("0"))	
	
	if (path != null && path.length > 0)
	    location = path + "?" + qString
	else	
	    location = location.pathname + "?" + qString
	
	return false;
}

function SetStarValue (qString, starElement, starName)
{
	if (starElement == null || starElement.checked)
	{
	    return remQStringName(qString, starName);
	}
	else
	{
        return setQStringName(qString, starName, new Array("false"))
	}
}

function CreateHttpRequest()
{
	var request;

	if (window.XMLHttpRequest)
	{
		request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		try
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			}
		}
	}
	return request
}





	/*function getDaysInMonths(aDate){
   // returns the last day of a given month
    
	
	var mo = new Number(aDate.getMonth());
    var y = new Number(aDate.getYear());

    var tmpDate = new Date(y, mo, 28);
    var checkMonth = tmpDate.getMonth();
    var lastDay = 27;

    while(lastDay <= 31){
        temp = tmpDate.setDate(lastDay + 1);
        if(checkMonth != tmpDate.getMonth())
            break;
        lastDay++
    }
    return lastDay;
}*/

var isPageLoad = true;
var fileName;
var ratesViewDisplay = false;
var monthsLong = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var weekdaysShort = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
var calTitle = "Choose a date:";
var myLabelYearPosition = 2;
var myLabelMonthPosition = 1;
var myLabelYearSuffix = "";
var myLabelMonthSuffix = " ";
var currentTabId = "Details";
var currentRateTabId = "rateViewSimple";
var mapAlreadyShown = false;
var gSearching = false;


function isFieldEmpty(fieldOneId, fieldTwoId) {
    if (document.getElementById(fieldOneId) != null && document.getElementById(fieldTwoId) != null) {
        if (document.getElementById(fieldOneId).value == 0 || document.getElementById(fieldTwoId).value == 0) {
            alert(typeof (JavaScriptEnterCheckinCheckout) == 'undefined' ? 'Please enter your checkin and checkout date.' : JavaScriptEnterCheckinCheckout)
            return true
        }
    }
    return false;
}

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)
}

	//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;
       
	   
	   
	   /* code added   to make the changes */
		//var myday = new Date(checkinDate);old code to set the date
		 var myday = new Date();
		 myday.setDate(day);
		 myday.setMonth(month-1);
		 myday.setYear(year);
		
		myday.setDate(myday.getDate()+1);
		  /* to get the date */
		 var newdate = myday.getDate();
		 if(newdate <10)
		 {
		   newdate ="0"+newdate;
		 }
		 /* to get the month */
		 newmonth= myday.getMonth()+1;
		if(newmonth <10)
		 {
			 newmonth ="0"+newmonth;
		 }
		  /* to get the year */
		  newyear = myday.getFullYear()
		   /* to concate the date , months and year */
		  var updated_date =      newyear+"-"+newmonth+"-"+newdate;
		    /* to display the concated month date and year*/
		  document.getElementById("hotelCheckout").value = updated_date;
		/* code added to make the changes ends here  */
		
		
		
		
		
		
		
		document.getElementById("checkinValue").value = checkinDate;
        document.getElementById("checkoutValue").value = document.getElementById(checkoutId).value;
	    checkinCal.hide();
		checkdate();

        //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
    this.hideDiv = function(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(chinc!=1)
		{
			checkinCalDiv.style.display = 'none';
		}
		if(ckout!=1)
		{
			checkoutCalDiv.style.display = 'none';
			ckout=0;
		}
		

        //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)
        }

        //if it is city page, set additional visibility control for both calendars
        if (document.getElementById("popupCheckin") != null) {
            hideHotelDiv(e)
            //hidePopupDiv(e)
        }
		chinc=0;
		ckout=0;
    }  
	
    document.onclick = hideDiv
}

// visibility control for hotel.aspx page rate tab first calendar and city.aspx 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';
    }
}
// visibility control for city.aspx page popup calendar.
function hidePopupDiv(e) {
    var target = (e ? e.target : event.srcElement);
    var checkinCalDiv = document.getElementById("popupCheckinCalContainer");
    var checkinDiv = document.getElementById("popupCheckin");
	
    var checkoutCalDiv = document.getElementById("popupCheckoutCalContainer");
    var checkoutDiv = document.getElementById("popupCheckout");
    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';
    }
}

//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;
}
/***************** End of yahoo calendar ************************/


/********************** dropdown checkin box **********************/
//changes departure month when arrival month is changed
function checkinUpdated() {

    inM = document.getElementById("checkinMonth");
    inD = document.getElementById("checkinDay");
    outM = document.getElementById("checkoutMonth");
    outD = document.getElementById("checkoutDay");

    var res = adjustDate(inM.options.selectedIndex, inD);
    if (res != 0) {
        outD.options.selectedIndex = 0;
        if (inM.options.selectedIndex == 11) {
            outM.options.selectedIndex = 0
        } else if (res == 4) {
            outM.options.selectedIndex = inM.options.selectedIndex + 1;
            outD.options.selectedIndex = 0;
        } else {
            outM.options.selectedIndex = inM.options.selectedIndex + 1;
            outD.options.selectedIndex = 1;
        }
    } else {
        outM.options.selectedIndex = inM.options.selectedIndex;
        if (outD.options.selectedIndex <= inD.options.selectedIndex) {
            outD.options.selectedIndex = inD.options.selectedIndex + 2;
        }
    }

    var checkinMonth = inM.options[inM.selectedIndex].value * 1;
    var checkinDay = inD.options[inD.selectedIndex].value * 1;
    var checkoutMonth = outM.options[outM.selectedIndex].value * 1;
    var checkoutDay = outD.options[outD.selectedIndex].value * 1;
    document.getElementById("checkinValue").value = getYear(inM.selectedIndex) + "-" + checkinMonth + "-" + checkinDay;
    document.getElementById("checkoutValue").value = getYear(outM.selectedIndex) + "-" + checkoutMonth + "-" + checkoutDay;
    return;
}

function checkoutUpdated() {
    outM = document.getElementById("checkoutMonth");
    outD = document.getElementById("checkoutDay");
	adjustDate(outM.options.selectedIndex, outD);

    var checkoutMonth = outM.options[outM.selectedIndex].value * 1;
    var checkoutDay = outD.options[outD.selectedIndex].value * 1;
    document.getElementById("checkoutValue").value = getYear(outM.selectedIndex) + "-" + checkoutMonth + "-" + checkoutDay;
    return;
}

function isLeapYear(yrStr) {
    var leapYear = false;
    var year = parseInt(yrStr, 10);
    // every fourth year is a leap year
    if (year % 4 == 0) {
        leapYear = true;
        // unless it's a multiple of 100
        if (year % 100 == 0) {
            leapYear = false;
            // unless it's a multiple of 400
            if (year % 400 == 0) {
                leapYear = true;
            }
        }
    }
    return leapYear;
}


function getDaysInMonth(mthIdx, YrStr) {
    // all the rest have 31
    var maxDays = 31
    // expect Feb. (of course)
    if (mthIdx == 1) {
        if (isLeapYear(YrStr)) {
            maxDays = 29;
        } else {
            maxDays = 28;
        }
    }

    // thirty days hath...
    if (mthIdx == 3 || mthIdx == 5 || mthIdx == 8 || mthIdx == 10) {
        maxDays = 30;
    }
    return maxDays;
}

function getYear(mthIdx) {
    var today = new Date()
    var theYear = parseInt(today.getFullYear())

    if (mthIdx < today.getMonth()) {
        theYear = (parseInt(today.getFullYear()) + 1)
    }

    return theYear
}

// do not allow selection of days that are not valid
// return non-zero if it is the last day of the month
function adjustDate(mthIdx, Dt) {
    var value = 0;
    var theYear = getYear(mthIdx)
    var numDays = getDaysInMonth(mthIdx, theYear);

    if (mthIdx == 1) {
        if (Dt.options.selectedIndex + 2 < numDays) {
            return 0;
        } else {
            if (Dt.options.selectedIndex + 1 > numDays) {
                Dt.options.selectedIndex = numDays - 1;
            }
            //check for leap year
            if ((Dt.options.selectedIndex + 1) == numDays) {
                return 1;
            } else {
                return 4;
            }
        }
    }

    if (Dt.options.selectedIndex + 2 < numDays) {
        value = 0;
    } else {
        if (Dt.options.selectedIndex + 1 > numDays) {
            Dt.options.selectedIndex--;
            value = 3;
        } else if (Dt.options.selectedIndex + 1 == numDays) {
            //index is 31 or 30
            value = 2;
        } else {
            value = 4;
        }
    }
    return value;
}
/********************** end of dropdown checkin box **********************/

function checkdate() {
  var url = "checkdate.php?date=";
  var dates = document.getElementById("hotelCheckin").value;
  
 
  https.open("GET", url + escape(dates), true);
  
 https.onreadystatechange = handleHttpResponses;
  https.send(null);
}

function getHTTPObjects() {

  var xmlhttp;

 if (window.XMLHttpRequest) 
	{
		return new XMLHttpRequest();
	}
	else if(window.ActiveXObject) 
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else 
	{
		alert('Status: Cound not create XmlHttpRequest Object.' + 'Consider upgrading your browser.');
		//document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.' + 'Consider upgrading your browser.';
	}

}
// The server-side script
function handleHttpResponses() {

  if (https.readyState == 4) {
    // Split the comma delimited response into an array
    results = https.responseText;
		
		document.getElementById("hotelCheckout").value=results; 
		document.getElementById("checkoutValue").value=results; 
		
 }
}
var https = getHTTPObjects(); // We create the HTTP Object

