﻿//Use for adjust calendar position
var calendarOffsetX = 0;
var calendarOffsetY = 0;

//Use for ABTEST 48 initMainSearchBox_ab48 + showsearch_ab48
// Just Duplicate function and changed parameter name "_ab"
function initMainSearchBox_ab48() {
    // First, check for AJAX support, otherwise give error message
    if (IsSupportAjax() == false) {
        alert(ErrorAjax);
        return;
    }

    if (CountryID = document.getElementById("ctl00_area_promo_CitySearchBox1_ddlSelectCountry")) {
        var CountryID = document.getElementById("ctl00_area_promo_CitySearchBox1_ddlSelectCountry").value;
    }

    // Get the dropdown lists
    var checkInMonthDropDown = document.getElementById('ddlCheckInMonthYear');
    var checkOutMonthDropDown = document.getElementById('ddlCheckOutMonthYear');
    var checkInDayDropDown = document.getElementById('ddlCheckInDay');
    var checkOutDayDropDown = document.getElementById('ddlCheckOutDay');

    // Build the month dropdowns, independant of the preset values
    BuildDayMonthDownList(checkInMonthDropDown);
    BuildDayMonthDownList(checkOutMonthDropDown);
    
    // Init values - we want the default to be -d- - mm, yyyy - in case of no session history
    if (document.getElementById("ctl00_area_promo_CitySearchBox1_arrivaldate").value != "" && CountryID != "0") {
        // Set the dropdowns for the months first
        var checkInDate = new Date();
        checkInDate.setTime(Date.parse(document.getElementById("ctl00_area_promo_CitySearchBox1_arrivaldate").value));
        var checkOutDate = new Date();
        checkOutDate.setTime(Date.parse(document.getElementById("ctl00_area_promo_CitySearchBox1_departdate").value));
        setCmbMonth(checkInMonthDropDown, checkInDate);
        setCmbMonth(checkOutMonthDropDown, checkOutDate);
    }

    // Build the dropdowns for the days    
    BuildDayDropDownList(checkInDayDropDown, checkInMonthDropDown)
    BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown)

    if (document.getElementById("ctl00_area_promo_CitySearchBox1_arrivaldate").value != "" && CountryID != "0") {
        // And set them
        checkInDayDropDown.selectedIndex = checkInDate.getDate();
        checkOutDayDropDown.selectedIndex = checkOutDate.getDate();
    }

    if (document.getElementById("ctl00_area_promo_CitySearchBox1_controlmode").value == "2")
        showsearch_ab48('Changedates');
}

function initMainSearchBox() {
    // First, check for AJAX support, otherwise give error message
    if (IsSupportAjax() == false) {
        alert(ErrorAjax);
        return;
    }

    if (CountryID = document.getElementById(ControlID + "ddlSelectCountry")) {
        var CountryID = document.getElementById(ControlID + "ddlSelectCountry").value;
    }

    // Get the dropdown lists
    var checkInMonthDropDown = document.getElementById('ddlCheckInMonthYear');
    var checkOutMonthDropDown = document.getElementById('ddlCheckOutMonthYear');
    var checkInDayDropDown = document.getElementById('ddlCheckInDay');
    var checkOutDayDropDown = document.getElementById('ddlCheckOutDay');

    // Build the month dropdowns, independant of the preset values
    BuildDayMonthDownList(checkInMonthDropDown);
    BuildDayMonthDownList(checkOutMonthDropDown);

    // Init values - we want the default to be -d- - mm, yyyy - in case of no session history
    if (document.getElementById(ControlID + "arrivaldate").value != "" && CountryID != "0") {
        // Set the dropdowns for the months first
        var checkInDate = new Date();
        checkInDate.setTime(Date.parse(document.getElementById(ControlID + "arrivaldate").value));
        var checkOutDate = new Date();
        checkOutDate.setTime(Date.parse(document.getElementById(ControlID + "departdate").value));
        setCmbMonth(checkInMonthDropDown, checkInDate);
        setCmbMonth(checkOutMonthDropDown, checkOutDate);
    }

    // Build the dropdowns for the days    
    BuildDayDropDownList(checkInDayDropDown, checkInMonthDropDown)
    BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown)

    if (document.getElementById(ControlID + "arrivaldate").value != "" && CountryID != "0") {

        // And set them
        checkInDayDropDown.selectedIndex = checkInDate.getDate();
        checkOutDayDropDown.selectedIndex = checkOutDate.getDate();
    }

    if (document.getElementById(ControlID + "controlmode").value == "2")
        showsearch('Changedates');
}

function setCmbMonth(cmbobj, checkDate) {
    var chkVal = frmtDate("MM,yyyy", 1, checkDate.getMonth(), checkDate.getFullYear());
    //alert("chkVal:"+chkVal);
    for (i = 0; i < cmbobj.length; i++) {
        if (cmbobj.options[i].value == chkVal) {
            cmbobj.selectedIndex = i;
            break;
        }
    }
}

function BuildCheckInDayDropDownList() {
    var checkInDayDropDown = document.getElementById('ddlCheckInDay');
    var checkInMonthDropDown = document.getElementById('ddlCheckInMonthYear');
    BuildDayDropDownList(checkInDayDropDown, checkInMonthDropDown)
    changeCheckInDay();
}

function BuildCheckOutDayDropDownList() {
    var checkOutDayDropDown = document.getElementById('ddlCheckOutDay');
    var checkOutMonthDropDown = document.getElementById('ddlCheckOutMonthYear');
    BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown);
    flagCheckOutChange = true;
}

function BuildDayDropDownList(dayDropDown, monthDropDown) {
    var preSelectedDay = cal_dateNow;
    var hasdate = true;
    if (dayDropDown.length > 0 && dayDropDown.selectedIndex > 0)
        preSelectedDay = dayDropDown.options[dayDropDown.selectedIndex].value;
    if (monthDropDown.length == 0)
        BuildDayMonthDownList(monthDropDown);

    var chosenMonth = monthDropDown.options[monthDropDown.selectedIndex].value;
    var numberOfDays = numberOfDaysPerMonthHashTable[chosenMonth];

    if (numberOfDays == undefined) {
        numberOfDays = 31;
        hasdate = false;
        preSelectedDay = 1;
    }

    // Clear the drop down list
    dayDropDown.options.length = 0;

    var newOption = new Option(txtDay, "");
    dayDropDown.options[0] = newOption;

    for (i = 1; i <= numberOfDays; i++) {
        var newOption = new Option(fmt00(i), fmt00(i));
        dayDropDown.options[i] = newOption;
    }

    // hack the javascript bug!
    if (parseInt(preSelectedDay) == 0) {
        preSelectedDay = preSelectedDay.substring(1);
    }

    if (numberOfDays >= parseInt(preSelectedDay) && hasdate) {
        dayDropDown.selectedIndex = parseInt(preSelectedDay);
    } else {
        if (preSelectedDay > 1) {
            if (preSelectedDay > numberOfDays)
                preSelectedDay = numberOfDays;

            preSelectedDay = numberOfDays;
            dayDropDown.selectedIndex = preSelectedDay;
        } else
            dayDropDown.selectedIndex = 0;
    }
}

function BuildDayMonthDownList(monthDropDown) {
    // Clear the drop down list
    monthDropDown.options.length = 0;

    // correction for none IE browsers
    if (cal_yearNow < 1900)
        cal_yearNow += 1900;

    var monthvalue;
    var curMonth = 0;
    var curYear = cal_yearNow;
    var nextyear = 0;
    var indcnt = 1;
    var newOption = new Option(txtMonth, "");
    monthDropDown.options[0] = newOption;
    for (i = cal_monthNow; i <= (cal_monthNow + 12); i++) {
        curMonth = i;
        if (i > 11) {
            curMonth = i - 12
            nextyear = 1;
        }
        curYear = cal_yearNow + nextyear;
        monthvalue = frmtDate(cal_cmbMonthFormat, 1, curMonth, curYear);

        var newOption = new Option(monthvalue, curMonth + 1 + "," + curYear);
        monthDropDown.options[indcnt++] = newOption;
    }
    monthDropDown.selectedIndex = 0;
}

function changeCheckInDay() {
    var checkInDayDropDown = document.getElementById('ddlCheckInDay');
    var checkOutDayDropDown = document.getElementById('ddlCheckOutDay');
    var checkInMonthDropDown = document.getElementById('ddlCheckInMonthYear');
    var checkOutMonthDropDown = document.getElementById('ddlCheckOutMonthYear');

    if (checkInMonthDropDown.selectedIndex == 0)
        return;

    var chosenMonth = checkInMonthDropDown.options[checkInMonthDropDown.selectedIndex].value;
    var numberOfDays = numberOfDaysPerMonthHashTable[chosenMonth];

    var chosenCheckInDay = parseInt(checkInDayDropDown.options[checkInDayDropDown.selectedIndex].value, 10);

    if (!chosenCheckInDay) {
        checkInDayDropDown.selectedIndex += 1;
        chosenCheckInDay = 1;
    }
    if ((chosenCheckInDay + 3) <= numberOfDays) {
        if (flagCheckOutChange == false || checkInMonthDropDown.selectedIndex > checkOutMonthDropDown.selectedIndex || (checkInMonthDropDown.selectedIndex == checkOutMonthDropDown.selectedIndex && checkInDayDropDown.selectedIndex > checkOutDayDropDown.selectedIndex)) {
            checkOutMonthDropDown.selectedIndex = checkInMonthDropDown.selectedIndex;
            BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown);
            checkOutDayDropDown.selectedIndex = chosenCheckInDay + 3;
        }
    } else {
        if (checkInMonthDropDown.selectedIndex >= 12) {
            alert("If you wish to book more than 1 year, please contact a customer service agent.");
            return false;
        }
        else {
            if (flagCheckOutChange == false || checkInMonthDropDown.selectedIndex > checkOutMonthDropDown.selectedIndex || (checkInMonthDropDown.selectedIndex == checkOutMonthDropDown.selectedIndex && checkInDayDropDown.selectedIndex > checkOutDayDropDown.selectedIndex)) {
                checkOutMonthDropDown.selectedIndex = checkInMonthDropDown.selectedIndex + 1;
                BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown);
                var remainingDays = 3 - (numberOfDays - chosenCheckInDay);
                checkOutDayDropDown.selectedIndex = remainingDays;
            }
        }
    }
}

// Set Hidden Values based on combo values
function SetDateValues() {
    var checkInDayDropDown = document.getElementById("ddlCheckInDay");
    var checkOutDayDropDown = document.getElementById("ddlCheckOutDay");
    var checkInMonthDropDown = document.getElementById("ddlCheckInMonthYear");
    var checkOutMonthDropDown = document.getElementById("ddlCheckOutMonthYear");

    if (checkInMonthDropDown.selectedIndex > 0) {
        var MonthYearIn = getDateFromDropDown(checkInMonthDropDown.selectedIndex);
        var checkInDateString = MonthYearIn.replace("dd", checkInDayDropDown.value);

        //alert("checkInDateString:"+checkInDateString);
        document.getElementById(ControlID + "arrivaldate").value = checkInDateString;
    }

    if (checkOutMonthDropDown.selectedIndex > 0) {
        var MonthYearOut = getDateFromDropDown(checkOutMonthDropDown.selectedIndex);
        var checkOutDateString = MonthYearOut.replace("dd", checkOutDayDropDown.value);
        //alert("checkOutDayDropDown:"+checkOutDayDropDown);

        document.getElementById(ControlID + "departdate").value = checkOutDateString;
    } else if (checkOutMonthDropDown.length == 0) {
        BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown);
    }
}

function SetDateValues2() {
    var checkInDayDropDown = document.getElementById("ddlCheckInDay2");
    var checkOutDayDropDown = document.getElementById("ddlCheckOutDay2");
    var checkInMonthDropDown = document.getElementById("ddlCheckInMonthYear2");
    var checkOutMonthDropDown = document.getElementById("ddlCheckOutMonthYear2");

    if (checkInMonthDropDown.selectedIndex > 0) {
        var MonthYearIn = getDateFromDropDown(checkInMonthDropDown.selectedIndex);
        var checkInDateString = MonthYearIn.replace("dd", checkInDayDropDown.value);

        //alert("checkInDateString:"+checkInDateString);
        document.getElementById(ControlID + "arrivaldate").value = checkInDateString;
    }

    if (checkOutMonthDropDown.selectedIndex > 0) {
        var MonthYearOut = getDateFromDropDown(checkOutMonthDropDown.selectedIndex);
        var checkOutDateString = MonthYearOut.replace("dd", checkOutDayDropDown.value);
        //alert("checkOutDayDropDown:"+checkOutDayDropDown);

        document.getElementById(ControlID + "departdate").value = checkOutDateString;
    } else if (checkOutMonthDropDown.length == 0) {
        BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown);
    }
}

// fmt00: pad with a leading zero for numbers between 0 and 9. only for positive integer.
function fmt00(number) {
    var intValue = parseInt(number)
    if (intValue >= 0 && intValue < 10) {
        return "0" + intValue;
    }
    return intValue
}

// Added more code 26/01/2007 
function getDateFromDropDown(index) {
    var arr = new Array();
    var now = new Date();
    for (i = 0; i < 13; i++) {
        now.setDate(1);
        // Correction on 20-Feb-2007 for Opera and other browsers that return for getYear the number of years since 1900 
        // instead of the year itself!
        var m = now.getMonth();
        var y = now.getYear();
        if (y < 1900)
            y += 1900;

        var str = (m + 1) + "/dd/" + y + "\n";
        arr.push(str);

        now.setMonth(++m);
        if (m > 11) {
            m = 0 + 1;
            now.setYear(++y);
            now.setMonth(0);
        }
    }

    if (arr.length > 0) {
        if (index <= arr.length) {
            return arr[index - 1];
        } else {
            return "";
        }
    } else {
        return "";
    }
}
//End added more code 26/01/2007

function chkEnableDay(chkday, chkmonth, chkyear) {
    //correction when roll over into next year
    if (chkmonth >= 12) {
        chkmonth -= 12;
        chkyear += 1;
    }
    var retval = true;
    var date = new Date();
    var dateNow = date.getDate();
    var monthNow = date.getMonth();
    var yearNow = date.getFullYear();
    if (yearNow < 1900) {
        yearNow += 1900;
    }
    // Check past
    if ((chkyear - yearNow) <= 0 && (chkmonth < monthNow || (chkmonth == monthNow && chkday < dateNow))) {
        retval = false;
    }
    // Check more then 1 year
    if (chkyear > yearNow && ((chkmonth >= monthNow && chkday > dateNow) || chkmonth > monthNow)) {
        retval = false;
    }
    if (chkyear < yearNow || (chkyear - yearNow > 1))
        retval = false;

    return retval;
}

function updDateCombos(obj, selday, selmonth, selyear) {
    var DayDropDown;
    var MonthDropDown;
    var monthvalue = frmtDate("MM,yyyy", selday, selmonth, selyear);
    var dayvalue = frmtDate("dd", selday, selmonth, selyear);

    if (obj.id == ControlID + "arrivaldate") {
        DayDropDown = document.getElementById('ddlCheckInDay');
        MonthDropDown = document.getElementById('ddlCheckInMonthYear');
        MonthDropDown.value = monthvalue;
        BuildCheckInDayDropDownList();
        // first need to set and build month before we can set the day
        DayDropDown.value = dayvalue;
        changeCheckInDay();
    } else {
        DayDropDown = document.getElementById('ddlCheckOutDay');
        MonthDropDown = document.getElementById('ddlCheckOutMonthYear');
        MonthDropDown.value = monthvalue;
        BuildCheckOutDayDropDownList();
        // first need to set and build month before we can set the day
        DayDropDown.value = dayvalue;
        flagCheckOutChange = true;
    }
    SetDateValues();
}

function doSearch() {
    var checkInDayDropDown = document.getElementById("ddlCheckInDay2");
    var checkOutDayDropDown = document.getElementById("ddlCheckOutDay2");
    var checkInMonthDropDown = document.getElementById("ddlCheckInMonthYear2");
    var checkOutMonthDropDown = document.getElementById("ddlCheckOutMonthYear2");
    
    if (document.getElementById(ControlID + "controlmode").value != 2) {
        if (document.getElementById(ControlID + "ddlSelectCountry2")) {
            // Check the Country input
            if (document.getElementById(ControlID + "ddlSelectCountry2").value == 0) {
                alert(ErrorCountry);
                return false;
            }
        }

        if (document.getElementById(ControlID + "ddlSelectCity2")) {
            // Check the City input
            if (document.getElementById(ControlID + "ddlSelectCity2").value == 0 && (checkInMonthDropDown.selectedIndex != 0 || checkOutMonthDropDown.selectedIndex != 0)) {
                alert(ErrorCity);
                return false;
            }
        }
    }

    if ((checkInMonthDropDown.selectedIndex != 0 && checkInDayDropDown.selectedIndex == 0) || (checkOutMonthDropDown.selectedIndex != 0 && checkOutDayDropDown.selectedIndex == 0)) {
        alert(ErrorDate);
        return false;
    }
    
    if (checkInMonthDropDown.selectedIndex == 0 && checkOutMonthDropDown.selectedIndex == 0) {
        document.getElementById(ControlID + "arrivaldate").value = "";
        document.getElementById(ControlID + "departdate").value = "";
        if (document.getElementById(ControlID + "controlmode").value == 2 || document.getElementById(ControlID + "controlmode").value == 4) {
            alert(ErrorDate);
            return false;
        }
    } else if (checkInMonthDropDown.selectedIndex == 0) {
        document.getElementById(ControlID + "arrivaldate").value = "";
        alert(ErrorNoArrival);
        return false;
    } else if (checkOutMonthDropDown.selectedIndex == 0) {
        document.getElementById(ControlID + "departdate").value = "";
        alert(ErrorNoDepart);
        return false;
    }

    var checkInDateString = document.getElementById(ControlID + "arrivaldate").value;    
    var checkOutDateString = document.getElementById(ControlID + "departdate").value;    
    var checkInDate = new Date();
    checkInDate.setTime(Date.parse(checkInDateString));
    var checkOutDate = new Date();
    checkOutDate.setTime(Date.parse(checkOutDateString));


    var now = new Date();
    if (daysElapsed(checkInDate, now) < 0) {
        alert(ErrorPast);
        return false;
    }
    if (checkInDate >= checkOutDate) {
        alert(ErrorLater);
        return false;
    }

    //Check if user search more 30 days, will be show alert popup and block.
    if (daysElapsed(checkOutDate, checkInDate) > 30) {
        alert(More30Days)
        return false;
    }

    if (validateCriteria())
        return true;
    else
        return false;
}

function validateCriteria() {
    var room = document.getElementById(ControlID + "ddlRoom").value;
    var adults = document.getElementById(ControlID + "ddlAdult").value;
    var children = document.getElementById(ControlID + "ddlChildren").value;
    document.getElementById(ControlID + "jsRooms").value = room;    
    document.getElementById(ControlID + "jsAdults").value = adults;
    document.getElementById(ControlID + "jsChildren").value = children;

    // IF ROOM, ADULTS OR CHILDREN INCLUDE STRING "+"
    if (room == "4") {
        alert(More3Rooms);
        return false;
        //return true; //for GroupBooking
    } else if ((adults * 1) + (children * 1) > (room * 4)) {
        alert(AdultChildMax);
    } else if ((((adults * 1) + (children * 1)) / (room * 1)) == 4) {
        if (confirm(RoomsMoreGuest)) {
            return true;
        } else {
            return false;
        }
    } else {
        return true;
    }
}

function y2k(d) {
    return (d < 1000) ? d + 1900 : d;
}

function daysElapsed(date1, date2) {
    var difference = Date.UTC(y2k(date1.getYear()), date1.getMonth(), date1.getDate(), 0, 0, 0)
            - Date.UTC(y2k(date2.getYear()), date2.getMonth(), date2.getDate(), 0, 0, 0);
    // difference is in milliseconds, neeed to get number of days instead.
    return difference / 1000 / 60 / 60 / 24;
}

function IsSupportAjax() {
    try {
        //Check Browser
        if (window.ActiveXObject) { //IE
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else { //NS, FF
            xmlhttp = new XMLHttpRequest();
        }
        if (xmlhttp != null) {
            return true;
        }
        else {
            return false;
        }
    }
    catch (err) {
        return false;
    }

}

// Choose date box in hotel page
var flagCheckOutChange = false;
var state = 'none';

var arrow = 'click_change sprite';
var imgarrow_down = new Image();
imgarrow_down.className = 'click_down sprite';

var imgarrow_right = new Image();
imgarrow_right.className = 'click_change sprite';

function showhide(layer_ref) {
    arrow = imgarrow_right.className;
    if (state == 'block') {
        state = 'none';
    }
    else {
        arrow = imgarrow_down.className;
        state = 'block';
    }

    if (document.getElementById) {
        showarrow = document.getElementById('imgArrow');
        showarrow.className = arrow;
        showdisplay = document.getElementById(layer_ref);
        showdisplay.style.display = state;
    } else if (document.all) { //IS IE 4 or 5 (or 6 beta)        
        eval("document.all.imgArrow.className = arrow");
        eval("document.all." + layer_ref + ".style.display = state");
    } else if (document.layers) { //IS NETSCAPE 4 or below        
        document.layers['imgArrow'].className = arrow;
        document.layers['imgArrow'].setAttribute(".classname", arrow)

        document.layers[layer_ref].style.display = state;
    }
}

//----------------- AB
var arrow_ab = 'click_plus_ab sprite';
var imgarrow_down_ab = new Image();
imgarrow_down_ab.className = 'click_minus_ab sprite';

var imgarrow_right_ab = new Image();
imgarrow_right_ab.className = 'click_plus_ab sprite';

function showhide_ab(layer_ref) {
    arrow_ab = imgarrow_right_ab.className;
    if (state == 'block') {
        state = 'none';
    }
    else {
        arrow_ab = imgarrow_down_ab.className;
        state = 'block';
    }

    if (document.getElementById) {
        showarrow = document.getElementById('imgArrow');
        showarrow.className = arrow_ab;
        showdisplay = document.getElementById(layer_ref);
        showdisplay.style.display = state;
    } else if (document.all) { //IS IE 4 or 5 (or 6 beta)        
        eval("document.all.imgArrow.className = arrow_ab");
        eval("document.all." + layer_ref + ".style.display = state");
    } else if (document.layers) { //IS NETSCAPE 4 or below        
        document.layers['imgArrow'].className = arrow_ab;
        document.layers['imgArrow'].setAttribute(".classname", arrow_ab)

        document.layers[layer_ref].style.display = state;
    }
}

function showsearch_ab48(layer_ref) {
    arrow = imgarrow_down_ab.className;

    if (IsSmartSearchResult == 'False') {
        state = '';
        arrow_state = 'none';
    }
    else {
        state = 'none';
        arrow_state = '';
        arrow = imgarrow_right_ab.className;
    }

    if (document.getElementById) {
        showarrow = document.getElementById('imgArrow');
        showarrow.className = arrow;
        showdisplay = document.getElementById(layer_ref);
        showdisplay.style.display = state;
        showarrow.style.display = arrow_state;
    } else if (document.all) { //IS IE 4 or 5 (or 6 beta)
        eval("document.all.imgArrow.className = arrow");
        eval("document.all.imgArrow.style.display = arrow_state");
        eval("document.all." + layer_ref + ".style.display = state");
    } else if (document.layers) { //IS NETSCAPE 4 or below
        document.layers['imgArrow'].className = arrow;
        document.layers['imgArrow'].setAttribute(".classname", arrow)
        document.layers['imgArrow'].style.display = arrow_state;
        document.layers[layer_ref].style.display = state;
    }
}

function showsearch(layer_ref) {
    arrow = imgarrow_down.className;

    if (IsSmartSearchResult == 'False') {
        state = '';
        arrow_state = 'none';
    }
    else {
        state = 'none';
        arrow_state = '';
        arrow = imgarrow_right.className;
    }

    if (document.getElementById) {
        showarrow = document.getElementById('imgArrow');
        showarrow.className = arrow;
        showdisplay = document.getElementById(layer_ref);
        showdisplay.style.display = state;
        showarrow.style.display = arrow_state;
    } else if (document.all) { //IS IE 4 or 5 (or 6 beta)
        eval("document.all.imgArrow.className = arrow");
        eval("document.all.imgArrow.style.display = arrow_state");
        eval("document.all." + layer_ref + ".style.display = state");
    } else if (document.layers) { //IS NETSCAPE 4 or below
        document.layers['imgArrow'].className = arrow;
        document.layers['imgArrow'].setAttribute(".classname", arrow)
        document.layers['imgArrow'].style.display = arrow_state;
        document.layers[layer_ref].style.display = state;
    }
}

function doGenDDL(objSource, strTargetAdult, strTargetChild) {
    var iValue = (objSource.value * 1);
    if (objSource.value == "4") { return; } //for groupbooking, we'll comment this line
    doGen(strTargetAdult, iValue, (iValue * 4));
    doGen(strTargetChild, 0, (iValue * 3));
}

function doGen(strTargetName, iStart, iEnd) {
    document.getElementById(ControlID + strTargetName).length = 0
    var oTarget = document.getElementById(ControlID + strTargetName);
    for (i = iStart; i <= iEnd; i++) {
        doCreateOption(i, i, oTarget);
    }
}

function doCreateOption(strText, strValue, oTarget) {
    var newOpt = new Option(strText, strValue);
    var selLength = oTarget.length;
    oTarget.options[selLength] = newOpt;
}

function searchType(obj) {
    var hidden = document.getElementById(ControlID + "SearchHotel");

    if (obj == 'C') {
        document.getElementById("Link_City").style.display = 'none';
        document.getElementById("Link_Hotel").style.display = 'block';
        document.getElementById("hotelslist").style.display = 'none';
        hidden.value = "no";

        //document.getElementById("divGGCodeSB").innerHTML = '';

        if (document.getElementById("ddlhotelslist"))
            document.getElementById("ddlhotelslist").style.display = 'none';

    }
    else {
        document.getElementById("Link_City").style.display = 'block';
        document.getElementById("Link_Hotel").style.display = 'none';
        document.getElementById("hotelslist").style.display = '';
        hidden.value = "yes";

        //document.getElementById("divGGCodeSB").innerHTML = '<script type=text/javascript>pageTracker._trackEvent(SearchBox, Search Specific Hotel, Expand);</Scrip>';        

        if (document.getElementById("ddlhotelslist")) {
            document.getElementById("ddlhotelslist").style.display = '';
        }
    }
}

function CityLoading() {
    var ddlSelectCountry = document.getElementById(ControlID + "ddlSelectCountry");
    var ddlSelectCity = document.getElementById(ControlID + "ddlSelectCity");

    if (ddlSelectCountry.value == "0") {
        ddlSelectCountry.selectedIndex = 0
    }
    else {
        ddlSelectCity.disabled = true;
        ddlSelectCity.options[0].text = "Loading..";
        ddlSelectCity.selectedIndex = 0;
    }
}

function HotelLoading() {
    var ddl = document.getElementById(ControlID + "ddlSelectHotel");
    ddl.disabled = true;
    if (ddl.options[0]) {
        ddl.options[0].text = "Loading..";
        ddl.selectedIndex = 0;
    }

    __doPostBack(ControlID + "ddlSelectCity", "SelectedIndexChanged");
}

this._doPostBack = function(eventTarget, eventArgument) {
    _additionalInput = null;

    if (this.get_inPostBack()) {
        if (window.event) {
            window.event.returnValue = false;
        }
        return;
    }

    _postbackSettings = null;
    var postbackElement = findNearestElement(eventTarget);
    if (postbackElement) {
        _postbackSettings = getPostbackSettings(postbackElement);
    }
    else {
        _postbackSettings = createPostbackSettings(true, _scriptManagerID);
    }
    if (!_postbackSettings.async) {
        _originalDoPostBack(eventTarget, eventArgument);
        return;
    }

    var form = _form;
    form.__EVENTTARGET.value = eventTarget;
    form.__EVENTARGUMENT.value = eventArgument;
    this._onFormSubmit();

    if (window.event) {
        window.event.returnValue = false;
    }
}

//For Calendar
var cal_fixedX = -1;            // x position (-1 if to appear below control)
var cal_fixedY = -1;            // y position (-1 if to appear below control)
var cal_startAt = 0;            // 0 - sunday ; 1 - monday
var cal_showWeekNumber = 0;     // 0 - don't show; 1 - show
var cal_showToday = 1; 	    // 0 - don't show; 1 - show
var cal_imgDir = '/images/'	// directory for images ... e.g. var cal_imgDir="/img/"

var cal_enablehistory = false;

var cal_gotoString = jsLang.txtGoCurrentMonth;
var cal_todayString = jsLang.txtTodayIs;
var cal_weekString = jsLang.txtWeek;
var cal_scrollLeftMessage = jsLang.txtPrevMonth;
var cal_scrollRightMessage = jsLang.txtNextMonth;
var cal_selectMonthMessage = jsLang.txtSelectMonth;
var cal_selectYearMessage = jsLang.txtSelectYear;

var cal_crossObj, cal_crossMonthObj, cal_crossYearObj, cal_monthSelected, cal_yearSelected, cal_dateSelected, ocal_monthSelected, ocal_yearSelected, ocal_dateSelected, cal_monthConstructed, cal_yearConstructed, cal_intervalID1, cal_intervalID2
var cal_timeoutID1, cal_timeoutID2, cal_ctflToPlaceValue, cal_ctlNow, cal_dateFormat, cal_nStartingYear;

//Browser checks
var cal_bPageLoaded = false;
var ie = document.all;
var dom = document.getElementById;
var ns4 = document.layers;

var cal_today = new Date();
var cal_dateNow = cal_today.getDate();
var cal_monthNow = cal_today.getMonth();
var cal_yearNow = cal_today.getYear();

var oFunctions;
var bShow = false;

//if (dom) {
//    var calwidth = 200;
//    calwidth = 384;
//    document.write("onclick='bShow=true' id='calendar' class='div-style'><table width=" + ((cal_showWeekNumber == 1) ? calwidth : (calwidth - 25)) + " class='table-style' border='0'><tr class='title-background-style'><td><table width='100%' border='0'><tr><td class='title-style'><B><span id='caption'></span></B></td></tr></table></td></tr><tr><td class='body-style'><span id='content'></span></td></tr>");

//    if (cal_showToday == 1) {
//        document.write("<tr class='today-style'><td><span id='lblToday'></span></td></tr>");
//    }
//    document.write("</table></div><div id='selectMonth' class='div-style'></div><div id='selectYear' class='div-style'></div>");
//}

var cal_monthName = cal_monthNames;
if (cal_startAt == 0) {
    cal_dayName = cal_shortDays;
} else {
    cal_dayName = new Array(cal_shortDays[1], cal_shortDays[2], cal_shortDays[3], cal_shortDays[4], cal_shortDays[5], cal_shortDays[6], cal_shortDays[0]);
}

/* hides <select> and <applet> objects (for IE only) */
function hideElement(elmID, overDiv) {
    if (ie) {
        for (i = 0; i < document.all.tags(elmID).length; i++) {
            obj = document.all.tags(elmID)[i];
            if (!obj || !obj.offsetParent) {
                continue;
            }

            // Find the element's offsetTop and offsetLeft relative to the BODY tag.
            objLeft = obj.offsetLeft;
            objTop = obj.offsetTop;
            objParent = obj.offsetParent;

            // Add HTML check solved problem using calendar within box_search
            while (objParent.tagName.toUpperCase() != "BODY" && objParent.tagName.toUpperCase() != "HTML" && objParent.tagName.toUpperCase() != "DIV") {
                objLeft += objParent.offsetLeft;
                objTop += objParent.offsetTop;
                objParent = objParent.offsetParent;
            }

            objLeft = chkLeftPos(objLeft);
            objHeight = obj.offsetHeight;
            objWidth = obj.offsetWidth;

            // condition to check if there is no need to hide obj
            if ((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
            else if ((overDiv.offsetTop + overDiv.offsetHeight) <= objTop);
            else if (overDiv.offsetTop >= (objTop + objHeight));
            else if (overDiv.offsetLeft >= (objLeft + objWidth));
            else {
                obj.style.visibility = "hidden";
            }
        }
    }
}

/* unhides <select> and <applet> objects (for IE only)   */
function showElement(elmID) {
    if (ie) {
        for (i = 0; i < document.all.tags(elmID).length; i++) {
            obj = document.all.tags(elmID)[i];
            if (!obj || !obj.offsetParent) {
                continue;
            }
            obj.style.visibility = "";
        }
    }
}

function swapImage(srcImg, destImg) {
    if (ie) {
        document.getElementById(srcImg).setAttribute("src", cal_imgDir + destImg);
    }
}

function init_calendar() {
    if (!ns4) {
        // correction for browsers as Opera
        if (cal_yearNow < 1900) {
            cal_yearNow += 1900;
        }
        cal_crossObj = (dom) ? document.getElementById("calendar").style : ie ? document.all.calendar : document.calendar;
        hideCalendar();

        cal_crossMonthObj = (dom) ? document.getElementById("selectMonth").style : ie ? document.all.selectMonth : document.selectMonth;
        cal_crossYearObj = (dom) ? document.getElementById("selectYear").style : ie ? document.all.selectYear : document.selectYear;

        cal_monthConstructed = false;
        cal_yearConstructed = false;

        if (cal_showToday == 1) {
            document.getElementById("lblToday").innerHTML = cal_todayString + " <a class='today-style' title='" + cal_gotoString + "' href='javascript:cal_monthSelected=cal_monthNow;cal_yearSelected=cal_yearNow;constructCalendar();'>" + cal_dayName[(cal_today.getDay() - cal_startAt == -1) ? 6 : (cal_today.getDay() - cal_startAt)] + ", " + cal_dateNow + " " + cal_monthName[cal_monthNow].substring(0, 3) + " " + cal_yearNow + "</a>";
        }
        document.getElementById("lblToday").innerHTML = "<a href='javascript:hideCalendar()' class='closecal' title='" + jsLang.txtClose + "'>" + jsLang.txtClose + "</a>";

        sHTML1 = "<table class='widthfull' cellspacing='0' cellpadding='0' border='0'><tr>";
        sHTML1 += "<td width='15' style='width:15px'><p id='spanLeft' title='" + cal_scrollLeftMessage + "' class='title-control-normal-style sprite arrowleft' onclick='javascript:decMonth()' onmouseout='clearInterval(cal_intervalID1);' onmousedown='clearTimeout(cal_timeoutID1);cal_timeoutID1=setTimeout(\"StartDecMonth()\",500)' onmouseup='clearTimeout(cal_timeoutID1);clearInterval(cal_intervalID1)'><span id='changeLeft' class='sprite arrowleft'>Arrow</span></p></td>";
        sHTML1 += "<td width='44%' align='center'><span id='spanMonth' class='title-control-style'></span></td>";
        sHTML1 += "<td width='44%' align='center'><span id='spanMonth2' class='title-control-style'></span></td>";
        sHTML1 += "<td width='15' style='width:15px'><p id='spanRight' title='" + cal_scrollRightMessage + "' class='title-control-normal-style sprite arrowright' onmouseout='clearInterval(cal_intervalID1);' onclick='incMonth()' onmousedown='clearTimeout(cal_timeoutID1);cal_timeoutID1=setTimeout(\"StartIncMonth()\",500)' onmouseup='clearTimeout(cal_timeoutID1);clearInterval(cal_intervalID1)'><span id='changeRight' class='sprite arrowright'>Arrow</span></p></td>";
        sHTML1 += "</tr></table>";
        document.getElementById("caption").innerHTML = sHTML1;
        cal_bPageLoaded = true;
    } else {
        alert("Your browser does not support this feature!");
    }

}

function hideCalendar() {
    if (cal_crossObj) {
        cal_crossObj.visibility = "hidden";
        if (cal_crossMonthObj != null) { cal_crossMonthObj.visibility = "hidden"; }
        if (cal_crossYearObj != null) { cal_crossYearObj.visibility = "hidden"; }
        if (document.getElementById("spanLeft")) { document.getElementById("spanLeft").style.visibility = "hidden"; }
        if (document.getElementById("spanRight")) { document.getElementById("spanRight").style.visibility = "hidden"; }

        showElement('SELECT');
        showElement('APPLET');
    }
}


function padZero(num) {
    return (num < 10) ? '0' + num : num;
}

function cal_constructDate(d, m, y) {
    var sTmp = cal_dateFormat;
    sTmp = sTmp.replace("dd", padZero(d));
    sTmp = sTmp.replace("d", d);
    sTmp = sTmp.replace("mmm", cal_monthName[m]);
    sTmp = sTmp.replace("mm", padZero(m + 1));
    return sTmp.replace("yyyy", y);
}

function frmtDate(frmt, d, m, y) {
    var sTmp = frmt;
    sTmp = sTmp.replace("dd", padZero(d));
    sTmp = sTmp.replace("d", d);
    sTmp = sTmp.replace("mmmm", cal_monthNames[m]);
    sTmp = sTmp.replace("MMMM", cal_monthNames[m]);
    sTmp = sTmp.replace("mmm", cal_monthOutput[m]);
    sTmp = sTmp.replace("MMM", cal_monthOutput[m]);
    sTmp = sTmp.replace("mm", padZero(m + 1));
    sTmp = sTmp.replace("MM", m + 1);
    return sTmp.replace("yyyy", y);
}

function closeCalendar() {
    hideCalendar();
    cal_ctlToPlaceValue.value = cal_constructDate(cal_dateSelected, cal_monthSelected, cal_yearSelected);
    if (typeof (oFunctions) == "function") {
        oFunctions(cal_ctlToPlaceValue, cal_dateSelected, cal_monthSelected, cal_yearSelected);
    }
}

/*** Month Pulldown	***/
function StartDecMonth() {
    cal_intervalID1 = setInterval("decMonth()", 80);
}

function StartIncMonth() {
    cal_intervalID1 = setInterval("incMonth()", 80);
}

function incMonth() {
    cal_monthSelected++;
    if (cal_monthSelected > 11) {
        cal_monthSelected = 0;
        cal_yearSelected++;
    }
    constructCalendar();
}

function decMonth() {
    cal_monthSelected--;
    if (cal_monthSelected < 0) {
        cal_monthSelected = 11;
        cal_yearSelected--;
    }
    constructCalendar();
}


function getLeftPos(obj) {
    // Find the element's offsetLeft relative to the BODY tag.
    var objLeft = obj.offsetLeft;
    var objParent = obj.offsetParent;

    while (objParent.tagName.toUpperCase() != "BODY") {
        objLeft += objParent.offsetLeft;
        objParent = objParent.offsetParent;
    }
    return objLeft;
}

/*** Year Pulldown ***/
function incYear() {
    for (i = 0; i < 7; i++) {
        newYear = (i + cal_nStartingYear) + 1;
        if (newYear == cal_yearSelected) {
            txtYear = "&nbsp;<strong>" + newYear + "</strong>&nbsp;";
        } else {
            txtYear = "&nbsp;" + newYear + "&nbsp;";
        }
        document.getElementById("y" + i).innerHTML = txtYear;
    }
    cal_nStartingYear++;
    bShow = true;
}

function decYear() {
    for (i = 0; i < 7; i++) {
        newYear = (i + cal_nStartingYear) - 1;
        if (newYear == cal_yearSelected) {
            txtYear = "&nbsp;<strong>" + newYear + "</strong>&nbsp;";
        }
        else {
            txtYear = "&nbsp;" + newYear + "&nbsp;";
        }
        document.getElementById("y" + i).innerHTML = txtYear;
    }
    cal_nStartingYear--;
    bShow = true;
}


/*** calendar ***/
function WeekNbr(today) {
    Year = takeYear(today);
    Month = today.getMonth();
    Day = today.getDate();
    now = Date.UTC(Year, Month, Day + 1, 0, 0, 0);
    var Firstday = new Date();
    Firstday.setYear(Year);
    Firstday.setMonth(0);
    Firstday.setDate(1);
    then = Date.UTC(Year, 0, 1, 0, 0, 0);
    var Compensation = Firstday.getDay();
    if (Compensation > 3) Compensation -= 4;
    else Compensation += 3;
    NumberOfWeek = Math.round((((now - then) / 86400000) + Compensation) / 7);
    return NumberOfWeek;
}

function takeYear(theDate) {
    x = theDate.getYear();
    var y = x % 100;
    y += (y < 38) ? 2000 : 1900;
    return y;
}

function cal_seletion(nDay, nMonth, nYear) {
    cal_dateSelected = nDay;
    cal_monthSelected = nMonth;
    cal_yearSelected = parseInt(nYear);
    closeCalendar();
}

function getMonthTable(selYear, selMonth) {
    // correction for doublemonths
    if (selMonth == 12) {
        selMonth = 0;
        selYear += 1;
    }

    var dateMessage;
    var startDate = new Date(selYear, selMonth, 1);
    var endDate = new Date(selYear, selMonth + 1, 1);
    endDate = new Date(endDate - (24 * 60 * 60 * 1000));
    numDaysInMonth = endDate.getDate();

    datePointer = 0;
    dayPointer = startDate.getDay() - cal_startAt;

    if (dayPointer < 0) {
        dayPointer = 6;
    }

    var sHTML = "<table	border='0' class='body-style' cellpadding='0' cellspacing='0' width='100%'><tr class='dayofweeks'>";
    if (cal_showWeekNumber == 1) {
        sHTML += "<td width='22' align='center'><strong>" + cal_weekString + "</strong></td><td width='1' rowspan='7' class='weeknumber-div-style'><img src='" + cal_imgDir + "/divider.gif' width='1'></td>";
    }
    for (i = 0; i < 7; i++) {
        sHTML += "<td width='22' align='right' style='padding-right:2px'>" + cal_dayName[i] + "</td>";
    }
    sHTML += "</tr><tr>";

    if (cal_showWeekNumber == 1) {
        sHTML += "<td align=right>" + WeekNbr(startDate) + "&nbsp;</td>";
    }
    for (var i = 1; i <= dayPointer; i++) {
        sHTML += "<td>&nbsp;</td>";
    }

    var bDayEnabled;
    var sDisabled = "";
    for (datePointer = 1; datePointer <= numDaysInMonth; datePointer++) {
        dayPointer++;
        bDayEnabled = true;

        //Check if day should be enabled or disabled for selection
        if (typeof (chkEnableDay) == "function") {
            bDayEnabled = chkEnableDay(datePointer, selMonth, selYear);
        }
        sHTML += "<td align='right' class='cal_day'>";
        var sStyle = "normal-day-style"; //regular day
        if ((datePointer == cal_dateNow) && (selMonth == cal_monthNow) && (selYear == cal_yearNow)) { //today
            sStyle = "current-day-style";
        }
        else if (dayPointer % 7 == (cal_startAt * -1) + 1) { //end-of-the-week day
            sStyle = "end-of-weekday-style";
        }

        //selected day
        if ((datePointer == ocal_dateSelected) && (selMonth == ocal_monthSelected) && (selYear == ocal_yearSelected)) {
            sStyle += " selected-day-style";
        }
        sDisabled = "";
        sHint = jsLang.txtSelectDay;
        if (bDayEnabled == false) {
            sStyle = "disabled-" + sStyle;
            sDisabled = " disabled";
            sHint = jsLang.txtDayDisabled;
        }

        var regexp = /\"/g;
        sHint = sHint.replace(regexp, "&quot;");
        dateMessage = "";

        if (bDayEnabled)
            sHTML += "<a class='" + sStyle + "' " + dateMessage + " title=\"" + sHint + "\" href='javascript:cal_seletion(" + datePointer + "," + selMonth + "," + selYear + ");'>&nbsp;" + datePointer + "&nbsp;</a>"
        else
            sHTML += "<label class='" + sStyle + "' " + sDisabled + " title=\"" + sHint + "\" >&nbsp;" + datePointer + "&nbsp;</label>"

        sHTML += "";
        if ((dayPointer + cal_startAt) % 7 == cal_startAt) {
            sHTML += "</tr><tr>";
            if ((cal_showWeekNumber == 1) && (datePointer < numDaysInMonth)) {
                sHTML += "<td align=right>" + (WeekNbr(new Date(selYear, selMonth, datePointer + 1))) + "&nbsp;</td>";
            }
        }
    }
    sHTML += "</tr></table>"
    return sHTML;
}

function constructCalendar() {
    var dateMessage;
    var startDate = new Date(cal_yearSelected, cal_monthSelected, 1);
    var endDate = new Date(cal_yearSelected, cal_monthSelected + 1, 1);
    endDate = new Date(endDate - (24 * 60 * 60 * 1000));
    numDaysInMonth = endDate.getDate();

    datePointer = 0;
    dayPointer = startDate.getDay() - cal_startAt;

    if (dayPointer < 0) {
        dayPointer = 6;
    }

    //Check if day should be enabled or disabled for selection
    var bPrevEnabled = true;
    var bNextEnabled = true;
    if (cal_monthSelected <= cal_monthNow && cal_yearSelected == cal_yearNow && cal_enablehistory == false) {
        bPrevEnabled = false;
    }
    if (bPrevEnabled)
        bPrevEnabled = chkEnableDay(1, cal_monthSelected, cal_yearSelected);

    if (typeof (chkEnableDay) == "function") {
        bNextEnabled = chkEnableDay(1, cal_monthSelected + 2, cal_yearSelected);
    }

    if (bPrevEnabled) {
        document.getElementById("spanLeft").style.visibility = (dom || ie) ? "visible" : "show";
        document.getElementById("spanLeft").disabled = false;
    } else {
        document.getElementById("spanLeft").style.visibility = "hidden";
        document.getElementById("spanLeft").disabled = true;
    }
    if (bNextEnabled) {
        document.getElementById("spanRight").style.visibility = (dom || ie) ? "visible" : "show";
        document.getElementById("spanRight").disabled = false;
    } else {
        document.getElementById("spanRight").style.visibility = "hidden";
        document.getElementById("spanRight").disabled = true;
    }
    // script for month table
    var mnt1Html = getMonthTable(cal_yearSelected, cal_monthSelected);
    var mnt2Html = "";
    mnt2Html = getMonthTable(cal_yearSelected, cal_monthSelected + 1);
    sHTML = "<table border='0' cellpadding='0' cellspacing='0' class='widthfull'><tr><td>" + mnt1Html + "</td><td style='width:1px;'>&nbsp;</td><td bgcolor='#909090' width='2'>&nbsp;</td><td style='width:1px;'></td><td>" + mnt2Html + "</td></tr></table>"
    document.getElementById("content").innerHTML = sHTML;

    document.getElementById("spanMonth").innerHTML = frmtDate(cal_dsplMonthFormat, cal_dateSelected, cal_monthSelected, cal_yearSelected);
    var calMonth2 = cal_monthSelected + 1;
    var calYear2 = cal_yearSelected;
    if (calMonth2 == 12) {
        calMonth2 = 0;
        calYear2 += 1;
    }
    document.getElementById("spanMonth2").innerHTML = frmtDate(cal_dsplMonthFormat, cal_dateSelected, calMonth2, calYear2);
}

function SetCalendarOffset(x, y) {
    calendarOffsetX = x;
    calendarOffsetY = y;
}

function popUpCalendar2(ctl, ctl2, format, OtherFunctions) {
    var leftpos = 0;
    var toppos = 0;
    oFunctions = OtherFunctions;
    if (cal_bPageLoaded) {
        if (cal_crossObj.visibility == "hidden") {
            cal_ctlToPlaceValue = ctl2;
            cal_dateFormat = format;

            formatChar = " ";
            aFormat = cal_dateFormat.split(formatChar);
            if (aFormat.length < 3) {
                formatChar = "/";
                aFormat = cal_dateFormat.split(formatChar);
                if (aFormat.length < 3) {
                    formatChar = ".";
                    aFormat = cal_dateFormat.split(formatChar);
                    if (aFormat.length < 3) {
                        formatChar = "-";
                        aFormat = cal_dateFormat.split(formatChar);
                        if (aFormat.length < 3) {
                            // invalid date	format
                            formatChar = "";
                        }
                    }
                }
            }

            tokensChanged = 0;
            if (formatChar != "") {
                // use user's date
                aData = ctl2.value.split(formatChar);

                for (i = 0; i < 3; i++) {
                    if ((aFormat[i] == "d") || (aFormat[i] == "dd")) {
                        cal_dateSelected = parseInt(aData[i], 10);
                        tokensChanged++;
                    }
                    else if ((aFormat[i] == "m") || (aFormat[i] == "mm")) {
                        cal_monthSelected = parseInt(aData[i], 10) - 1;
                        tokensChanged++;
                    }
                    else if (aFormat[i] == "yyyy") {
                        cal_yearSelected = parseInt(aData[i], 10);
                        tokensChanged++;
                    }
                    else if (aFormat[i] == "mmm") {
                        for (j = 0; j < 12; j++) {
                            if (aData[i] == cal_monthName[j]) {
                                cal_monthSelected = j;
                                tokensChanged++;
                            }
                        }
                    }
                }
            }
            if ((tokensChanged != 3) || isNaN(cal_dateSelected) || isNaN(cal_monthSelected) || isNaN(cal_yearSelected)) {
                cal_dateSelected = cal_dateNow;
                cal_monthSelected = cal_monthNow;
                cal_yearSelected = cal_yearNow;
            }

            ocal_dateSelected = cal_dateSelected;
            ocal_monthSelected = cal_monthSelected;
            ocal_yearSelected = cal_yearSelected;

            aTag = ctl;
            do {
                if (ie) {
                    aTag = aTag.offsetParent.offsetParent;
                } else {
                    aTag = aTag.offsetParent;
                }
                //aTag = aTag.offsetParent.offsetParent;
                leftpos += aTag.offsetLeft;                
                toppos += aTag.offsetTop;
            } while (aTag.tagName != "BODY" && aTag.tagName != "HTML" && aTag.tagName != "DIV");
            // Add HTML check solved problem using calendar within box_search

//            //Need to convert to string for firefox
//            var posleft = ctl.offsetLeft + leftpos + calendarOffsetX;
//            // Check leftpos to document.body.offsetWidth
//            posleft = chkLeftPos(posleft);

//            var strLeft = new String(posleft + "px");
//            var postop = ctl.offsetTop + toppos + ctl.offsetHeight + 2 + calendarOffsetY;
//            var strTop = new String(postop + "px");


            if (ie) {
                //For IE
                chkWideScreen();	
                if (WideScreen == true) {
                    var posleft = leftpos - ctl.offsetWidth + calendarOffsetX;    
                } else {
                    //var posleft = ctl.offsetLeft + leftpos + calendarOffsetX;
                    var posleft = leftpos + ctl.offsetLeft - (ctl.offsetWidth * 2) + 8 + calendarOffsetX;		
                }                
                        
                // Check leftpos to document.body.offsetWidth
                posleft = chkLeftPos(posleft);
                var strLeft = new String(posleft + "px");
                var postop = ctl.offsetTop + toppos + ctl.offsetHeight + 2 + calendarOffsetY;
                var strTop = new String(postop + "px");

            } else {
            //For FF
                var posleft = ctl.offsetLeft + leftpos + (ctl.offsetWidth * 2) - 2 + calendarOffsetX;            
                // Check leftpos to document.body.offsetWidth
                posleft = chkLeftPos(posleft);

                var strLeft = new String(posleft + "px");
                var postop = ctl.offsetTop + toppos + ctl.offsetHeight + 2 + calendarOffsetY;
                var strTop = new String(postop + "px");

            }				
		
            
            cal_crossObj.left = cal_fixedX == -1 ? strLeft : cal_fixedX;
            cal_crossObj.top = cal_fixedY == -1 ? strTop : cal_fixedY;

            constructCalendar(1, cal_monthSelected, cal_yearSelected);
            cal_crossObj.visibility = (dom || ie) ? "visible" : "show";

            hideElement('SELECT', document.getElementById("calendar"));
            hideElement('APPLET', document.getElementById("calendar"));

            bShow = true;
        }
    }
    else {
        init_calendar();
        popUpCalendar2(ctl, ctl2, format, OtherFunctions);
    }
}

function chkWideScreen() {
    if (((screen.width / 4) * 3) == screen.height) {
        WideScreen = true;
    }
    //alert(screen.width + " " + screen.height);
    //alert((screen.width / 4) * 3);	   
}
	
function chkLeftPos(lefpos) {
    var retval = lefpos - 42;
    var rightpos = lefpos + document.getElementById("calendar").offsetWidth;
    var winWidth = document.body.offsetWidth;
    var offset = 0;

    if (rightpos > winWidth) {
        offset = rightpos - winWidth + 1;
        retval -= offset;
        if (retval < 0)
            retval = 0;
    }
    return retval
}

document.onkeypress = function hidecal1() {
    if (event.keyCode == 27) {
        hideCalendar();
    }
}
document.onclick = function hidecal2() {
    if (!bShow) {
        hideCalendar();
    }
    bShow = false;
}

/* ---------------------------------- ABTEST CTY024 SmartSearch PopUp - Below -----------------------------------*/
function initMainSearchBox_popup() {
    // First, check for AJAX support, otherwise give error message
    if (IsSupportAjax() == false) {
        alert(ErrorAjax);
        return;
    }
    if (CountryID = document.getElementById(ControlID + "ddlSelectCountry2")) {
        var CountryID = document.getElementById(ControlID + "ddlSelectCountry2").value;
    }

    // Get the dropdown lists
    var checkInMonthDropDown = document.getElementById('ddlCheckInMonthYear2');
    var checkOutMonthDropDown = document.getElementById('ddlCheckOutMonthYear2');
    var checkInDayDropDown = document.getElementById('ddlCheckInDay2');
    var checkOutDayDropDown = document.getElementById('ddlCheckOutDay2');

    // Build the month dropdowns, independant of the preset values
    BuildDayMonthDownList(checkInMonthDropDown);
    BuildDayMonthDownList(checkOutMonthDropDown);

    // Init values - we want the default to be -d- - mm, yyyy - in case of no session history
    if (document.getElementById(ControlID + "arrivaldate").value != "" && CountryID != "0") {
        // Set the dropdowns for the months first
        var checkInDate = new Date();
        checkInDate.setTime(Date.parse(document.getElementById(ControlID + "arrivaldate").value));
        var checkOutDate = new Date();
        checkOutDate.setTime(Date.parse(document.getElementById(ControlID + "departdate").value));
        setCmbMonth(checkInMonthDropDown, checkInDate);
        setCmbMonth(checkOutMonthDropDown, checkOutDate);
    }

    // Build the dropdowns for the days    
    BuildDayDropDownList(checkInDayDropDown, checkInMonthDropDown)
    BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown)

    if (document.getElementById(ControlID + "arrivaldate").value != "" && CountryID != "0") {

        // And set them
        checkInDayDropDown.selectedIndex = checkInDate.getDate();
        checkOutDayDropDown.selectedIndex = checkOutDate.getDate();
    }

    if (document.getElementById(ControlID + "controlmode").value == "2")
        showsearch_ab48('Changedates');

}
function BuildCheckInDayDropDownList2() {
    var checkInDayDropDown = document.getElementById('ddlCheckInDay2');
    var checkInMonthDropDown = document.getElementById('ddlCheckInMonthYear2');
    BuildDayDropDownList(checkInDayDropDown, checkInMonthDropDown);
    changeCheckInDay2();
}
function BuildCheckOutDayDropDownList2() {
    var checkOutDayDropDown = document.getElementById('ddlCheckOutDay2');
    var checkOutMonthDropDown = document.getElementById('ddlCheckOutMonthYear2');
    BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown);
    flagCheckOutChange = true;
}
function changeCheckInDay2() {
    var checkInDayDropDown = document.getElementById('ddlCheckInDay2');
    var checkOutDayDropDown = document.getElementById('ddlCheckOutDay2');
    var checkInMonthDropDown = document.getElementById('ddlCheckInMonthYear2');
    var checkOutMonthDropDown = document.getElementById('ddlCheckOutMonthYear2');

    if (checkInMonthDropDown.selectedIndex == 0)
        return;

    var chosenMonth = checkInMonthDropDown.options[checkInMonthDropDown.selectedIndex].value;
    var numberOfDays = numberOfDaysPerMonthHashTable[chosenMonth];
    var chosenCheckInDay = parseInt(checkInDayDropDown.options[checkInDayDropDown.selectedIndex].value, 10);

    if (!chosenCheckInDay) {
        checkInDayDropDown.selectedIndex += 1;
        chosenCheckInDay = 1;
    }
    if ((chosenCheckInDay + 3) <= numberOfDays) {
        if (flagCheckOutChange == false || checkInMonthDropDown.selectedIndex > checkOutMonthDropDown.selectedIndex || (checkInMonthDropDown.selectedIndex == checkOutMonthDropDown.selectedIndex && checkInDayDropDown.selectedIndex > checkOutDayDropDown.selectedIndex)) {
            checkOutMonthDropDown.selectedIndex = checkInMonthDropDown.selectedIndex;
            BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown);
            checkOutDayDropDown.selectedIndex = chosenCheckInDay + 3;
        }
    } else {
        if (checkInMonthDropDown.selectedIndex >= 12) {
            alert("If you wish to book more than 1 year, please contact a customer service agent.");
            return false;
        }
        else {
            if (flagCheckOutChange == false || checkInMonthDropDown.selectedIndex > checkOutMonthDropDown.selectedIndex || (checkInMonthDropDown.selectedIndex == checkOutMonthDropDown.selectedIndex && checkInDayDropDown.selectedIndex > checkOutDayDropDown.selectedIndex)) {
                checkOutMonthDropDown.selectedIndex = checkInMonthDropDown.selectedIndex + 1;
                BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown);
                var remainingDays = 3 - (numberOfDays - chosenCheckInDay);
                checkOutDayDropDown.selectedIndex = remainingDays;
            }
        }
    }
}
function SetDateValues2() {
    var checkInDayDropDown = document.getElementById("ddlCheckInDay2");
    var checkOutDayDropDown = document.getElementById("ddlCheckOutDay2");
    var checkInMonthDropDown = document.getElementById("ddlCheckInMonthYear2");
    var checkOutMonthDropDown = document.getElementById("ddlCheckOutMonthYear2");

    if (checkInMonthDropDown.selectedIndex > 0) {
        var MonthYearIn = getDateFromDropDown(checkInMonthDropDown.selectedIndex);
        var checkInDateString = MonthYearIn.replace("dd", checkInDayDropDown.value);

        //alert("checkInDateString:"+checkInDateString);
        document.getElementById(ControlID + "arrivaldate").value = checkInDateString;
    }

    if (checkOutMonthDropDown.selectedIndex > 0) {
        var MonthYearOut = getDateFromDropDown(checkOutMonthDropDown.selectedIndex);
        var checkOutDateString = MonthYearOut.replace("dd", checkOutDayDropDown.value);
        //alert("checkOutDayDropDown:"+checkOutDayDropDown);

        document.getElementById(ControlID + "departdate").value = checkOutDateString;
    } else if (checkOutMonthDropDown.length == 0) {
        BuildDayDropDownList(checkOutDayDropDown, checkOutMonthDropDown);
    }
}
function updDateCombos2(obj, selday, selmonth, selyear) {
    var DayDropDown;
    var MonthDropDown;
    var monthvalue = frmtDate("MM,yyyy", selday, selmonth, selyear);
    var dayvalue = frmtDate("dd", selday, selmonth, selyear);

    if (obj.id == ControlID + "arrivaldate") {
        DayDropDown = document.getElementById('ddlCheckInDay2');
        MonthDropDown = document.getElementById('ddlCheckInMonthYear2');
        MonthDropDown.value = monthvalue;
        BuildCheckInDayDropDownList2();
        // first need to set and build month before we can set the day
        DayDropDown.value = dayvalue;
        changeCheckInDay2();

        // Duplicate logic above, for set Date on Main Control
        DayDropDown = document.getElementById('ddlCheckInDay2');
        MonthDropDown = document.getElementById('ddlCheckInMonthYear2');
        BuildCheckInDayDropDownList();
        DayDropDown.value = dayvalue;
        changeCheckInDay();
    } else {
        DayDropDown = document.getElementById('ddlCheckOutDay2');
        MonthDropDown = document.getElementById('ddlCheckOutMonthYear2');
        MonthDropDown.value = monthvalue;
        BuildCheckOutDayDropDownList2();
        // first need to set and build month before we can set the day
        DayDropDown.value = dayvalue;
        flagCheckOutChange = true;

        // Duplicate logic above, for set Date on Main Control
        DayDropDown = document.getElementById('ddlCheckOutDay2');
        MonthDropDown = document.getElementById('ddlCheckOutMonthYear2');
        MonthDropDown.value = monthvalue;
        BuildCheckOutDayDropDownList();
        DayDropDown.value = dayvalue;
        flagCheckOutChange = true;
    }
    SetDateValues2();
}
	