/*
 *
 * 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,
 * which just changes all off-site <a> links to
 * use target _blank
 *
 * - chris paul <inc fastmedia.net>
 *
 */



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'))
      {
        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)
      {
         if ((anchor.href.indexOf('http:\/\/')==0 || anchor.href.indexOf('https:\/\/')==0)
             && anchor.href.indexOf(base_url)<0) {
	    anchor.target = '_blank';
         }
      }
    } 
  }
}