﻿/* 

--------------------------------- 
Price Summary Control functions 
---------------------------------

- ietruebodyPriceSummary()
- ShowPriceSummary()
- positiontipPriceSummary()
- HidePriceSummary

*/


// Decide browser version
var ns6 = (document.getElementById) ? true : false;
var ie4 = (document.all) ? true : false;
var ie5 = false;
var mX = 4;
var mY = 4;
var IsInnerMessageBoxClicked = false;

var boxWidth = 250;

// IE Stupidity Check.
if (ie4) {
    if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0) || (navigator.userAgent.indexOf('MSIE 7') > 0) || (navigator.userAgent.indexOf('MSIE 8') > 0)) {
        ie5 = true;
    }
    if (ns6) {
        ns6 = false;
    }
}


//Handle mouse location
document.onmousemove = mouseMove;
function mouseMove(e) {
    try {
        if (ns6) {
            mX = e.pageX;
            mY = e.pageY;
        }
        else if (ie5) {
            mX = window.event.clientX;

            if (document.body.clientWidth > document.documentElement.clientWidth)
                mY = (document.body.scrollTop + window.event.clientY);
            else
                mY = (document.documentElement.scrollTop + window.event.clientY);
        }
        else if (ie4) {
            mX = event.x;
            mY = event.y;
        }
    } catch (e) { }
}



function ietruebodyPriceSummary() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

function ShowPriceSummary(divid, event) {
    var ie = document.all
    var ns6 = document.getElementById && !document.all
    if (ns6 || ie) {
        var tipobj = document.all ? document.all[divid] : document.getElementById ? document.getElementById(divid) : ""
        positiontipPriceSummary(event, divid)
        return false
    }
}

function positiontipPriceSummary(e, divid) {
    var ie = document.all
    var ns6 = document.getElementById && !document.all
    var offsetxpoint = -160 //Customize x offset of tooltip
    var offsetypoint = 20 //Customize y offset of tooltip

    var tipobj = document.all ? document.all[divid] : document.getElementById ? document.getElementById(divid) : ""
    var curX = (ns6) ? this.mX - this.scrollX : event.clientX + ietruebodyPriceSummary().scrollLeft;
    var curY = (ns6) ? this.mY - this.scrollY : event.clientY + ietruebodyPriceSummary().scrollTop;
    //Find out how close the mouse is to the corner of the window
    var rightedge = ie && !window.opera ? ietruebodyPriceSummary().clientWidth - event.clientX - offsetxpoint : window.innerWidth - curX - offsetxpoint + 160
    var bottomedge = ie && !window.opera ? ietruebodyPriceSummary().clientHeight - event.clientY - offsetypoint : window.innerHeight - curY - offsetypoint - 20
    var topedge = ie && !window.opera ? event.clientY : curY

    var leftedge = (offsetxpoint < 0) ? offsetxpoint * (-1) : -1000


    //if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge < tipobj.offsetWidth)
    //move the horizontal position of the menu to the left by it's width
        tipobj.style.left = ie ? ietruebodyPriceSummary().scrollLeft + event.clientX - tipobj.offsetWidth + "px" : window.pageXOffset + curX - tipobj.offsetWidth + "px"
    else if (curX < leftedge)
        tipobj.style.left = "5px"
    else
    //position the horizontal position of the menu where the mouse is positioned
        tipobj.style.left = this.mX + offsetxpoint + "px"

    //same concept with the vertical position
    if (topedge < tipobj.offsetHeight)
        tipobj.style.top = ie ? ietruebodyPriceSummary().scrollTop + event.clientY + offsetypoint + "px" : window.pageYOffset + curY + offsetypoint + "px"
    else
        tipobj.style.top = this.mY - tipobj.offsetHeight + "px"
    tipobj.style.visibility = "visible"

}

function HidePriceSummary(divid) {
    var ie = document.all
    var ns6 = document.getElementById && !document.all
    if (ns6 || ie) {
        var tipobj = document.all ? document.all[divid] : document.getElementById ? document.getElementById(divid) : ""

        tipobj.style.visibility = "hidden"
        tipobj.style.left = "-1000px"
        tipobj.style.backgroundColor = ''
        tipobj.style.width = ''
    }
}


/* 

------------------------------------- 
Air ResultItemFlight Control functions
-------------------------------------

- showHoverInfo()
- hideHoverInfo()
- SetInnerMessageBoxClicked()
*/
function showHoverInfo(width, left, top) {
    var innerMsgBox = document.getElementById('msgBoxInner');
    var activeMsgBox = document.getElementById('msgBox');

    if (width != null) {
        activeMsgBox.style.width = boxWidth = width;
    }

    if (document.body.clientWidth > document.documentElement.clientWidth) {

        $("#msgBox").css({ 'width': width, position: 'absolute', 'zIndex': 10000, 'textAlign': 'left',
            'left': (left != null ? left : (document.body.clientWidth < (mX + boxWidth + 20) ? mX - boxWidth : mX)),
            'top': (top != null ? top : mY + 5)
        }).show();

    } else {
        $("#msgBox").css({ 'width': width, position: 'absolute', 'zIndex': 10000, 'textAlign': 'left',
            'left': (left != null ? left : (document.documentElement.clientWidth < (mX + boxWidth + 20) ? mX - boxWidth : mX)),
            'top': (top != null ? top : mY + 5)
        }).show();

    }
    $(document).bind('click', moreInfoDialogClose);
}

//hide message box & its cover
function hideHoverInfo() {
    $("#msgBox").hide();
    $(document).unbind('click', moreInfoDialogClose);
}

function SetInnerMessageBoxClicked() {
    IsInnerMessageBoxClicked = true;
}

var moreInfoDialogClose = function(event) {
    if (IsInnerMessageBoxClicked == false) {
        hideHoverInfo();
    }
    IsInnerMessageBoxClicked = false;
}


/* 

-------------------------------------- 
TechnicalStop Detail Control functions 
--------------------------------------

- ietruebodyTechnicalStop()
- ShowTechnicalStop()
- positiontipTechnicalStop()
- HideTechnicalStop

*/


function ietruebodyTechnicalStop() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}



function ShowTechnicalStop(divid, event) {
    var ie = document.all
    var ns6 = document.getElementById && !document.all

    if (ns6 || ie) {

        var tipobj = document.all ? document.all[divid] : document.getElementById ? document.getElementById(divid) : ""
        positiontipTechnicalStop(event, divid)
        return false
    }
}

function positiontipTechnicalStop(e, divid) {
    var ie = document.all
    var ns6 = document.getElementById && !document.all
    var offsetxpoint = 200 //Customize x offset of tooltip
    var offsetypoint = -5 //Customize y offset of tooltip
    var tipobj = document.all ? document.all[divid] : document.getElementById ? document.getElementById(divid) : ""
    var curX = (ns6) ? this.mX - this.scrollX : event.clientX + ietruebodyTechnicalStop().scrollLeft;
    var curY = (ns6) ? this.mY - this.scrollY : event.clientY + ietruebodyTechnicalStop().scrollTop;
    //Find out how close the mouse is to the corner of the window
    var rightedge = ie && !window.opera ? ietruebodyTechnicalStop().clientWidth - event.clientX - offsetxpoint : window.innerWidth - curX - offsetxpoint + 160
    var bottomedge = ie && !window.opera ? ietruebodyTechnicalStop().clientHeight - event.clientY - offsetypoint : window.innerHeight - curY - offsetypoint - 20
    var topedge = ie && !window.opera ? event.clientY : curY

    var leftedge = (offsetxpoint < 0) ? offsetxpoint * (-1) : -1000


    //if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge < tipobj.offsetWidth)
    //move the horizontal position of the menu to the left by it's width
        tipobj.style.left = ie ? ietruebodyTechnicalStop().scrollLeft + event.clientX - tipobj.offsetWidth + "px" : window.pageXOffset + curX - tipobj.offsetWidth + "px"
    else if (curX < leftedge)
        tipobj.style.left = "5px"
    else
    //position the horizontal position of the menu where the mouse is positioned
        tipobj.style.left = this.mX + offsetxpoint + "px"

    //same concept with the vertical position
    if (topedge < tipobj.offsetHeight)
        tipobj.style.top = ie ? ietruebodyTechnicalStop().scrollTop + event.clientY + offsetypoint + "px" : window.pageYOffset + curY + offsetypoint + "px"
    else {
        tipobj.style.top = this.mY + "px"

    }
    tipobj.style.visibility = "visible"

}

function HideTechnicalStop(divid) {
    var ie = document.all
    var ns6 = document.getElementById && !document.all

    if (ns6 || ie) {
        var tipobj = document.all ? document.all[divid] : document.getElementById ? document.getElementById(divid) : ""

        tipobj.style.visibility = "hidden"
        tipobj.style.left = "-1000px"
        tipobj.style.backgroundColor = ''
        tipobj.style.width = ''
    }
}
/* 

-------------------------------------- 
AirResultItemFlight Detail Control
--------------------------------------
*/

function ShowFlightDetails(lnkShowDetailId, divDisplayId, pIndex,displayWhiteLabel) {
    setTimeout(function() {
        try {
            if ($('#' + divDisplayId).text().trim.length < 10) {
                $.get("../Air/AirResultItemDetail.aspx?pIndex=" + pIndex + "&displayWhiteLabel=" + displayWhiteLabel, function(response) {                    
                    var divElemPos = response.indexOf('<div id="flightDetails"', 0);
                    var divElemEndPos = response.lastIndexOf('</div>');
                    var divContent = response.substring(divElemPos, divElemEndPos + 6);
                    $('#' + divDisplayId).html(divContent).slideDown(200);
                });
            }
            else {
                $('#' + divDisplayId).show();
            }
        } catch (e) { }
    }, 1500);
}

function HideFlightDetails(lnkHideDetailId) {
    setTimeout(function() {
        $('#' + lnkHideDetailId).parents(".ItineraryDetails").slideUp(200);
    }, 1500);
}
     
