﻿AddEvent(window,'load',InitialisePage,false);

function InitialisePage()
{
    // gets called when page finished loading - add any hooks into here...
    ExternalLinkHandler();
}
 
function ExternalLinkHandler()
{
    /*
    iterates through all the <a> tags on the page, assigning target attributes
    to any links detected as external. To make an external link immune from this
    function, add samewindow to the css class attribute:
    <a href="http://somewhere" class="samewindow" />
    */
    
    if(!compatible)
        return false;
        
    var domainRegExp = new RegExp("^https?://(?!" + document.domain.replace(".","\.") + ")","i");
    var anchors = document.getElementsByTagName('A');    

    for(var i=0;i<anchors.length;i++)
    {
        
        if(domainRegExp.test(anchors[i].href) && 
            (!anchors[i].onclick) && 
            (!anchors[i].onmousedown) && 
            (anchors[i].className.indexOf("samewindow") < 0)
        )
        { 
            anchors[i].target = "_blank";
        }
    }
    
}