
/*
**
** $Id: external.js 37 2003-11-29 03:28:33Z cpaul $
** $Source$
**
** the 'target' attribute is not XHTML compliant:
**
** <a href="link.html" target="_blank"> 
**
** however, the target parameter is DOM compliant,
** so a workaround is to use javascript to set
** the target for 'external' links
**
** as per: 
** http://www.sitepoint.com/article/1041/3
**
** 29-nov-2003 wrote externalLinksByHref function
**
*/



function externalLinksByRel() {
  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';
  }
}


function externalLinksByHref() {
  var base_url = (document.URL ? document.URL : document.location.href).substr(0,(document.URL ? document.URL : document.location.href).indexOf('/',8));
  if (document.getElementsByTagName) {
    var anchors = document.getElementsByTagName('a');
    for (var i=0; i<anchors.length; i++) {
      var anchor = anchors[i];
      if ((anchor.getAttribute('href').indexOf('http:\/\/')==0 || anchor.getAttribute('href').indexOf('https:\/\/')==0)
          && anchor.getAttribute('href').indexOf(base_url)<0) {
	anchor.target = '_blank';
      }
    }
  }
  else if (document.links) {
    var anchors = document.links;
    for (var i=anchors.length-1; i>=0; i--) {
      var anchor = anchors[i];
      if ((anchor.href.indexOf('http:\/\/')==0 || anchor.href.indexOf('https:\/\/')==0)
           && anchor.href.indexOf(base_url)<0) {
	anchor.target = '_blank';
      }
    } 
  }
}

//window.onload = externalLinksByRel;
window.onload = externalLinksByHref;

