﻿
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////
//// TOGGLE WINDOW
////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

function toggleWindow(sWindow) {
    if (document.all) {
        if (document.all(sWindow).style.display == 'none') {
            document.all(sWindow).style.display = 'block';
        }
        else {
            document.all(sWindow).style.display = 'none';
        }
    }
    else if (document.getElementById) {
        if (document.getElementById(sWindow).style.display == 'none') {
            document.getElementById(sWindow).style.display = 'block';
            document.getElementById(sWindow).style.visibility = 'visible';
        }
        else {
            document.getElementById(sWindow).style.display = 'none';
            document.getElementById(sWindow).style.visibility = 'hidden';
        }
    }
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////
//// SHOW HIDE DIV TAGS CODE
////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

function ToggleLayer(LayerToToggle) {
    var elem, vis;
    if (document.getElementById) // this is the way the standards work
        elem = document.getElementById(LayerToToggle);
    else if (document.all) // this is the way old msie versions work
        elem = document.all[LayerToToggle];
    else if (document.layers) // this is the way nn4 works
        elem = document.layers[LayerToToggle];
    vis = elem.style;
    // if the style.display value is blank we try to figure it out here
    if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
        vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
    vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
}

function SearchFormShowLayer(LayerToShow) {
    // First Hide All Layers - Need to update this with all layers
    if (LayerToShow != 'modal-search-categories-box')
        HideLayer('modal-search-categories-box');
    if (LayerToShow != 'modal-search-suppliers-box')
        HideLayer('modal-search-suppliers-box');
    if (LayerToShow != 'modal-search-countries-box')
        HideLayer('modal-search-countries-box');
    if (LayerToShow != 'modal-search-budget-box')
        HideLayer('modal-search-budget-box');
    if (LayerToShow != 'modal-search-flexibility-box')
        HideLayer('modal-search-flexibility-box');
    if (LayerToShow != 'modal-search-duration-box')
        HideLayer('modal-search-duration-box');
    if (LayerToShow != 'modal-search-departurepoints-box')
        HideLayer('modal-search-departurepoints-box');
    if (LayerToShow != 'modal-search-passengers-box')
        HideLayer('modal-search-passengers-box');





    // Now Show
    ShowLayer(LayerToShow);
}

function ShowLayer(LayerToShow) {
    try {
        var elem, vis;
        if (document.getElementById) // this is the way the standards work
            elem = document.getElementById(LayerToShow);
        else if (document.all) // this is the way old msie versions work
            elem = document.all[LayerToShow];
        else if (document.layers) // this is the way nn4 works
            elem = document.layers[LayerToShow];
        vis = elem.style;
        vis.display = 'block';
    }
    catch (err) { }
}

function HideLayer(LayerToHide) {
    try {
        var elem, vis;
        if (document.getElementById) // this is the way the standards work
            elem = document.getElementById(LayerToHide);
        else if (document.all) // this is the way old msie versions work
            elem = document.all[LayerToHide];
        else if (document.layers) // this is the way nn4 works
            elem = document.layers[LayerToHide];
        vis = elem.style;
        vis.display = 'none';
    }
    catch (err) { }
}


////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////
//// WRITE OUT FORM SELECTIONS
////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

function WriteFormSelections(FormName, CheckBoxId, ElementName, DefaultAllValue, DefaultAllId, DefaultCheckbox) {
    var selectionString = "";
    var haveSelections = false;


    if (DefaultCheckbox) {
        // If this is the default checkbox being checked then uncheck all...
        for (i = 0; i < document.forms[FormName].elements.length; i++) {
            el = document.forms[FormName].elements[i];
            if (el.type == "checkbox" && el.id.indexOf(CheckBoxId) != -1) {
                el.checked = false;
            }
        }
        // ...and set the default value
        el = document.getElementById(DefaultAllId);
        el.checked = true;
        selectionString = DefaultAllValue + "<br />";
    }
    else {
        // See what ones are checked and build up the display selections
        for (i = 0; i < document.forms[FormName].elements.length; i++) {
            el = document.forms[FormName].elements[i];
            if (el.type == "checkbox" && el.id.indexOf(CheckBoxId) != -1) {
                if (el.id != DefaultAllId) {
                    if (el.checked) {
                        haveSelections = true;
                        var displayName = el.name;
                        displayName = displayName.split("|")[1];
                        selectionString = selectionString + displayName + "<br />";
                    }
                }
            }
        }

        if (haveSelections) {
            // If we have selections then uncheck default
            el = document.getElementById(DefaultAllId);
            el.checked = false;
        }
        else {
            // Otherwise, just check default and display it
            el = document.getElementById(DefaultAllId);
            el.checked = true;
            selectionString = DefaultAllValue + "<br />";
        }
    }

    document.getElementById(ElementName).innerHTML = selectionString;
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////
//// FORM INPUTS
////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

function PopulateFormInput(ElementId, Value, ElementToHide) {
    el = document.getElementById(ElementId);
    el.value = Value;
    HideLayer(ElementToHide)
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////
//// HEADLINE OFFERS
////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

function FadeDivs(DivFadeIn, DivsFadeOut) {
    $('#' + DivFadeIn).fadeIn('slow');
    if (DivsFadeOut.split('|')[0] != DivFadeIn) { $('#' + DivsFadeOut.split('|')[0]).fadeOut('slow'); }
    if (DivsFadeOut.split('|')[1] != DivFadeIn) {$('#' + DivsFadeOut.split('|')[1]).fadeOut('slow'); }
    if (DivsFadeOut.split('|')[2] != DivFadeIn) {$('#' + DivsFadeOut.split('|')[2]).fadeOut('slow'); }
    if (DivsFadeOut.split('|')[3] != DivFadeIn) { $('#' + DivsFadeOut.split('|')[3]).fadeOut('slow'); }
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////
//// CHANGE CURSOR BUSY
////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

function changeCursorBusy() {
    $("html").addClass('busy');
}

function changeCursorNotBusy() {
    $("html").removeClass('busy');
} 
