// @(#) $Id: externalRedirects.js 57652 2008-01-02 15:45:19Z matthew $

function externalLinksRedirect () {
    for ( var i = 0 ; i < document.links.length; i++ ) {
        var link = document.links[i];

        if (link.href == "")
            continue;
        if (! link.protocol.match(/^http/) )
            continue;

        // Curse the infernal variations of DOM0.  Sometimes hostname
        // has a port number on it, sometimes it doesn't.  Ditto for
        // "host" (which should always have a port number).  Instead,
        // just strip off anything after a colon and hope for the best.
        var port = document.location.port;
        var link_hostname = link.hostname.replace(/:[0-9]+$/, "");

        // Ignore internal links.
        if ( link_hostname == document.location.hostname )
            continue;

        var extURL = link.href;
        var inner = link.innerHTML;
        link.href = link.protocol + '//' + document.location.hostname + ':' + port + '/external_link' + '?url=' + extURL + '&js=1';
        link.innerHTML = inner;
    }
}

addLoadEvent( externalLinksRedirect);

// vim: set ai et sw=4 :

