﻿/**** /online/_scripts/common.js ****/

var $j = jQuery.noConflict();
$j(document).ready(
function() {
    calculateHW();
	etpage.load();
});

$j(window).resize(calculateHW);


function calculateHW() {
    var viewWidth, viewHeight, bodyWidth, bodyHeight;
    bodyHeight = $j(document).height();
    bodyWidth = $j(document).width();
    if (self.innerHeight) {
        viewWidth = self.innerWidth; viewHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        viewWidth = document.documentElement.clientWidth;
        viewHeight = document.documentElement.clientHeight;
    }
    else if (document.body) {
        viewWidth = document.body.clientWidth;
        viewHeight = document.body.clientHeight;
    }

    if (viewWidth < 982) {
        bodyWidth = 982;
    }
    if (bodyHeight < viewHeight) {
        bodyHeight = viewHeight;
    }
}


var etpage = {};
etpage.prime = function() { };

etpage.load = function() {
//alert('in');
        lazyLoadBackground();
        resizableBackground();

};

etpage.prime();
//window.onload=function(){alert('in');}
//jQuery(window).load(etpage.load);
if (jQuery.browser.msie && jQuery.browser.version < 7)
    document.execCommand("BackgroundImageCache", false, true);

function lazyLoadBackground() {
	//alert('in');
    bodyClass = 'et_js_body';
    htmlClass = 'et_js_html';
    var html = jQuery(document.documentElement);
    var body = jQuery(document.body);
   // alert(html.id);
    if (!(jQuery.browser.msie && jQuery.browser.version <= 6)) {
        html.addClass(htmlClass);
        body.addClass(bodyClass);
    } else {
        html.addClass(htmlClass);
        body.addClass(htmlClass);
        var htmlBgCss = body.css('backgroundImage');
        html.css('backgroundImage', htmlBgCss);
        body.addClass(bodyClass + '_ie6');
        
        
    }
}
function resizableBackground() {
    var html = jQuery(document.documentElement);
    if (!(jQuery.browser.msie && jQuery.browser.version <= 6)) {
       
        var body = jQuery(document.body);
        var bgPath = html.css('backgroundImage');
        bgPath = bgPath.substring(bgPath.indexOf('url(') + 4, bgPath.indexOf(')')).replace(/"/g, '');
        var patternPath = body.css('backgroundImage');
        var ratio = 1;
        if (patternPath == '' || patternPath == 'non' || bgPath == '' || bgPath == 'non')
            return;
        function resize() {
            var box = et.dom.getEnv();
            var h = box.clientHeight, w = box.clientWidth;
            if (h < w) {
                h = w / ratio;
            } else {
                w = h * ratio;
            }
            html.css('background-position', (box.clientWidth - w) / 2 + ' ' + (box.clientHeight - h) / 2);
            bgContainer.css({ height: box.clientHeight, width: box.clientWidth }).find('img').css({ height: h, width: w, marginLeft: (box.clientWidth - w) / 2, marginTop: (box.clientHeight - h) / 2 });
        }
        
        var patternContainer = jQuery('<div class="et_resizable_pattern"></div>').appendTo(document.body);
        var bgContainer = jQuery('<div class="et_resizable_background"><img src="' + bgPath + '" /></div>').add(patternContainer).css({ 'overflow': 'hidden', 'position': 'fixed', 'zIndex': -2, 'top': 0, 'left': 0, 'backgroundImage': patternPath }).appendTo(document.body); patternContainer.css('zIndex', -1);
        var img = new Image();
        img.onload = function() { ratio = this.width / this.height; resize(); };
        img.src = bgPath; html.css('backgroundImage', 'none');
        body.css('backgroundImage', 'none');
        jQuery(window).resize(resize);
    } else {

    function resizeForIE() {
        var box = et.dom.getEnv();
        var h = box.clientHeight, w = box.clientWidth;
        var cw = (box.clientWidth - 1440) / 2, ch = (box.clientHeight - 1440) / 2;
        var ratio = 1;
        if (h < w) {
            h = w / ratio;
        } else {
            w = h * ratio;
        }
        if(cw<=0 && ch<=0)
            html.css('background-position', cw + ' ' + ch);
        else
            html.css('background-position', (box.clientWidth - w) / 2 + ' ' + (box.clientHeight - h) / 2);
    }
    jQuery(window).resize(resizeForIE);

    resizeForIE();
    }
}
et = {};
et.dom = {};
et.dom.getEnv = function() {
    var msie = navigator.userAgent.toLowerCase().indexOf("msie") != -1;
    var clientWidth = 0, clientHeight = 0;
    var body = document.body, html = document.documentElement;
    if (typeof (window.innerWidth) == 'number') {
        clientWidth = window.innerWidth;
        clientHeight = window.innerHeight;
    } else if (html && (html.clientWidth || html.clientHeight)) {
        clientWidth = html.clientWidth;
        clientHeight = html.clientHeight;
    } else if (body && (body.clientWidth != null || body.clientHeight != null)) {
        clientWidth = body.clientWidth;
        clientHeight = body.clientHeight;
    }
    var sLeft = 0, sTop = 0, bWidth = 0, bHeight = 0;
    if (typeof (window.pageYOffset) == 'number') {
        sTop = window.pageYOffset;
        sLeft = window.pageXOffset;
        bHeight = body.scrollHeight;
        bWidth = body.scrollWidth;
    } else if (body && (body.scrollLeft || body.scrollTop)) {
        sTop = body.scrollTop;
        sLeft = body.scrollLeft;
        bHeight = body.scrollHeight;
        bWidth = body.scrollWidth;
    } else if (html && (html.scrollLeft != null || html.scrollTop != null)) {
        sTop = html.scrollTop;
        sLeft = html.scrollLeft;
        bHeight = html.scrollHeight;
        bWidth = html.scrollWidth;
    }
    return { bodyHeight: bHeight, bodyWidth: bWidth, bodyScrollTop: sTop, bodyScrollLeft: sLeft, clientWidth: clientWidth, clientHeight: clientHeight
    };
};


/*****COMMON*****/


        // Added for the defect CBWEB- 62
        
        function displaybookingconditions(isPriceIncrease)
        { setTimeout("TB_show('Booking Conditions','/myprofile/confirmbookingconditions.aspx?height=150&width=550&isPriceIncrease=" + isPriceIncrease + "','~/_images/LoadingAnimation.gif')",100); 
        }

 
        function openWin(theurl)
{
	var newWin = window.open("","printWin","height=600,width=750 ,left=10,top=10,status=yes,toolbar=no,menubar=yes,scrollbars=yes,location=no,resizable=no");
	newWin.location.href=theurl;
	newWin.focus();
	return false;
}

function openPopup(url)
{
	
	var newWindow = window.open("","","height=570px,width=750px,left=0,top=0,status=yes,toolbar=no,menubar=no,scrollbars=yes,location=no,resizable=no");
        newWindow.location.href=url;
        newWindow.focus();
}

function OpenPop(theurl)
{
	
	var newWin = window.open("","","height=570px,width=750px,left=0,top=0,status=yes,toolbar=no,menubar=no,scrollbars=yes,location=no,resizable=no");
        newWin.location.href=theurl;
        newWin.focus();
}
        
/***LOgin Validation check****/

function Validchk(username,password,unamediv,passdiv,message)
{
	var un=username;
	var uname;
	uname=document.getElementById(username).value;
	pass=document.getElementById(password).value;
	if(uname=='' && pass==''){
	document.getElementById(unamediv).style.visibility = 'visible';
	document.getElementById(unamediv).style.display='block';
	document.getElementById(passdiv).style.visibility = 'visible';
	document.getElementById(passdiv).style.display='block';
	document.getElementById(message).style.visibility = 'visible';
	document.getElementById(message).style.display='block';
	return false;
	}
	else if(uname=='')
	{
	document.getElementById(unamediv).style.visibility = 'visible';
	document.getElementById(unamediv).style.display='block';
	document.getElementById(passdiv).style.visibility = 'hidden';
	document.getElementById(passdiv).style.display='none';
	document.getElementById(message).style.visibility = 'visible';
	document.getElementById(message).style.display='block';
	return false;
	}
	else if(pass=='')
	{
	document.getElementById(passdiv).style.visibility = 'visible';
	document.getElementById(passdiv).style.display='block';
	document.getElementById(unamediv).style.visibility = 'hidden';
	document.getElementById(unamediv).style.display='none';
	document.getElementById(message).style.visibility = 'visible';
	document.getElementById(message).style.display='block';
	return false;
	}
	else
	{
	document.getElementById(unamediv).style.visibility = 'hidden';
	document.getElementById(unamediv).style.display='none';
	document.getElementById(passdiv).style.visibility = 'hidden';
	document.getElementById(passdiv).style.display='none';
	document.getElementById(message).style.visibility = 'hidden';
	document.getElementById(message).style.display='none';
	return true;
	}
}

function frmload(unamediv,passdiv,message,messagetext)
{	
	messagetext = messagetext.toLowerCase();
	document.getElementById(unamediv).style.visibility = 'hidden';
	document.getElementById(unamediv).style.display='none';
	document.getElementById(passdiv).style.visibility = 'hidden';
	document.getElementById(passdiv).style.display='none';
	if (messagetext != "initialize" || messagetext == "loginfailed")
	{
		document.getElementById(message).style.visibility = 'visible';
		document.getElementById(message).style.display='block';
	}
	else
	{
		document.getElementById(message).style.visibility = 'hidden';
		document.getElementById(message).style.display='none';
	}
}	

//For the Login_Error(Logon Page)

function LogonValidchk(username,password,unamediv,passdiv)
{
	var un=username;
	var uname;
	uname=document.getElementById(username).value;
	pass=document.getElementById(password).value;
	if(uname=='' && pass=='')
	{
	document.getElementById(unamediv).style.visibility = 'visible';
	document.getElementById(unamediv).style.display='block';
	document.getElementById(passdiv).style.visibility = 'visible';
	document.getElementById(passdiv).style.display='block';
	return false;
	}
	else if(uname=='')
	{
	document.getElementById(unamediv).style.visibility = 'visible';
	document.getElementById(unamediv).style.display='block';
	document.getElementById(passdiv).style.visibility = 'hidden';
	document.getElementById(passdiv).style.display='none';
	return false;
	}
	else if(pass=='')
	{
	document.getElementById(passdiv).style.visibility = 'visible';
	document.getElementById(passdiv).style.display='block';
	document.getElementById(unamediv).style.visibility = 'hidden';
	document.getElementById(unamediv).style.display='none';
	return false;
	}
	else
	{
	document.getElementById(unamediv).style.visibility = 'hidden';
	document.getElementById(unamediv).style.display='none';
	document.getElementById(passdiv).style.visibility = 'hidden';
	document.getElementById(passdiv).style.display='none';
	return true;
	}
}
function Logonfrmload(unamediv,passdiv,messagetext)
{	
	messagetext = messagetext.toLowerCase();
	document.getElementById(unamediv).style.visibility = 'hidden';
	document.getElementById(unamediv).style.display='none';
	document.getElementById(passdiv).style.visibility = 'hidden';
	document.getElementById(passdiv).style.display='none';
}

/**Hover State**/

// JScript File
var _frame='FrameWrapper';
var _timerG;
var test;
var _showHover;
function IsTimerSet()
{
    return test;
}
var EF = {
    /* Short hand to return object in global */
    $_script: function () {
        return this.Global.ScriptHandler
    },
    $_util: function () {
        return this.Global.Utilities
    },
    /* -- Global */
    Global: {
                GetInterchangableGateway: function(ddObj) {
                    var msg,key,ddValue;
                    var gateways = new Array();
                    gateways['NYC'] = 'Newark, LaGuardia or JFK';
                    gateways['MIA'] = 'Miami or Fort Lauderdale';
                    gateways['WAS'] = 'BWI, Dulles or Ronald Reagan National';
                    gateways['IAH'] = 'George Bush Intercontinental or Hobby';
                   
                    key = ddObj.options[ddObj.selectedIndex].value;
                    ddValue = ddObj.options[ddObj.selectedIndex].text;
                    msg = ""
                   
                    if(typeof(gateways[key]) != 'undefined')
                        msg = "\"" + ddValue + "\" is an interchangeable gateway and you may be flying out of " +gateways[key]+"."
                    else if(key=='LO') 
                    {
                       msg="You have chosen the 'Land-Only' option. It is recommended you wait 50 days prior to departure to book your flight itinerary."
                    }
                    //alert(gateways[key]);
                    return msg;
                },
        Utilities: {
            CookieManager: {
                /* Create cookie */
                Bake: function (name, value, days) {
                     var now = new Date();
			days = days || 1
                    now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * days)
                   // alert (";expires=" + now.toGMTString());

                    
                    document.cookie = name + "=" + value + "; Max-Age=" + (60 * 60 * 24 * days) + "; path=/;" +";expires=" + now.toGMTString() ;
                },
                /* Create session cookie */
                Session: function (name, value) {
                    document.cookie = name + "=" + value + "; path=/";
                },
                Consume: function (name, key) {
                    var arr = this._Check(name);
                    var condition = undefined;
                    if (arr) {
                        arr = unescape(arr).split("&");
                        for (var i = 0; i < arr.length; i++) {
                            var t = arr[i].split("|");
                            for (var g = 0; g < t.length; g++) {
                                t[g] = t[g].split("=");
                            }
                            for (var counter = 0; counter < t.length; counter++) {
                                if (unescape(t[counter][0]) == key) {
                                    condition = t[counter][1];
                                    break;
                                }
                            }
                        }
                        return condition;
                    } else {
                        return condition;
                    }
                },
                /* Checks for key or key/value pair in cookie - hacked together for leadform*/
                Check: function (name, key, value) {
              
                    var arr = this._Check(name);
                      
               
                    var condition = false;
                    if (arr) {
                        arr = unescape(arr).split("&");
                        for (var i = 0; i < arr.length; i++) {
                            var t = arr[i].split("|");
                            for (var g = 0; g < t.length; g++) {
                                t[g] = t[g].split("=");                                
                            }
                            for (var counter = 0; counter < t.length; counter++) {
                                if (arguments.length == 2) {
                                    if (unescape(t[counter][0]) == key) {
                                        condition = true;
                                        break;
                                    }
                                } else {
                                    if (unescape(t[counter][0]) == key & unescape(t[counter][1]) == value) {
                                        condition = true;
                                        break;
                                    }
                                }
                            }
                        }
                        return condition;
                    } else {
                        return condition;
                    }
                },
                /* Helper - returns value of specified cookie */
                _Check: function (name) {
                    var s = document.cookie.split(';');
                    
                    for (var i = 0, l = s.length; i < l; i++) {
                        var c = s[i].toString(), f, r;
                        f = c.substring(0, c.indexOf("="))                        
                        r = c.substring(c.indexOf("=") + 1, c.length)
                        
                        while (f.charAt(0) == " ") 
                        {
                        f = f.substring(1, f.length)
                        }
                        
                        if (f == name) 
                        {
                        return r;
                        }
                    }
                }
            },
            GetDimensions: function (Width_Height_or_Both) {
                Width_Height_or_Both = Width_Height_or_Both.toLowerCase()
                switch (Width_Height_or_Both) {
                    case "width":
                        return { "width": width() }
                        break;
                    case "height":
                        return { "height": height() }
                        break;
                    case "both":
                        return { "width": width(), "height": height() }
                        break;
                    // If nothing, just return both...  
                    default:
                        return { "width": width(), "height": height() }
                        break;
                        window.location
                }
                function height() {
                    return Math.max(
            Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
            Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
            Math.max(document.body.clientHeight, document.documentElement.clientHeight)
          );
                }
                function width() {
                    return Math.max(
            Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
            Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
            Math.max(document.body.clientWidth, document.documentElement.clientWidth)
          );
                }
            }
        }
    },
    /* -- HoverLead */
    HoverLead: {
       
            Private: function () {
                var playing = new Boolean();
                return function setter(condition) {
                    if (arguments.length == 0) return playing;
                    playing = condition;
                    if (playing == "true") {
			
                        EF.HoverLead.killTimer(test);
                        return playing;
                    } else if (playing == "false") {
                        EF.HoverLead.setTimer();
                        return playing;
                    }
                }
            },
            showModal: function () {
                /* Load ColorBox for pop-in -- Will eventually replace nryo and ThickBox */
            	 if(EF.HoverLead.Private._wrapper != 'undefined' && EF.HoverLead.Private._wrapper !='')
            {
		$('body').append('<div id="' + EF.HoverLead.Private._wrapper  + '"></div>')
		$('#' + EF.HoverLead.Private._wrapper).append('<iframe id="HoverFrame" class="HoverFrame" scrolling="no" frameborder="0" allowTransparency="true" style="border:none;width:' + EF.HoverLead.Private._width + 'px;height:' + EF.HoverLead.Private._height + 'px;" src="' + EF.HoverLead.Private._liveball + '"></iframe>') 
                 	  
               TB_MPPshow(EF.HoverLead.Private._wrapper,EF.HoverLead.Private._width,EF.HoverLead.Private._height,EF.HoverLead.Private._isscroll);
              }
            },
            closeModal: function () {
                /* Create EFLD cookie */
                EF.Global.Utilities.CookieManager.Session("EFLD", escape("Viewed=True"));

                /* Increment counter */
		if ((!EF.Global.Utilities.CookieManager.Check("EFFEDCK", "Count")) || isNaN(EF.Global.Utilities.CookieManager.Consume("EFFEDCK", "Count"))) 
                    EF.Global.Utilities.CookieManager.Bake("EFFEDCK", "Count=0", "180");

                var _count = parseInt(EF.Global.Utilities.CookieManager.Consume("EFFEDCK", "Count")) + 1;
                EF.Global.Utilities.CookieManager.Bake("EFFEDCK", "Count=" + _count, "180");
		
                TB_MPPHide('FrameWrapper');
                
            },
	    closeParentModal: function () {
                /* Create EFLD cookie */
                EF.Global.Utilities.CookieManager.Session("EFPARFLD", escape("Viewed=True"));

                /* Increment counter */
		if ((!EF.Global.Utilities.CookieManager.Check("EFPARFEDCK", "Count")) || isNaN(EF.Global.Utilities.CookieManager.Consume("EFPARFEDCK", "Count"))) 
                    EF.Global.Utilities.CookieManager.Bake("EFPARFEDCK", "Count=0", "180");

                var _count = parseInt(EF.Global.Utilities.CookieManager.Consume("EFPARFEDCK", "Count")) + 1;
                EF.Global.Utilities.CookieManager.Bake("EFPARFEDCK", "Count=" + _count, "180");
		
                TB_MPPHide('FrameWrapper');
                
            },
            setTimer: function () {
                //EF.HoverLead.Private._timer = setTimeout('EF.HoverLead.showModal()', EF.HoverLead.Private._timeout);
		test = setTimeout('if(!EF.HoverLead.checkForLoginInit()){EF.HoverLead.showModal();}', EF.HoverLead.Private._timeout);
		
		
            },
            resetTimer: function () {
		        if(_showHover)
		             EF.HoverLead.Init('/splash/HoverLead.aspx');
            },
	    resetParentTimer: function () {
		        if(_showHover)
		             EF.HoverLead.Init('/splash/ParentHover.aspx');
            },
            killTimer: function (timer) {
                try {
                    clearTimeout(test);
                } catch (err) { }
            },
            checkForLoginInit: function() {
		
                if(document.getElementById('CloseWindowCtl') != null && document.getElementById('CloseWindowCtl').href=="javascript:TB_remove();EF.HoverLead.resetTimer();")
		{
		    return true; 
		}
                else
                    return false;
            },
            Init: function (url, timeout, width, height, iframe,isScroll,wrapper) {
                /* Create counter cookie, if nec. */
		
                if (!EF.Global.Utilities.CookieManager.Check("EFFEDCK", "Count")) {
                    EF.Global.Utilities.CookieManager.Bake("EFFEDCK", "Count=0", "180");
                }
                if (EF.Global.Utilities.CookieManager.Check("EFLD", "Viewed", "True") || EF.Global.Utilities.CookieManager.Check("EFFEDCK", "Count", "3")) return /*silently*/;
                EF.HoverLead.Private._liveball = url;
                EF.HoverLead.Private._timeout = timeout || 45000;
                EF.HoverLead.Private._width = width || 417;
                EF.HoverLead.Private._height = height || 619;
                EF.HoverLead.Private._iscroll = isScroll || '0';
                EF.HoverLead.Private._wrapper = wrapper || 'FrameWrapper'
                EF.HoverLead.Private._iframe = iframe || 'ctl00_ContentPlaceHolder1_HoverFrame'
		_showHover = true;
                _frame='FrameWrapper';
		
                this.setTimer();		
                
            },
	    ParentInit: function (url, timeout, width, height, iframe,isScroll,wrapper) {
                /* Create counter cookie, if nec. */
		
                if (!EF.Global.Utilities.CookieManager.Check("EFPARFEDCK", "Count")) {
                    EF.Global.Utilities.CookieManager.Bake("EFPARFEDCK", "Count=0", "180");
                }
                if (EF.Global.Utilities.CookieManager.Check("EFPARFLD", "Viewed", "True") || EF.Global.Utilities.CookieManager.Check("EFPARFEDCK", "Count", "3")) return /*silently*/;
                EF.HoverLead.Private._liveball = url;
                EF.HoverLead.Private._timeout = timeout || 45000;
                EF.HoverLead.Private._width = width || 417; 
                EF.HoverLead.Private._height = height || 835;
                EF.HoverLead.Private._iscroll = isScroll || '0';
                EF.HoverLead.Private._wrapper = wrapper || 'FrameWrapper'
                EF.HoverLead.Private._iframe = iframe || 'ctl00_ContentPlaceHolder1_HoverFrame'
		_showHover = true;
                _frame='FrameWrapper';
		
                this.setTimer();		
                
            },
            FlashInit: function () {
                return EF.HoverLead.Private._temp = new this.Private()
            }
        
    }
}
//EF.HoverLead.Private._showHover = false;
