var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;
var popCal;
var popFrame;

//////////////////////////////
var VnDisabledArr = new Array();
var ShipDisabledArr = new Array();
var PortDisabledArr = new Array();
var MonthDisabledArr = new Array();
var LengthDisabledArr = new Array();
var VendorTypeArr = new Array();

var v = 0;
var i = 0;
var j = 0;
var k = 0;
var l = 0;
var m = 0;


function AddVndItem(DisabledId) {
    VnDisabledArr[i] = DisabledId;
    i++;
}

function AddShipItem(DisabledId) {
    ShipDisabledArr[j] = DisabledId;
    j++;
}

function AddPortItem(DisabledId) {
    PortDisabledArr[k] = DisabledId;
    k++;
}

function AddMonthItem(DisabledName) {
    MonthDisabledArr[l] = DisabledName;
    l++;
}

function AddLengthItem(DisabledName) {
    LengthDisabledArr[m] = DisabledName;
    m++;
}


function IsDisabledItem(OptionItem, type) {
    if (type == "Vendor") return Check(VnDisabledArr, OptionItem.value);
    else if (type == "Ship") return Check(ShipDisabledArr, OptionItem.value);
    else if (type == "Port") return Check(PortDisabledArr, OptionItem.value);
    else if (type == "Month") return Check(MonthDisabledArr, OptionItem.text);
    else if (type == "Length") return Check(LengthDisabledArr, OptionItem.value);
}

function Check(DisabledArr, Id) {
    var p = 0;

    for (p = 0; p < DisabledArr.length; p++) {
        if (DisabledArr[p] == Id) {
            return true;
        }
    }

    return false;
}

function AssignHid(HidenVar, Hiddata) {
    getElement(HidenVar).value = Hiddata;
}

function KeepSelection(thisObject, Value, Type) {
    var p = 0;

    //Deselect All
    for (p = 0; p < thisObject.options.length; p++)
        thisObject.options[p].selected = false;

    if (Value == undefined || Value == -1) {
        thisObject.options[0].selected = true;
        return;
    }

    for (p = 0; p < thisObject.options.length; p++) {
        if (thisObject.options[p].value == Value) {
            thisObject.options[p].selected = true;
        }
    }

}

function CompareFrom_TO_Dates(dtdropdown) {

    try {
        //DateDropDown && DateTo
        var FromDate = getElement('DateDropDown').value;
        var ToDate = getElement('DateTo').value;

        if (FromDate != null && ToDate != null) {
            if (dtdropdown == 'fromdate') {
                if (Date.parse(ToDate) < Date.parse(FromDate)) {
                    getElement('DateTo').value = FromDate;
                }
            }
            else if (dtdropdown == 'todate') {
                if (Date.parse(FromDate) > Date.parse(ToDate)) {
                    getElement('DateDropDown').value = ToDate;
                }
            }
        }
    }
    catch (e) {
    }
}

function VendorType(VenID, VenTypeID, VenName, VenAvialable) {
    this.ID = VenID;
    this.Type = VenTypeID;
    this.Name = VenName;
    this.IsAvialable = VenAvialable;
}

function AddVendorType(VenID, VenTypeID, VenName, VenAvialable) {
    var MyVendorType = new VendorType(VenID, VenTypeID, VenName, VenAvialable);
    VendorTypeArr[v] = MyVendorType;
    v++;
}

var MonthArr = new Array();
var q = 0;

function Month(MonthId, MonthName, MonthAvialable, MonthDate) {
    this.ID = MonthId;
    this.Name = MonthName;
    this.IsAvialable = MonthAvialable;
    this.Day = MonthDate;
}


function AddMonth(MonthId, MonthName, MonthAvialable, MonthDate) {
    var MyMonth = new Month(MonthId, MonthName, MonthAvialable, MonthDate);
    MonthArr[q] = MyMonth;
    q++;
}

function Vendor_Intelligent_Selection() {
    var VnDrpObj = getElement('VndDropDown');
    var vendtype = getElement('CruiseTypeDropDown').value;
    if (vendtype != -1) {
        VnDrpObj.options[0].selected = false;
    }
    else {
        VnDrpObj.options[0].selected = true;

        for (z = 1; z < VnDrpObj.options.length; z++) {
            VnDrpObj.options[z].selected = false;
        }

        return;
    }

    for (z = 1; z < VnDrpObj.options.length; z++) {
        if (VnDrpObj.options[z].disabled == false) {
            VnDrpObj.options[z].selected = true;
        }
    }
}

function Month_Intelligent_Selection(DateDropDownId) {
    var MyMonthObj = getElement(DateDropDownId); //DateDropDown
    var selectedMonth = MyMonthObj.options[MyMonthObj.options.selectedIndex].text;
    var IsDisabledFound = false;
    var IsAssigned = false;
    var h = 0;

    //forward selection
    for (h = 0; h < MonthArr.length; h++) {
        if (IsDisabledFound) {
            if (MonthArr[h].IsAvialable == 'true') {
                var c = 0
                for (c = 0; c < MyMonthObj.options.length; c++) {
                    if (MonthArr[h].Name == MyMonthObj.options[c].text && IsAssigned == false) {
                        IsAssigned = true;
                        MyMonthObj.options[c].selected = true;
                        MyMonthObj.options[c].className = "dwDropdownitemNormal";
                        AssignHid('hidDId', MonthArr[h].Day);
                    }
                }
            }
        }

        if (selectedMonth == MonthArr[h].Name && MonthArr[h].IsAvialable == 'false') {
            IsDisabledFound = true;
        }
    }

    if (IsAssigned) return;

    //Backward selection
    for (h = MonthArr.length - 1; h >= 0; h--) {
        if (IsDisabledFound) {
            if (MonthArr[h].IsAvialable == 'true') {
                var c = 0
                for (c = 0; c < MyMonthObj.options.length; c++) {
                    if (MonthArr[h].Name == MyMonthObj.options[c].text && IsAssigned == false) {
                        IsAssigned = true;
                        MyMonthObj.options[c].selected = true;
                        MyMonthObj.options[c].className = "dwDropdownitemNormal";
                        AssignHid('hidDId', MonthArr[h].Day);
                    }
                }
            }
        }

        if (selectedMonth == MonthArr[h].Name && MonthArr[h].IsAvialable == 'false') {
            IsDisabledFound = true;
        }
    }
}



function getMyVenIdArrayByType(VType) {
    var z = 0;
    var y = 0;
    //var MyArray = new Array();
    var DrpObj = getElement('VndDropDown');
    DrpObj.innerHTML = "";
    getElement('ShipsDropDown').innerHTML = "";

    if (VType == -1) {
        DrpObj.options[y] = new Option;
        DrpObj.options[y].text = "All Cruiselines";
        DrpObj.options[y].value = -1;
        DrpObj.options[y].className = "dwDropdownitemNormal";
        y++;
    }

    for (z = 0; z < VendorTypeArr.length; z++) {
        if (VendorTypeArr[z].Type == VType || VType == 9 || VType == -1) {
            DrpObj.options[y] = new Option;
            DrpObj.options[y].text = VendorTypeArr[z].Name;
            DrpObj.options[y].value = VendorTypeArr[z].ID;
            if (VendorTypeArr[z].IsAvialable == 'true') {
                DrpObj.options[y].className = "dwDropdownitemNormal";
            }
            else {
                DrpObj.options[y].className = "dwDropdownitemDisabled";
            }
            y++;
        }
    }
}

function OnChangeCruiseSort(thisObject, selectAllOptionLevel) {
    getMyVenIdArrayByType(thisObject.options[thisObject.options.selectedIndex].value);
}

///////////////////////////////
var VndTypeClicked = false;
function OnSearchOptionChange(thisObject, selectAllOptionLevel, type, hidId, dtdropdown) {
    if (thisObject.options.selectedIndex >= 0) {
        if (IsDisabledItem(thisObject.options[thisObject.options.selectedIndex], type)) {
            KeepSelection(thisObject, getElement(hidId).value, type);
            return;
        }

        if (type == "Month") CompareFrom_TO_Dates(dtdropdown);
        if (type == "VendorType")
            VndTypeClicked = true;
        else
            VndTypeClicked = false;

        try {
            __doPostBack(thisObject.id, '');
            //to adjust left search widget height with results page height

            if (getElement('ZoneDropDown') != null)
                getElement('ZoneDropDown').disabled = true;
            if (getElement('VndDropDown') != null)
                getElement('VndDropDown').disabled = true;
            if (getElement('DateDropDown') != null)
                getElement('DateDropDown').disabled = true;
            if (getElement('LenDropDown') != null)
                getElement('LenDropDown').disabled = true;
            if (getElement('PortDropDown') != null)
                getElement('PortDropDown').disabled = true;
            if (getElement('ShipsDropDown') != null)
                getElement('ShipsDropDown').disabled = true;
            if (getElement('LoadFromDays') != null)
                getElement('LoadFromDays').disabled = true;
            if (getElement('LoadToDays') != null)
                getElement('LoadToDays').disabled = true;
            if (getElement('CruiseTypeDropDown') != null)
                getElement('CruiseTypeDropDown').disabled = true;
            if (getElement('FromLength') != null)
                getElement('FromLength').disabled = true;
            if (getElement('SortDropDown') != null)
                getElement('SortDropDown').disabled = true;
            if (getElement('ToLength') != null)
                getElement('ToLength').disabled = true;
            if (getElement('DateTo') != null)
                getElement('DateTo').disabled = true;
        }
        catch (e) {
        }
    }
}

function GetSearchWidgetHeight(searchFrame, frame, tableName) {
    try {
        if (window.parent.document.getElementById(frame) != null) {
            if (searchFrame != null && frame != null) {
                if (window.parent.document.getElementById(frame).height > 700) {
                    window.parent.document.getElementById(searchFrame).height = ((window.parent.document.getElementById(frame).height)) + "px";
                    var searchframe1 = window.parent.document.getElementById(searchFrame);
                    if (searchframe1.contentDocument) {    // Firefox
                        _obj = searchframe1.contentDocument;
                    }
                    else if (searchframe1.contentWindow) {
                        // Internet Explorer
                        _obj = searchframe1.contentWindow.document;
                    }
                    _obj.getElementById(tableName).style.height = window.parent.document.getElementById(frame).height + "px";
                }
                else {
                    window.parent.document.getElementById(searchFrame).height = 730;
                }
            }
        }
        else if (window.parent.document.getElementById(searchFrame) != null) {
            window.parent.document.getElementById(searchFrame).height = 1700 + "px";
        }
    }
    catch (e) {
        if (window.parent.document.getElementById(frame) != null) {
            window.parent.document.getElementById(frame).height = 1700;
            if (searchFrame != null) {
                window.parent.document.getElementById(searchFrame).height = 1700;
                var searchframe1 = window.parent.document.getElementById(searchFrame);
                if (searchframe1.contentDocument) {    // Firefox
                    _obj = searchframe1.contentDocument;
                }
                else if (searchframe1.contentWindow) {
                    // Internet Explorer
                    _obj = searchframe1.contentWindow.document;
                }
                _obj.getElementById(tableName).style.height = 1700 + "px";
            }
        }
        else if (window.parent.document.getElementById(searchFrame) != null) {
            window.parent.document.getElementById(searchFrame).height = 1700 + "px";
        }
    }
}

function IncludeOfflineVendorsChanged(thisObject) {
    __doPostBack(thisObject.id, '');
}

function SendState(strFile, target, isRadioSortCruises) {

    var strUrl = strFile;

    var type = strUrl.toString().substring(34);

    Querystring(null);
    strUrl += GetQueryStringParams(isRadioSortCruises, type);

    if (target == "_childframe") {
        try {
            childFrame = window.parent.getResultFrame();
            childFrame.src = "/CS/" + strUrl;
            return;
        }
        catch (e) {
        }
    }

    if (Querystring_get('nw', null) == 'true' || target == "_blank")
        window.open(strUrl);
    else {
        if (target && target == "_top")
            window.top.location.href = strUrl;
        else if (target && target == "_self")
            window.location.href = strUrl;
        else if (target) {
            //Creates the messenger that will send the new URL to the parent frame.
            var messenger = document.createElement("iframe");

            alert(target + '#http://cs.cruisebase.com/cs/' + strUrl);

            //(Optional) - Set an id - not really required.
            messenger.setAttribute("id", "messenger");

            //Add the iFrame to the body of the page.
            document.body.appendChild(messenger);

            //Set the src attribute - Everything from here is handled by the target 
            //page that was sent in.
            //target will equal the helper.aspx url + query string parameter
            messenger.setAttribute("src", target + '#http://cs.cruisebase.com/cs/' + strUrl);

            //The load event helper.aspx page will parse the query string parameter and set
            //the iFrame src on Connexions site. It's allowed because those two sites are
            //on the same domain.
        }
        else
            window.parent.location.href = 'http://' + self.location.host + '/cs/' + strUrl;
    }
}

//To navigate to Advance search only
function SendState7(strFile, target, isRadioSortCruises) {
    var strUrl = strFile;

    //For Advance search
    var type = strUrl.toString().substring(18);

    Querystring(null);
    strUrl += GetQueryStringParams(isRadioSortCruises, type);

    if (target == "_childframe") {
        try {
            childFrame = window.parent.getResultFrame();
            childFrame.src = "/CS/" + strUrl;
            return;
        }
        catch (e) {
        }
    }

    if (Querystring_get('nw', null) == 'true' || target == "_blank")
        window.open(strUrl);
    else {
        if (target && target == "_top")
            window.top.location.href = strUrl;
        else if (target && target == "_self")
            window.location.href = strUrl;
        else if (target) {
            //Creates the messenger that will send the new URL to the parent frame.
            var messenger = document.createElement("iframe");

            alert(target + '#http://cs.cruisebase.com/cs/' + strUrl);

            //(Optional) - Set an id - not really required.
            messenger.setAttribute("id", "messenger");

            //Add the iFrame to the body of the page.
            document.body.appendChild(messenger);

            //Set the src attribute - Everything from here is handled by the target 
            //page that was sent in.
            //target will equal the helper.aspx url + query string parameter
            messenger.setAttribute("src", target + '#http://cs.cruisebase.com/cs/' + strUrl);

            //The load event helper.aspx page will parse the query string parameter and set
            //the iFrame src on Connexions site. It's allowed because those two sites are
            //on the same domain.
        }
        else
            window.parent.location.href = 'http://' + self.location.host + '/cs/' + strUrl;
    }
}

function GetQueryStringParams(isRadioSortCruises, type) {
    var queryString = "";

    //controls
    var cbDest = getElement("ZoneDropDown");
    var cbMonth = getElement("DateDropDown");
    var cbDateTo = getElement("DateTo");
    var cbLen = getElement("LenDropDown");
    var cbLenFrom = getElement("FromLength");
    var cbLenTo = getElement("ToLength");
    var cbVnd = getElement("VndDropDown");

    // optional controls	
    var cbShp = getElement("ShipsDropDown");
    var cbPort = getElement("PortDropDown");
    var cbSort = getElement("SortDropDown");
    var cbSenior = getElement("lfChk55p");
    var cbMilitary = getElement("lfChkUSM");
    var cbZip1 = getElement("selResidency");
    var cbZip2 = getElement("Zip2");
    var cbPromoCode = getElement("txtPromoCode");
    var cbPastPassenger = getElement("PastPassenger");
    var cbPPVid = getElement("SelVIds");

    //hidden
    var cbRef = getElement("Ref");
    var cbShowSenior = getElement("ShowSenior");
    var cbShowMilitary = getElement("ShowMilitary");
    var cbShowPastPassenger = getElement("ShowPastPassenger");
    var cbEO = getElement("EO");
    var cbpsl = getElement("PSL");
    var DayFrom = getElement("LoadFromDays");
    var DayTo = getElement("LoadToDays");
    var multiVendor = "";
    var hidCP = getElement("vhidden");

    if (type == 'advanced') {
        queryString += "&";
    }
    else {
        queryString += "?";
    }

    var skinId;
    if (Querystring_get('skin', null) != null) {
        skinId = Querystring_get('skin', null);
    }
    else if (Querystring_get('ag', null) != null) {
        skinId = Querystring_get('ag', null);
    }
    else if (Querystring_get('clientid', null) != null) {
        skinId = Querystring_get('clientid', null);
    }
    if (skinId != null && queryString.indexOf("skin=") < 0) {
        if (skinId.length == 1) {
            queryString += "skin=00" + skinId;
        }
        else if (skinId.length == 2) {
            queryString += "skin=0" + skinId;
        }
        else {
            queryString += "skin=" + skinId;
        }
    }

    var multiDest = "";
    if (cbDest != null) {
        for (var i = 0; i < cbDest.options.length; i++) {
            if (cbDest.options[i].selected) {
                if (multiDest == "")
                    multiDest += cbDest.options[i].value;
                else
                    multiDest += "," + cbDest.options[i].value;
            }
        }
    }
    if (multiDest == "") {
        if (cbDest != null)
        { }
        else if (Querystring_get('did', null) != null) {
            multiDest = Querystring_get('did', null);
        }
        else if (Querystring_get('cd', null) != null) {
            multiDest = Querystring_get('cd', null);
        }
    }
    if (multiDest != "" && multiDest != null && multiDest != "1") {
        if (multiDest.indexOf(',') > 0) {
            var arrDest = multiDest.split(',');
            multiDest = "";
            for (var i = 0; i < arrDest.length; i++) {
                if (arrDest[i] != "") {
                    if (multiDest == "")
                        multiDest += arrDest[i];
                    else
                        multiDest += "," + arrDest[i];
                }
            }
        }
        queryString += "&CD=" + multiDest;
    }

    if (cbVnd != null) {
        for (var i = 0; i < cbVnd.options.length; i++) {
            if (cbVnd.options[i].selected) {
                if (multiVendor == "")
                    multiVendor += cbVnd.options[i].value;
                else
                    multiVendor += "," + cbVnd.options[i].value;
            }
        }
    }
    else if (Querystring_get('cv', null) != null) {
        multiVendor = Querystring_get('cv', null);
    }
    else if (Querystring_get('vid', null) != null) {
        multiVendor = Querystring_get('vid', null);
    }
    if (multiVendor != "" && multiVendor != -1) {
        if (multiVendor.indexOf(',') > 0) {
            var arrVendor = multiVendor.split(',');
            multiVendor = "";
            for (var i = 0; i < arrVendor.length; i++) {
                if (arrVendor[i] != "") {
                    if (multiVendor == "")
                        multiVendor += arrVendor[i];
                    else
                        multiVendor += "," + arrVendor[i];
                }
            }
        }
        queryString += "&CV=" + multiVendor;
    }

    if (cbMonth != null) {
        queryString += "&DF=";
        if (DayFrom != null) {
            var arrDate = escape(cbMonth.value).split('/');
            queryString += arrDate[0] + "/" + escape(DayFrom.value) + "/" + arrDate[2];
        }
        else {
            queryString += escape(cbMonth.value);
        }
    }

    if (cbDateTo != null) {
        queryString += "&DT=";

        if (DayTo != null) {
            var arrDate = escape(cbDateTo.value).split('/');
            queryString += arrDate[0] + "/" + escape(DayTo.value) + "/" + arrDate[2];
        }
        else
            queryString += escape(cbDateTo.value);
    }

    var length = "";
    if (cbLen != null && cbLen.value != '' && cbLen.value != '0|999') {
        queryString += "&CL=" + escape(cbLen.value);
    }
    else if (cbLenFrom != null && cbLenTo != null) {
        if (cbLenFrom.value != '' && cbLenTo.value != '')
            length = escape(cbLenFrom.value) + "|" + escape(cbLenTo.value);
        if (length != '0|999') {
            queryString += "&CL=" + length;
        }
    }
    if (queryString.indexOf('CL=') < 0) {
        if (cbLen != null)
        { }
        else if (Querystring_get('cl', null) != null) {
            queryString += "&CL=" + Querystring_get('cl', null);
        }
        else if (Querystring_get('len', null) != null) {
            queryString += "&CL=" + Querystring_get('len', null);
        }
    }

    var multiShips = "";
    if (cbShp != null) {
        for (var i = 0; i < cbShp.options.length; i++) {
            if (cbShp.options[i].selected) {
                if (multiShips == "")
                    multiShips += cbShp.options[i].value;
                else
                    multiShips += "," + cbShp.options[i].value;
            }
        }
    }
    if (multiShips == "") {
        if (cbShp != null)
        { }
        else if (Querystring_get('sid', null) != null) {
            multiShips = Querystring_get('sid', null);
        }
        else if (Querystring_get('csp', null) != null) {
            multiShips = Querystring_get('csp', null);
        }
        else if (Querystring_get('ships', null) != null && Querystring_get('ships', null).toUpperCase() != 'Y'
	        && Querystring_get('ships', null).toUpperCase() != 'N') {
            multiShips = Querystring_get('ships', null);
        }
    }
    if (multiShips != "" && multiShips != -1) {
        if (multiShips.indexOf(',') > 0) {
            var arrPorts = multiShips.split(',');
            multiShips = "";
            for (var i = 0; i < arrPorts.length; i++) {
                if (arrPorts[i] != "") {
                    if (multiShips == "")
                        multiShips += arrPorts[i];
                    else
                        multiShips += "," + arrPorts[i];
                }
            }
        }
        queryString += "&CSP=" + multiShips;
    }

    var multiPorts = "";
    if (cbPort != null) {
        for (var i = 0; i < cbPort.options.length; i++) {
            if (cbPort.options[i].selected) {
                if (multiPorts == "")
                    multiPorts += cbPort.options[i].value;
                else
                    multiPorts += "," + cbPort.options[i].value;
            }
        }
    }
    if (multiPorts == "") {
        if (cbPort != null)
        { }
        else if (Querystring_get('pid', null) != null) {
            multiPorts = Querystring_get('pid', null);
        }
        else if (Querystring_get('cp', null) != null) {
            multiPorts = Querystring_get('cp', null);
        }
        else if (Querystring_get('ports', null) != null && Querystring_get('ports', null).toUpperCase() != 'Y'
	        && Querystring_get('ports', null).toUpperCase() != 'N') {
            multiPorts = Querystring_get('ports', null);
        }
    }
    if (multiPorts != "" && multiPorts != -1) {
        if (multiPorts.indexOf(',') > 0) {
            var arrPorts = multiPorts.split(',');
            multiPorts = "";
            for (var i = 0; i < arrPorts.length; i++) {
                if (arrPorts[i] != "") {
                    if (multiPorts == "")
                        multiPorts += arrPorts[i];
                    else
                        multiPorts += "," + arrPorts[i];
                }
            }
        }
        queryString += "&CP=" + multiPorts;
    }

    if (isRadioSortCruises != null && isRadioSortCruises == 'true') {
        //Sort Radio Buttons
        var rdoSort = document.Form1.rdoSortCruises;
        if (rdoSort != null && rdoSort.length > 0) {
            for (i = 0; i < rdoSort.length; i++) {
                if (rdoSort[i].checked)
                    queryString += "&CST=" + rdoSort[i].value;
            }
        }
    }
    else if (cbSort != null && cbSort.value != '' && cbSort.value != null && cbSort.value != '-1') {
        if (skinId == "388" || skinId == "348") {
            if (cbSort.value != '2') {
                queryString += "&CST=" + cbSort.value;
            }
        }
        else if (cbSort.value != '10') {
            queryString += "&CST=" + cbSort.value;
        }
    }
    if (queryString.indexOf('CST=') < 0) {
        if (cbSort != null)
        { }
        else if (Querystring_get('cst', null) != null) {
            queryString += "&CST=" + Querystring_get('cst', null);
        }
        else if (Querystring_get('sort', null) != null && Querystring_get('sort', null).toUpperCase() != 'Y'
	        && Querystring_get('sort', null).toUpperCase() != 'N') {
            queryString += "&CST=" + Querystring_get('sort', null);
        }
    }

    if (cbSenior != null) {
        if ((cbSenior.type == "select-one") || (cbSenior.type == "hidden")) {
            if (cbSenior.value != null && cbSenior.value != '')
                queryString += "&SN=" + escape(cbSenior.value);
        }
        else if (escape(cbSenior.checked) == 'true') {
            queryString += "&SN=true";
        }
    }
    if (queryString.indexOf("SN=") < 0) {
        if (cbSenior != null)
        { }
        else if (Querystring_get('sn', null) != null) {
            queryString += "&SN=" + Querystring_get('sn', null);
        }
    }

    if (cbMilitary != null) {
        if ((cbMilitary.type == "select-one") || (cbMilitary.type == "hidden")) {
            if (cbMilitary.value != null && cbMilitary.value != '')
                queryString += "&MT=" + escape(cbMilitary.value);
        }
        else if (escape(cbMilitary.checked) == 'true') {
            queryString += "&MT=true";
        }
    }
    if (queryString.indexOf("MT=") < 0) {
        if (cbMilitary != null)
        { }
        else if (Querystring_get('mt', null) != null) {
            queryString += "&MT=" + Querystring_get('mt', null);
        }
    }
    
    if (cbPastPassenger != null && cbPastPassenger.checked == true) {
        if (cbPPVid != null && cbPPVid.value != '' && cbPPVid.value != null) {
            queryString += "&PP=" + cbPPVid.value;
        }
    }
    if (queryString.indexOf("PP=") < 0) {
        if (Querystring_get('pp', null) != null) {
            if (cbPastPassenger != null && cbPastPassenger.checked == false) {
            }
            else
                queryString += "&PP=" + Querystring_get('pp', null);
        }
    }

    if (cbZip1 != null && cbZip1.value != '' && cbZip1.value != '-1') {
        queryString += "&ZP1=" + escape(cbZip1.value);
    }
    if (queryString.indexOf("ZP1=") < 0) {
        if (cbZip1 != null)
        { }
        else if (Querystring_get('zp1', null) != null) {
            queryString += "&ZP1=" + Querystring_get('zp1', null).toUpperCase();
        }
        else if (Querystring_get('st1', null) != null) {
            queryString += "&ZP1=" + Querystring_get('st1', null).toUpperCase();
        }
    }

    if (cbPromoCode != null) {
        if (cbPromoCode.value != '' && cbPromoCode.value != null)
            queryString += "&PC=" + escape(cbPromoCode.value);
    }
    if (Querystring_get('pc', null) != null && (cbPromoCode == null) && (queryString.indexOf("PC=") < 0)) {
        queryString += "&PC=" + Querystring_get('pc', null);
    }

    if (Querystring_get('phone', null) != null && (queryString.indexOf("Phone=") < 0)) {
        queryString += "&Phone=" + Querystring_get('phone', null);
    }

    if ((cbEO != null) && (cbEO.type != "select-one")) {
        queryString += "&EO=" + escape(cbEO.checked);
    }
    else if (Querystring_get('eo', null) != null) {
        queryString += "&EO=" + Querystring_get('eo', null);
    }

    if (cbRef != null) {
        if (cbRef.value != '' && cbRef.value != '-1')
            queryString += "&Ref=" + escape(cbRef.value);
    }

    if (Querystring_get('pin', null) != null && queryString.indexOf("PIN=") < 0) {
        queryString += "&PIN=" + Querystring_get('pin', null);
    }

    if (Querystring_get('lid', null) != null) {
        queryString += "&LID=" + Querystring_get('lid', null);
    }

    if (Querystring_get('look', null) != null) {
        queryString += "&look=" + Querystring_get('look', null);
    }

    if (Querystring_get('template', null) != null) {
        queryString += "&template=" + Querystring_get('template', null);
    }

    if (Querystring_get('vendor', null) != null) {
        queryString += "&vendor=" + Querystring_get('vendor', null);
    }

    if (Querystring_get('adv', null) != null) {
        queryString += "&ADV=" + Querystring_get('adv', null);
    }

    if (cbpsl != null && cbpsl.value != '' && cbpsl.value != '-1') {
        queryString += "&PSL=" + escape(cbpsl.value);
    }
    else if (Querystring_get('psl', null) != null && Querystring_get('psl', null) != '-1') {
        queryString += "&PSL=" + Querystring_get('psl', null);
    }

    if (Querystring_get('logo', null) != null && Querystring_get('logo', null) != '0') {
        queryString += "&logo=" + Querystring_get('logo', null);
    }

    if (Querystring_get('branch', null) != null) {
        queryString += "&branch=" + Querystring_get('branch', null);
    }

    if (Querystring_get('ms', null) != null) {
        queryString += "&MS=" + Querystring_get('ms', null);
    }

    if (Querystring_get('grouponly', null) != null) {
        queryString += "&GroupOnly=" + Querystring_get('grouponly', null);
    }

    if (Querystring_get('xml', null) != null) {
        queryString += "&xml=" + Querystring_get('xml', null);
    }

    if (Querystring_get('bestdeal', null) != null) {
        queryString += "&bestdeal=" + Querystring_get('bestdeal', null);
    }

    if (Querystring_get('so', null) != null) {
        queryString += "&SO=" + Querystring_get('so', null);
    }

    if (Querystring_get('parentag', null) != null) {
        queryString += "&ParentAG=" + Querystring_get('parentag', null);
    }

    if (Querystring_get('pageno', null) != null) {
        queryString += "&PageNo=" + Querystring_get('pageno', null);
    }
    else if (Querystring_get('pg', null) != null) {
        queryString += "&PageNo=" + Querystring_get('pg', null);
    }

    if (Querystring_get('lcompcruises', null) != null) {
        queryString += "&CmpCruises=" + Querystring_get('lcompcruises', null);
    }
    else if (Querystring_get('cmpcruises', null) != null) {
        queryString += "&CmpCruises=" + Querystring_get('cmpcruises', null);
    }

    if (Querystring_get('includeofflinevendors', null) != null) {
        queryString += "&IncludeOfflineVendors=" + Querystring_get('includeofflinevendors', null);
    }

    if (Querystring_get('liid', null) != null) {
        queryString += "&IID=" + Querystring_get('liid', null);
    }
    else if (Querystring_get('iid', null) != null) {
        queryString += "&IID=" + Querystring_get('iid', null);
    }

    if (Querystring_get('lsno', null) != null) {
        queryString += "&SNO=" + Querystring_get('lsno', null);
    }
    else if (Querystring_get('sno', null) != null) {
        queryString += "&SNO=" + Querystring_get('sno', null);
    }

    if (Querystring_get('cc', null) != null) {
        queryString += "&CC=" + Querystring_get('cc', null);
    }

    if (Querystring_get('transitcode', null) != null) {
        queryString += "&TransitCode=" + Querystring_get('transitcode', null);
    }

    if (Querystring_get('home', null) != null) {
        queryString += "&Home=" + Querystring_get('home', null);
    }

    return queryString;
}

function SendStatePortSearch(strFile, target) {
    var strUrl = strFile;
    var cbShowSenior = getElement("ShowSenior");
    var cbShowMilitary = getElement("ShowMilitary");
    var cbShowPastPassenger = getElement("ShowPastPassenger");
    var cbSenior = getElement("lfChk55p");
    var cbMilitary = getElement("lfChkUSM");
    var cbPastPassenger = getElement("PastPassenger");
    var cbResidency = getElement("selResidency");
    var txtPromoCode = getElement("txtPromoCode");
    var cbVnd = getElement("VndDropDown");
    var cbMonth = getElement("DateDropDown");
    var skinId;

    Querystring(null);

    if (strUrl.indexOf("skin=") < 0) {
        if (Querystring_get('skin', null) != null) {
            var arrURL = strUrl.split('?');
            if (arrURL.length == 1)
                strUrl += "?skin=" + Querystring_get('skin', null);
            else
                strUrl += "&skin=" + Querystring_get('skin', null);
            skinId = Querystring_get('skin', null);
        }
        else if (Querystring_get('ag', null) != null) {
            var arrURL = strUrl.split('?');
            if (arrURL.length == 1)
                strUrl += "?skin=" + Querystring_get('ag', null);
            else
                strUrl += "&skin=" + Querystring_get('ag', null);
            skinId = Querystring_get('ag', null);
        }
        else if (Querystring_get('clientid', null) != null) {
            var arrURL = strUrl.split('?');
            if (arrURL.length == 1)
                strUrl += "?skin=" + Querystring_get('clientid', null);
            else
                strUrl += "&skin=" + Querystring_get('clientid', null);
            skinId = Querystring_get('clientid', null);
        }
    }

    if (Querystring_get('pin', null) != null && strUrl.indexOf("PIN=") < 0) {
        var arrURL = strUrl.split('?');
        if (arrURL.length == 1)
            strUrl += "?PIN=" + Querystring_get('pin', null);
        else
            strUrl += "&PIN=" + Querystring_get('pin', null);
    }

    if (Querystring_get('phone', null) != null && strUrl.indexOf("Phone=") < 0) {
        var arrURL = strUrl.split('?');
        if (arrURL.length == 1)
            strUrl += "?Phone=" + Querystring_get('phone', null);
        else
            strUrl += "&Phone=" + Querystring_get('phone', null);
    }

    if (Querystring_get('lid', null) != null) {
        var arrURL = strUrl.split('?');
        if (arrURL.length == 1)
            strUrl += "?LID=" + Querystring_get('lid', null);
        else
            strUrl += "&LID=" + Querystring_get('lid', null);
    }

    strUrl += "&HP=true&CT=4";

    //------------------------------sn,mt,pp-------------------------------------
    if (cbSenior != null && escape(cbSenior.checked) == 'true') {
        strUrl += "&SN=true";
    }
    else if (Querystring_get('sn', null) != null) {
        strUrl += "&SN=" + Querystring_get('sn', null);
    }

    if (cbMilitary != null && escape(cbMilitary.checked) == 'true') {
        strUrl += "&MT=true";
    }
    else if (Querystring_get('mt', null) != null) {
        strUrl += "&MT=" + Querystring_get('mt', null);
    }

    if (Querystring_get('pp', null) != null) {
        strUrl += "&PP=" + Querystring_get('pp', null);
    }

    if (cbResidency != null && cbResidency.type != "hidden") {
        for (var i = 0; i < cbResidency.options.length; i++) {
            if (cbResidency.options[i].selected && cbResidency.options[i].value != '-1') {
                strUrl += "&ZP1=" + cbResidency.options[i].value;
            }
        }
    }
    if (strUrl.indexOf("ZP1=") < 0) {
        if (Querystring_get('zp1', null) != null) {
            strUrl += "&ZP1=" + Querystring_get('zp1', null);
        }
        else if (Querystring_get('st1', null) != null) {
            strUrl += "&ZP1=" + Querystring_get('st1', null);
        }
    }

    if (txtPromoCode != null && txtPromoCode.value != null && txtPromoCode.value != '') {
        strUrl += "&PC=" + txtPromoCode.value;
    }
    else if (Querystring_get('pc', null) != null) {
        strUrl += "&PC=" + Querystring_get('pc', null);
    }

    //----------------------------end of sn,mt,pp----------------------------------------

    if (Querystring_get('vendor', null) != null) {
        var arrURL = strUrl.split('?');
        if (arrURL.length == 1)
            strUrl += "?vendor=" + Querystring_get('vendor', null);
        else
            strUrl += "&vendor=" + Querystring_get('vendor', null);
    }

    var multivendor = "";
    if (cbVnd != null) {
        for (var i = 0; i < cbVnd.options.length; i++) {
            if (cbVnd.options[i].selected) {
                if (multivendor == "")
                    multivendor += cbVnd.options[i].value;
                else
                    multivendor += "," + cbVnd.options[i].value;
            }
        }
    }

    if (multivendor == "") multivendor = -1;

    if (multivendor != -1) {
        strUrl += "&CV=" + multivendor;
    }

    if (Querystring_get('template', null) != null) {
        strUrl += "&Template=" + Querystring_get('template', null);
    }

    if (cbMonth != null) {
        strUrl += "&DF=" + escape(cbMonth.value);
    }
    else if (Querystring_get('df', null) != null) {
        strUrl += "&DF=" + Querystring_get('df', null);
    }

    if (Querystring_get('dt', null) != null) {
        strUrl += "&DT=" + Querystring_get('dt', null);
    }

    if (Querystring_get('cst', null) != null) {
        strUrl += "&sort=" + Querystring_get('cst', null);
    }
    else if (Querystring_get('sort', null) != null) {
        strUrl += "&sort=" + Querystring_get('sort', null);
    }

    if (Querystring_get('eo', null) != null) {
        strUrl += "&EO=" + Querystring_get('eo', null);
    }

    if (Querystring_get('look', null) != null) {
        strUrl += "&look=" + Querystring_get('look', null);
    }
    if (Querystring_get('logo', null) != null && Querystring_get('logo', null) != '0') {
        strUrl += "&logo=" + Querystring_get('logo', null);
    }
    if (Querystring_get('grouponly', null) != null) {
        strUrl += "&GroupOnly=" + Querystring_get('grouponly', null);
    }
    if (Querystring_get('branch', null) != null) {
        strUrl += "&Branch=" + Querystring_get('branch', null);
    }
    if (Querystring_get('bestdeal', null) != null) {
        strUrl += "&BestDeal=" + Querystring_get('bestdeal', null);
    }
    if (Querystring_get('cc', null) != null) {
        strUrl += "&CC=" + Querystring_get('cc', null);
    }
    if (Querystring_get('transitcode', null) != null && Querystring_get('transitcode', null) != '') {
        var arrURL = strUrl.split('?');
        if (arrURL.length == 1)
            strUrl += "?TransitCode=" + Querystring_get('transitcode', null);
        else
            strUrl += "&TransitCode=" + Querystring_get('transitcode', null);
    }

    if (Querystring_get('home', null) != null) {
        var arrURL = strUrl.split('?');
        if (arrURL.length == 1)
            strUrl += "?Home=" + Querystring_get('home', null);
        else
            strUrl += "&Home=" + Querystring_get('home', null);
    }

    if ((skinId != null && skinId == "132") || Querystring_get('nw', null) == 'true' || target == "_blank") {
        window.open(strUrl);
    }
    else {
        if (target && target == "_top") {
            window.top.location.href = strUrl;
        }
        else if (target && target == "_self") {
            window.location.href = strUrl;
        }
        else {
            window.parent.location.href = 'http://' + self.location.host + '/cs/' + strUrl;
        }
    }
}

function SendStateAdvanced(strFile, target) {
    var strUrl = strFile;
    var cbSkin = getElement("Skin");

    if (cbSkin == null) {
        cbSkin = getElement("AG");
        if (cbSkin == null) {
            cbSkin = getElement("clientid");
        }
    }

    if (strUrl.indexOf("skin=") < 0) {
        strUrl += "&skin=" + ((cbSkin != null) ? escape(cbSkin.value) : '1');
    }
    Querystring(null);

    if (cbSkin.value == "132" || Querystring_get('nw', null) == 'true' || target == "_blank")
        window.open(strUrl);
    else {
        if (target && target == "_top") {
            window.top.location.href = strUrl;
        }
        else {
            window.parent.location.href = 'http://' + self.location.host + '/cs/' + strUrl;
        }
    }
}

function Querystring(qs) { // optionally pass a querystring to parse
    this.params = new Object()
    this.get = Querystring_get

    if (qs == null)
        qs = location.search.substring(1, location.search.length)

    if (qs.length == 0) return

    qs = qs.replace(/\+/g, ' ') //// Turn <plus> back to <space>
    var args = qs.split('&') // parse out name/value pairs separated via &

    // split out each name=value pair
    for (var i = 0; i < args.length; i++) {
        var value;
        var pair = args[i].split('=')
        var name = unescape(pair[0]).toLocaleLowerCase();

        if (name == 'home') {
            if (pair.length == 2)
                value = unescape(pair[1])
            else if (pair.length == 3)
                value = unescape(pair[1]) + "=" + unescape(pair[2])
        }
        else if (pair.length == 2) {
            value = unescape(pair[1])
        }
        else {
            value = name
        }
        this.params[name] = value
    }
}

function Querystring_get(key, default_) {
    // This silly looking line changes UNDEFINED to NULL
    if (default_ == null) default_ = null;

    var value = this.params[key]
    if (value == null) {
        if (this.params['L' + key] != null)
            value = this.params['L' + key]
        else
            value = default_;
    }

    return value
}

function displayCalendar(dateValue, inputControl, clientWindow) {
    try {
        if (eval(popFrame.validateDateX(dateValue, 'From Date', 1033)))
            popFrame.fPopCalendar(inputControl, inputControl, popCal, clientWindow);
    }
    catch (e) {
    }

    return false;
}

//-----------------------------------------------------------------------------
// COMMOM FUNCTIONS
//-----------------------------------------------------------------------------
function getElement(name) {
    var value = null;
    //	if(isIE4 || isIE5){
    //		value = document.all(name);
    //	}else if (isNS6){
    //		value = document.getElementById(name);
    //	}
    value = document.getElementsByName(name);
    if (value.length > 0)
        return value[0];
    else return null;
}

function getElements(name) {
    var values = null;
    if (isIE4 || isIE5) {
        values = document.all(name);
    } else if (isNS6) {
        values = document.getElementsByName(name);
    }
    return values;
}
//-----------------------------------------------------------------------------

function initCal() {
    try {
        popCal = window.parent.document.getElementById('popCal');
        popFrame = window.parent.document.frames('popFrame');
    }
    catch (e) {
    }
}

function hideCalendar() {
    try {
        window.parent.document.onclick.call();
    }
    catch (e) {
    }
}

function MM_openBrWindow(theURL, winName, features) { //v2.0

    var strURL = '';
    var strPage = '';
    var intUrl = 0;
    intUrl = theURL.indexOf("?");
    if (intUrl > 0) {
        strPage = theURL.substr(0, intUrl + 1);

        strURL = theURL.substr(intUrl + 1).split('&');
        for (var i = 0; i < strURL.length; i++) {
            var pos = strURL[i].indexOf('=');
            var value = strURL[i].substr(pos + 1);
            if (value != "") {
                strPage += strURL[i] + "&";
            }
        }
        strPage = strPage.substr(0, strPage.length - 1);
    }
    else {
        strPage = theURL;
    }
    newwindow = window.open(strPage, winName, features);
    if (window.focus) {
        newwindow.focus();
    }
}

function setDisplay(id, dp_dstyle, input_dstyle) {
    document.getElementById(id).style.display = dp_dstyle;
    document.getElementById('vtext').style.display = input_dstyle;
    document.getElementById('btnDown').style.display = input_dstyle;
    document.getElementById(id).focus();
}

function msClose(thisObject, hidId, type) {
    var ostring = ""; // only for demo purposes
    var otext = "";
    var items = 0;
    var txtitems = 0;
    o = document.getElementById(thisObject.id);
    o.style.display = "none";

    for (var i = 0; i < o.options.length; i++) {
        if (o.options[i].selected) {
            ostring += (items++ > 0 ? "," : "") + o.options[i].value; // only for demo purposes
            otext += (txtitems++ > 0 ? "," : "") + o.options[i].text;
            if (i == 0) break;  // if "All" selected, skip all other options
        }
    }

    document.getElementById('vtext').style.display = "block";
    document.getElementById('btnDown').style.display = "block";
    document.getElementById("vtext").value = otext;
    document.getElementById("vhidden").value = ostring;

    if (IsDisabledItem(ostring, type)) {
        KeepSelection(thisObject, getElement(hidId).value, type);
        return;
    }

    try {
        __doPostBack(thisObject.id, '');
        if (getElement('ZoneDropDown') != null)
            getElement('ZoneDropDown').disabled = true;
        if (getElement('VndDropDown') != null)
            getElement('VndDropDown').disabled = true;
        if (getElement('DateDropDown') != null)
            getElement('DateDropDown').disabled = true;
        if (getElement('LenDropDown') != null)
            getElement('LenDropDown').disabled = true;
        if (getElement('PortDropDown') != null)
            getElement('PortDropDown').disabled = true;
        if (getElement('ShipsDropDown') != null)
            getElement('ShipsDropDown').disabled = true;
        if (getElement('LoadFromDays') != null)
            getElement('LoadFromDays').disabled = true;
        if (getElement('LoadToDays') != null)
            getElement('LoadToDays').disabled = true;
        if (getElement('CruiseTypeDropDown') != null)
            getElement('CruiseTypeDropDown').disabled = true;
        if (getElement('FromLength') != null)
            getElement('FromLength').disabled = true;
        if (getElement('ToLength') != null)
            getElement('ToLength').disabled = true;
        if (getElement('DateTo') != null)
            getElement('DateTo').disabled = true;
    }
    catch (e) {
    }
}

function IsDisabledItem(ostring, type) {
    if (type == "Port") return Check(PortDisabledArr, ostring);
}

function Check(DisabledArr, Ids) {
    var p = 0;
    var q = 0;
    var arrIds = Ids.toString().split(',');
    for (p = 0; p < DisabledArr.length; p++) {
        for (q = 0; q < arrIds.length; q++) {
            if (DisabledArr[p] == arrIds[q]) {
                return true;
            }
        }
    }
    return false;
}

function SelectedVendors(allPPVids) {
    var v = 0;
    var sCount = 0;
    var sel = document.getElementById('SelVIds');
    sel.value = '';
    
    var allChks = allPPVids + ",";
    var arrChks = allChks.split(",");
    
    for (var i = 0; i < arrChks.length; i++) 
    {
        if (document.getElementById(arrChks[i]) != null && document.getElementById(arrChks[i]).type == 'checkbox'
        && document.getElementById(arrChks[i]).checked == true)
        {
            sel.value += arrChks[i] + ",";
            sCount = sCount + 1;
        }
    }
    if (sel.value == '' || sel.value == null) {
        document.getElementById('PastPassenger').checked = false;
    }
    else {
        sel.value = sel.value.substring(0, sel.value.length - 1);
        if (sCount == arrChks.length-1) {
            sel.value = "y";
        }
    }
}

function ShowHideCVList(allPPVids) 
{
    document.getElementById('lfPpaxOvly').style.display = document.getElementById('PastPassenger').checked ? 'inline' : 'none';

    if (document.getElementById('PastPassenger').checked == false) { 
        var allChks = allPPVids + ",";
        var arrChks = allChks.split(",");

        for (var i = 0; i < arrChks.length; i++) {
            if (document.getElementById(arrChks[i]) != null && document.getElementById(arrChks[i]).type == 'checkbox'
                && document.getElementById(arrChks[i]).checked == true) {
                document.getElementById(arrChks[i]).checked = false;
            }
        }
        var sel = document.getElementById('SelVIds');
        sel.value = '';
    }
}

function RetainVendors(allPPVids) 
{
    document.getElementById('lfPpaxOvly').style.display = document.getElementById('PastPassenger').checked ? 'inline' : 'none';

    var sel = document.getElementById('SelVIds');

    var allChks = allPPVids + ",";
    var arrAllChks = allChks.split(",");
    if (sel.value == 'y') {
        sel.value = allPPVids;
    }
    var selChks = sel.value + ",";
    var arrChks = selChks.split(",");

    for (var i = 0; i < arrChks.length; i++) {
        for (var j = 0; j < arrAllChks.length; j++) {
            if (document.getElementById(arrChks[i]) != null && document.getElementById(arrChks[i]).type == 'checkbox'
                && arrAllChks[j] == arrChks[i]) {
                document.getElementById(arrAllChks[j]).checked = true;
            }
        }
    }
}
