var JSONobj = '';
var AiirlineDetailsFrame = 0;
var HotelDetailsFrame = 1;
var HotelDetailsFrameForConfirmation = 0;
var PopUpWindowID = '';
var DD_S_Area = '';
var HF_S_Destination = '';
var HF_S_DestinationName = '';
var DD_S_Departure = '';
var DD_S_Hotel = '';
var DD_S_Destination = '';
var HF_S_Hotel = '';
var HF_S_Departure = ''
var DD_S_Duration = '';
var TB_S_DepartureDate = '';
var HF_SelectedDest = ''

var DD_S_NoOfRooms = '';
var UC_RoomsForPassenger2 = '';
var UC_RoomsForPassenger3 = '';

var DD_CA_AgeOfChildOne = '';
var DD_CA_AgeOfChildTwo = '';
var DD_CA_AgeOfChildThree = '';

var HF_SC_NextDayLanding = '';
var HF_SC_AreaXml = '';
var TB_SC_NextDayLanding = '';
var TB_SC_DefaultCheckOutTime = '';
var TB_SC_DefaultCheckInTime = '';
var TB_SC_isMeetAndGreet = '';

var DIV_Transfers = ''
var DIV_Supplements = '';
var Area = '';
var HDN_Room = '';
var HDN_Display = '';
//----------------Add for Special Offers----------//
var Hf_DestinationName = '';
var HF_S_DestinationID = '';
var DDL_SP_Destination = '';
var DDL_SP_Region = '';
//-------------------For Advance Search--------------------------//

var Display = '';
var Text = '';
//----------------------FoR best Deals in Recent Popular Searched------------//
var DD_BD_BoardBasis = '';
var DD_BD_Area = '';
var HF_BD_Destination = '';
var DD_BD_Destination = '';
var HF_BD_BoardBasis = '';
var BTN_SC_Search = '';
/////=====================================================//
function SearchValidations() {
    var Msg = '';
    var MsgAdults = '';
    var iSelectedNoofRooms = 0;
    if (document.getElementById(DD_S_NoOfRooms) != null) {
        iSelectedNoofRooms = document.getElementById(DD_S_NoOfRooms).value
        var i, iCountofAdultsChildren;
        iCountofAdultsChildren = 0;
        var NoOFAdults = "";
        var NoOFChildren = "";

        for (i = 1; i <= iSelectedNoofRooms; i++) {
            if (document.getElementById("ctl00_CPH_MainContainer_UC_MasterSearchControl_UC_SearchControl_UC_RoomsForPassenger" + i + "_DD_S_Adults") != null) {
                NoOFAdults = document.getElementById("ctl00_CPH_MainContainer_UC_MasterSearchControl_UC_SearchControl_UC_RoomsForPassenger" + i + "_DD_S_Adults");
            }
            else {
                NoOFAdults = document.getElementById("ctl00_CPH_MainContainer_CTL_SearchControl_UC_RoomsForPassenger" + i + "_DD_S_Adults");
            }

            if (document.getElementById("ctl00_CPH_MainContainer_UC_MasterSearchControl_UC_SearchControl_UC_RoomsForPassenger" + i + "_DD_S_Childrens") != null) {
                NoOFChildren = document.getElementById("ctl00_CPH_MainContainer_UC_MasterSearchControl_UC_SearchControl_UC_RoomsForPassenger" + i + "_DD_S_Childrens");
            }
            else {
                NoOFChildren = document.getElementById("ctl00_CPH_MainContainer_CTL_SearchControl_UC_RoomsForPassenger" + i + "_DD_S_Childrens");
            }
            iCountofAdultsChildren = parseInt(iCountofAdultsChildren) + parseInt(NoOFAdults.value);
            iCountofAdultsChildren = parseInt(iCountofAdultsChildren) + parseInt(NoOFChildren.value);

            if (iCountofAdultsChildren > 9) {
                MsgAdults = 'Your search is for a total of more than 9 adults and children.\nPlease call letsgo2 to help with this enquiry.\n';
            }
        }
    }

    if (document.getElementById(DD_S_Area).value == '' || document.getElementById(DD_S_Area).value == 'Please Choose') {
        Msg = 'Please Select Area.\n';
    }
    if (document.getElementById(DD_S_Destination).value == '' || document.getElementById(DD_S_Destination).value == 'Please Choose') {
        Msg += 'Please select Destination.\n';
    }
    if (document.getElementById(DD_S_Departure).value == '' || document.getElementById(DD_S_Departure).value == 'Please Choose') {
        Msg += 'Please select Departure airport.\n';
    }
    if (document.getElementById(DD_S_Duration).value == '' || document.getElementById(DD_S_Duration).value == 'Please Choose' || document.getElementById(DD_S_Duration).value == '0') {
        Msg += 'Please Select Duration.\n';
    }

    if (document.getElementById(TB_S_DepartureDate).value == '') {
        Msg += 'Please Enter Date.\n';
    }
    if (document.getElementById(TB_S_DepartureDate).value != '')
    // alert(document.getElementById(TB_S_DepartureDate).value);
        if ((!isDate(document.getElementById(TB_S_DepartureDate).value, GlobalDateFormat))) {
        Msg += "Please Enter Valid Date.\n";
        document.getElementById(TB_S_DepartureDate).focus();
    } else {
        //            var todaydate = new Date;
        //            // convert departure date into datetime format
        //            var depdat = getDateFromFormat(document.getElementById(TB_S_DepartureDate).value, "dd/MM/yyyy");

        //            var days = days_between(todaydate, depdat);
        //           if (days > 365) {
        //               Msg += "Thank you for selecting letsgo2 for your holiday. The dates you have selected are not currently available to confirm online as airlines generally only release confirmed seats 12 months prior to departure. Please contact our travel consultants on 0208 329 2600, who will be able to offer you further advice or take your details for an advance registration.";
        //               
        //           }
    }


    if (MsgAdults != '') {
        alert(MsgAdults);
        return false;
    }
    else if (Msg != '') {
        alert(Msg);
        return false;
    }
    else {
        var todaydate = new Date;
        // convert departure date into datetime format
        var depdat = getDateFromFormat(document.getElementById(TB_S_DepartureDate).value, "dd/MM/yyyy");

        var days = days_between(todaydate, depdat);
        if (days > 365) {
            alert("Thank you for selecting letsgo2 for your holiday. The dates you have selected are not currently available to confirm online as airlines generally only release confirmed seats 12 months prior to departure. Please contact our travel consultants on 0208 329 2600, who will be able to offer you further advice or take your details for an advance registration.");
        }
        document.getElementById(HF_S_DestinationName).value = $("#DD_S_Destination option:selected").text();
        SearchDestinationName = $("#DD_S_Destination option:selected").text();
        HoldingPageTypeId = 1;
        //load holidng page
        BodyOnBeforeUnload();
        return true;
    }

}
// this function will check depature date > 300 days or not
function days_between(date1, date2) {

    //    var newdate1 = getDateFromFormat(date1, "MM/dd/yy");
    //    var newdate2 = getDateFromFormat(date2, "MM/dd/yy");
    var newdate1 = date1;
    var newdate2 = date2;
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24;

    // Convert both dates to milliseconds
    var date1_ms = newdate1;
    var date2_ms = newdate2;

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms);

    // Convert back to days and return
    return Math.round(difference_ms / ONE_DAY);

}

function SetSearchHoldingPageData(DestinationName) {
    SearchDestinationName = DestinationName;
    HoldingPageTypeId = 1;
    BodyOnBeforeUnload();
    return true;
}

function ShowHoldingPage(id) {
    //alert('HoldingPage');
    $.ajax({
        // try to leverage ajaxQueue plugin to abort previous requests
        type: "POST",
        mode: "abort",
        // limit abortion to this input
        port: "searchHoldingPage",
        dataType: "xml",
        url: "/FillSearchFields.asmx/IsSearchComplete",
        data: { ID: id },
        success: function(data) {
            window.location = "Default.aspx"

        },
        complete: function(res, status) {
            //alert('Search completed!');

        }
    });
    return false;
}
//To fill area by zone code
function FillArea(xiDestinationID, xiAreaID) {
    var lCode = document.getElementById(xiDestinationID).value;
    ClearAllDropDown();
    var lID = document.getElementById(xiDestinationID).value;
    var xiCode = "";
    document.getElementById(HF_S_Departure).value = '';
    JSONobj = eval($("#DIV_AreaList").text());
    for (var i = 0; i < JSONobj.length; i++) {
        if (JSONobj[i].RegionID == lCode) {
            if (JSONobj[i].RedirectTo) {
                if (JSONobj[i].SearckPageLinkUrl)
                    location.href = JSONobj[i].SearckPageLinkUrl;
            }
            document.getElementById(HF_SC_AreaXml).value = JSONobj[i];
            BindAreaDropdown(JSONobj[i].RegionMasterList, xiAreaID);
            break;
        }
    }
}



function BindAreaDropdown(data, xiAreaID) {
    if (data) {
        var objDD_S_Destination = document.getElementById(DD_S_Destination);
        var AreaDropdown = document.getElementById(xiAreaID);
        for (var j = AreaDropdown.getElementsByTagName("optgroup").length - 1; j >= 0; j--) {
            objDD_S_Destination.removeChild(AreaDropdown.getElementsByTagName("optgroup")[j]);
        }
        if (AreaDropdown) {
            var ListOfAreaData = data;
            // document.getElementById(HF_SC_AreaXml).value = ListOfAreaData;
            AreaDropdown.options.length = 0;
            var optn = document.createElement("OPTION");
            optn.text = "Please Choose";
            optn.value = "";
            optn.nodeValue = "";
            $(optn).css("color", "#111111");
            AreaDropdown.options.add(optn);
            var optnLine = document.createElement("OPTION");
            optnLine.value = '';
            optnLine.text = '--------------------------------------------------------';
            $(optnLine).attr("disabled", "disabled");
            $(optnLine).css("color", "#999999");
            AreaDropdown.options.add(optnLine);
            var lSubTypeID = '';
            for (var i = 0; i < ListOfAreaData.length; i++) {
                var optn = document.createElement("OPTION");
                try {
                    optn.value = ListOfAreaData[i].RegionCode;
                    optn.text = ListOfAreaData[i].RegionName;
                    lSubTypeID = ListOfAreaData[i].SubTypeID;
                    optn.nodeValue = ListOfAreaData[i].RegionID;
                }
                catch (e) {
                    optn.value = ListOfAreaData[i].RegionCode;
                    optn.text = ListOfAreaData[i].RegionName;
                    lSubTypeID = ListOfAreaData[i].SubTypeID;
                    optn.nodeValue = ListOfAreaData[i].RegionID;
                }
                if (lSubTypeID == '2') {
                    if (AreaDropdown.options[AreaDropdown.options.length - 1].value != '') {
                        var optnLine = document.createElement("OPTION");
                        optnLine.value = '';
                        optnLine.text = '--------------------------------------------------------';
                        $(optnLine).attr("disabled", "disabled");
                        $(optnLine).css("color", "#999999");
                        AreaDropdown.options.add(optnLine);
                    }
                    var optgroup = document.createElement("optgroup");

                    $(optgroup).attr('label', optn.text);
                    $(optgroup).css("color", "#FF9933");
                    $(optgroup).addClass("optiongroup");
                    AreaDropdown.appendChild(optgroup);
                }
                if (lSubTypeID != '2') {
                    $(optn).css("color", "#111111");
                    AreaDropdown.options.add(optn);
                }
                var SubDestination = ListOfAreaData[i].RegionMasterList;
                if (SubDestination) {
                    for (var j = 0; j < SubDestination.length; j++) {
                        var Suboptn = document.createElement("OPTION");
                        Suboptn.value = SubDestination[j].RegionCode;
                        Suboptn.text = SubDestination[j].RegionName;
                        $(Suboptn).css("color", "#111111");
                        AreaDropdown.options.add(Suboptn);
                    }
                }
            }
        }
    }
}



//To fill airport/hotel/nextdaylanding by destination code
function FillAirport(lFeatureId) {
    //Clear selected hotel
    if (document.getElementById(HF_S_Hotel)) {
        document.getElementById(HF_S_Hotel).value = '';
    }
    var lID = document.getElementById(DD_S_Area).value;
    var lCode = document.getElementById(DD_S_Destination).value;
    var xiID = 0;
    document.getElementById(HF_S_Destination).value = lCode;
    if (lCode != "") {
        JSONobj = eval($("#DIV_AreaList").text());
        if (JSONobj) {
            for (var i = 0; i < JSONobj.length; i++) {
                if (JSONobj[i].RegionID == lID) {
                    var JSONAirportHotelObject = JSONobj[i].RegionMasterList;
                    if (JSONAirportHotelObject) {
                        for (var j = 0; j < JSONAirportHotelObject.length; j++) {
                            if (JSONAirportHotelObject[j].RegionCode == lCode) {
                                if (JSONAirportHotelObject[j].RedirectTo) {
                                    if (JSONAirportHotelObject[j].SearckPageLinkUrl)
                                        location.href = JSONAirportHotelObject[j].SearckPageLinkUrl;
                                }
                                //document.getElementById(HF_SC_AreaXml).value = JSONobj[i];
                                //-----------For Airport
                                BindAirportDropdown(JSONAirportHotelObject[j], DD_S_Departure, "ListOfUKAirports", "AirPortCode", "AirPortName");
                                //-----------For Hotel
                                BindHotelDropdown(JSONAirportHotelObject[j], DD_S_Hotel, "ListOFHotel", "HotelCode", "HotelName");
                                //-----------For Next Day Landing
                                BindNextDayLandingDetails(JSONAirportHotelObject[j]);
                                if (document.getElementById(HF_S_Departure).value != "")
                                    document.getElementById(DD_S_Departure).value = document.getElementById(HF_S_Departure).value;
                                break;
                            }
                            else {
                                var SubDestination = JSONAirportHotelObject[j].RegionMasterList
                                if (SubDestination) {
                                    for (var k = 0; k < SubDestination.length; k++) {
                                        if (SubDestination[k].RegionCode == lCode) {
                                            //-----------For Airport
                                            BindAirportDropdown(SubDestination[k], DD_S_Departure, "ListOfUKAirports", "AirPortCode", "AirPortName");
                                            //-----------For Hotel
                                            BindHotelDropdown(SubDestination[k], DD_S_Hotel, "ListOFHotel", "HotelCode", "HotelName");
                                            //-----------For Next Day Landing
                                            BindNextDayLandingDetails(SubDestination[k]);
                                            if (document.getElementById(HF_S_Departure).value != "")
                                                document.getElementById(DD_S_Departure).value = document.getElementById(HF_S_Departure).value;
                                            break;
                                        }
                                    }
                                }
                            }

                        }
                    }
                    break;
                }
            }
        }
    }
}
//To parse area XML and bind to  dropdown
function BindAirportDropdown(data, xiAreaID, XMLNode, CodeField, NameField) {
    if (data) {
        var AirportDropdown = document.getElementById(xiAreaID);
        if (AirportDropdown) {
            var ListOfAirportData = data;
            AirportDropdown.options.length = 0;
            var optn = document.createElement("OPTION");
            optn.text = "Please Choose";
            optn.value = "";
            AirportDropdown.options.add(optn);
            var ListOFAirData = ListOfAirportData.ListOfUKAirports;
            if (ListOFAirData) {
                for (var AirportIndex = 0; AirportIndex < ListOFAirData.length; AirportIndex++) {
                    var optn = document.createElement("OPTION");
                    optn.value = ListOFAirData[AirportIndex].AirPortCode;
                    optn.text = ListOFAirData[AirportIndex].AirPortName;
                    AirportDropdown.options.add(optn);

                }
            }
        }
    }
}
function BindHotelDropdown(data, xiAreaID, XMLNode, CodeField, NameField) {
    if (data) {
        var AirportDropdown = document.getElementById(xiAreaID);
        if (AirportDropdown) {
            var ListOfAirportData = data;
            AirportDropdown.options.length = 0;
            var optn = document.createElement("OPTION");
            optn.text = "Show All";
            optn.value = "";
            AirportDropdown.options.add(optn);
            var ListOFHotelData = ListOfAirportData.ListOFHotel;
            if (ListOFHotelData) {
                for (var HotelIndex = 0; HotelIndex < ListOFHotelData.length; HotelIndex++) {
                    var optn = document.createElement("OPTION");
                    optn.value = ListOFHotelData[HotelIndex].HotelCode;
                    optn.text = ListOFHotelData[HotelIndex].HotelName;
                    AirportDropdown.options.add(optn);
                }
            }
        }
    }
}
//To parse area XML and bind to  dropdown
function BindDropdown(data, xiAreaID, XMLNode, CodeField, NameField) {
    if (typeof (data) != String) {
        var rows = data.getElementsByTagName("string");
        var xmlDoc;
        if (window.DOMParser) {
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(rows[0].textContent, "text/xml");
        }
        else // Internet Explorer
        {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";
            xmlDoc.loadXML(rows[0].text);
        }
        if (xmlDoc) {
            var AreaDropdown = document.getElementById(xiAreaID);
            if (AreaDropdown) {

                var ListOfAreaData = xmlDoc.getElementsByTagName(XMLNode);
                AreaDropdown.options.length = 0;

                var optn = document.createElement("OPTION");

                if (xiAreaID == 'DD_S_Hotel') {
                    optn.text = "Show All";
                }
                else {
                    optn.text = "Please Choose";
                }
                optn.value = "";
                AreaDropdown.options.add(optn);

                for (var i = 0; i < ListOfAreaData.length; i++) {
                    var optn = document.createElement("OPTION");
                    var Area = new Array();
                    try {
                        optn.value = ListOfAreaData[i].selectSingleNode("./" + CodeField).text;
                        optn.text = ListOfAreaData[i].selectSingleNode("./" + NameField).text;
                    }
                    catch (e) {
                        optn.value = ListOfAreaData[i].getElementsByTagName(CodeField)[0].textContent;
                        optn.text = ListOfAreaData[i].getElementsByTagName(NameField)[0].textContent;
                    }

                    AreaDropdown.options.add(optn);
                }
            }
        }
    }


}
//To Clear All DropDown
function ClearAllDropDown() {
    var objDD_S_Destination = document.getElementById(DD_S_Destination);
    for (i = objDD_S_Destination.length - 1; i >= 0; i--) {
        objDD_S_Destination.options[i] = null;
    }

    for (var j = objDD_S_Destination.getElementsByTagName("optgroup").length - 1; j >= 0; j--) {
        objDD_S_Destination.removeChild(objDD_S_Destination.getElementsByTagName("optgroup")[j]);
    }

    for (i = objDD_S_Destination.length - 1; i >= 0; i--) {
        objDD_S_Destination.options[i] = null;
    }

    var objDD_S_Departure = document.getElementById(DD_S_Departure);
    for (i = objDD_S_Departure.length - 1; i >= 0; i--) {
        objDD_S_Departure.options[i] = null;
    }

    var objDD_S_Hotel = document.getElementById(DD_S_Hotel);
    for (i = objDD_S_Hotel.length - 1; i >= 0; i--) {
        objDD_S_Hotel.options[i] = null;
    }


    //To set Default value of Destination  -11/03/11
    if (objDD_S_Destination.length == 0) {

        var optnDest = document.createElement("OPTION");
        optnDest.text = "Please Choose";
        optnDest.value = "";
        objDD_S_Destination.options.add(optnDest);
    }

    //To set Default value of Departure  -11/03/11
    if (objDD_S_Departure.length - 1 < 0) {
        var optnDept = document.createElement("OPTION");
        optnDept.text = "Please Choose";
        optnDept.value = "";
        objDD_S_Departure.options.add(optnDept);
    }

    //To set Default value of HotelDropDown -10/03/11
    if (objDD_S_Hotel.length == 0) {

        var optn = document.createElement("OPTION");
        optn.text = "Show All";
        optn.value = "";
        objDD_S_Hotel.options.add(optn);
    }
}
//To parse area XML and bind to  dropdown by dropdown ref
function BindDropdownByRef(data, xiAreaID, XMLNode, CodeField, NameField, RoomTypeCode) {
    if (typeof (data) != String) {
        var rows = data.getElementsByTagName("string");
        var xmlDoc;
        if (window.DOMParser) {
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(rows[0].textContent, "text/xml");
        }
        else // Internet Explorer
        {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";
            xmlDoc.loadXML(rows[0].text);
        }
        if (xmlDoc) {
            var AreaDropdown = xiAreaID;
            if (AreaDropdown) {

                var ListOfAreaData = xmlDoc.getElementsByTagName(XMLNode);
                AreaDropdown.find('option').remove().end()
                AreaDropdown.append(optn);

                for (var i = 0; i < ListOfAreaData.length; i++) {
                    var optn = document.createElement("OPTION");
                    var Area = new Array();
                    var selected = '';
                    var selectedVal = '';

                    try {
                        optn.value = ListOfAreaData[i].selectSingleNode("./" + CodeField).text + "|" + RoomTypeCode;
                        optn.text = ListOfAreaData[i].selectSingleNode("./" + NameField).text;

                        selected = ListOfAreaData[i].selectSingleNode("./Selected").text;
                    }
                    catch (e) {
                        optn.value = ListOfAreaData[i].getElementsByTagName(CodeField)[0].textContent + "|" + RoomTypeCode;
                        optn.text = ListOfAreaData[i].getElementsByTagName(NameField)[0].textContent;
                        selected = ListOfAreaData[i].getElementsByTagName('Selected')[0].textContent;
                    }
                    optn.value = optn.value.replace(/\"/g, "");
                    if (selected == 'true') {
                        selectedVal = optn.value;
                    }
                    AreaDropdown.append(' <option value="' + optn.value + '">' + optn.text + '</option>');
                }
                $(AreaDropdown).val(selectedVal);
            }
        }
    }
}
function BindNextDayLandingDetails(data) {
    var NextDaylanding = 0;
    var CheckInTime = '';
    var CheckOutTime = '';
    var isMeetAndGreet = '';
    // NextDaylanding = ReadXML(data, "RegionMaster", "NextDayLanding");
    document.getElementById(TB_SC_NextDayLanding).value = data.NextDayLanding;
    // CheckInTime = ReadXML(data, "RegionMaster", "DefaultCheckInTime");
    document.getElementById(TB_SC_DefaultCheckInTime).value = data.DefaultCheckInTime;
    //CheckOutTime = ReadXML(data, "RegionMaster", "DefaultCheckOutTime");
    document.getElementById(TB_SC_DefaultCheckOutTime).value = data.DefaultCheckOutTime;
    // isMeetAndGreet = ReadXML(data, "RegionMaster", "isMeetAndGreet");
    document.getElementById(TB_SC_isMeetAndGreet).value = data.isMeetAndGreet;
}
function DepatureChange() {
    var lCode = document.getElementById(DD_S_Departure).value;
    document.getElementById(HF_S_Departure).value = lCode;
}

function HotelChange() {
    var lCode = document.getElementById(DD_S_Hotel).value;
    document.getElementById(HF_S_Hotel).value = lCode;

}

function FillDropDownAfterSearch(xiArea, xiDestination, xiDeparture, lFeatureId) {
    document.getElementById(DD_S_Area).value = xiArea;
    document.getElementById(HF_S_Destination).value = xiDestination;
    document.getElementById(HF_S_Departure).value = xiDeparture;
    FillDropDownAfterPostBack(lFeatureId);
}



function FillDropDownAfterPostBack(lFeatureId) {
    var lID = document.getElementById(DD_S_Area).value;
    if ($.QueryString["HotelOnly"]) {
        InitializeHotelOnly();
    }
    JSONobj = eval($("#DIV_AreaList").text());
    if (lID != "") {
        for (var i = 0; i < JSONobj.length; i++) {
            if (JSONobj[i].RegionID == lID) {
                document.getElementById(HF_SC_AreaXml).value = JSONobj[i];
                BindAreaDropdown(JSONobj[i].RegionMasterList, DD_S_Destination);
                if (document.getElementById(HF_S_Destination).value != "")
                    document.getElementById(DD_S_Destination).value = document.getElementById(HF_S_Destination).value;
                else
                    document.getElementById(DD_S_Destination).selectedIndex = 0;
            }
        }
    }
    var lCode = document.getElementById(HF_S_Destination).value;
    if (lCode != "") {
        for (var i = 0; i < JSONobj.length; i++) {
            if (JSONobj[i].RegionID == lID) {
                var JSONAirportHotelObject = JSONobj[i].RegionMasterList;
                for (var j = 0; j < JSONAirportHotelObject.length; j++) {
                    if (JSONAirportHotelObject[j].RegionCode == lCode) {
                        //-----------For Airport
                        BindAirportDropdown(JSONAirportHotelObject[j], DD_S_Departure, "ListOfUKAirports", "AirPortCode", "AirPortName");
                        if (document.getElementById(HF_S_Departure).value != "") {
                            document.getElementById(DD_S_Departure).value = document.getElementById(HF_S_Departure).value;
                            if (document.getElementById(DD_S_Departure).selectedIndex == -1)
                                document.getElementById(DD_S_Departure).selectedIndex = 0;
                        }
                        else
                            document.getElementById(DD_S_Departure).selectedIndex = 0;

                        //-----------For Hotel
                        BindHotelDropdown(JSONAirportHotelObject[j], DD_S_Hotel, "ListOFHotel", "HotelCode", "HotelName");
                        if (document.getElementById(HF_S_Hotel).value != "")
                            document.getElementById(DD_S_Hotel).value = document.getElementById(HF_S_Hotel).value;
                        else
                            document.getElementById(DD_S_Hotel).selectedIndex = 0;
                        //-----------For Next Day Landing
                        BindNextDayLandingDetails(JSONAirportHotelObject[j]);
                        if (document.getElementById(HF_S_Departure).value != "")
                            document.getElementById(DD_S_Departure).value = document.getElementById(HF_S_Departure).value;
                    }
                    else {
                        var SubDestination = JSONAirportHotelObject[j].RegionMasterList
                        if (SubDestination) {
                            for (var k = 0; k < SubDestination.length; k++) {
                                if (SubDestination[k].RegionCode == lCode) {
                                    //-----------For Airport
                                    BindAirportDropdown(SubDestination[k], DD_S_Departure, "ListOfUKAirports", "AirPortCode", "AirPortName");
                                    if (document.getElementById(HF_S_Departure).value != "") {
                                        document.getElementById(DD_S_Departure).value = document.getElementById(HF_S_Departure).value;
                                        if (document.getElementById(DD_S_Departure).selectedIndex == -1)
                                            document.getElementById(DD_S_Departure).selectedIndex = 0;
                                    }
                                    else
                                        document.getElementById(DD_S_Departure).selectedIndex = 0;

                                    //-----------For Hotel
                                    BindHotelDropdown(SubDestination[k], DD_S_Hotel, "ListOFHotel", "HotelCode", "HotelName");
                                    if (document.getElementById(HF_S_Hotel).value != "")
                                        document.getElementById(DD_S_Hotel).value = document.getElementById(HF_S_Hotel).value;
                                    else
                                        document.getElementById(DD_S_Hotel).selectedIndex = 0;
                                    //-----------For Next Day Landing
                                    BindNextDayLandingDetails(SubDestination[k]);
                                    if (document.getElementById(HF_S_Departure).value != "")
                                        document.getElementById(DD_S_Departure).value = document.getElementById(HF_S_Departure).value;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    ResetAfterPostback();
}


//To display tabs in Search Results
function SetSearchResultsTabId(TabId) {
    if (document.getElementById(TabId)) {
        var TabbedPanels1 = new Spry.Widget.TabbedPanels(TabId);
    }
}

//Display AirlineOffersDetails popup on search results page
function ShowAirlineOffersDetails(AirlineCode) {

    PopUpWindowID = '#DIV_AirlineOffersDetailsPopup';
    document.getElementById("DIV_AirlineOffersDetailsPopup").style.display = '';
    //window.frames[AiirlineDetailsFrame].location.replace('AirlineDetails.aspx?FareNumber=' + FareNumberString);
    $('#IF_AirlineOffersDetails').attr('src', 'AirlineOffersDetails.aspx?AirlineCode=' + AirlineCode);
    return false;
}

//Display Airline details popup on search results page
function ShowAirlineDetails(FareNumberString, AirlineClass) {

    PopUpWindowID = '#DIV_AirlineDetailsPopup';
    document.getElementById("DIV_AirlineDetailsPopup").style.display = '';
    //window.frames[AiirlineDetailsFrame].location.replace('AirlineDetails.aspx?FareNumber=' + FareNumberString);
    //    $('#IF_AirlineDetails').attr('src', 'AirlineDetails.aspx?FareNumber=' + FareNumberString);
    $('#IF_AirlineDetails').attr('src', "AirlineDetails.aspx?FareNumber=" + FareNumberString + "&AirlineClass=" + AirlineClass);

    return false;
}

//Following js is used to show/hide details, popup contents

$(document).ready(function() {
    //alert("a");

    $(".departDates li").hover(function() {
        $(this).children(".showFlightPopup").stop(true, true).toggle("slow");
    });
    //    $(".departDates li").hover(function() {
    //    $(this).children(".showFlightPopup").stop().toggle("slow");
    //    });
    //alert("b");
    //Tabs click popup
    $.currentTabPopup = "";

    //Follwoing function is used to close Preferred/Added value/Transfers popup  on Search result page on mouse click
    //It checks $.IsCurrentClickOnTab value which is initially set in function " $(".TabbedPanelsTabGroup li").click(function() "
    $.IsCurrentClickOnTab = "";
    if (document.getElementById("lpButDivID-1302769451")) {
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = "https://server.iad.liveperson.net/hc/7463944/?cmd=mTagRepstate&site=7463944&buttonID=13&divID=lpButDivID-1302769451&bt=1&c=1";
        document.body.appendChild(script);
    }
    $(document).click(function(e) {
        if ($.IsCurrentClickOnTab != 1) {
            if ($(".TabbedPanelsTabGroup li").children(".resultsTabPopup").is(":hidden")) {
                if (typeof $.currentTabPopup == "object") {
                    $.currentTabPopup.hide();
                }
            }
        }
        else {
            $.IsCurrentClickOnTab = 0;
        }
    }

 );


    $(".TabbedPanelsTabGroup li").click(function() {
        if ($(this).children(".resultsTabPopup").is(":hidden")) {
            if (typeof $.currentTabPopup == "object") {
                $.currentTabPopup.hide();
            }
        }
        $(this).children(".resultsTabPopup").toggle();
        $.currentTabPopup = $(this).children(".resultsTabPopup");

        //This used to close Preferred/Added value/Transfers popup on Search result page on mouse click
        $.IsCurrentClickOnTab = 1;
    });
    //Opening hours tooltip
    $(".openingHours").hover(function() {
        $(".showOpeningHours").animate({ opacity: "show", top: "116" }, "slow");
    }, function() {
        $(".showOpeningHours").animate({ opacity: "hide", top: "126" }, "slow");
    });


    //=============== comment to avoid script error============= manju// 
    //Rounded Corners Js
    //$('.searchbutton').corners();

    // added for the more info black button for rounded corners

    //$('.caribbeanHInfoLink').corner();
    // $('.moreInfoBtn').corner();


    // Map Location Popup
    $(".loadMapPopup").click(function() {
        loadMapLocation();
        centerPopup();
    });

    //Flight Details Popup
    $(".flightPopupButton").click(function() {
        //alert('a');
        loadPopup();
        centerPopup();
    });

    $(".whatsThisLink").click(function() {
        //alert('a');
        loadPopup();
        centerPopup();
    });



    $(".changePasswordpopupCloseButton").click(function() {
        $(".backgroundWrapper").fadeOut("slow");
        popupStatus = 0;
        PopUpWindowID = '#DIV_ChangePassword';
        $(PopUpWindowID).slideUp("slow");
    });
    $(".holidayCallBackRequestpopupCloseButton").click(function() {
        $(".backgroundWrapper").fadeOut("slow");
        popupStatus = 0;
        PopUpWindowID = '#DIV_HolidayRequestCallBack';
        $(PopUpWindowID).slideUp("slow");

    });

    $(".HoteldetailspopupCloseButton").click(function() {
        disablePopup();
        $(PopUpWindowID).slideUp("slow");
        //$('#DIV_HoldingPage').hide();
        //   window.frames[HotelDetailsFrame].location.replace("HotelDetailsPopUp.aspx");
        $('#IF_HotelDetails').attr('src', 'HotelDetailsPopUp.aspx');

    });
    $(".SearchResultNotFoundPopUpCloseButton").click(function() {
        $(".backgroundWrapper").fadeOut("slow");
        popupStatus = 0;
        PopUpWindowID = '#DIV_ResultNotFound';
        $(PopUpWindowID).slideUp("slow");

    });
    $(".popupCloseButton, .closeMap").click(function() {
        disablePopup();
        $(PopUpWindowID).slideUp("slow");
        //$('#DIV_HoldingPage').hide();
        // window.frames[HotelDetailsFrame].location.replace("HotelDetailsPopUp.aspx");

    });
    $(".closeMap").click(function() {
        disablePopup();
        $(".mapLocation").slideUp("slow");
    });

    var popupStatus = 0;


    function loadPopup() {

        if (popupStatus == 0) {
            $(".backgroundWrapper").css({ "opacity": "0.7" });
            $(".backgroundWrapper").fadeIn("slow");
            $(PopUpWindowID).fadeIn("slow");
            popupStatus = 1;
        }
    };
    function loadMapLocation() {
        if (popupStatus == 0) {
            $(".backgroundWrapper").css({ "opacity": "0.7" });
            $(".backgroundWrapper").fadeIn("slow");
            $(".mapLocation").fadeIn("slow");
            popupStatus = 1;
        }
    };
    function disablePopup() {


        if (popupStatus == 1) {
            $(".backgroundWrapper").fadeOut("slow");
            popupStatus = 0;
        }
    };


    function centerPopup() {
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $(PopUpWindowID).height();
        var popupWidth = $(PopUpWindowID).width();
        var mapLHeight = $(".mapLocation").height();
        var mapLWidth = $(".mapLocation").width();

        //Flight details popup centering
        $(PopUpWindowID).css({
            "position": "fixed",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
        // Map location popup centering
        $(".mapLocation").css({
            "position": "fixed",
            "top": windowHeight / 2 - mapLHeight / 2,
            "left": windowWidth / 2 - mapLWidth / 2
        });



    };

    //popup show/hide toggle
    $(".flightLinkDesc:not(:first)").hide();
    $(".flightLinkDesc:first").show();
    $(".flightClassDetails ul li a:first").addClass("flightLiLinkActice");

    $(".flightClassDetails ul li a").click(function() {

        var currentDescDiv = $(this).next();

        $(".flightLinkDesc").hide(0, function() {
            currentDescDiv.show();
            $(".flightClassDetails ul li a").removeClass("flightLiLinkActice");
            $(".flightClassDetails ul li a:first").removeClass("flightLiLinkActice");
        });
        $(this).addClass("flightLiLinkActice");


    });

    //Full flight details toggle	
    $(".departReturnSeparator, .departReturnSeparator a").click(function() {

        $(this).toggleClass("departReturnSeparatorNoBorder");
        $(this).children().toggleClass("fullFlightDetailsActive");

        var currentFDetailsPrev = $(this).prev(".showHideRouteDetals");
        //var currentFDetailsNext = $(this).next().next(".showHideRouteDetals");
        var currentFDetailsNext = $(this).next().next().next(".showHideRouteDetals");
        var currentFTitlesNext = $(this).next(".showHideRouteTitles");

        currentFDetailsPrev.toggle(300);
        currentFDetailsNext.toggle(300);
        currentFTitlesNext.toggle(300);
    });

    $(".departReturnSeparator a").click(function() {

        $(this).toggleClass("departReturnSeparatorNoBorder");
        //  $(this).$("a").toggleClass("fullFlightDetailsActive");
        $(this).children().toggleClass("fullFlightDetailsActive");

        var currentFDetailsPrev = $(this).prev(".showHideRouteDetals");
        //var currentFDetailsNext = $(this).next().next(".showHideRouteDetals");
        var currentFDetailsNext = $(this).next().next().next(".showHideRouteDetals");
        var currentFTitlesNext = $(this).next(".showHideRouteTitles");

        currentFDetailsPrev.toggle(300);
        currentFDetailsNext.toggle(300);
        currentFTitlesNext.toggle(300);
    });

});

function FillPricing(data, DD_RoomType) {
    var lTotalPrice = 0;
    var lAveragePrice = 0;
    //var lCurrencySymbol = '';
    var lOrginalPrice = 0;
    var lRoomStatus = '';
    var lAvailableRoom = '';
    var lAvailableRoomText = '';
    var lSpecialOffersDescription = '';
    lTotalPrice = ReadXML(data, "SearchResultPriceUI", "TotalPrice");
    lOrginalPrice = ReadXML(data, "SearchResultPriceUI", "OrginalPrice");
    //alert(DD_RoomType);
    lAveragePrice = ReadXML(data, "SearchResultPriceUI", "AveragePrice");
    //lCurrencySymbol = ReadXML(data, "SearchResultPriceUI", "CurrencySymbol");
    lRoomStatus = ReadXML(data, "SearchResultPriceUI", "RoomStatus");
    lAvailableRoom = ReadXML(data, "SearchResultPriceUI", "AvailableRooms");

    lSpecialOffersDescription = ReadXML(data, "SearchResultPriceUI", "SpecialOffersDescription");
    $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#AvaragePriceDetails')).empty().append("&pound;" + lAveragePrice); ;
    $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#OrginalPriceDetails')).empty();
    $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#p_PriceDisplay')).removeClass("priceDisplayOD");
    $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#TotalPriceDetails_Discount')).empty();
    $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#OrginalPriceDetails_Discount')).empty();
    if (lTotalPrice == lOrginalPrice) {
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#OrginalPriceDetails')).empty().append("&pound;" + lOrginalPrice);
    }
    else {
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#p_PriceDisplay')).addClass("priceDisplayOD");
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#TotalPriceDetails_Discount')).empty().append("&pound;" + lTotalPrice);
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#OrginalPriceDetails_Discount')).empty().append("&pound;" + lOrginalPrice);
    }
    $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#RoomStatus')).empty().append(lRoomStatus);
    $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#AvailableRooms')).empty().append(lAvailableRoom);


    if (lRoomStatus == "On Request" || lRoomStatus == "OnRequest") {
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#RoomStatus')).removeClass("highlightedGreenText");
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#RoomStatus')).addClass("orangeColorTxt");
    }
    else {
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#RoomStatus')).removeClass("orangeColorTxt");
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#RoomStatus')).addClass("highlightedGreenText");
    }
    //$($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#TAB_AddedValue')).find(".resultsTabPopup").empty().append("<strong>Added Value:</strong>" + lSpecialOffersDescription);
    if (lSpecialOffersDescription == '')
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#TAB_AddedValue')).css("display", "none");
    else {
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#TAB_AddedValue')).css("display", "");
        $($('#' + DD_RoomType).parents(".TabbedPanels")[0]).find(('#TAB_AddedValue')).find(".resultsTabPopup").empty().append("<strong>Added Value:</strong>" + lSpecialOffersDescription);
    }

}

function DDL_RoomTypeSelectedValueChange(DD_RoomType, lDataItemIndex) {

    var lRoomtypeCode = document.getElementById(DD_RoomType).value;
    var data = '';
    var lBoardTypeCode = '';
    //alert(DD_RoomType);
    GetPrices(lRoomtypeCode, lBoardTypeCode, lDataItemIndex, DD_RoomType);
    return false;
}

function Alternate_DDL_RoomTypeSelectedValueChange(DD_RoomType, lDataItemIndex) {

    var lRoomtypeCode = document.getElementById(DD_RoomType).value;
    var data = '';
    var lBoardTypeCode = '';
    //alert(DD_RoomType);
    GetPricesForAlternateResults(lRoomtypeCode, lBoardTypeCode, lDataItemIndex, DD_RoomType);
    return false;
}

function GetPricesForAlternateResults(lRoomtypeCode, lBoardTypeCode, lDataItemIndex, DD_RoomTypeID, DisplayIndex) {
    //alert(lBoardTypeCode);
    $.ajax({
        // try to leverage ajaxQueue plugin to abort previous requests
        type: "POST",
        mode: "abort",
        // limit abortion to this input
        port: "RoomTypeSelectedValueChange",
        dataType: "xml",
        url: "/FillSearchFields.asmx/Alternate_DDL_SR_RoomType_SelectedIndexChanged",
        data: { RoomTypeCode: lRoomtypeCode, BoardTypeCode: lBoardTypeCode, DataItemIndex: lDataItemIndex },
        success: function(data) {
            if (lBoardTypeCode == '') {
                //alert(1);
                BindDropdownByRef(data, $($('#' + DD_RoomTypeID).parents("div")[0]).find(('#DDL_SR_BoardType')), "BoardType", "BoardTypeCodeName", "Name", lRoomtypeCode);
                FillPricing(data, DD_RoomTypeID);
                // alert(1);
                // $($($('#' + DD_RoomTypeID).parents("div")[0]).find(('#DDL_SR_BoardType'))).selectmenu({ style: 'dropdown' });
            }
            else {
                //alert(2);
                DD_RoomTypeID = "ctl00_CPH_MainContainer_UC_SearchResults_LV_SR_SearchResults_ctrl" + DisplayIndex + "_DDL_SR_RoomType";
                FillPricing(data, DD_RoomTypeID);
            }
        }
    });
}


function GetPrices(lRoomtypeCode, lBoardTypeCode, lDataItemIndex, DD_RoomTypeID, DisplayIndex) {
    //alert(lBoardTypeCode);
    $.ajax({
        // try to leverage ajaxQueue plugin to abort previous requests
        type: "POST",
        mode: "abort",
        // limit abortion to this input
        port: "RoomTypeSelectedValueChange",
        dataType: "xml",
        url: "/FillSearchFields.asmx/DDL_SR_RoomType_SelectedIndexChanged",
        data: { RoomTypeCode: lRoomtypeCode, BoardTypeCode: lBoardTypeCode, DataItemIndex: lDataItemIndex },
        success: function(data) {
            if (lBoardTypeCode == '') {
                //alert(1);
                BindDropdownByRef(data, $($('#' + DD_RoomTypeID).parents("div")[0]).find(('#DDL_SR_BoardType')), "BoardType", "BoardTypeCodeName", "Name", lRoomtypeCode);
                FillPricing(data, DD_RoomTypeID);
                // alert(1);
                // $($($('#' + DD_RoomTypeID).parents("div")[0]).find(('#DDL_SR_BoardType'))).selectmenu({ style: 'dropdown' });
            }
            else {
                //alert(2);
                DD_RoomTypeID = "ctl00_CPH_MainContainer_UC_SearchResults_LV_SR_SearchResults_ctrl" + DisplayIndex + "_DDL_SR_RoomType";
                FillPricing(data, DD_RoomTypeID);
            }
        }
    });
}

function DDL_BoardTypeSelectedValueChange(id, index, DisplayIndex) {

    var myindex = id.selectedIndex
    // alert(id.options[myindex].value)
    var SelValue = id.options[myindex].value.split('|');
    //alert(SelValue[1] + "-----" + SelValue[0] + "-----" + index + "-----" + id.id);
    //alert(index);
    GetPrices(SelValue[1], SelValue[0], index, id.id, DisplayIndex);

}


function GetMapLocations(xiHotelCode, xiAreaCode, xiHotel) {
    //  alert(xiHotelCode);
    //alert(xiHotel);

    //xiHotel.replace('0', "'");
    $('#HotelName').empty().append(xiHotel);
    var HotelName = $('#HotelName').html().replace('@', "'");
    $('#HotelName').empty().append(HotelName);

    if (xiHotelCode != "") {
        //-----for Airport
        $.ajax({
            // try to leverage ajaxQueue plugin to abort previous requests
            type: "POST",
            mode: "abort",
            // limit abortion to this input
            port: "GetHotelLocations",
            dataType: "xml",
            url: "/FillSearchFields.asmx/GetHotelLocations",
            data: { lCode: xiHotelCode, lArea: xiAreaCode },
            success: function(data) {
                //alert(data);
                if (typeof (data) != String) {
                    var rows = data.getElementsByTagName("string");
                    var xmlDoc;
                    if (window.DOMParser) {
                        parser = new DOMParser();
                        xmlDoc = parser.parseFromString(rows[0].textContent, "text/xml");
                    }
                    else // Internet Explorer
                    {
                        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                        xmlDoc.async = "false";
                        xmlDoc.loadXML(rows[0].text);
                    }
                    showMap(xmlDoc);
                }

            }
        });
    }
    return false;
}

//Display Hotel details popup on search results page
function ShowHotelDetails(HotelCode) {
    //alert(HotelCode);
    PopUpWindowID = '#DIV_HotelDetailsPopup';
    document.getElementById("DIV_HotelDetailsPopup").style.display = '';
    //window.frames[HotelDetailsFrame].location.replace("HotelDetailsPopUp.aspx?Id=" + HotelCode + "&ShowMap=false");

    $('#IF_HotelDetails').attr('src', "HotelDetailsPopUp.aspx?Id=" + HotelCode + "&ShowMap=false");

    //ShowHoldingDiv();

    return false;
}

function ShowHotelDetailsForConfirmation(HotelCode) {
    //alert(HotelCode);
    PopUpWindowID = '#DIV_HotelDetailsPopup';
    document.getElementById("DIV_HotelDetailsPopup").style.display = '';
    window.frames[HotelDetailsFrameForConfirmation].location.replace("/SearchResults/HotelDetailsPopUp.aspx?Id=" + HotelCode + "&ShowMap=false");
    return false;
}

function ShowChangePasswordDiv(Divid, flag) {
    //    alert(1);
    //    if (flag == 0) {
    //        PopUpWindowID = '#' + Divid;
    //        document.getElementById(Divid).style.display = '';
    //        ShowPoopUp(PopUpWindowID);
    //    }
    //    $(".backgroundWrapper").css({ "opacity": "0.7" });
    //    $(".backgroundWrapper").fadeIn("slow");
    //    return true;
}

var popupStatus = 0;
function ShowPoopUp(PopUpWindowID) {
    if (popupStatus == 0) {
        $(".backgroundWrapper").css({ "opacity": "0.7" });
        $(".backgroundWrapper").fadeIn("slow");
        $(PopUpWindowID).fadeIn("slow");
        popupStatus = 1;
    }
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(PopUpWindowID).height();
    var popupWidth = $(PopUpWindowID).width();
    var mapLHeight = $(".mapLocation").height();
    var mapLWidth = $(".mapLocation").width();
    //Flight details popup centering
    $(PopUpWindowID).css({
        "position": "fixed",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
}

function ShowQuotationPriceChange() {

    PopUpWindowID = '#ctl00_CPH_MainContainer_UC_CustomerDetails_DIV_QuotationPriceChange';
    document.getElementById("ctl00_CPH_MainContainer_UC_CustomerDetails_DIV_QuotationPriceChange").style.display = '';
    ShowPoopUp(PopUpWindowID);
}

//Display No of rooms
function ShowNumberOfRooms() {
    document.getElementById("Room1").style.display = "none";
    document.getElementById("Room2").style.display = "none";
    document.getElementById("Room3").style.display = "none";

    if (document.getElementById(DD_S_NoOfRooms).value == "1") {

        document.getElementById("Room1").style.display = '';
        document.getElementById("Room2").style.display = "none";
        document.getElementById("Room3").style.display = "none";
    }
    if (document.getElementById(DD_S_NoOfRooms).value == "2") {

        document.getElementById("Room1").style.display = '';
        document.getElementById("Room2").style.display = '';
        document.getElementById("Room3").style.display = "none";
    }
    if (document.getElementById(DD_S_NoOfRooms).value == "3") {
        document.getElementById("Room1").style.display = '';
        document.getElementById("Room2").style.display = '';
        document.getElementById("Room3").style.display = '';
    }
    ShowHideDivForChildAges();
}

//Displays Child Ages
function ShowChildAges() {
    var RoomOne = document.getElementById(RoomOneChildID);
    var RoomTwo = document.getElementById(RoomTwoChildID);
    var RoomThree = document.getElementById(RoomThreeChildID);

    if (RoomOne.value > 0 || RoomTwo.value > 0 || RoomThree.value > 0) {
        document.getElementById("DIV_ChildAge").style.display = "";
        document.getElementById("LI_childdropdown").style.display = "";
    }
    else {
        document.getElementById("DIV_ChildAge").style.display = 'none';
        document.getElementById("LI_childdropdown").style.display = 'none';
    }

    if (RoomOne.value == 0) {
        document.getElementById("DIV_Room_1_Child").style.display = 'none';
    }
    if (RoomOne.value == 1) {
        document.getElementById("DIV_Room_1_Child").style.display = "";
        $('#DIV_Room_1_Child').find('#DIV_CA_ChildTwo').css('display', 'none');
        $('#DIV_Room_1_Child').find('#DIV_CA_ChildThree').css('display', 'none');
    }
    if (RoomOne.value == 2) {
        document.getElementById("DIV_Room_1_Child").style.display = "";
        $('#DIV_Room_1_Child').find('#DIV_CA_ChildTwo').css('display', '');
        $('#DIV_Room_1_Child').find('#DIV_CA_ChildThree').css('display', 'none');
    }
    if (RoomOne.value == 3) {
        $('#DIV_Room_1_Child').find('#DIV_CA_ChildTwo').css('display', '');
        $('#DIV_Room_1_Child').find('#DIV_CA_ChildThree').css('display', '');
        document.getElementById("DIV_Room_1_Child").style.display = "";
    }

    if (RoomTwo.value == 0) {
        document.getElementById("DIV_Room_2_Child").style.display = 'none';
    }
    if (RoomTwo.value == 1) {
        document.getElementById("DIV_Room_2_Child").style.display = "";
        $('#DIV_Room_2_Child').find('#DIV_CA_ChildTwo').css('display', 'none');
        $('#DIV_Room_2_Child').find('#DIV_CA_ChildThree').css('display', 'none');
    }
    if (RoomTwo.value == 2) {
        document.getElementById("DIV_Room_2_Child").style.display = "";
        $('#DIV_Room_2_Child').find('#DIV_CA_ChildTwo').css('display', '');
        $('#DIV_Room_2_Child').find('#DIV_CA_ChildThree').css('display', 'none');
    }
    if (RoomTwo.value == 3) {
        $('#DIV_Room_2_Child').find('#DIV_CA_ChildTwo').css('display', '');
        $('#DIV_Room_2_Child').find('#DIV_CA_ChildThree').css('display', '');
        document.getElementById("DIV_Room_2_Child").style.display = "";
    }

    if (RoomThree.value == 0) {
        document.getElementById("DIV_Room_3_Child").style.display = 'none';
    }
    if (RoomThree.value == 1) {
        document.getElementById("DIV_Room_3_Child").style.display = "";
        $('#DIV_Room_3_Child').find('#DIV_CA_ChildTwo').css('display', 'none');
        $('#DIV_Room_3_Child').find('#DIV_CA_ChildThree').css('display', 'none');
    }
    if (RoomThree.value == 2) {
        document.getElementById("DIV_Room_3_Child").style.display = "";
        $('#DIV_Room_3_Child').find('#DIV_CA_ChildTwo').css('display', '');
        $('#DIV_Room_3_Child').find('#DIV_CA_ChildThree').css('display', 'none');
    }
    if (RoomThree.value == 3) {
        $('#DIV_Room_3_Child').find('#DIV_CA_ChildTwo').css('display', '');
        $('#DIV_Room_3_Child').find('#DIV_CA_ChildThree').css('display', '');
        document.getElementById("DIV_Room_3_Child").style.display = "";
    }
}

//Show Or Hide Div of Child Age OnChange Of Room Numbers 
function ShowHideDivForChildAges() {
    var NoOfRooms = document.getElementById(DD_S_NoOfRooms);
    var RoomOneChild = document.getElementById(RoomOneChildID);
    var RoomTwoChild = document.getElementById(RoomTwoChildID);
    var RoomThreeChild = document.getElementById(RoomThreeChildID);

    if (NoOfRooms.value == 1) {
        RoomTwoChild.value = 0;
        RoomThreeChild.value = 0;
    }
    if (NoOfRooms.value == 2) {
        RoomThreeChild.value = 0;
    }

    document.getElementById("DIV_Room_1_Child").style.display = 'none';
    document.getElementById("DIV_Room_2_Child").style.display = 'none';
    document.getElementById("DIV_Room_3_Child").style.display = 'none';
    document.getElementById("DIV_ChildAge").style.display = 'none';

    if (RoomOneChild.value > 0) {
        document.getElementById("DIV_ChildAge").style.display = "";
        document.getElementById("DIV_Room_1_Child").style.display = "";
    }
    if (RoomTwoChild.value > 0) {
        document.getElementById("DIV_ChildAge").style.display = "";
        document.getElementById("DIV_Room_2_Child").style.display = "";
    }
    if (RoomThreeChild.value > 0) {
        document.getElementById("DIV_ChildAge").style.display = "";
        document.getElementById("DIV_Room_3_Child").style.display = "";
    }
}

//function ProceedHolidaySummary() {
//    var ReadImportantInfo = document.getElementById(CB_ReadImportantInfo);
//    if (ReadImportantInfo.checked != true) {
//        alert("Please read Important Holiday Information & Proceed");
//        document.getElementById(CB_ReadImportantInfo).focus();
//        return false;
//    }
//  HoldingPageTypeId = 1;
//    BodyOnBeforeUnload();
//    return true;
//}

function AddTransfer(CheckBox, xiDescription, xiPrice) {
    // alert(xiDescription + "  " + xiPrice);


    $.ajax({
        // try to leverage ajaxQueue plugin to abort previous requests
        type: "POST",
        mode: "abort",
        // limit abortion to this input
        port: "AddtransferPrice",
        dataType: "xml",
        url: "/FillPaymentDetails.asmx/AddtransferPriceInTotalPrice",
        data: { isChecked: CheckBox.checked, xiDescription: xiDescription, xiPrice: xiPrice },
        success: function(data) {
            FillPricdetails(data);
        }
    });

    return true;
}

function Addsupplement(CheckBox, xiDescription, xiPrice) {
    // alert(xiDescription + "  " + xiPrice);


    //    $.ajax({
    //        // try to leverage ajaxQueue plugin to abort previous requests
    //        type: "POST",
    //        mode: "abort",
    //        // limit abortion to this input
    //        port: "AddtransferPrice",
    //        dataType: "xml",
    //        url: "/FillPaymentDetails.asmx/AddsupplementPriceInTotalPrice",
    //        data: { isChecked: CheckBox.checked, xiDescription: xiDescription, xiPrice: xiPrice },
    //        success: function(data) {
    //            FillPricdetails(data);
    //        }
    //    });

    return true;
}


function FillPricdetails(data) {
    var lTotalPrice = 0;
    var lAvaragePrice = 0;
    var OrgnPrice = 0;
    var lDiscountPrice = 0.00;
    lTotalPrice = ReadXML(data, "Package", "TotalPrice");
    lAvaragePrice = ReadXML(data, "Package", "AvaragePrice");
    OrgnPrice = ReadXML(data, "Package", "OriginalPrice");
    lDiscountPrice = OrgnPrice - lTotalPrice;
    var CurrencySymbol = ReadXML(data, "Package", "CurrencySymbol");

    $("#LT_TotalPrice").empty().append("&pound;" + lTotalPrice);
    $("#LT_TotalPrice1").empty().append("&pound;" + lTotalPrice);
    $("#H1_HS_TotalPrice").empty().append("&pound;" + OrgnPrice);
    $("#AvaragePriceDetails").empty().append("&pound;" + lAvaragePrice);
    if (lTotalPrice == OrgnPrice) {
        $("[onlineDiscount='true']").css("display:none");
        //   $("#H2_HS_OnlineDiscountValue").empty().append("&pound;" + lTotalPrice);
        $("#H2_HS_OnlineDiscountValue").empty();
        $("#H2_HS_DiscountText").empty();
    }
    else {
        $("[onlineDiscount='true']").css("display:");
        $("#H2_HS_OnlineDiscountValue").empty().append("&pound;" + lTotalPrice);
        $("#H2_HS_DiscountText").empty().append("&pound;" + lDiscountPrice.toFixed(2));

    }
}

//Newly added for Leftnav OfferControl
function SetURL(HotelUrl) {
    HotelUrl = HotelUrl.replace(' ', '');
    if (HotelUrl.length > 0) {
        return true;
    }
    else {
        return false;
    }
}



function SupplementTransferCheck() {

    $("#" + DIV_Transfers + " INPUT[type='checkbox']").click(function() {

        var chkTransferCount = $($("#" + DIV_Transfers + " INPUT[type='checkbox']")).length;

        if (chkTransferCount > 0) {
            if (this.checked) {
                for (i = 0; i < chkTransferCount; i++) {
                    $("#" + DIV_Transfers + " INPUT[type='checkbox']")[i].checked = false;
                    $("#" + DIV_Transfers + " INPUT[type='checkbox']")[i].disabled = true;
                }
                this.disabled = false;
                this.checked = true;
            }
            else {
                for (i = 0; i < chkTransferCount; i++) {
                    $("#" + DIV_Transfers + " INPUT[type='checkbox']")[i].checked = false;
                    $("#" + DIV_Transfers + " INPUT[type='checkbox']")[i].disabled = false;
                }
            }
        }
    });

    //    $("#" + DIV_Supplements + " INPUT[type='checkbox']").click(function() {

    //        var chkSupplemntCount = $($("#" + DIV_Supplements + " INPUT[type='checkbox']")).length;

    //        if (chkSupplemntCount > 0) {
    //            if (this.checked) {
    //                for (i = 0; i < chkSupplemntCount; i++) {
    //                    $("#" + DIV_Supplements + " INPUT[type='checkbox']")[i].checked = false;
    //                    $("#" + DIV_Supplements + " INPUT[type='checkbox']")[i].disabled = true;
    //                }
    //                this.disabled = false;
    //                this.checked = true;
    //            }
    //            else {
    //                for (i = 0; i < chkSupplemntCount; i++) {
    //                    $("#" + DIV_Supplements + " INPUT[type='checkbox']")[i].checked = false;
    //                    $("#" + DIV_Supplements + " INPUT[type='checkbox']")[i].disabled = false;
    //                }
    //            }
    //        }
    //    });

}

function checkBoxDisableOnStartUp() {

    var chkTransferCount = $($("#" + DIV_Transfers + " INPUT[type='checkbox']")).length;

    if (chkTransferCount > 0) {
        for (i = 0; i < chkTransferCount; i++) {
            if ($("#" + DIV_Transfers + " INPUT[type='checkbox']")[i].checked == true) {

                disableAllCheckBox(chkTransferCount, 1);

                $("#" + DIV_Transfers + " INPUT[type='checkbox']")[i].disabled = false;
                $("#" + DIV_Transfers + " INPUT[type='checkbox']")[i].checked = true
            }
        }
    }

    //    var chkSupplemntCount = $($("#" + DIV_Supplements + " INPUT[type='checkbox']")).length;

    //    if (chkSupplemntCount > 0) {
    //        for (i = 0; i < chkSupplemntCount; i++) {
    //            if ($("#" + DIV_Supplements + " INPUT[type='checkbox']")[i].checked == true) {

    //                disableAllCheckBox(chkSupplemntCount, 0);

    //                $("#" + DIV_Supplements + " INPUT[type='checkbox']")[i].disabled = false;
    //                $("#" + DIV_Supplements + " INPUT[type='checkbox']")[i].checked = true
    //            }
    //        }
    //    }

}

function disableAllCheckBox(xiCount, xiForWhat) {

    if (xiForWhat == 1) {
        for (j = 0; j < xiCount; j++) {
            $("#" + DIV_Transfers + " INPUT[type='checkbox']")[j].disabled = true;
        }
    }
    else if (xiForWhat == 0) {
        for (j = 0; j < xiCount; j++) {
            $("#" + DIV_Supplements + " INPUT[type='checkbox']")[j].disabled = true;
        }
    }
}

function ShowHoldingDivForBestRegionDeals(DestinationName) {
    SearchDestinationName = DestinationName;
    HoldingPageTypeId = 1;
    BodyOnBeforeUnload();
    return true;
}

function changePasswordPopUp() {
    PopUpWindowID = '#DIV_ChangePassword';

    if (popupStatus == 0) {
        $(".backgroundWrapper").css({ "opacity": "0.7" });
        $(".backgroundWrapper").fadeIn("slow");
        $(PopUpWindowID).fadeIn("slow");
        popupStatus = 1;
    }
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(PopUpWindowID).height();
    var popupWidth = $(PopUpWindowID).width();


    //InviteFriend Change Password popup centering
    $(PopUpWindowID).css({
        "position": "fixed",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
}
function HolidayCallBackRequestPopUp() {

    var PopUpWindowID = '#DIV_HolidayRequestCallBack';
    var popupStatus = 0;
    if (popupStatus == 0) {
        $(".backgroundWrapper").css({ "opacity": "0.7" });
        $(".backgroundWrapper").fadeIn("slow");
        $(PopUpWindowID).fadeIn("slow");
        popupStatus = 1;
    }
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(PopUpWindowID).height();
    var popupWidth = $(PopUpWindowID).width();

    $(PopUpWindowID).css({
        "position": "fixed",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
}
function SearchResultNotFoundPopUp() {

    var PopUpWindowID = '#DIV_ResultNotFound';
    var popupStatus = 0;
    if (popupStatus == 0) {
        $(".backgroundWrapper").css({ "opacity": "0.7" });
        $(".backgroundWrapper").fadeIn("slow");
        $(PopUpWindowID).fadeIn("slow");
        popupStatus = 1;
    }
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(PopUpWindowID).height();
    var popupWidth = $(PopUpWindowID).width();

    $(PopUpWindowID).css({
        "position": "fixed",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
}
//============================Added By manju===============================//

function FillDestinationForSpecialOffers() {
    document.getElementById(HF_S_DestinationID).value = "";
    document.getElementById(Hf_DestinationName).value = "";
    var lCode = document.getElementById(DDL_SP_Region).value;
    ClearAllDropDown();
    if (lCode != "") {
        $.ajax({
            type: "POST",
            mode: "abort",
            port: "AreaDropdown",
            dataType: "xml",
            url: "/FillSearchFields.asmx/GetAreaByDestinationFoeSpecialOffer",
            data: { Code: lCode },
            success: function(data) {
                BindDestinationDropdown(data);
            }
        });
    }
}

//-------------------------Added by manju for Special offers on 20111208-----------------------//
function BindDestinationDropdown(data) {
    if (typeof (data) != String) {
        var rows = data.getElementsByTagName("string");
        var xmlDoc;
        if (window.DOMParser) {
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(rows[0].textContent, "text/xml");
        }
        else // Internet Explorer
        {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";
            xmlDoc.loadXML(rows[0].text);
        }
        if (xmlDoc) {
            var objDD_S_Destination = document.getElementById(DDL_SP_Destination);
            var DestinationDropdown = document.getElementById(DDL_SP_Destination);
            for (var j = DestinationDropdown.getElementsByTagName("optgroup").length - 1; j >= 0; j--) {
                objDD_S_Destination.removeChild(DestinationDropdown.getElementsByTagName("optgroup")[j]);
            }
            if (DestinationDropdown) {
                var ListOfAreaData = xmlDoc.getElementsByTagName('RegionMaster');
                //document.getElementById(HF_SC_AreaXml).value = data;
                DestinationDropdown.options.length = 0;

                var optn = document.createElement("OPTION");
                optn.text = "Please Choose";
                optn.value = "";
                optn.nodeValue = "";

                $(optn).css("color", "#111111");
                DestinationDropdown.options.add(optn);

                var optnLine = document.createElement("OPTION");
                optnLine.value = '';
                optnLine.text = '--------------------------------------------------------';
                $(optnLine).attr("disabled", "disabled");
                $(optnLine).css("color", "#999999");
                DestinationDropdown.options.add(optnLine);

                var lSubTypeID = '';

                for (var i = 0; i < ListOfAreaData.length; i++) {
                    var optn = document.createElement("OPTION");
                    var Area = new Array();
                    try {
                        optn.value = ListOfAreaData[i].selectSingleNode("./RegionID").text;
                        optn.text = ListOfAreaData[i].selectSingleNode("./RegionName").text;
                        // open.disabled = "disabled";
                        lSubTypeID = ListOfAreaData[i].selectSingleNode("./SubTypeID").text;
                        //lSubTypeID = ReadXML(data, "RegionMaster", "./SubTypeID");
                        optn.nodeValue = ListOfAreaData[i].selectSingleNode("./RegionID").text;
                    }
                    catch (e) {
                        optn.value = ListOfAreaData[i].getElementsByTagName("RegionID")[0].textContent;
                        optn.text = ListOfAreaData[i].getElementsByTagName("RegionName")[0].textContent;
                        lSubTypeID = ListOfAreaData[i].getElementsByTagName("SubTypeID")[0].textContent;
                        optn.nodeValue = ListOfAreaData[i].getElementsByTagName("RegionID")[0].textContent;
                    }
                    if (lSubTypeID == '2') {

                        if (DestinationDropdown.options[DestinationDropdown.options.length - 1].value != '') {
                            var optnLine = document.createElement("OPTION");
                            optnLine.value = '';
                            optnLine.text = '--------------------------------------------------------';
                            $(optnLine).attr("disabled", "disabled");
                            $(optnLine).css("color", "#999999");
                            DestinationDropdown.options.add(optnLine);
                        }
                        var optgroup = document.createElement("optgroup");

                        $(optgroup).attr('label', optn.text);
                        $(optgroup).css("color", "#FF9933");
                        $(optgroup).addClass("optiongroup");
                        DestinationDropdown.appendChild(optgroup);
                    }

                    if (lSubTypeID != '2') {
                        $(optn).css("color", "#111111");
                        DestinationDropdown.options.add(optn);
                    }
                    //AreaDropdown.options.add(optn);
                }
            }
        }
    }
}
function FillDestinationDropDownAfterPostBack() {
    //FillArea(DD_S_Area, DD_S_Destination);
    var lCode = document.getElementById(DDL_SP_Region).value;

    if (lCode != "") {
        $.ajax({
            // try to leverage ajaxQueue plugin to abort previous requests
            type: "POST",
            mode: "abort",
            // limit abortion to this input
            port: "AreaDropdown",
            dataType: "xml",
            url: "/FillSearchFields.asmx/GetAreaByDestinationFoeSpecialOffer",
            data: { Code: lCode },
            success: function(data) {
                //BindDropdown(data, DD_S_Destination, "Area", "Code", "name");
                BindDestinationDropdown(data);

                if (document.getElementById(HF_S_DestinationID).value != "")
                    document.getElementById(DDL_SP_Destination).value = document.getElementById(HF_S_DestinationID).value;
                else
                    document.getElementById(DDL_SP_Destination).selectedIndex = 0;
            }
        });
    }
}

function FillDestinationID() {
    document.getElementById(HF_S_DestinationID).value = "";
    document.getElementById(Hf_DestinationName).value = "";
    var lCode = document.getElementById(DDL_SP_Destination).value;
    var lDesc = document.getElementById(DDL_SP_Destination);
    document.getElementById(HF_S_DestinationID).value = lCode;
    document.getElementById(Hf_DestinationName).value = lDesc.options[lDesc.selectedIndex].text;
}

//Added by manju for the New modification in the search control
function ResetSearchControlOrigional() {
    if (document.getElementById("A_Search")) {
        if (document.getElementById("A_Search").innerHTML == "Advanced search") {
            document.getElementById("HotelRegion").style.display = '';
            document.getElementById("AirLineclass").style.display = '';
            document.getElementById("A_Search").innerHTML = "Basic search";
            document.getElementById(HDN_Room).value = 'True';
        }
        else {
            document.getElementById("ctl00_CPH_MainContainer_UC_MasterSearchControl_UC_SearchControl_DD_S_NoOfRooms").selectedIndex = 0;
            document.getElementById("ctl00_CPH_MainContainer_UC_MasterSearchControl_UC_SearchControl_DD_S_CabinClass").selectedIndex = 0;
            document.getElementById("ctl00_CPH_MainContainer_UC_MasterSearchControl_UC_SearchControl_CB_DirectFlights").checked = false;
            document.getElementById(DD_S_Hotel).selectedIndex = 0;
            document.getElementById("HotelRegion").style.display = "none";
            document.getElementById("AirLineclass").style.display = "none";
            document.getElementById("A_Search").innerHTML = "Advanced search"
            document.getElementById(HDN_Room).value = 'False';
        }
        ShowNumberOfRooms();
    }
}
function ResetAfterPostback() {
    var valuedispaly = document.getElementById(HDN_Room).value
    if (valuedispaly == "True") {
        document.getElementById("HotelRegion").style.display = "none";
        document.getElementById("AirLineclass").style.display = "none";
        document.getElementById("A_Search").innerHTML = "Advanced search"
    }
    else {
        document.getElementById("HotelRegion").style.display = '';
        document.getElementById("AirLineclass").style.display = '';
        document.getElementById("A_Search").innerHTML = "Basic search";
    }
    ResetSearchControlOrigional();
}


function InitializeHotelOnly() {
    if (document.getElementById("SearchHotelOnlyFrame")) {
        document.getElementById("SearchHotelOnlyFrame").src = "/HotelOnly/HotelOnly.aspx";
    }
}
/*function CallSearchOnExpire() {
    if (document.getElementById(BTN_SC_Search)) {
        document.getElementById(BTN_SC_Search).click();
    }
}
*/

function CallSearchOnExpire() {
    setTimeout("CallSearchClick();", 2000);
}

function CallSearchClick() {
    if (document.getElementById(BTN_SC_Search)) {
        document.getElementById(BTN_SC_Search).click();
    }

}

(function($) {
    $.QueryString = (function(a) {
        if (a == "") return {};
        var b = {};
        for (var i = 0; i < a.length; ++i) {
            var p = a[i].split('=');
            if (p.length != 2) continue;
            b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
        }
        return b;
    })(window.location.search.substr(1).split('&'))
})(jQuery);
