﻿var imgID;
var roomTypeID;
var g_ShowAll = false;
var isBedBankSupplier = false;
var UcHotelInfoSummaryPanelID;

function setBedBankSupplier(val) {
    isBedBankSupplier = val;
    //ToggleRoomTypes(false);
}

function TogglePolicy(RoomTypeID, Show) {
    var tr;
    tr = document.getElementById('trPolicy_' + RoomTypeID);
    //alert(RoomTypeID + ":" + Show);

    if (tr) {
        if (Show) {
            HideAllPolicy();
            tr.style.display = "";
        }
        else {
            tr.style.display = "none";
        }
    }
}

function PolicyAgreed(RoomTypeID) {
    var chk;
    var agreed;

    chk = document.getElementById('chkPolicy_' + RoomTypeID);

    if (chk) {
        if (chk.checked)
            agreed = true;
        else
            agreed = false;
    }
    else
        agreed = false;


    if (agreed) {
        return true;
    }
    else {
        alert("You must agree to the Cancellation Terms");
        return false;
    }
}

function HideAllPolicy() {
    //var tbl = document.getElementById("tblRoomType");
    //var trs = tbl.getElementsByTagName("tr");
    var trs = document.getElementsByTagName("tr");

    for (var i = 0; i < trs.length; i++) {
        if (trs[i].id.indexOf('trPolicy') > -1)
            trs[i].style.display = "none";
    }
}

function SetUpdatePrice(ClientID, UniqueID, RoomTypeID) {

    var img = document.getElementById(ClientID);

    img.src = 'images/Loading.gif';

    __doPostBack(UniqueID, '');

    //alert(RoomTypeID + ":" + g_RoomTypeID);

    //TogglePolicy(RoomTypeID, true);

    imgID = ClientID;
    roomTypeID = RoomTypeID;
    //alert(g_RoomTypeID + ":" + RoomTypeID);

    //stops the server postback, as postback is being evocked directly using __doPostBack
    return false;
}

function EndRequestHandler(sender, args) {
    if (args.get_error() == undefined) {
        //TogglePolicy(roomTypeID, true);    

        //ToggleRoomTypes(g_ShowAll); 
        var g_RoomTypeID = '<%=Request.QueryString["RoomTypeID"]%>';

        if (g_RoomTypeID == roomTypeID)
            ToggleRoomTypes(false);
        else
            ToggleRoomTypes(true);
    }
    else {
        var img = document.getElementById(imgID);

        if (img) {
            //img.src = "images/detailPage/getPrice.gif";
            img.style.display = "none";
        }
    }
}

function SetCP(chk) {
    //alert(chk.text);
}

function ShowToolTip() {
    var Text = "Please click to see the final price and cancellation policy";

    ShowTip(Text);
}

var pnlBack = document.getElementById('<%=pnlBack.ClientID%>');

if (pnlBack) {
    if (history.length == 0)
        document.getElementById(pnlBack).style.display = "none";
    else
        document.getElementById(pnlBack).style.display = "";
}



var tellFriend = true;

//Function to Toggle Visibility
//By : DA
//Date: 27/05/05
function SetVisibility(id, doHide) {
    if (doHide) {
        document.getElementById(id).style.display = 'none';
        document.getElementById(id).style.visibility = 'hidden';
    }
    else {
        document.getElementById(id).style.display = 'block';
        document.getElementById(id).style.visibility = 'visible';
    }
}

function PrintDetails() {
    divContainer = document.getElementById('divAgentMasterContainer');

    if (divContainer != null)
        divContainer.className = "";

    ToggleHotelImage(true);
    SetVisibility('logo', true);
    SetVisibility('mainNav', true);
    SetVisibility('subNav', true);
    SetVisibility('lhCol', true);
    SetVisibility('rhCol', true);
    SetVisibility('ctl00_ContentPlaceHolder1_divPrint', true);
    SetVisibility('divFooter', true);
    SetVisibility('divHotelImages', false);
    SetVisibility('tdLeftColumn', true);
    SetVisibility('divContainerFooter', true);
    SetVisibility('divContentAreaTop', true);
    SetVisibility('divContentAreaBottom', true);
    window.print();

    if (divContainer != null)
        divContainer.className = 'container';

    ToggleHotelImage(false);
    SetVisibility('logo', false);
    SetVisibility('mainNav', false);
    SetVisibility('subNav', false);
    SetVisibility('lhCol', false);
    SetVisibility('rhCol', false);
    SetVisibility('ctl00_ContentPlaceHolder1_divPrint', false);
    SetVisibility('divFooter', false);
    SetVisibility('divHotelImages', true);
    SetVisibility('tdLeftColumn', false);
    SetVisibility('divContainerFooter', false);
    SetVisibility('divContentAreaTop', false);
    SetVisibility('divContentAreaBottom', false);
}

function ToggleHotelImage(bShow) {
    var strImage;

    strImage = '';

    if (bShow) {
        strImage = '<table>';

        for (var x = 0; x < galleryImages.length; x++) {
            strImage = strImage + '<tr><td><img src="' + galleryImages[x].toString() + '" class="hotelPreview" width="180px" height="120px"/><br>&nbsp;<br></td></tr>';
        }

        strImage = strImage + '</table>';
    }
    document.getElementById('divHotelImages').innerHTML = strImage;
}

function ToggleEmail() {
    var div = document.getElementById("<%=pnlEmail.ClientID%>");

    if (div.style.display == "none") {
        div.style.display = "";
    }
    else {
        div.style.display = "none";
    }
}

function SearchClickedHotelInfo() {
    //SearchClicked()
}



function ToggleRoomTypes(ShowAll) {

    if (isBedBankSupplier) {

        if (document.getElementById("btnToggleRoomType")) {
            document.getElementById("btnToggleRoomType").style.display = "";
        }

        var g_RoomTypeID = '<%=Request.QueryString["RoomTypeID"]%>';
        var g_ShowAll = ShowAll;

        //alert("Length:" + g_RoomTypeID.length);


        var DivS = document.getElementsByTagName("div");
        var counter = 0;

        for (var i = 0; i < DivS.length; i++) {
            if (DivS[i].id.indexOf('ucHotelInfoAvailability_pnlAvailibility') > -1)        //its a room type div
            {
                if (ShowAll) {
                    DivS[i].style.display = "";

                    if (document.getElementById("btnToggleRoomType")) {
                        document.getElementById("btnToggleRoomType").style.display = "none";
                    }
                }
                else {
                    if (g_RoomTypeID.length > 0) {
                        if (DivS[i].id.indexOf(g_RoomTypeID) == -1) {
                            DivS[i].style.display = "none";
                        }
                    }
                    else {
                        if (counter > 0) {
                            DivS[i].style.display = "none";
                        }
                    }
                }

                counter++;
                //alert(DivS[i].id);
            }
        }
//        if (counter < 2)
//            document.getElementById("btnToggleRoomType").style.display = "none";

    }

    return false;
}

function setUcHotelInfoSummaryPanelID(ID) {
    UcHotelInfoSummaryPanelID = ID;
}

function SetYourStay(bookUrl, total, wasPrice, roomType, boardBasis, strOffers) {

    //alert(UcHotelInfoSummaryPanelID + "lblRoomType");

    ge(UcHotelInfoSummaryPanelID + "lblAccommodationPrice").innerHTML = total;
    ge(UcHotelInfoSummaryPanelID + "lblWasPrice").innerHTML = wasPrice;
    ge(UcHotelInfoSummaryPanelID + "hypBookNow").href = bookUrl;

    ge(UcHotelInfoSummaryPanelID + "lblRoomType").innerHTML = roomType;
    ge(UcHotelInfoSummaryPanelID + "lblBoardBasis").innerHTML = boardBasis;
    
    //Added to stop PostBack by Server Control
    return true;
}

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
