﻿function isValidHref(linkHref) {
    return /^https?:\/\/[\w\-\.]+(:\d*)?\/.*$/.test(linkHref);
}


function getServer(linkHref) {
    if(linkHref.split('/').length < 3) return("unknown");
    else return(linkHref.split('/')[2].split(':')[0]);
}

function externalizeLinks() {
    if(!isValidHref(window.location.href))
        return;
        
    var aTags = document.getElementsByTagName('a');
    for(var i = 0; i < aTags.length; ++i)
        if(isValidHref(aTags[i].href) && isValidHref(window.location.href) && getServer(aTags[i].href) != getServer(window.location.href))
            aTags[i].onclick = function() {
                window.open(this.href).focus();
                return(false);
            };
}

if(window.addEventListener)  window.addEventListener('load', externalizeLinks, false);   // for good browsers
else if(window.attachEvent)  window.attachEvent('onload', externalizeLinks);             // for IE

