var warningMessage = 'You have selected a link to an external website. Select OK to continue to this link.';
function addExternalLinkWarning() {
    $('a').filter(function() {
        if (this.hostname) {
            var lHostname = this.hostname.substring(0, this.hostname.indexOf(":") > -1 ? this.hostname.indexOf(":") : this.hostname.length);
            if (lHostname.length >= location.hostname.length)
                return (!((lHostname == location.hostname) || (lHostname.match("\." + location.hostname + "$") == ("." + location.hostname))));
            else
                return (!(location.hostname.match("/\." + lHostname + "$") == ("." + lHostname)));
        }
    })
    .click(function() {
    return (window.confirm(warningMessage));
    })
    .attr('target', '_blank');
}

function addExternalLinkWarningbyTag(ob) {
    var result = false;
    ob.click = null;
        if (ob.hostname) {
            var lHostname = ob.hostname.substring(0, ob.hostname.indexOf(":") > -1 ? ob.hostname.indexOf(":") : ob.hostname.length);
            if (lHostname.length >= location.hostname.length)
                result = (!((lHostname == location.hostname) || (lHostname.match("\." + location.hostname + "$") == ("." + location.hostname))));
            else
                result = (!(location.hostname.match("/\." + lHostname + "$") == ("." + lHostname)));
            if(result)
                return (window.confirm(warningMessage));        
        }
}
_spBodyOnLoadFunctionNames.push("addExternalLinkWarning");


