/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Jeroen Haan | http://www.haan.net */
/* -----------------------------------------------
   Link Enhancer - v.1.1
   (c) 2007 www.haan.net
   contact: jeroen@haan.net
   You may use this script but please leave the credits on top intact.
   Please inform us of any improvements made.
   When useful we will add your credits.
  ------------------------------------------------ */
  
// Give the outbound links a blank target and their own style
// and optional the inbound too or vise versa
// It will leave the mailto alone and skip anchor tags without the href attribute

function enhanceLinks() {
 var links = document.getElementsByTagName("a");
var thisDomain = document.domain.split('www.');
 var thisDomain = (thisDomain[1]) ? thisDomain[1] : document.domain ;
//var thisDomain = '';
 for (var i = 0; i < links.length; i++) {
  if(links[i].href.indexOf('.pdf') > 0 || links[i].href.indexOf('/recruit/') > 0 || links[i].href.indexOf('/package/paples/') > 0 || links[i].href.indexOf('grandit.nhs.co.jp/') > 0 || links[i].href.indexOf('/sap/') > 0 || links[i].href.indexOf('.doc') > 0|| links[i].href.indexOf('.wmv') > 0 || links[i].href.indexOf('.docx') > 0 || links[i].href.indexOf('.xls') > 0 || links[i].href.indexOf('.xlsx') > 0 || links[i].href.indexOf('.ppt') > 0 || links[i].href.indexOf('.pptx') > 0 || links[i].href.indexOf('.jpg') > 0 || links[i].href.indexOf('.gif') > 0 || links[i].href.indexOf('.png') > 0 || (links[i].href.indexOf(thisDomain) == -1 && links[i].href != '' && links[i].href.indexOf('javascript:') == -1)) {
links[i].target = '_blank';
 }
}
}

// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  enhanceLinks();
}
);
