﻿
function showHideOneWay(chkOneWayClientId) {
    //alert(chkOneWayClientId);
    var retli = document.getElementById('ret-li');
    if (document.getElementById(chkOneWayClientId).checked) {
        retli.className = 'hideThis';
    }
    else {
        retli.className = 'showThis';
    }
}
function showHideHotels(chkHotelsID) {
    var retli = document.getElementById('hotelLi');
    if (document.getElementById(chkHotelsID).checked) {
        retli.className = 'showThis';
    }
    else {
        retli.className = 'hideThis';
    }
}
var cb2;
var cb3;
cb3 = "asdfasdf";
var RAD1ID;
var RAD2ID;
var txtReturnDate;
var CalendarExtender1;

function loadVariables(txtret, calExt) {
    txtReturnDate = txtret;
    CalendarExtender1 = calExt;
}

function cb_onDataBound(pComboboxItem, pDropDownLine) {
    var customAttributes = pComboboxItem.get_attributes();
    if (customAttributes.getAttribute("Type") == 'Airport') {
        pDropDownLine.update(
                '<span class="airport"><span class="item">'
                + pComboboxItem.get_text().substring(0, pComboboxItem.get_text().indexOf("]") + 1)
                + ' <span class="hideme">(Airport)</span></span></span>'
            );
    }
    else {
        if (pComboboxItem.get_text().indexOf(")") > 0) {
            pDropDownLine.update(
                   '<span class="city"><span class="item">'
                    + pComboboxItem.get_text().substring(0, pComboboxItem.get_text().indexOf(")") + 1)
                    + ' <span class="hideme">(city)</span></span></span>'
                );
        }
        else {
            pDropDownLine.update(
                   '<span href="#" class="city"><span class="item">'
                    + pComboboxItem.get_text()
                    + ' <span class="hideme">(city)</span></span></span>'
                    );
        }
    }
}

function cb_onDataBound2(pComboboxItem, pDropDownLine) {

    var customAttributes = pComboboxItem.get_attributes();
    if (customAttributes.getAttribute("Type") == 'Airport') {
        pDropDownLine.update(
                '<span class="airport"><span class="item">'
                + pComboboxItem.get_text().substring(0, pComboboxItem.get_text().indexOf("]") + 1)
                + ' <span class="hideme">(Airport)</span></span></a>'
            );
    }
    else {
        if (pComboboxItem.get_text().indexOf(")") > 0) {
            pDropDownLine.update(
                   '<span class="city"><span class="item">'
                    + pComboboxItem.get_text().substring(0, pComboboxItem.get_text().indexOf(")") + 1)
                    + ' <span class="hideme">(city)</span></span></span>'
                );
        }
        else {
            pDropDownLine.update(
                   '<span class="city"><span class="item">'
                    + pComboboxItem.get_text()
                    + ' <span class="hideme">(city)</span></span></span>'
                    );
        }
    }
}

function pageLoad2(p1, p2) {
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(cancelPostBack);
    RAD1ID = p1;
    RAD2ID = p2;
    initComboExtensions();
    cb2 = document.getElementById(RAD1ID);
    cb2.onDataBound = cb_onDataBound;
    cb3 = document.getElementById(RAD2ID);
    cb3.onDataBound = cb_onDataBound2;
}
// pageLoad2();

function OnClientItemsRequested(sender, eventArgs) {
    var cbbox = document.getElementById(RAD1ID);
    if (cbbox.onDataBound != null) {
        var ulList = $(RAD1ID + "_DropDown").getElementsByClassName("rcbList")[0];
        var liElements = ulList.childElements();
        var items = sender.get_items();
        var startPos = 0;

        //if there is no <span> in the first <li> then it's a new list
        if (liElements[0].childElements().length == 0)
            startPos = 0;
        else
            startPos = cbbox.nrOfComboItems - 1;

        var dataItem;
        var dropDownLine;
        for (var index = startPos; index < liElements.length; ++index) {
            dataItem = items.getItem(index);
            if (dataItem != null) {
                dropDownLine = liElements[index];
                cbbox.onDataBound(dataItem, dropDownLine);
            }
        }
        cbbox.nrOfComboItems = liElements.length;
        cbbox.lastRequestFilter = "";
         if (sender.get_items().get_count() == 0) {
                sender.toggleDropDown();
            }
    }
}

function OnClientItemsRequested2(sender, eventArgs) {
    var cbbox = document.getElementById(RAD2ID);
    if (cbbox.onDataBound != null) {
        var ulList = $(RAD2ID + "_DropDown").getElementsByClassName("rcbList")[0];
        var liElements = ulList.childElements();
        var items = sender.get_items();
        var startPos = 0;

        //if there is no <span> in the first <li> then it's a new list
        if (liElements[0].childElements().length == 0)
            startPos = 0;
        else
            startPos = cbbox.nrOfComboItems - 1;

        var dataItem;
        var dropDownLine;
        for (var index = startPos; index < liElements.length; ++index) {
            dataItem = items.getItem(index);
            if (dataItem != null) {
                dropDownLine = liElements[index];
                cbbox.onDataBound(dataItem, dropDownLine);
            }
        }
        cbbox.nrOfComboItems = liElements.length;
        cbbox.lastRequestFilter = "";
    }
}
function checkDates(txtDepart, txtRet) {
    obj1 = document.getElementById(txtDepart);
    obj2 = document.getElementById(txtRet);
    Connect.updateReturnDate2(obj1.value, obj2.value, sucDates);
}

function cancelPostBack(sender, args) {
    if (Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
        // alert('One postback at a time please');
        args.set_cancel(true);
    }
}
