﻿// JScript File

var ddwindowlinks={
//Enter domains to be EXCLUDED from opening in new window:
excludedomains: ["cms.macmillan.co.uk", "cms.macmillan.com", "international.macmillan.com", "www.macmillan.co.uk"]

}


function getNewWindowLinks() {

var rexcludedomains=new RegExp(ddwindowlinks.excludedomains.join("|"), "i")

 // Check that the browser is DOM compliant
 if (document.getElementById && document.createElement && document.appendChild) {
 // Change this to the text you want to use to alert the user that a new window will be opened
 var strNewWindowAlert = " (opens in a new window)";
 // Find all links
 var objWarningText;
 var strWarningText;
 var link;
 var links = document.getElementsByTagName('a');


 for (var i = 0; i < links.length; i++) {
 link = links[i];

if (link.hostname.search(rexcludedomains)==-1 && link.href.indexOf("http:")!=-1){

 // Create an em element containing the new window warning text and insert it after the link text
 objWarningText = document.createElement("em");
 strWarningText = document.createTextNode(strNewWindowAlert);
 //objWarningText.appendChild(strWarningText);
 //link.appendChild(objWarningText);
 link.onclick = openInNewWindow;
 }
 }
 objWarningText = null;
 }
 }


 function openInNewWindow() {

 var newWindow = window.open(this.getAttribute('href'), '_blank');
 newWindow.focus();
 return false;
 }


addEvent(window, 'load', getNewWindowLinks);

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
