/* 
    TECHNICAL EXPLANATION:

    Use Javascript to give anchors with attribute rel="external" a target attribute of "_blank".

    EXPLANATION FOR THE APPROACH:
    
    This file was created following the example on a blog at http://loadaveragezero.com/app/s9y/index.php?/archives/95-Serving-Valid-XHTML-Strict-with-target_blank.html
    and article at http://www.sitepoint.com/article/standards-compliant-world.
    The purpose is to allow the HTML pages to be XHTML compliant.  
    
    This explanation was in the comments at http://24ways.org/2005/transitional-vs-strict-markup
    target="_blank" is deprecated because it suggests a behaviour. The ideal is that XHTML deals with the content, 
    CSS with the presentation, and JavaScript with the behaviour. target="_blank" violates this, 
    and is therefore deprecated. 
 */ 

function externalLinks() { 
    if (document.getElementsByTagName) { 
        var anchors = document.getElementsByTagName("a"); 
        for (var i=0; i < anchors.length; i++) { 
            var anchor = anchors[i]; 
            if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
                anchor.target = "_blank"; 
            }
        } 
    }
} 

//from http://www.siteexperts.com/forums/viewConverse.asp?dir=-1&d_id=2967
//the statement "window.onload = myOnLoad()" means...
//  'Assign the value returned by the function myOnLoad to the event handler 'onload' 
//  of the window object'. 
//the statement "window.onload = myOnLoad()" means...
//  the reference to the function without the parentheses is called a function pointer.  
//  the onload event handler requires a function value and that is what scenario 2 provides:  
//  a function rather than the return value of the function.
window.onload = externalLinks;
