﻿// JScript File
var page = thisPage();

// misc pop ups
function newWin(url, title) {
    myWin = window.open(url, "", "toolbar=no,width=460,height=500,left=25,top=100,directories=no,status=no,scrollbars=yes,resizable,menubar=no");
}
function newWin2(url) {
    myWin = window.open(url, "", "toolbar=no,width=900,height=700,left=25,top=100,directories=yes,status=yes,scrollbars=yes,resizable,menubar=yes");
}
// open Taxes and Fees Page
function OpenFees() {
    newwin = window.open("/taxes_and_fees.aspx", "FeeSummary", "toolbar=no,width=400,height=400,left=25,top=100,directories=no,status=no,scrollbars=yes,resizable,menubar=no");
}

// Set pagetime out values
if (page == 'flightResults.aspx') {
    setTimeout("timeoutSearchResults()", 720000); // timeout in 4 minutes = 240000 720000 in 12 min
}
if (page == 'Paymentinfo.aspx') {
    setTimeout("timeoutPaymentPage()", 720000); // timeout in 4 minutes = 240000
}

function FlightResultsRefresh() { // Show Search Results Timed-out
    blackOutScreen(true);
    var WaitMsg = document.getElementById('WaitMsg');
    centerThisDiv(WaitMsg, 380, 150);
    WaitMsg.style.top = '200px';
    WaitMsg.style.display = 'block';
    scrolldelay = setInterval('keepAtTop()', 100);
    var ResultsDiv = document.getElementById('SearchTable');
    ResultsDiv.style.display = 'none';
}

function timeoutSearchResults() { // Show Search Results Timed-out
    blackOutScreen(true);
    var tipBox = document.getElementById('tipBox');
    centerThisDiv(tipBox, 380, 150);
    tipBox.style.top = '200px';
    tipBox.style.display = 'block';
    scrolldelay = setInterval('keepAtTop()', 100);
}

function timeoutPaymentPage() { // Show Search Results Timed-out
    blackOutScreen(true);
    var tipBox = document.getElementById('tipBox');
    centerThisDiv(tipBox, 380, 150);
    tipBox.style.top = '200px';
    tipBox.style.display = 'block';
    scrolldelay = setInterval('keepAtTop()', 100);
}

function keepAtTop() {
    window.scroll(0, 0);
}

function popLowestFareTips() {  // Show Low Fare Tips
    blackOutScreen(true);
    var tipBox = document.getElementById('tipBox');
    centerThisDiv(tipBox, 380, 150);
    tipBox.style.display = 'block';
    return false;
}

function closeTipBox() {
    blackOutScreen(false);
    var tipBox = document.getElementById('tipBox');
    tipBox.style.display = 'none';
    if (typeof (scrolldelay) != 'undefined') {
        clearInterval(scrolldelay);
    }

    return false;
}
function blackOutScreen(blnBlack) {
    var blackOut = document.getElementById('blackOut');
    if (blackOut == null) {
        blackOut = document.createElement('div');
        blackOut.setAttribute('id', 'blackOut');
        blackOut.style.display = 'none';
        blackOut.style.position = 'absolute';
        blackOut.style.left = '0px';
        blackOut.style.top = '0px';
        blackOut.style.width = '100%';
        blackOut.style.height = '100%';
        blackOut.style.overflow = 'hidden';
        blackOut.style.opacity = 0.8;
        blackOut.style.MozOpacity = 0.8;
        blackOut.style.filter = 'alpha(opacity=80)';
        blackOut.style.zIndex = 10;
        blackOut.style.backgroundColor = '#FFFFFF';
        document.getElementsByTagName("body")[0].appendChild(blackOut);
        blackOut = document.getElementById('blackOut');
    }
    if (blnBlack) {
        blackOut.style.display = 'block';
    } else {
        blackOut.style.display = 'none';
    }
}

function refreshPage() {
    window.location.reload(false);
}

function centerThisDiv(el, width, height) {
    var w = 640;
    var h = 480;  // if we can't get a doc size we assume it's small
    if (document.body.clientWidth) {
        w = document.body.clientWidth;
        h = document.body.clientHeight;
    }
    else if (window.innerWidth) {
        w = window.innerWidth;
        h = window.innerHeight;
    }

    var leftPos = (w - width) / 2;
    var topPos = (h - height) / 2;
    el.style.top = topPos + 'px';
    el.style.left = leftPos + 'px';
}

function thisPage() {
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    return sPage;
}

/* Search Form Specific Functions */
function HideLayer(layer) {
    document.getElementById(layer).style.display = 'none';
}

function ShowLayer(layer) {
    document.getElementById(layer).style.display = 'block';
}

function LoadFlights() {
    ShowLayer("ReturnDiv");
    ShowLayer("ReturnTimeDiv");
    document.getElementById('<%= FlightType.ClientID %>_0').checked = true;
}

// Handles Switch between one-way, round-trip, and multi-city
function ShowSearch(el) {
    searchType = getSearchType();
    if (searchType == 'R') {
        showElement('ReturnDiv');
        showElement('ReturnTimeDiv');
    }
    if (searchType == 'O') {
        hideElement('ReturnDiv');
        hideElement('ReturnTimeDiv');
    }
    if (searchType == 'M') {
        window.location = '/flights/flightsearch-multicity.aspx?modify=' + modify;
    }
}

function ShowSearchMulti(el) {
    searchType = getSearchType();
    if (searchType == 'R') {
        window.location = '/bike_flights.aspx';
        //showElement('ReturnDiv');
        //showElement('ReturnTimeDiv');
    }
    if (searchType == 'O') {
        window.location = '/bike_flights.aspx?st=O';
        //hideElement('ReturnDiv');
        //hideElement('ReturnTimeDiv');
    }
    if (searchType == 'M') {
        window.location = '/flights/flightsearch-multicity.aspx';
    }
}

function getSearchType() {
    el = document.getElementById('ctl00_ContentPlaceHolder1_FlightType_0');
    if (el.checked == true) {
        return 'R';
    }
    el = document.getElementById('ctl00_ContentPlaceHolder1_FlightType_1');
    if (el.checked == true) {
        return 'O';
    }
    el = document.getElementById('ctl00_ContentPlaceHolder1_FlightType_2');
    if (el.checked == true) {
        return 'M';
    } else {
        return '';
    }
}

function hideElement(id) {
    div = document.getElementById(id);
    div.style.display = 'none';
}

function showElement(id) {
    div = document.getElementById(id);
    div.style.display = 'block';
}


var aCal;
var dateFormat = 'MM/dd/yyyy';
function openFromCalendar() {
    try {
        aCal.hidePopup();
    } catch (err) {

    }
    now = new Date();
    aCal = new CalendarPopup("fromCal");
    aCal.offsetX = 0;
    aCal.offsetY = 26;
    aCal.setCssPrefix("fCal");
    aCal.addDisabledBeforeDates(null, formatDate(now, dateFormat));
    aCal.select(document.getElementById("ctl00_ContentPlaceHolder1_StartDate1"), 'ctl00_ContentPlaceHolder1_StartDate1', dateFormat);
}

function openToCalendar() {
    try {
        aCal.hidePopup();
    } catch (err) {

    }
    var now = new Date();
    var toDateEl = document.getElementById("ctl00_ContentPlaceHolder1_EndDate1");
    var fromDateEl = document.getElementById("ctl00_ContentPlaceHolder1_StartDate1");
    aCal = new CalendarPopup("toCal");
    aCal.setCssPrefix("fCal");
    startDate = fromDateEl.value;
    if ((startDate != "") && (isDate(startDate, dateFormat))) {
        aCal.addDisabledBeforeDates(null, startDate);
        toDateEl.value = startDate;
    } else {
        aCal.addDisabledBeforeDates(null, formatDate(now, dateFormat));
    }
    aCal.offsetX = 0;
    aCal.offsetY = 26;
    aCal.select(toDateEl, 'ctl00_ContentPlaceHolder1_EndDate1', dateFormat);
}

function openToCalendar2() {
    try {
        aCal.hidePopup();
    } catch (err) {

    }
    var now = new Date();
    var toDateEl = document.getElementById("ctl00_ContentPlaceHolder1_StartDate2");
    var fromDateEl = document.getElementById("ctl00_ContentPlaceHolder1_StartDate1");
    aCal = new CalendarPopup("toCal");
    aCal.setCssPrefix("fCal");
    startDate = fromDateEl.value;
    if ((startDate != "") && (isDate(startDate, dateFormat))) {
        aCal.addDisabledBeforeDates(null, startDate);
        toDateEl.value = startDate;
    } else {
        aCal.addDisabledBeforeDates(null, formatDate(now, dateFormat));
    }
    aCal.offsetX = 0;
    aCal.offsetY = 26;
    aCal.select(toDateEl, 'ctl00_ContentPlaceHolder1_StartDate2', dateFormat);
}

function openToCalendar3() {
    try {
        aCal.hidePopup();
    } catch (err) {

    }
    var now = new Date();
    var toDateEl = document.getElementById("ctl00_ContentPlaceHolder1_StartDate3");
    var fromDateEl = document.getElementById("ctl00_ContentPlaceHolder1_StartDate2");
    aCal = new CalendarPopup("toCal");
    aCal.setCssPrefix("fCal");
    startDate = fromDateEl.value;
    if ((startDate != "") && (isDate(startDate, dateFormat))) {
        aCal.addDisabledBeforeDates(null, startDate);
        toDateEl.value = startDate;
    } else {
        aCal.addDisabledBeforeDates(null, formatDate(now, dateFormat));
    }
    aCal.offsetX = 0;
    aCal.offsetY = 26;
    aCal.select(toDateEl, 'ctl00_ContentPlaceHolder1_StartDate3', dateFormat);
}
/*
function openCalendar(Id, ClientId, FirstClientId) {
try {
aCal.hidePopup();
} catch (err) {

}
now = new Date();
aCal = new CalendarPopup(Id);
aCal.offsetX = 0;
aCal.offsetY = 26;
aCal.setCssPrefix("fCal");
aCal.addDisabledBeforeDates(null, formatDate(now, dateFormat));
aCal.select(document.getElementById(ClientId), ClientId, dateFormat);
}
*/
function openCalendar(Id, ClientId, FirstClientId) {
    try {
        aCal.hidePopup();
    } catch (err) {

    }
    var now = new Date();
    var toDateEl = document.getElementById(ClientId);
    var fromDateEl = document.getElementById(FirstClientId);
    aCal = new CalendarPopup(Id);
    aCal.setCssPrefix("fCal");
    if (fromDateEl) {
        startDate = fromDateEl.value;
    } else {
        startDate = null;
    }
    if ((startDate != "") && (isDate(startDate, dateFormat))) {
        aCal.addDisabledBeforeDates(null, startDate);
        toDateEl.value = startDate;
    } else {
        aCal.addDisabledBeforeDates(null, formatDate(now, dateFormat));
    }
    aCal.offsetX = 0;
    aCal.offsetY = 26;
    aCal.select(toDateEl, ClientId, dateFormat);
}
