﻿///REmark
var SearchControl = {

    elementIds: new Object(),

    showElement: function (elementId) {
        $("#" + elementId).show();
    },

    hideElement: function (elementId) {
        $("#" + elementId).hide();
    },

    show: function (searchType) {
        switch (searchType) {
            case "flight":
                this.showElement(this.elementIds.Flight.DivFlight);
                this.showElement(this.elementIds.Flight.ImgFlight);
                break;
            case "hotel":
                this.showElement(this.elementIds.Hotel.DivHotel);
                this.showElement(this.elementIds.Hotel.ImgHotel);
                break;
            case "car":
                if (IsEnabledRoviaBucks == "true" || IsEnabledRoviaBucks == "True") {
//                    alert(CarNotAllowedUsingRoviaBucksMessage);
                }
                this.showElement(this.elementIds.Car.DivCar);
                this.showElement(this.elementIds.Car.ImgCar);
                break;
            case "deal":
                if (this.elementIds.Deal != null && this.elementIds.Deal != "") {
                    this.showElement(this.elementIds.Deal.DivDeal);
                }
                break;
            case "vacation":
                this.showElement(this.elementIds.Vacation.divVacation);
                this.showElement(this.elementIds.Vacation.imgVacation);
                break;
            case "activity":
                this.showElement(this.elementIds.Activity.divActivity);
                this.showElement(this.elementIds.Activity.imgActivity);
                break;
            case "villas":
                if (this.elementIds.Villas != null) {
                    this.showElement(this.elementIds.Villas.divVillas);
                    this.showElement(this.elementIds.Villas.imgVillas);
                }
                break;
            case "dtvacation":
                if (this.elementIds.DTVacation != null) {
                    this.showElement(this.elementIds.DTVacation.divDTVacation);
                    this.showElement(this.elementIds.DTVacation.imgDTVacation);
                }
                break;
            case "cruise":
                if (this.elementIds.Cruise != null) {
                    this.showElement(this.elementIds.Cruise.divCruise);
                    this.showElement(this.elementIds.Cruise.imgCruise);
                }
                break;
        }

        if (typeof initQuickSearchTye == "function") {
            //this function used in Quick search widget
            initQuickSearchTye(searchType);
        }
    },

    hide: function (searchType) {
        switch (searchType) {
            case "flight":
                this.hideElement(this.elementIds.Flight.DivFlight);
                this.hideElement(this.elementIds.Flight.ImgFlight);
                break;
            case "hotel":
                this.hideElement(this.elementIds.Hotel.DivHotel);
                this.hideElement(this.elementIds.Hotel.ImgHotel);
                break;
            case "car":
                this.hideElement(this.elementIds.Car.DivCar);
                this.hideElement(this.elementIds.Car.ImgCar);
                break;
            case "deal":
                if (this.elementIds.Deal != null && this.elementIds.Deal != "") {
                    this.hideElement(this.elementIds.Deal.DivDeal);
                }
                break;
            case "vacation":
                this.hideElement(this.elementIds.Vacation.divVacation);
                this.hideElement(this.elementIds.Vacation.imgVacation);
                break;
            case "activity":
                this.hideElement(this.elementIds.Activity.divActivity);
                this.hideElement(this.elementIds.Activity.imgActivity);
                break;
            case "villas":
                if (this.elementIds.Villas != null) {
                    this.hideElement(this.elementIds.Villas.divVillas);
                    this.hideElement(this.elementIds.Villas.imgVillas);
                }
                break;
            case "dtvacation":
                if (this.elementIds.DTVacation != null) {
                    this.hideElement(this.elementIds.DTVacation.divDTVacation);
                    this.hideElement(this.elementIds.DTVacation.imgDTVacation);
                }
                break;
            case "cruise":
                if (this.elementIds.Cruise != null) {
                    this.hideElement(this.elementIds.Cruise.divCruise);
                    this.hideElement(this.elementIds.Cruise.imgCruise);
                }
                break;

        }
    }
};

var IsEnabledRoviaBucks = false;
var CarNotAllowedUsingRoviaBucksMessage = "Car rentals using Rovia Bucks is currently not available until further notice";
function initialSetup(eleIds) {
    if (eleIds.IsEnabledRoviaBucks != undefined) {
        IsEnabledRoviaBucks = eleIds.IsEnabledRoviaBucks;

        if (eleIds.CarNotAllowedUsingRoviaBucksMsg != undefined)
            CarNotAllowedUsingRoviaBucksMessage = eleIds.CarNotAllowedUsingRoviaBucksMsg;
    }


    SearchControl.elementIds = eleIds;
    registerStartUpEvents();
    setDatePickers();
    setAutoSuggest();
    flightCheck();
    setInitSearchAllow();
    initCarCode();
    initVacation();
    initHotel();
    initDTVacation();

}
function initVacation() {
    var eleIds = SearchControl.elementIds;
    var ddlChild = $(eleIds.Vacation.ddlChild);
    var hfChildAge = $(eleIds.Vacation.childAge);
    if (ddlChild.length > 0) {
        var _val = parseInt(ddlChild.val());
        if (_val > 0) {
            displayVacChildAge(ddlChild[0]);
            var _childAge = [];
            if (hfChildAge.length > 0)
                _childAge = hfChildAge[0].value.split('|');
            if (_childAge.length > 0) {
                var _cnt = 0;
                $("#divVacChildAge select").each(function () {
                    if (_cnt < _childAge.length)
                        $(this).val(_childAge[_cnt]);
                    _cnt++;
                });
            }
        }
    }
}
function initHotel() {
    var eleIds = SearchControl.elementIds;
    var ddlChild = $(eleIds.Hotel.ddlChild);
    var hfChildAge = $(eleIds.Hotel.childAge);
    if (ddlChild.length > 0) {
        var _val = parseInt(ddlChild.val());
        if (_val > 0) {
            displayHotelChildAge(ddlChild[0]);
            var _childAge = [];
            if (hfChildAge.length > 0)
                _childAge = hfChildAge[0].value.split('|');
            if (_childAge.length > 0) {
                var _cnt = 0;
                $("#divHChildAge select").each(function () {
                    if (_cnt < _childAge.length)
                        $(this).val(_childAge[_cnt]);
                    _cnt++;
                });
            }
        }
    }
}
function initDTVacation() {
    var eleIds = SearchControl.elementIds;
    if (eleIds.DTVacation != undefined) {
        var ddlChild = $(eleIds.DTVacation.ddlChild);
        var hfChildAge = $(eleIds.DTVacation.childAge);
        if (ddlChild.length > 0) {
            var _val = parseInt(ddlChild.val());
            if (_val > 0) {
                displayDTVacationChildAge(ddlChild[0]);
                var _childAge = [];
                if (hfChildAge.length > 0)
                    _childAge = hfChildAge[0].value.split('|');
                if (_childAge.length > 0) {
                    var _cnt = 0;
                    $("#dvDTVacChildAgeHolder").addClass('dvchildAge');
                    $("#dvDTVacChildAgeHolder select").each(function () {
                        if (_cnt < _childAge.length)
                            $(this).val(_childAge[_cnt]);
                        _cnt++;
                    });
                }
            }
        }
    }
}
function setInitSearchAllow() {
    var eleIds = SearchControl.elementIds;
    if ($("#" + SearchControl.elementIds.Flight.RadFlight).is(":checked")) {
        SearchControl.show("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.hide("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal");
        if (eleIds.Flight.AOC != null) {
            if ($("#" + eleIds.Flight.AOC).is(":checked"))
                $("#divFlightAdvOpt").slideDown();
        }
        SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    }
    else if ($("#" + SearchControl.elementIds.Hotel.RadHotel).is(":checked")) {
        SearchControl.hide("flight");
        SearchControl.show("hotel");
        SearchControl.hide("car");
        SearchControl.hide("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal");
        if (eleIds.Hotel.AOC != null) {
            if ($("#" + eleIds.Hotel.AOC).is(":checked"))
                $("#divHotelAdvOpt").slideDown();
        }
        SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    }
    else if ($("#" + SearchControl.elementIds.Car.RadCar).is(":checked")) {
        SearchControl.hide("flight");
        SearchControl.hide("hotel");
        SearchControl.show("car");
        SearchControl.hide("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal");
        if (SearchControl.elementIds.Car.AOC != null) {
            if ($("#" + SearchControl.elementIds.Car.AOC).is(":checked"))
                $("#divCarAdvOpt").slideDown();
        }
        SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    }
    else if (SearchControl.elementIds.Deal != null && SearchControl.elementIds.Deal != "" && $("#" + SearchControl.elementIds.Deal.RadDeal).is(":checked")) {
        SearchControl.hide("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.hide("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.show("deal");
        SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    }
    else if ($("#" + SearchControl.elementIds.Vacation.radVacation).is(":checked")) {
        SearchControl.hide("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.show("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal");
        SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    }
    else if ($("#" + SearchControl.elementIds.Activity.radActivity).is(":checked")) {
        SearchControl.hide("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.hide("vacation");
        SearchControl.show("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal");
        SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    }
    else if ($("#" + SearchControl.elementIds.Cruise.radCruise).is(":checked")) {
        SearchControl.hide("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.hide("vacation");
        SearchControl.hide("activity");
        SearchControl.show("cruise");
        SearchControl.hide("deal");
        SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    }
    else if (eleIds.Villas != undefined && eleIds.Villas != null && $("#" + eleIds.Villas.radVillas).is(":checked")) {
        SearchControl.hide("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.hide("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal");
        SearchControl.show("villas");
        SearchControl.hide("dtvacation");
    }
    else if (eleIds.DTVacation != undefined && eleIds.DTVacation != null && $("#" + eleIds.DTVacation.radDTVacation).is(":checked")) {
        SearchControl.hide("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.hide("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal");
        SearchControl.hide("villas");
        SearchControl.show("dtvacation");
    }
    var _vacType = "";
    if ($(SearchControl.elementIds.Vacation.radHC).is(":checked"))
        _vacType = "HotelCar";
    else if ($(SearchControl.elementIds.Vacation.radHA).is(":checked"))
        _vacType = "HotelAir";
    else if ($(SearchControl.elementIds.Vacation.radHAC).is(":checked"))
        _vacType = "HotelAirCar";

    vacationTypeChange(_vacType);
}

function registerStartUpEvents() {
    var eleIds = SearchControl.elementIds;

    $("#" + eleIds.Flight.RadFlight).click(function () {
        $('#' + eleIds.Error).html('').hide();
        SearchControl.show("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.hide("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal");
        SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
        flightCheck(eleIds.Flight);
    });

    $("#" + eleIds.Hotel.RadHotel).click(function () {
        $('#' + eleIds.Error).html('').hide();
        SearchControl.hide("flight");
        SearchControl.show("hotel");
        SearchControl.hide("car");
        SearchControl.hide("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal");
        SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    });

    $("#" + eleIds.Car.RadCar).click(function () {
        $('#' + eleIds.Error).html('').hide();
        SearchControl.hide("flight");
        SearchControl.hide("hotel");
        SearchControl.show("car");
        SearchControl.hide("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal"); SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    });


    if (eleIds.Deal != null && eleIds.Deal != "") {
        $("#" + eleIds.Deal.RadDeal).click(function () {
            $('#' + eleIds.Error).html('').hide();
            SearchControl.hide("flight");
            SearchControl.hide("hotel");
            SearchControl.hide("car");
            SearchControl.hide("vacation");
            SearchControl.hide("activity");
            SearchControl.hide("cruise");
            SearchControl.show("deal");
            SearchControl.hide("villas");
            SearchControl.hide("dtvacation");

        });
    }

    $("#" + eleIds.Vacation.radVacation).click(function () {
        $('#' + eleIds.Error).html('').hide();
        SearchControl.hide("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.show("vacation");
        SearchControl.hide("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal");
        SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    });
    $("#" + eleIds.Activity.radActivity).click(function () {
        $('#' + eleIds.Error).html('').hide();
        SearchControl.hide("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.hide("vacation");
        SearchControl.show("activity");
        SearchControl.hide("cruise");
        SearchControl.hide("deal"); SearchControl.hide("villas");
        SearchControl.hide("dtvacation");
    });
    if (eleIds.Cruise != null) {
        $("#" + eleIds.Cruise.radCruise).click(function () {
            $('#' + eleIds.Error).html('').hide();
            SearchControl.hide("flight");
            SearchControl.hide("hotel");
            SearchControl.hide("car");
            SearchControl.hide("vacation");
            SearchControl.hide("activity");
            SearchControl.show("cruise");
            SearchControl.hide("deal"); SearchControl.hide("villas");
            SearchControl.hide("dtvacation");
        });
    }

    if (eleIds.Villas != null) {
        $("#" + eleIds.Villas.radVillas).click(function () {
            $('#' + eleIds.Error).html('').hide();
            SearchControl.hide("flight");
            SearchControl.hide("hotel");
            SearchControl.hide("car");
            SearchControl.hide("vacation");
            SearchControl.hide("activity");
            SearchControl.hide("cruise");
            SearchControl.hide("deal");
            SearchControl.show("villas");
            SearchControl.hide("dtvacation");
        });
    }
    if (eleIds.DTVacation != null) {
        $("#" + eleIds.DTVacation.radDTVacation).click(function () {
            $('#' + eleIds.Error).html('').hide();
            SearchControl.hide("flight");
            SearchControl.hide("hotel");
            SearchControl.hide("car");
            SearchControl.hide("vacation");
            SearchControl.hide("activity");
            SearchControl.hide("cruise");
            SearchControl.hide("deal");
            SearchControl.hide("villas");
            SearchControl.show("dtvacation");
        });
    }

    $("#" + eleIds.Car.DropOffDdl).change(function () {
        var value = $("#" + eleIds.Car.DropOffDdl).val();
        if (value == "SAP")
            SearchControl.hideElement(eleIds.Car.DropOffLoc);
        else
            SearchControl.showElement(eleIds.Car.DropOffLoc);
    });

    if (eleIds.Deal != null && eleIds.Deal != "") {
        var chkDealLoc = $("#" + eleIds.Deal.RadLocation);
        var chkDealKeyword = $("#" + eleIds.Deal.RadKeyword);
        var chkDealActivity = $("#" + eleIds.Deal.RadActivity);
        var ddlDealLoc = $("#" + eleIds.Deal.ddlLocation);
        var ddlDealKeyword = $("#" + eleIds.Deal.ddlKeyword);
        var ddlDealActivity = $("#" + eleIds.Deal.ddlActivity);

        chkDealLoc.click(function () {
            ddlDealLoc.attr("disabled", "");
            ddlDealKeyword.attr("disabled", "disabled");
            ddlDealActivity.attr("disabled", "disabled");
        });

        chkDealKeyword.click(function () {

            ddlDealLoc.attr("disabled", "disabled");
            ddlDealKeyword.attr("disabled", "");
            ddlDealActivity.attr("disabled", "disabled");
        });

        chkDealActivity.click(function () {
            ddlDealLoc.attr("disabled", "disabled");
            ddlDealKeyword.attr("disabled", "disabled");
            ddlDealActivity.attr("disabled", "");
        });
        if (chkDealActivity.is(":checked"))
            chkDealActivity.trigger("click");
        if (chkDealKeyword.is(":checked"))
            chkDealKeyword.trigger("click");
        if (chkDealLoc.is(":checked"))
            chkDealLoc.trigger("click");
    }

    $("#" + eleIds.Flight.RadRT).click(function () {
        $("#" + eleIds.Flight.DivRTDate).css("visibility", "visible");
        hideDiv(eleIds.Flight.Flight2);
        hideDiv(eleIds.Flight.Flight3);
        hideDiv(eleIds.Flight.Flight4);
        hideDiv(eleIds.Flight.Flight5);
        hideDiv(eleIds.Flight.MoreFlights);
        $("#" + eleIds.Flight.DividerImg).attr("height", "193");
    });

    $("#" + eleIds.Flight.RadOW).click(function () {
        $("#" + eleIds.Flight.DivRTDate).css("visibility", "hidden");
        hideDiv(eleIds.Flight.Flight2);
        hideDiv(eleIds.Flight.Flight3);
        hideDiv(eleIds.Flight.Flight4);
        hideDiv(eleIds.Flight.Flight5);
        hideDiv(eleIds.Flight.MoreFlights);
        $("#" + eleIds.Flight.DividerImg).attr("height", "193");
    });

    $("#" + eleIds.Flight.RadMD).click(function () {
        $("#" + eleIds.Flight.DivRTDate).css("visibility", "hidden");
        if ($("#" + eleIds.Flight.IsMultiFlight).val() == "Y") {
            document.getElementById(eleIds.Flight.IsMultiFlight).value = '';
            showDiv(eleIds.Flight.Flight2);
            showDiv(eleIds.Flight.Flight3);
            showDiv(eleIds.Flight.Flight4);
            showDiv(eleIds.Flight.Flight5);
            hideDiv(eleIds.Flight.MoreFlights);
        }
        else {
            showDiv(eleIds.Flight.Flight2);
            showDiv(eleIds.Flight.Flight3);
            hideDiv(eleIds.Flight.Flight4);
            hideDiv(eleIds.Flight.Flight5);
            showDiv(eleIds.Flight.MoreFlights);
            $("#" + eleIds.Flight.DividerImg).attr("height", "290");
        }
    });
    if (eleIds.Flight.AOC != null) {
        $("#" + eleIds.Flight.AOC).click(function () {
            var isChecked = $("#" + eleIds.Flight.AOC).is(":checked");
            if (isChecked)
                $("#divFlightAdvOpt").slideDown();
            else
                $("#divFlightAdvOpt").slideUp();
        });
    }
    if (eleIds.Hotel.AOC != null) {
        $("#" + eleIds.Hotel.AOC).click(function () {
            if ($("#" + eleIds.Hotel.AOC).is(":checked"))
                $("#divHotelAdvOpt").slideDown();
            else
                $("#divHotelAdvOpt").slideUp();
        });
    }
    if (eleIds.Car.AOC != null) {
        $("#" + eleIds.Car.AOC).click(function () {
            var isChecked = $("#" + eleIds.Car.AOC).is(":checked");
            if (isChecked)
                $("#divCarAdvOpt").slideDown();
            else
                $("#divCarAdvOpt").slideUp();
        });
    }
}

function flightCheck() {
    var flight = SearchControl.elementIds.Flight;

    if ($("#" + flight.RadFlight).is(":checked")) {
        SearchControl.show("flight");
        SearchControl.hide("hotel");
        SearchControl.hide("car");
        SearchControl.hide("activity");


        if ($("#" + flight.RadRT).is(":checked")) {
            $("#" + flight.DivRTDate).css("visibility", "visible");
            hideDiv(flight.Flight2);
            hideDiv(flight.Flight3);
            hideDiv(flight.Flight4);
            hideDiv(flight.Flight5);
            hideDiv(flight.MoreFlights);
            $("#" + flight.DividerImg).attr("height", "193");
        }
        else if ($("#" + flight.RadOW).is(":checked")) {
            $("#" + flight.DivRTDate).css("visibility", "hidden");
            hideDiv(flight.Flight2);
            hideDiv(flight.Flight3);
            hideDiv(flight.Flight4);
            hideDiv(flight.Flight5);
            hideDiv(flight.MoreFlights);
            $("#" + flight.DividerImg).attr("height", "193");
        }
        else if ($("#" + flight.RadMD).is(":checked")) {
            $("#" + flight.DivRTDate).css("visibility", "hidden");
            if ($("#" + flight.IsMultiFlight).val() == "Y") {

                document.getElementById(flight.IsMultiFlight).value = '';
                showDiv(flight.Flight2);
                showDiv(flight.Flight3);
                showDiv(flight.Flight4);
                showDiv(flight.Flight5);
                hideDiv(flight.MoreFlights);
            }
            else {
                showDiv(flight.Flight2);
                showDiv(flight.Flight3);
                hideDiv(flight.Flight4);
                hideDiv(flight.Flight5);
                showDiv(flight.MoreFlights);
                $("#" + flight.DividerImg).attr("height", "290");
            }
        }
    }
}

function setDatePickers() {
    var eleIds = SearchControl.elementIds;

    /* Flight Datepicker */
    if (eleIds.Flight != null && eleIds.Flight.DivFlight != null && $("#" + eleIds.Flight.DivFlight).length > 0) {
        var _txtF1D = $('#' + eleIds.Flight.Flight1DD);
        var _txtF1A = $('#' + eleIds.Flight.Flight1AD);
        var _txtF2D = $('#' + eleIds.Flight.Flight2DD);
        var _txtF3D = $('#' + eleIds.Flight.Flight3DD);
        var _txtF4D = $('#' + eleIds.Flight.Flight4DD);
        var _txtF5D = $('#' + eleIds.Flight.Flight5DD);

        _txtF1D.datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true
        }).bind("change", function (e) {
            _txtF1A.datepicker('option', 'minDate', $(this).datepicker('getDate'));
            _txtF1A.val('mm/dd/yyyy');
        });

        var f1ArrivalDate = new Date();
        var f1DepartDate = _txtF1D.datepicker('getDate');
        if (f1DepartDate != null && f1DepartDate != '') {
            f1ArrivalDate = f1DepartDate;
        }

        _txtF1A.datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: f1ArrivalDate, showButtonPanel: true });

        _txtF1D.datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true
        }).bind("change", function (e) {
            _txtF2D.datepicker('option', 'minDate', $(this).datepicker('getDate'));
            if (_txtF2D.val() != 'mm/dd/yyyy' && $(this).datepicker('getDate') > _txtF2D.datepicker('getDate')) {
                _txtF2D.val('mm/dd/yyyy');
            }
            _txtF2D.trigger('change');
        });

        _txtF2D.datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true
        }).bind("change", function (e) {
            _txtF3D.datepicker('option', 'minDate', $(this).datepicker('getDate'));
            if (_txtF3D.val() != 'mm/dd/yyyy' && $(this).datepicker('getDate') > _txtF2D.datepicker('getDate')) {
                _txtF3D.val('mm/dd/yyyy');
            }
            _txtF3D.trigger('change');
        });


        _txtF3D.datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true
        }).bind("change", function (e) {
            _txtF4D.datepicker('option', 'minDate', $(this).datepicker('getDate'));
            if (_txtF4D.val() != 'mm/dd/yyyy' && $(this).datepicker('getDate') > _txtF3D.datepicker('getDate')) {
                _txtF4D.val('mm/dd/yyyy');
            }
            _txtF4D.trigger('change');
        });

        _txtF4D.datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true
        }).bind("change", function (e) {
            _txtF5D.datepicker('option', 'minDate', $(this).datepicker('getDate'));
            if (_txtF5D.val() != 'mm/dd/yyyy' && $(this).datepicker('getDate') > _txtF4D.datepicker('getDate')) {
                _txtF5D.val('mm/dd/yyyy');
            }
            _txtF5D.trigger('change');
        });

        _txtF5D.datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true });

    }
    /* hotel datepicker */
    if (eleIds.Hotel != null && eleIds.Hotel.DivHotel != null && $("#" + eleIds.Hotel.DivHotel).length > 0) {
        var _txtHotelCID = $("#" + eleIds.Hotel.CID);
        var _txtHotelCOD = $("#" + eleIds.Hotel.COD);
        var txtHotelCODName = "#" + eleIds.Hotel.CID;

        _txtHotelCID.datepicker({ defaultDate: +2, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true,
            onClose: function (dateText, inst) {
                var date = $(this).datepicker('getDate');
                if (date != null) {
                    _txtHotelCOD.datepicker('setDate', new Date($(this).datepicker('getDate').setDate($(this).datepicker('getDate').getDate() + 7)));
                    _txtHotelCOD.datepicker('option', 'minDate', $(this).datepicker('getDate'));
                    _txtHotelCOD.css("color", "black");
                }
                else {
                    _txtHotelCOD.datepicker('setDate', new Date());
                    _txtHotelCOD.datepicker('option', 'minDate', new Date());
                    _txtHotelCOD.css("color", "black")
                }
            }
        });

        var hotelCheckInDate = new Date();
        var hotelCheckOutDate = _txtHotelCID.datepicker('getDate');
        if (hotelCheckOutDate != null && hotelCheckOutDate != '') {
            hotelCheckInDate = hotelCheckOutDate;
        }

        _txtHotelCOD.datepicker({ defaultDate: +7, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: hotelCheckInDate, showButtonPanel: true });
    }


    /* car datepicker */
    if (eleIds.Car != null && eleIds.Car.DivCar != null && $("#" + eleIds.Car.DivCar).length > 0) {
        var _txtCarPUD = $("#" + eleIds.Car.PUD);
        var _txtCarDOD = $("#" + eleIds.Car.DOD);
        var _txtCarDODName = "#" + eleIds.Car.DOD;
        _txtCarPUD.datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true,
            onClose: function (dateText, inst) {
                var date = $(this).datepicker('getDate');
                if (date != null) {
                    _txtCarDOD.datepicker('setDate', new Date($(this).datepicker('getDate').setDate($(this).datepicker('getDate').getDate() + 7)));
                    _txtCarDOD.datepicker('option', 'minDate', $(this).datepicker('getDate'));
                    _txtCarDOD.css("color", "black")
                }
                else {
                    _txtCarDOD.datepicker('setDate', new Date());
                    _txtCarDOD.datepicker('option', 'minDate', new Date());
                    _txtCarDOD.css("color", "black")
                }
            }
        });

        var ddlCarPUD = $("#" + eleIds.Car.PUD);
        if (ddlCarPUD.length > 0) {
            var _carPUD = $("#" + eleIds.Car.PUD).datepicker('getDate');
            if (_carPUD != null)
                $("#" + eleIds.Car.DOD).datepicker('option', 'minDate', _carPUD);
        }

        var carPickUpDate = new Date();
        var carDropOffDate = _txtCarPUD.datepicker('getDate');
        if (carDropOffDate != null && carDropOffDate != '') {
            carPickUpDate = carDropOffDate;
        }

        _txtCarDOD.datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: carPickUpDate, showButtonPanel: true });
    }

    //Vacation
    if (eleIds.Vacation != null && eleIds.Vacation.divVacation != null && $("#" + eleIds.Vacation.divVacation).length > 0) {
        var _txtVEndD = $("#" + eleIds.Vacation.endDT);
        var _txtVStartD = $("#" + eleIds.Vacation.startDT);
        var _txtVCI = $("#" + eleIds.Vacation.checkIn);
        _txtVEndD.datepicker({ defaultDate: +7, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true });
        _txtVStartD.datepicker({ defaultDate: +2, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true })
        .bind("change", function (e) {
            var date = $(this).datepicker('getDate');
            if (date != null) {
                _txtVEndD.datepicker('setDate', new Date($(this).datepicker('getDate').setDate($(this).datepicker('getDate').getDate() + 7)));
                _txtVCI.datepicker('setDate', new Date($(this).datepicker('getDate').setDate($(this).datepicker('getDate').getDate())));
                _txtVEndD.datepicker('option', 'minDate', $(this).datepicker('getDate'));
                _txtVCI.datepicker('option', 'minDate', $(this).datepicker('getDate'));
            }
            else {
                _txtVEndD.datepicker('setDate', new Date());
                _txtVEndD.datepicker('option', 'minDate', new Date());
                _txtVEndD.css("color", "black")
            }
        });

        _txtVCI.datepicker({ defaultDate: +7, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true });
        $("#" + eleIds.Vacation.checkOutHC).datepicker({ defaultDate: +7, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true });
        $("#" + eleIds.Vacation.checkInHC).datepicker({ defaultDate: +2, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true })
        .bind("change", function (e) {
            var date = $(this).datepicker('getDate');
            if (date != null) {
                $("#" + eleIds.Vacation.checkOutHC).datepicker('setDate', new Date($(this).datepicker('getDate').setDate($(this).datepicker('getDate').getDate() + 7)));
                $("#" + eleIds.Vacation.checkOutHC).datepicker('option', 'minDate', $(this).datepicker('getDate'));
            }
            else {
                _txtHotelCOD.datepicker('setDate', new Date());
                _txtHotelCOD.datepicker('option', 'minDate', new Date());
                _txtHotelCOD.css("color", "black")
            }
        });
    }
    /* Activity datepicker */
    if (eleIds.Activity != null && eleIds.Activity.divActivity != null && $("#" + eleIds.Activity.divActivity).length > 0) {
        var _txtActivityDODName = "#" + eleIds.Activity.DOD;
        $("#" + eleIds.Activity.DOD).datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true,
            onClose: function (dateText, inst) {
                var date = $(this).datepicker('getDate');
                if (date != null) {
                    $("#" + eleIds.Activity.DOR).datepicker('setDate', new Date($(this).datepicker('getDate').setDate($(this).datepicker('getDate').getDate() + 7)));
                    $("#" + eleIds.Activity.DOR).datepicker('option', 'minDate', $(this).datepicker('getDate'));
                    $("#" + eleIds.Activity.DOR).css("color", "black")
                }
                else {
                    $("#" + eleIds.Activity.DOR).datepicker('setDate', new Date());
                    $("#" + eleIds.Activity.DOR).datepicker('option', 'minDate', new Date());
                    $("#" + eleIds.Activity.DOR).css("color", "black")
                }
            }
        });

        var activityDepartDate = new Date();
        var activityReturnDate = $("#" + eleIds.Activity.DOD).datepicker('getDate');
        if (activityReturnDate != null && activityReturnDate != '') {
            activityDepartDate = activityReturnDate;
        }

        $("#" + eleIds.Activity.DOR).datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: activityDepartDate, showButtonPanel: true });
    }

    /*Cruise Date Picker*/
    if (eleIds.Cruise != null && eleIds.Cruise.divCruise != null) {
        $("#" + eleIds.Cruise.txtDT).datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true });
    }
    if (eleIds.Villas != undefined && eleIds.Villas != null) {
        $("#" + eleIds.Villas.txtCI).datepicker({ defaultDate: +0, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true });
    }
    /*DTVacation Datepicker*/
    if (eleIds.DTVacation != null && eleIds.DTVacation.divDTVacation != null && $("#" + eleIds.DTVacation.divDTVacation).length > 0) {
        var _txtDTVacationCID = $("#" + eleIds.DTVacation.CID);
        var _txtDTVacationCOD = $("#" + eleIds.DTVacation.COD);
        //var txtHotelCODName = "#" + eleIds.DTVacation.CID;

        _txtDTVacationCID.datepicker({ defaultDate: +2, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: new Date(), showButtonPanel: true,
            onClose: function (dateText, inst) {
                var date = $(this).datepicker('getDate');
                if (date != null) {
                    _txtDTVacationCOD.datepicker('setDate', new Date($(this).datepicker('getDate').setDate($(this).datepicker('getDate').getDate() + 2)));
                    _txtDTVacationCOD.datepicker('option', 'minDate', $(this).datepicker('getDate'));
                    _txtDTVacationCOD.css("color", "black");
                }
                else {
                    _txtDTVacationCOD.datepicker('setDate', new Date());
                    _txtDTVacationCOD.datepicker('option', 'minDate', new Date());
                    _txtDTVacationCOD.css("color", "black")
                }
            }
        });

        var dtvacationCheckInDate = new Date();
        var dtvacationCheckOutDate = _txtDTVacationCID.datepicker('getDate');
        if (dtvacationCheckOutDate != null && dtvacationCheckOutDate != '') {
            dtvacationCheckInDate = dtvacationCheckOutDate;
        }

        _txtDTVacationCOD.datepicker({ defaultDate: +7, stepMonths: 2, numberOfMonths: 2, duration: '', minDate: dtvacationCheckInDate, showButtonPanel: true });
    }
}


function ValidateAirSearch() {
    var flight = SearchControl.elementIds.Flight;
    var error = SearchControl.elementIds.Error;
    var departLoc = $('#' + flight.From1).val();
    var arriveLoc = $('#' + flight.To1).val();
    var departDate = $('#' + flight.Flight1DD).val();
    var arriveDate = $('#' + flight.Flight1AD).val();
    $('#' + error).html('').hide();

    //Round Trip
    if ($('#' + flight.RadRT).is(':checked') == true) {
        if (departLoc.length == 0 || arriveLoc.length == 0) {
            $('#' + error).html('Both Airport required').show();
            return false;
        }
        if (arriveDate == 'mm/dd/yyyy' || departDate == 'mm/dd/yyyy') {
            $('#' + error).html('Both Return Date & Depart Date required').show();
            return false;
        }
    }
    //One Way
    else if ($('#' + flight.RadOW).is(':checked') == true) {
        if (departLoc.length == 0 || arriveLoc.length == 0) {
            $('#' + error).html('Both Airport required').show();
            return false;
        }
        if (departDate == 'mm/dd/yyyy') {
            $('#' + error).html('Depature Date required').show();
            return false;
        }
    }

    //MultiCity
    else if ($('#' + flight.RadMD).is(':checked') == true) {
        if (departLoc.length == 0 || arriveLoc.length == 0) {
            $('#' + error).html('Airport Code  Required for 1st Flight').show();
            return false;
        }
        if (departDate == 'mm/dd/yyyy') {
            $('#' + error).html('Depature Date required for 1st Flight').show();
            return false;
        }

        if ($('#' + flight.From2).val().length > 0 && $('#' + flight.To2).val().length > 0 && $('#' + flight.Flight2DD).val() == 'mm/dd/yyyy') {
            $('#' + error).html('Depature Date required for 2nd Flight').show();
            return false;
        }
        if ($('#' + flight.From3).val().length > 0 && $('#' + flight.To3).val().length > 0 && $('#' + flight.Flight3DD).val() == 'mm/dd/yyyy') {
            $('#' + error).html('Depature Date required for 3rd Flight').show();
            return false;
        }
    }

    return true;
}

function setAutoSuggest() {
    var eleIds = SearchControl.elementIds;
    var serviceUrl = eleIds.Flight.AS;
    $(".flightsuggest").autocomplete(serviceUrl,
	            {
	                width: "400px",
	                dataType: "json",
	                max: 9,
	                selectFirst: false,
	                formatItem: function (data, i, max, value, term) {
	                    return value;
	                },
	                parse: function (data) {
	                    var array = new Array();
	                    if (data != null) {
	                        for (var i = 0; i < data.length; i++) {
	                            array[array.length] = { data: data[i], value: data[i], result: data[i] };
	                        }
	                    }
	                    return array;
	                },
	                result: function (event, data, formatted) {
	                    $(this).val(data);
	                }
	            });

    $(".locsuggest").autocomplete(eleIds.Hotel.AS,
	            {                
	                width: "350px",
	                dataType: "json",
	                max: 9,
	                selectFirst: false,
	                formatItem: function (data, i, max, value, term) {
	                    return value;
	                },
	                parse: function (data) {
	                    var array = new Array();
	                    var tempValue = "";
	                    if (data != null) {
	                        for (var i = 0; i < data.length; i++) {
	                            tempValue = "";
	                            switch (data[i].SearchType) {
	                                case 'City':
	                                    tempValue = data[i].Name + (data[i].StateCode == "" ? "" : ', ' + data[i].StateCode) + (data[i].CountryCode == "" ? "" : ', ' + data[i].CountryCode + ' ');
	                                    break;
	                                case 'Airport':
	                                    tempValue = data[i].CityName + (data[i].StateCode == "" ? "" : ', ' + $.trim(data[i].StateCode)) + (data[i].Name == "" ? "" : ' - ' + data[i].Name) + (data[i].Code == "" ? "" : ' (' + data[i].Code + ')');
	                                    break;
	                                case 'PointOfInterest':
	                                    tempValue = data[i].Name + (data[i].StateCode == "" ? "" : ', ' + $.trim(data[i].StateCode)) + (data[i].CountryCode == "" ? "" : ', ' + data[i].CountryCode + ' ');
	                                    break;
	                                case 'Hotel':
	                                    tempValue = data[i].Name + (data[i].StateCode == "" ? "" : ', ' + $.trim(data[i].StateCode)) + (data[i].CountryCode == "" ? "" : ', ' + data[i].CountryCode + ' ');
	                                    break;
	                            }
	                            //var tempResult = data[i].Name + (data[i].Code == "" ? "" : ' (' + data[i].Code + ')');
	                            array[array.length] = { data: data[i], value: tempValue, result: tempValue };
	                        }
	                    }
	                    return array;
	                }
	            });

    $(".locsuggest").result(function (event, data, formatted) {
        $("#selection").val(data.Name + "," + data.Code + "," + data.Latitude + "," + data.Longitude + "," + data.SearchType + "," + data.StateCode + "," + data.CountryCode);
    });

    $(".locsuggest").Watermark("Enter city, airport or address", 'black');


    //car Local suggest
    $(".carlocsuggest").autocomplete(eleIds.Hotel.AS,
	            {
	                width: "350px",
	                dataType: "json",
	                max: 9,
	                selectFirst: false,
	                formatItem: function (data, i, max, value, term) {
	                    return value;
	                },
	                parse: function (data) {
	                    var array = new Array();
	                    var tempValue = "";
	                    if (data != null) {
	                        for (var i = 0; i < data.length; i++) {
	                            tempValue = "";
	                            switch (data[i].SearchType) {
	                                case 'City':
	                                    tempValue = data[i].Name + (data[i].StateCode == "" ? "" : ', ' + data[i].StateCode) + (data[i].CountryCode == "" ? "" : ', ' + data[i].CountryCode + ' ');
	                                    break;
	                                case 'PointOfInterest':
	                                    tempValue = data[i].Name + (data[i].StateCode == "" ? "" : ', ' + $.trim(data[i].StateCode)) + (data[i].CountryCode == "" ? "" : ', ' + data[i].CountryCode + ' ');
	                                    break;
	                                case 'Hotel':
	                                    tempValue = data[i].Name + (data[i].StateCode == "" ? "" : ', ' + $.trim(data[i].StateCode)) + (data[i].CountryCode == "" ? "" : ', ' + data[i].CountryCode + ' ');
	                                    break;
	                            }
	                            //var tempResult = data[i].Name + (data[i].Code == "" ? "" : ' (' + data[i].Code + ')');
	                            array[array.length] = { data: data[i], value: tempValue, result: tempValue };
	                        }
	                    }
	                    return array;
	                }
	            });

    $(".carlocsuggest").result(function (event, data, formatted) {
        $("#selection").val(data.Name + "," + data.Code + "," + data.Latitude + "," + data.Longitude + "," + data.SearchType + "," + data.StateCode + "," + data.CountryCode);
    });

    $(".carlocsuggest").Watermark("Enter city, airport or address", 'black');
    $(".dateWM").Watermark("mm/dd/yyyy", "black");

}


function AillinesNoPreference(lstSelectedAir) {

    var lstSelectedAirlines = document.getElementById(lstSelectedAir);

    if (lstSelectedAirlines != null) {
        if (lstSelectedAirlines.options.length > 1) {
            for (i = 0; i < lstSelectedAirlines.options.length; i++) {
                if (lstSelectedAirlines.options[i].text == "No Preference") {
                    lstSelectedAirlines.options[i] = null;
                    lstSelectedAirlines.selectedIndex = -1;
                }
            }
        }

    }

    if (lstSelectedAirlines.options.length == 0) {

        lstSelectedAirlines.options[0] = new Option("No Preference", null);
    }
    return false;

}

var carCodesTemplate = function () {
    this.CC = ''; // Company code
    this.CN = ''; // Company name
    this.DC = '-'; // Discount code
    this.PC = '-'; // Promotional code
    this.ID = ''; // Unique ID
}

function setCarError(msg) {
    $("#divCarCodeError").html(msg);
    $("#divCarCodeError").show();
}

function initCarCode() {
    var carEles = SearchControl.elementIds.Car;
    var strCarDiscs = $("#" + carEles.HF).val();
    if (strCarDiscs != undefined && strCarDiscs != "") {
        var rowCarDisc = strCarDiscs.split('^');
        if (rowCarDisc.length > 0) {
            for (var i = 0; i < rowCarDisc.length; i++) {
                if (rowCarDisc[i] != "") {
                    var carDisc = rowCarDisc[i].split('|');
                    if (carDisc.length == 0)
                        return;
                    var code = new carCodesTemplate();
                    code.CC = carDisc[0];
                    code.CN = carDisc[0];
                    var option = $("#" + carEles.CN + " option").filter(function () { if ($(this).attr('value') == carDisc[0]) { return true; } else { return false; } });
                    if (option != null && option.html() != null && option.html() != 'null' && option.html() != '')
                        code.CN = option.html();
//                    if (carDisc[1] == "PromotionalCode")
//                        code.PC = carDisc[2];
//                    else
//                        code.DC = carDisc[2];

                    if (carDisc[1]!=="") {
                        code.DC = carDisc[1];
                    }
                    if (carDisc[2] !== "") {
                        code.PC = carDisc[2];
                    }
                    code.ID = $(".carsClass").length;
                    $("#tempDiv").setTemplateElement("carCodesTemplate");
                    $("#tempDiv").processTemplate(code);
                    $("#divCarCodes").append($("#tempDiv").html());
                }
            }
            $("#divCarCodeHeading").show();
            $("#divCarCodesHolder").show();
        }

    }
}
function addCarCode() {
    $("#divCarCodesHolder").show();
    var carEles = SearchControl.elementIds.Car;

    var compCode = $("#" + carEles.CN).val();
    var compName = $("#" + carEles.CN).find('option').filter(':selected').text();
    var discCode = $("#" + carEles.DC).val();
    var promoCode = $("#" + carEles.PC).val();
    var carDiscCode=GetCompanyCode(compCode,1)
    var carPromCode = GetCompanyCode(compCode,2)

    if ($(".carsClass").length > 6) {
        setCarError("Sorry! You cannot add more than 6 entries.");
        return;
    }
    if (compCode == "NP") {
        setCarError("Please select a rental company");
        return;
    }
    

    if (discCode == "" && promoCode == "") {
        setCarError("Please enter discount/promotional code");
        return;
    }

    if (discCode != "" && carDiscCode != "") {
        setCarError("Sorry! You cannot add codes for same company again.");
        return;
    }
        if (promoCode != "" && carPromCode != "") {
        setCarError("Sorry! You cannot add codes for same company again.");
        return;
    }

    if (carDiscCode != "" || carPromCode != "") {
        var id = GetId(compCode);
        removeCarCode(id, compCode);

    }

    if (discCode == "" && carDiscCode != "")
        discCode = carDiscCode;
    if (promoCode == "" && carPromCode != "")
        promoCode =carPromCode;

    $("#divCarCodeError").hide();
    $("#divCarCodeHeading").show();
    var code = new carCodesTemplate();
    code.CC = compCode;
    code.CN = compName;
    code.DC = (discCode == "") ? "-" : discCode;
    code.PC = (promoCode == "") ? "-" : promoCode;
    code.ID = $(".carsClass").length;

    $("#tempDiv").setTemplateElement("carCodesTemplate");
    $("#tempDiv").processTemplate(code);
    $("#divCarCodes").append($("#tempDiv").html());

    $("#" + carEles.CN).val("");
    $("#" + carEles.DC).val("");
    $("#" + carEles.PC).val("");
    $("#" + carEles.HF).val($("#" + carEles.HF).val() + "^" + compCode + "|" + discCode + "|" + promoCode);
}

function removeCarCode(id, compCode) {

    var values = $("#" + SearchControl.elementIds.Car.HF).val().toString().split("^");
    var newValues = "";
    if ($(".carsClass").length != 0) {
        for (var i = 0; i < values.length; i++) {
            var cc = values[i].split("|")[0];
            if (cc == compCode)
                continue;
            else
                newValues += values[i];
        }
        $("#" + SearchControl.elementIds.Car.HF).val(newValues);
    }

    $(".carCode" + id).remove();
    if ($(".carsClass").length == 0) {
        $("#divCarCodeHeading").hide();
    }
}

function GetId(compCode) {
    var values = $("#" + SearchControl.elementIds.Car.HF).val().toString().split("^");
    var arr = $(".carsClass");
    if (arr.length != 0) {
        for (var i = 0; i < arr.length; i++) {
            var cc = $($(arr[i]).children()[0]).val();
            if (cc == compCode)
                return $(arr[i]).attr('id');
        }
    }
    return 0;

}

function GetCompanyCode(compCode,index) {
    var values = $("#" + SearchControl.elementIds.Car.HF).val().toString().split("^");
    if ($(".carsClass").length != 0) {
        for (var i = 0; i < values.length; i++) {
            var cc = values[i].split("|")[0];
            var code = values[i].split("|")[index];
            if (cc == compCode && code!="")
                return code;
        }
    }
    return "";

}

/* Cruise */

var ships = new Array();
ships[8] = new Array();
ships[8][0] = new Array(2, 'Adventure Of The Seas');
ships[8][1] = new Array(250592, 'Allure Of The Seas');
ships[8][2] = new Array(35, 'Brilliance Of The Seas');
ships[8][3] = new Array(42, 'Empress Of The Seas');
ships[8][4] = new Array(37, 'Enchantment Of The Seas');
ships[8][5] = new Array(1, 'Explorer Of The Seas');
ships[8][6] = new Array(248, 'Freedom Of The Seas');
ships[8][7] = new Array(38, 'Grandeur Of The Seas');
ships[8][8] = new Array(626, 'Independence of the Seas');
ships[8][9] = new Array(187, 'Jewel Of The Seas');
ships[8][10] = new Array(39, 'Legend Of The Seas');
ships[8][11] = new Array(307, 'Liberty Of The Seas');
ships[8][12] = new Array(40, 'Majesty Of The Seas');
ships[8][13] = new Array(162, 'Mariner Of The Seas');
ships[8][14] = new Array(41, 'Monarch Of The Seas');
ships[8][15] = new Array(116, 'Navigator Of The Seas');
ships[8][16] = new Array(250591, 'Oasis Of The Seas');
ships[8][17] = new Array(43, 'Radiance Of The Seas');
ships[8][18] = new Array(45, 'Rhapsody Of The Seas');
ships[8][19] = new Array(137, 'Serenade Of The Seas');
ships[8][20] = new Array(47, 'Sovereign Of The Seas');
ships[8][21] = new Array(50, 'Splendour Of The Seas');
ships[8][22] = new Array(55, 'Vision Of The Seas');
ships[8][23] = new Array(3, 'Voyager Of The Seas');

ships[1] = new Array();
ships[1][0] = new Array(5, 'Carnival Conquest');
ships[1][1] = new Array(6, 'Carnival Destiny');

ships[1][2] = new Array(54223, 'Carnival Dream');

ships[1][3] = new Array(12, 'Carnival Ecstasy');
ships[1][4] = new Array(13, 'Carnival Elation');
ships[1][5] = new Array(14, 'Carnival Fantasy');
ships[1][6] = new Array(15, 'Carnival Fascination');
ships[1][7] = new Array(305, 'Carnival Freedom');
ships[1][8] = new Array(126, 'Carnival Glory');
ships[1][9] = new Array(17, 'Carnival Imagination');
ships[1][10] = new Array(18, 'Carnival Inspiration');
ships[1][11] = new Array(7, 'Carnival Legend');
ships[1][12] = new Array(228, 'Carnival Liberty');

ships[1][13] = new Array(54224, 'Carnival Magic');

ships[1][14] = new Array(171, 'Carnival Miracle');
ships[1][15] = new Array(20, 'Carnival Paradise');
ships[1][16] = new Array(8, 'Carnival Pride');
ships[1][17] = new Array(21, 'Carnival Sensation');
ships[1][18] = new Array(9, 'Carnival Spirit');
ships[1][19] = new Array(53974, 'Carnival Splendor');
ships[1][20] = new Array(22, 'Carnival Triumph');
ships[1][21] = new Array(212, 'Carnival Valor');
ships[1][22] = new Array(10, 'Carnival Victory');
ships[1][23] = new Array(11, 'Celebration');
ships[1][24] = new Array(16, 'Holiday');

ships[9] = new Array();
ships[9][0] = new Array(24, 'Wind Spirit');
ships[9][1] = new Array(25, 'Wind Star');
ships[9][2] = new Array(26, 'Wind Surf');
ships[2] = new Array();
ships[2][0] = new Array(324, 'Azamara Journey');
ships[2][1] = new Array(325, 'Azamara Quest');
ships[2][2] = new Array(54491, 'Celebrity Solstice');
ships[2][3] = new Array(215, 'Celebrity Xpedition');
ships[2][4] = new Array(27, 'Century');
ships[2][5] = new Array(28, 'Constellation');
ships[2][6] = new Array(29, 'Galaxy');
ships[2][7] = new Array(31, 'Infinity');
ships[2][8] = new Array(32, 'Mercury');
ships[2][9] = new Array(33, 'Millennium');
ships[2][10] = new Array(34, 'Summit');
ships[3] = new Array();
ships[3][0] = new Array(124, 'Crystal Serenity');
ships[3][1] = new Array(57, 'Crystal Symphony');
ships[7] = new Array();
ships[7][0] = new Array(204, 'Explorer II');
ships[7][1] = new Array(59, 'Paul Gauguin');
ships[7][2] = new Array(61, 'Seven Seas Mariner');
ships[7][3] = new Array(62, 'Seven Seas Navigator');
ships[7][4] = new Array(134, 'Seven Seas Voyager');
ships[4] = new Array();
ships[4][0] = new Array(64, 'Amsterdam');
ships[4][1] = new Array(330, 'Eurodam');
ships[4][2] = new Array(68, 'Maasdam');
ships[4][3] = new Array(254, 'Noordam');

ships[4][4] = new Array(426844, 'Nieuw Amsterdam');

ships[4][5] = new Array(125, 'Oosterdam');
ships[4][6] = new Array(71, 'Prinsendam');
ships[4][7] = new Array(73, 'Rotterdam');
ships[4][8] = new Array(96, 'Ryndam');
ships[4][9] = new Array(74, 'Statendam');
ships[4][10] = new Array(75, 'Veendam');
ships[4][11] = new Array(76, 'Volendam');
ships[4][12] = new Array(190, 'Westerdam');
ships[4][13] = new Array(78, 'Zaandam');
ships[4][14] = new Array(115, 'Zuiderdam');
ships[6] = new Array();
ships[6][0] = new Array(189, 'Caribbean Princess');
ships[6][1] = new Array(127, 'Coral Princess');
ships[6][2] = new Array(253, 'Crown Princess');
ships[6][3] = new Array(66, 'Dawn Princess');
ships[6][4] = new Array(128, 'Diamond Princess');
ships[6][5] = new Array(306, 'Emerald Princess');
ships[6][6] = new Array(67, 'Golden Princess');
ships[6][7] = new Array(69, 'Grand Princess');
ships[6][8] = new Array(129, 'Island Princess');

ships[6][9] = new Array(257843, 'Ocean Princess');

ships[6][10] = new Array(132, 'Pacific Princess');
ships[6][11] = new Array(80, 'Regal Princess');
ships[6][12] = new Array(308, 'Royal Princess');
ships[6][13] = new Array(54597, 'Ruby Princess');
ships[6][14] = new Array(169, 'Sapphire Princess');
ships[6][15] = new Array(82, 'Sea Princess');
ships[6][16] = new Array(83, 'Star Princess');
ships[6][17] = new Array(84, 'Sun Princess');
ships[6][18] = new Array(131, 'Tahitian Princess');

ships[5] = new Array();
ships[5][0] = new Array(86, 'Norwegian Dawn');
ships[5][1] = new Array(87, 'Norwegian Dream');

ships[5][2] = new Array(391274, 'Norwegian Epic');

ships[5][3] = new Array(319, 'Norwegian Gem');
ships[5][4] = new Array(53923, 'Norwegian Jade');
ships[5][5] = new Array(231, 'Norwegian Jewel');
ships[5][6] = new Array(88, 'Norwegian Majesty');
ships[5][7] = new Array(301, 'Norwegian Pearl');
ships[5][8] = new Array(214, 'Norwegian Spirit');
ships[5][9] = new Array(91, 'Norwegian Star');
ships[5][10] = new Array(92, 'Norwegian Sun');
ships[5][11] = new Array(173, 'Pride of Aloha');
ships[5][12] = new Array(172, 'Pride of America');
ships[5][13] = new Array(264, 'Pride of Hawaii');
ships[16] = new Array();
ships[16][0] = new Array(97, 'Costa Allegra');
ships[16][1] = new Array(98, 'Costa Atlantica');
ships[16][2] = new Array(99, 'Costa Classica');
ships[16][3] = new Array(291, 'Costa Concordia');
ships[16][4] = new Array(117, 'Costa Europa');
ships[16][5] = new Array(202, 'Costa Fortuna');
ships[16][6] = new Array(232, 'Costa Magica');
ships[16][7] = new Array(203, 'Costa Marina');
ships[16][8] = new Array(136, 'Costa Mediterranea');
ships[16][9] = new Array(102, 'Costa Romantica');
ships[16][10] = new Array(318, 'Costa Serena');
ships[16][11] = new Array(103, 'Costa Victoria');
ships[17] = new Array();
ships[17][0] = new Array(105, 'Queen Elizabeth 2');
ships[17][1] = new Array(130, 'Queen Mary 2');
ships[17][2] = new Array(201, 'Queen Victoria');
ships[18] = new Array();
ships[18][0] = new Array(106, 'Seabourn Legend');
ships[18][1] = new Array(151214, 'Seabourn Odyssey');
ships[18][2] = new Array(107, 'Seabourn Pride');
ships[18][3] = new Array(108, 'Seabourn Spirit');
ships[19] = new Array();
ships[19][0] = new Array(110, 'Silver Cloud');
ships[19][1] = new Array(111, 'Silver Shadow');
ships[19][2] = new Array(121, 'Silver Whisper');
ships[19][3] = new Array(112, 'Silver Wind');
ships[20] = new Array();
ships[20][0] = new Array(392655, 'Disney Dream');
ships[20][1] = new Array(119, 'Disney Magic');
ships[20][2] = new Array(120, 'Disney Wonder');
ships[54] = new Array();
ships[54][0] = new Array(122, 'Marco Polo');
ships[56] = new Array();
ships[56][0] = new Array(138, 'Pacific Explorer');
ships[56][1] = new Array(140, 'Spirit of 98');
ships[56][2] = new Array(141, 'Spirit of Alaska');
ships[56][3] = new Array(142, 'Spirit of Columbia');
ships[56][4] = new Array(143, 'Spirit of Discovery');
ships[56][5] = new Array(144, 'Spirit of Endeavour');
ships[56][6] = new Array(321, 'Spirit of Nantucket');
ships[56][7] = new Array(145, 'Spirit of Oceanus');
ships[56][8] = new Array(317, 'Spirit of Yorktown');
ships[58] = new Array();
ships[58][0] = new Array(147, 'S.V. Legacy');
ships[58][1] = new Array(148, 'S.V. Mandalay');
ships[58][2] = new Array(146, 'S.V. Polynesia');
ships[58][3] = new Array(149, 'S.V. Yankee Clipper');
ships[59] = new Array();
ships[59][0] = new Array(152, 'Viking Burgundy');
ships[59][1] = new Array(250, 'Viking Century Sky');
ships[59][2] = new Array(260, 'Viking Century Sun');
ships[59][3] = new Array(153, 'Viking Danube');
ships[59][4] = new Array(154, 'Viking Europe');
ships[59][5] = new Array(54477, 'Viking Fontane');
ships[59][6] = new Array(155, 'Viking Kirov');
ships[59][7] = new Array(199, 'Viking Lavrinenkov');
ships[59][8] = new Array(54478, 'Viking Lomonosov');
ships[59][9] = new Array(156, 'Viking Neptune');
ships[59][10] = new Array(158, 'Viking Pakhomov');
ships[59][11] = new Array(159, 'Viking Pride');
ships[59][12] = new Array(160, 'Viking Schumann');
ships[59][13] = new Array(251, 'Viking Seine');
ships[59][14] = new Array(198, 'Viking Sky');
ships[59][15] = new Array(161, 'Viking Spirit');
ships[59][16] = new Array(252, 'Viking Sun');
ships[59][17] = new Array(213, 'Viking Surkov');
ships[60] = new Array();
ships[60][0] = new Array(229, 'MSC Armonia');
ships[60][1] = new Array(163, 'MSC Lirica');
ships[60][2] = new Array(164, 'MSC Melody');
ships[60][3] = new Array(261, 'MSC Musica');
ships[60][4] = new Array(205, 'MSC Opera');
ships[60][5] = new Array(322, 'MSC Orchestra');
ships[60][6] = new Array(54703, 'MSC Poesia');
ships[60][7] = new Array(165, 'MSC Rhapsody');
ships[60][8] = new Array(249, 'MSC Sinfonia');
ships[61] = new Array();
ships[61][0] = new Array(168, 'Insignia');
ships[61][1] = new Array(237, 'Nautica');
ships[61][2] = new Array(167, 'Regatta');
ships[63] = new Array();
ships[63][0] = new Array(245, 'Arcadia-UK');
ships[63][1] = new Array(244, 'Artemis-UK');
ships[63][2] = new Array(175, 'Aurora-UK');
ships[63][3] = new Array(176, 'Oceana-UK');
ships[63][4] = new Array(177, 'Oriana');
ships[63][5] = new Array(28464, 'Ventura');
ships[67] = new Array();
ships[67][0] = new Array(218, 'American Queen');
ships[67][1] = new Array(328, 'Columbia Queen');
ships[67][2] = new Array(329, 'Contessa');
ships[67][3] = new Array(216, 'Delta Queen');
ships[67][4] = new Array(258, 'Empress of the North');
ships[67][5] = new Array(217, 'Mississippi Queen');
ships[67][6] = new Array(257, 'Queen of the West');
ships[68] = new Array();
ships[68][0] = new Array(219, 'Royal Clipper');
ships[68][1] = new Array(220, 'Star Clipper');
ships[68][2] = new Array(221, 'Star Flyer');
ships[69] = new Array();
ships[69][0] = new Array(222, 'Sea Dream I');
ships[69][1] = new Array(223, 'Sea Dream II');
ships[71] = new Array();
ships[71][0] = new Array(227, 'MV Discovery');
ships[75] = new Array();
ships[75][0] = new Array(28251, 'Sylvias ship');
ships[75][1] = new Array(230, 'Test Ship 01');
ships[75][2] = new Array(256, 'Test Ship 02');
ships[78] = new Array();
ships[78][0] = new Array(289, 'Calypso');
ships[78][1] = new Array(239, 'The Emerald');
ships[78][2] = new Array(240, 'Thomson Celebration');
ships[78][3] = new Array(241, 'Thomson Destiny');
ships[78][4] = new Array(242, 'Thomson Spirit');
ships[83] = new Array();
ships[83][0] = new Array(277, 'Douro Queen');
ships[83][1] = new Array(296, 'Giselle');
ships[83][2] = new Array(281, 'Litvinov');
ships[83][3] = new Array(28255, 'M.S. Medea');
ships[83][4] = new Array(151331, 'M.S. Miriam');
ships[83][5] = new Array(28256, 'M.S. Prince Abbas');
ships[83][6] = new Array(297, 'River Ambassador');
ships[83][7] = new Array(274, 'River Baroness');
ships[83][8] = new Array(269, 'River Countess');
ships[83][9] = new Array(271, 'River Duchess');
ships[83][10] = new Array(270, 'River Empress');
ships[83][11] = new Array(268, 'River Princess');
ships[83][12] = new Array(272, 'River Queen');
ships[83][13] = new Array(259, 'River Royale');
ships[83][14] = new Array(295, 'Victoria Anna');
ships[83][15] = new Array(294, 'Victoria Empress');
ships[83][16] = new Array(285, 'Victoria Katarina');
ships[83][17] = new Array(282, 'Victoria Prince');
ships[83][18] = new Array(283, 'Victoria Queen');
ships[83][19] = new Array(286, 'Victoria Rose');
ships[83][20] = new Array(284, 'Victoria Star');
ships[83][21] = new Array(280, 'Yesenin');
ships[70] = new Array();
ships[70][0] = new Array(28992, 'Amacello');
ships[70][1] = new Array(265, 'Amadagio');
ships[70][2] = new Array(54575, 'Amadante');
ships[70][3] = new Array(150996, 'Amadouro');
ships[70][4] = new Array(312, 'Amalegro');
ships[70][5] = new Array(54587, 'Swiss Pearl');
ships[70][6] = new Array(311, 'Tamr Henna');
ships[70][7] = new Array(266, 'Tolstoy');

function SetCruiseShip(hdnFldId, drpDwnId) {
    var elem = document.getElementById(drpDwnId);
    document.getElementById(hdnFldId).value = elem.options[elem.selectedIndex].value;
}

function GetCruiseShips(ddlShip, ddlCruise) {
    index = document.getElementById(ddlCruise).value;
    if (index == '')
        argc = 0;
    else
        argc = ships[index].length;

    var ddl = document.getElementById(ddlShip);
    if (ddl.innerText == null) {
        opt = '';
        for (i = 0; i < argc; i++) {
            t = ships[index][i][1];
            v = ships[index][i][0];
            opt += '<option value="' + v + '">' + t + '</option>';
        }
        ddl.innerHTML = opt;
    }
    else {
        for (j = 0; j < argc; j++) {
            ddl.options[j] = new Option(ships[index][j][1]);
            ddl.options[j].value = ships[index][j][0];
        }
    }

    if (index == '') {
        ddl.style.visibility = 'hidden';
    }
    else {
        ddl.style.visibility = 'visible';
    }
}


function CruiseSearch(rbtnSearch,
                rbtnDest,
                rbtnLines,
                DdlDestinations,
                txtDepartDate,
                DdlDuration,
                DdlCruiseLine,
                DdlCruiseShip,
                DdlCruiseDestination2,
                DdlCruiseLine2,
                hidCruiseSearchUrl,
                hidCruiseDestUrl,
                hidCruiseLineUrl,
                hidDealerId,
                divError) {
    var url = "";
    var baseurl = "";
    var querystring = "";
    ShowCruiseError('')

    if ($get(hidCruiseSearchUrl).value == '' && $get(hidCruiseDestUrl).value == '' && $get(hidCruiseLineUrl).value == '') {
        ShowCruiseError('Cruise base url missing.');
        return false;
    }

    if ($get(rbtnSearch).checked == true) {
        if ($get(DdlDestinations).value == '' && $get(DdlCruiseLine).value == '') {
            ShowCruiseError('Select a destination');
            return false;
        }

        baseurl = $get(hidCruiseSearchUrl).value
        querystring += "?triptype=Cruise";
        querystring += "&DestinationID=" + $get(DdlDestinations).value;
        querystring += "&operator=";

        var date = $get(txtDepartDate).value;

        querystring += "&cruise_month=" + date.substring(0, 2);
        querystring += "&cruise_year=" + date.substring(6, 10); ;
        querystring += "&cruise_duration=" + $get(DdlDuration).value;
        querystring += "&VendorID=" + $get(DdlCruiseLine).value;
        querystring += "&ShipID=" + $get(DdlCruiseShip).value; ;
    }
    else if ($get(rbtnDest).checked == true) {
        if ($get(DdlCruiseDestination2).value == '') {
            ShowCruiseError('Select a destination');
            return false;
        }
        baseurl = $get(hidCruiseDestUrl).value
        querystring += "?DestinationID=" + $get(DdlCruiseDestination2).value;
    }
    else if ($get(rbtnLines).checked == true) {
        if ($get(DdlCruiseLine2).value == '') {
            ShowCruiseError('Select a Cruise Line');
            return false;
        }
        baseurl = $get(hidCruiseLineUrl).value
        querystring += "?VendorID=" + $get(DdlCruiseLine2).value;
    }

    querystring = querystring + "&PIN=" + $get(hidDealerId).value;
    url = baseurl + querystring;
    window.open(url, 'Cruise', 'height=650,width=1050,resizable=yes,scrollbars=yes,menubar=yes,toolbar=yes,location=yes');
}

function ShowCruiseError(message) {
    if (message != '') {
        showDiv('divErrorCruise');
        $get('divErrorCruise').innerHTML = message;
    }
    else
        hideDiv('divErrorCruise');
}

function MakeDateObject(str) {
    try {
        var date = new Date();
        var arr = str.split("/");
        date.setDate(arr[1]);
        date.setMonth(arr[0]);
        date.setFullYear(arr[2]);
        return date;
    }
    catch (err) {
        return null;
    }
}
