function makeExternalLinks() {

    // Fail safe for bad browsers
    if(!document.getElementsByTagName) return false;

    // The A tags
    var aTags = document.getElementsByTagName('a'); 

    // How many? Helps with loop optimization
    var aTagsLength = aTags.length;

    for (var i=0; i < aTagsLength; i++) {

        // The current tag
        var thisTag = aTags[i];                                               

        // if it has a href and has the rel 'ext', then set its target to _blank
        if (thisTag.getAttribute('href') && thisTag.getAttribute('rel') == "ext") {
            thisTag.target = "_blank"; 
            thisTag.title += " (opens in a new window)";
        }
    }
}

function makePopupLinks() {

    // Fail safe for bad browsers
    if(!document.getElementsByTagName) return false;

    // The A tags
    var aTags = document.getElementsByTagName('a'); 

    // How many? Helps with loop optimization
    var aTagsLength = aTags.length;

    for (var i=0; i < aTagsLength; i++) {

        // The current tag
        var thisTag = aTags[i];                                               

        // if it has a href and has the rel 'ext', then set its target to _blank
        if (thisTag.getAttribute('href') && thisTag.getAttribute('rel') == "popup") {
            thisTag.href = "javascript:newsWin('" + thisTag.href + "');"
            thisTag.title += " (opens in a popup window)";
        }
    }
}

function makeDisclaimer() {

    // Fail safe for bad browsers
    if(!document.getElementById('disc')) return false;

    // Get the disclaimer tag
    var aTag = document.getElementById('disc'); 

    aTag.title += " (opens in a popup window)";
    aTag.href = "javascript:disclaimWin('" + aTag.href + "');"

}

// Opens news story in a popup
function newsWin(page) {
 Open1Win = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,height=505,width=820,location=no,scrollbars=yes,resizable=yes,status=no,left=100,top=100");
}


// Opens disclaimer in a popup
function disclaimWin(page) {
 OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,height=505,width=658,location=no,scrollbars=yes,resizable=no,status=no,left=100,top=100");
}

// Gets around the problem of having multiple onload handlers ----------------------------------
// http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
// http://www.quirksmode.org/js/events_advanced.html

function addEvent(obj, evType, fn) { 

    // W3C type of event registration model
    if (obj.addEventListener) { 
        
        obj.addEventListener(evType, fn, false); 
        return true; 
        
    // MS event registration model    
    } else if (obj.attachEvent) { 

        var r = obj.attachEvent("on"+evType, fn); 
        return r; 
        
    // Bad browsers that can't do either
    } else { 
    
        return false; 
        
    } 
}

addEvent(window, 'load', makeExternalLinks);
addEvent(window, 'load', makePopupLinks);
addEvent(window, 'load', makeDisclaimer);