/**
 * This script replaces all the anchors linking to external urls using
 * the 'rel="external"' attribute (XHTML Strict compliant) with
 * 'target="_blank"' attribute such that browsers open the resource in a new window
 **/

function externalLinks() {
 if (!document.getElementsByTagName) return;
 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";
 }
}
//window.onload = externalLinks;


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/* *
 * Instead of calling externalLinks with window.onload,
 * we add it to the 'queue' of functions to be called on window.onload.
 * This way we avoid conflicts with other scripts.
 * */
addLoadEvent(externalLinks);