﻿jQuery.extend(jQuery.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.', '');

            if (jQuery.inArray(fixedHostname, safeList) >= 0) {
                return false;
            }
            if (fixedHostname.indexOf('javascript') > 0 || fixedHostname.indexOf('(') > 0) {
                return false;
            }
            else {
                return true;
            }
        }
        else {
            return false;
        }

    }
});


var warn_on_leave_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?";


function warn_on_leave(site) {
    if (confirm(warn_on_leave_msg)) {
        window.open(site);
    } else {
        return;
    }
}

$(document).ready(function() {
    $('a:external').addClass("external_link");

    $('a.external_link').removeAttr("target");

    $('a').click(function() {
        if ($(this).hasClass('external_link')) {
            if (!warn_on_leave($(this)[0].href)) {
                return false;
            }
        }
    });
});
	
