﻿// put here all the functions that need to be on the top of the page
// ****** main.js
function initMenu() {
    var menu = document.getElementById("menu");
    if (menu) {
        width = menu.offsetWidth;
        nod = menu.getElementsByTagName("span");
        width_e = Math.round((width - 2 * nod.length) / nod.length);
        for (var i = 0; i < nod.length; i++) {
            nod[i].style.width = width_e + "px";
        }
        if ((width_e * nod.length + nod.length * 2) > width)
            nod[0].style.width = width_e - ((width_e * nod.length + nod.length * 2) - width) + "px";
    }
}
if (window.addEventListener) {
    window.addEventListener("load", initMenu, false);
}
else if (window.attachEvent && !window.opera) {
    window.attachEvent("onload", initMenu);
}

function IsDefined(obj) {
    //alert(typeof(obj) != "undefined")
    return (obj != "undefined");
    //return (typeof(obj) != "undefined");
}

function IsTypeDefined(obj) {
    //alert(typeof(obj) != "undefined")
    //return (obj != "undefined");
    var result = (typeof (obj) != "undefined");

    //alert(result);

    return result;
}
// **** end of main.js



//********* search calender
///Inits controls properties i.e. calendars custom properties
function InitHotelsControls() {
    //alert('initcarsc')
    CalendarsIDs =
            {
                strPickerFromID: 'PickerFromHotels',
                strCalendarFromID: 'CalendarFromHotels',
                strPickerToID: 'PickerToHotels',
                strCalendarToID: 'CalendarToHotels',

                strDdlMonthFromID: 'ddlFromHotelsMonth',
                strDdlMonthToID: 'ddlToHotelsMonth'
            };
    //alert(1)
    //alert(CalendarsIDs.strCalendarFromID)
    if (IsDefined(typeof (PickerFromHotels)))
        SetCalendarProperties(PickerFromHotels, CalendarsIDs);
    //alert(2)
    if (IsDefined(typeof (CalendarFromHotels)))
        SetCalendarProperties(CalendarFromHotels, CalendarsIDs);
    if (IsDefined(typeof (PickerToHotels)))
        SetCalendarProperties(PickerToHotels, CalendarsIDs);
    if (IsDefined(typeof (CalendarToHotels)))
        SetCalendarProperties(CalendarToHotels, CalendarsIDs);

    //alert(CalendarFromCar.GetProperty('CalendarsIDs').strCalendarFromID);
}

function InitIsraelHotelsControls() {
    //alert('initcarsc')
    CalendarsIDs =
            {
                strPickerFromID: 'PickerFromIsraelHotels',
                strCalendarFromID: 'CalendarFromIsraelHotels',
                strPickerToID: 'PickerToIsraelHotels',
                strCalendarToID: 'CalendarToIsraelHotels',

                strDdlMonthFromID: 'ddlFromIsraelHotelsMonth',
                strDdlMonthToID: 'ddlToIsraelHotelsMonth'
            };

    if (IsDefined(typeof (PickerFromIsraelHotels)))
        SetCalendarProperties(PickerFromIsraelHotels, CalendarsIDs);
    if (IsDefined(typeof (CalendarFromIsraelHotels)))
        SetCalendarProperties(CalendarFromIsraelHotels, CalendarsIDs);
    if (IsDefined(typeof (PickerToIsraelHotels)))
        SetCalendarProperties(PickerToIsraelHotels, CalendarsIDs);
    if (IsDefined(typeof (CalendarToIsraelHotels)))
        SetCalendarProperties(CalendarToIsraelHotels, CalendarsIDs);

    //alert(CalendarFromCar.GetProperty('CalendarsIDs').strCalendarFromID);
}

function InitCarControls() {
    //alert('initcarsc')
    CalendarsIDs =
            {
                strPickerFromID: 'PickerFromCar',
                strCalendarFromID: 'CalendarFromCar',
                strPickerToID: 'PickerToCar',
                strCalendarToID: 'CalendarToCar',

                strDdlMonthFromID: 'ddlFromCarMonth',
                strDdlMonthToID: 'ddlToCarMonth',
                strLblDdlHoursFromClientID: "lblDdlHoursFromClientID",
                strLblDdlHoursToClientID: "lblDdlHoursToClientID"
            };

    //alert(CalendarsIDs.strLblDdlHoursFromClientID)
    if (IsDefined(typeof (PickerFromCar)))
        SetCalendarProperties(PickerFromCar, CalendarsIDs);
    if (IsDefined(typeof (CalendarFromCar)))
        SetCalendarProperties(CalendarFromCar, CalendarsIDs);
    if (IsDefined(typeof (PickerToCar)))
        SetCalendarProperties(PickerToCar, CalendarsIDs);
    if (IsDefined(typeof (CalendarToCar)))
        SetCalendarProperties(CalendarToCar, CalendarsIDs);

    //alert(CalendarFromCar.GetProperty('CalendarsIDs').strCalendarFromID);
}

function InitFlightControls() {
    CalendarsIDs =
            {
                strPickerFromID: 'PickerFromFlight',
                strCalendarFromID: 'CalendarFromFlight',
                strPickerToID: 'PickerToFlight',
                strCalendarToID: 'CalendarToFlight',
                strPickerSingleID: 'PickerSingle',
                strCalendarSingleID: 'CalendarSingle',
                strPickerFlight4ID: 'PickerFlight4',
                strCalendarFlight4ID: 'CalendarFlight4',
                strDdlMonthFromID: 'ddlFromFlightMonth',
                strDdlMonthToID: 'ddlToFlightMonth'
            };

    if (IsDefined(typeof (PickerFromFlight)))
        SetCalendarProperties(PickerFromFlight, CalendarsIDs);
    if (IsDefined(typeof (CalendarFromFlight)))
        SetCalendarProperties(CalendarFromFlight, CalendarsIDs);
    if (IsDefined(typeof (PickerToFlight)))
        SetCalendarProperties(PickerToFlight, CalendarsIDs);
    if (IsDefined(typeof (CalendarToFlight)))
        SetCalendarProperties(CalendarToFlight, CalendarsIDs);
    if (IsDefined(typeof (PickerSingle)))
        SetCalendarProperties(PickerSingle, CalendarsIDs);
    if (IsDefined(typeof (CalendarSingle)))
        SetCalendarProperties(CalendarSingle, CalendarsIDs);
    if (IsDefined(typeof (PickerFlight4)))
        SetCalendarProperties(PickerFlight4, CalendarsIDs);
    if (IsDefined(typeof (CalendarFlight4)))
        SetCalendarProperties(CalendarFlight4, CalendarsIDs);
}

function InitPackageControls() {
    //alert('initPackcontrols')
    CalendarsIDs =
                {
                    strPickerFromID: 'PickerFromPackage',
                    strCalendarFromID: 'CalendarFromPackage',
                    strPickerToID: 'PickerToPackage',
                    strCalendarToID: 'CalendarToPackage',

                    strDdlMonthFromID: 'ddlFromPackageMonth',
                    strDdlMonthToID: 'ddlToPackageMonth',
                    IsdoubleCalendar: true
                };

    //alert(CalendarsIDs.strCalendarFromID)
    if (IsDefined(typeof (PickerFromPackage)))
        SetCalendarProperties(PickerFromPackage, CalendarsIDs);
    if (IsDefined(typeof (CalendarFromPackage)))
        SetCalendarProperties(CalendarFromPackage, CalendarsIDs);
    if (IsDefined(typeof (PickerToPackage)))
        SetCalendarProperties(PickerToPackage, CalendarsIDs);
    if (IsDefined(typeof (CalendarToPackage)))
        SetCalendarProperties(CalendarToPackage, CalendarsIDs);

    //alert(CalendarFromCar.GetProperty('CalendarsIDs').strCalendarFromID);
}

function InitFlyAndDriveControls() {
    CalendarsIDs =
            {
                strPickerFromID: 'PickerFromFlyAndDrive',
                strCalendarFromID: 'CalendarFromFlyAndDrive',
                strPickerToID: 'PickerToFlyAndDrive',
                strCalendarToID: 'CalendarToFlyAndDrive',

                strDdlMonthFromID: 'ddlFromFlyAndDriveMonth',
                strDdlMonthToID: 'ddlToFlyAndDriveMonth',
                IsdoubleCalendar: true
            };

    //alert(CalendarsIDs.strCalendarFromID)
    if (IsDefined(typeof (PickerFromFlyAndDrive)))
        SetCalendarProperties(PickerFromFlyAndDrive, CalendarsIDs);
    if (IsDefined(typeof (CalendarFromFlyAndDrive)))
        SetCalendarProperties(CalendarFromFlyAndDrive, CalendarsIDs);
    if (IsDefined(typeof (PickerToFlyAndDrive)))
        SetCalendarProperties(PickerToFlyAndDrive, CalendarsIDs);
    if (IsDefined(typeof (CalendarToFlyAndDrive)))
        SetCalendarProperties(CalendarToFlyAndDrive, CalendarsIDs);
    //alert(CalendarFromCar.GetProperty('CalendarsIDs').strCalendarFromID);
}


///adds the CalendarsIDs object to objCalendar properties as a custom property
///CalendarsIDs holds all the relevant control ids for that calendar so
///the generic functions in SearchCalendars.js would know what calendars to change when objCalendar date is changed
function SetCalendarProperties(objCalendar, CalendarsIDs) {
    if (objCalendar)
        objCalendar.SetProperty('CalendarsIDs', CalendarsIDs);
}



///End Init Controls functions
//** end of search calendar


function initPopup() {
    var cal = $(".calendar a.btn-calendar, .calendar a.close");
    cal.click(function() {
        if ($(this).hasClass("btn-calendar")) {
            $(this).parents('div.calendar').addClass("o-calendar");
            var hold = $(this).parents('div.calendar').children(".holder");
            if (window.attachEvent && !window.opera) { hideSelectBoxes(hold[0]); }
        }
        else if ($(this).hasClass("close")) {
            $(this).parents('div.calendar').removeClass("o-calendar");
            var hold = $(this).parents('div.calendar').children(".holder");
            if (window.attachEvent && !window.opera) { showSelectBoxes(hold[0]); }
        }
        return false;
    });
    $('div.more-link span.more a').click(function() {//alert($(this).parents('div.more-link').eq(0).className)
        ///nnn
        $(this).parents('div.more-link').eq(0).toggleClass("open");
        return false;
    });
}

if (window.addEventListener) {
    window.addEventListener("load", initPopup, false);
}
else if (window.attachEvent && !window.opera) {
    window.attachEvent("onload", initPopup);
}

/////////////

///gets the object in the custom CalendarsIDs property of calendar (sender). the CalendarsIDs property
///holds all the control ids relevant to the calendar and that are affected by his date change.
///sender could also be a picker. This property is set by client script.
function InitCalendarObjects(sender) {
 
    CalendarObjects =
            {
                objPickerFrom: eval(sender.GetProperty('CalendarsIDs').strPickerFromID),
                objCalendarFrom: eval(sender.GetProperty('CalendarsIDs').strCalendarFromID),
                objPickerTo: eval(sender.GetProperty('CalendarsIDs').strPickerToID),
                objCalendarTo: eval(sender.GetProperty('CalendarsIDs').strCalendarToID),
                objPickerSingle: eval(sender.GetProperty('CalendarsIDs').strPickerSingleID),
                objCalendarSingle: eval(sender.GetProperty('CalendarsIDs').strCalendarSingleID),
                objPickerFlight4: eval(sender.GetProperty('CalendarsIDs').strPickerFlight4ID),
                objCalendarFlight4: eval(sender.GetProperty('CalendarsIDs').strCalendarFlight4ID),
                ///the ids of the calendar drop downs
                strDdlMonthFromID: sender.GetProperty('CalendarsIDs').strDdlMonthFromID,
                strDdlMonthTorID: sender.GetProperty('CalendarsIDs').strDdlMonthToID,
                IsdoubleCalendar: (IsTypeDefined(sender.GetProperty('CalendarsIDs').IsdoubleCalendar)) ? sender.GetProperty('CalendarsIDs').IsdoubleCalendar : false,
                ///the cars hours combos. innerHTML is needed for ff instead of innerText
                objDdlHoursFrom: (IsTypeDefined(sender.GetProperty('CalendarsIDs').strLblDdlHoursFromClientID)) ? $get($get(sender.GetProperty('CalendarsIDs').strLblDdlHoursFromClientID).innerHTML) : null,
                objDdlHoursTo: (IsTypeDefined(sender.GetProperty('CalendarsIDs').strLblDdlHoursToClientID)) ? $get($get(sender.GetProperty('CalendarsIDs').strLblDdlHoursToClientID).innerHTML) : null
            };
    //alert(CalendarObjects.objDdlHoursFrom.value)
    return CalendarObjects;
}
