﻿var popup_area_id = "popup_area";
var overlay_id = "master_overlay";
var iframe_id = "iframe_hide";
var popup_id = "master_popup";

var popup_parent_id = "";

// composite ids, for jQuery calls
var PopupAreaID = "#" + popup_area_id;
var OverlayID = "#" + overlay_id;
var IframeID = "#" + iframe_id;
var PopupID = "#" + popup_id;

var ie6 = (jQuery.browser.msie && jQuery.browser.version < 7);

//appends div and iframe elements necessary to show popups on page to DOM
function AppendPopupElements() {
    $('body').append('<div id="' + popup_area_id + '"></div>');

    $(PopupAreaID).append('<div id="' + overlay_id + '"></div>');

    //append iframe to hide select elements in IE 6
    if (jQuery.browser.msie && jQuery.browser.version < 7) {
        $(PopupAreaID).append('<iframe id="' + iframe_id + '" frameborder="0" scrolling="no" src="javascript;"></iframe>');
    }

    $(PopupAreaID).append('<div id="' + popup_id + '"></div>');

}

function ShowPopup(id) {
    // bind keypress event to handle ESC key    
    document.onkeydown = function(e) {
        var keycode;

        if (e == null) // ie
        {
            keycode = event.keyCode;
        }
        else // mozilla
        {
            keycode = e.which;
        }

        if (keycode == 27) {
            ClosePopup();
        }
    };

    var oWidth;
    var oHeight;

    oWidth = $(window).width();

    if ($(window).height() >= $(document).height()) {
        oHeight = $(window).height();
    }
    else {
        oHeight = $(document).height();
    }

    $(OverlayID).css('width', oWidth);
    $(OverlayID).css('height', oHeight);

    // IE 6 specific code
    if (ie6) {
        $(IframeID).css('width', oWidth);
        $(IframeID).css('height', oHeight);

        $(OverlayID).css('position', 'absolute');
        $(PopupID).css('position', 'absolute');
    }

    // show elements, and set master area invisible, to calculate dimensions

    $(PopupAreaID).css('visibility', 'hidden');

    $(PopupAreaID).css('display', 'block');
    $(OverlayID).css('display', 'block');

    if (ie6) {
        $(IframeID).css('display', 'block');
    }

    $(PopupID).css('display', 'block');

    //prepare popup contents

    popup_parent_id = '#' + $('#' + id).parent().attr('id');

    $(PopupID).append($('#' + id));

    var h = $(PopupID).height();
    var w = $(PopupID).width();

    $(PopupID).css('height', h + 'px');
    $(PopupID).css('width', w + 'px');

    var l = ($(window).width() / 2) - ($(PopupID).width() / 2);
    var t = ($(window).height() / 2) - ($(PopupID).height() / 2);

    var st = $(window).scrollTop();

    t = t + st;

    $(PopupID).css('left', l + 'px');
    $(PopupID).css('top', t + 'px');

    $(PopupAreaID).css('visibility', 'visible');

    $('div').ifixpng();
}

function ClosePopup() {
    // hide elements
    $(PopupAreaID).css('display', 'none');
    $(OverlayID).css('display', 'none');

    if (ie6) {
        $(IframeID).css('display', 'none');
    }

    $(PopupID).css('display', 'none');

    $(popup_parent_id).append($(PopupID + "> div"));

}

// Check whether links are external:
// (Only works with elements that have href):
$.extend($.expr[':'], {
    external: function(a, i, m) {
        if (!a.href) { return false; }
        if (a.hostname && a.hostname!= window.location.hostname) {
            var fixedHostname = a.hostname.replace(/^\s+|\s+$/g, '').toLowerCase().replace('qa.', '').replace('stage.','').replace('www.', '');
            //fixedHostname = fixedHostname.left(fixedHostname.indexOf(':'), fixedHostname.length - fixedHostname.indexOf(':'));
            if (jQuery.inArray(fixedHostname, safeList) >= 0) {
                return false;
            }
            if (fixedHostname.indexOf('javascript') > 0 || fixedHostname.indexOf('(') > 0 )
            {
                return false;
            }
            
            if (a.hostname.substr(0, a.hostname.indexOf(':')) == window.location.hostname)
            {
                //alert(a.hostname.substr(0, a.hostname.indexOf(':')));
                return false;
            }
            else 
            {
                return true;
            }
        }
        else return false;
    }
});

 var msg = "\nLinks which take you out of Abbott Laboratories worldwide \n"+
 "web site are not under the control of Abbott Laboratories, \n"+
 "and Abbott Laboratories is not responsible for the contents \n"+
 "of any such site or any further links from such site. Abbott \n"+
 "Laboratories is providing these links to you only as a \n"+
 "convenience, and the inclusion of any link does not imply \n"+
 "endorsement of the linked site by Abbott Laboratories.\n\n"+
 "Do you wish to leave this site?"; 

    $(document).ready(function() { 
        $('a:external').attr('target', '_blank').click(function(e) 
         { 
            if (confirm(msg) !=true ) 
            {
                e.preventDefault();    
            }
          }
        )
    });