function externaliseLinks() {
  var links = document.getElementsByTagName("A");
  for(var x=0; x<links.length; x++) {
    var h = links[x].rel;
    if(h=="external") {
      links[x].onclick=function() {
        window.open(this.href, "_blank");
        return false;
      }
	  //links[x].title+=" "+links[x].href+" (link opens in a new window)";
	  links[x].title+=" "+" (link opens in a new window)";
    }
    if(h=="pdf") {
      links[x].onclick=function() {
        window.open(this.href, "_blank");
        return false;
      }
	  links[x].title+=" (new window)";
    }
    if(h=="pdfWelsh") {
      links[x].onclick=function() {
        window.open(this.href, "_blank");
        return false;
      }
	  links[x].title+=" (n grain ffenest)";
    }
	
	var c = links[x].className;
	if(c=="smallerText") {
      links[x].onclick=function() {
        //document.body.style.fontSize = "62.5%";
        setFontSize(62.5);
        return false;
	  }
	}
	if(c=="normalText") {
      links[x].onclick=function() {
        setFontSize(70);
        return false;
	  }
	}
	if(c=="largerText") {
      links[x].onclick=function() {
        setFontSize(80);
        return false;
	  }
	}
  }
}



function setFontSize(wSize) {
	document.body.style.fontSize = wSize+"%";
	createCookie("AoSfontsize", wSize);
}

function checkFontCookie() {
	var wS = readCookie("AoSfontsize");
	if (wS) {
		setFontSize(wS);
	}
}



function showFontSizeControls() {
	var els = document.getElementsByTagName("SPAN");
	for(var x=0; x<els.length; x++){
		if(els[x].className == "textSizeControls" || els[x].className == "JSshow") {
			els[x].style.display = "inline";
		}
	}
}



// fab cookie recipes by ppk at quirksmode.org
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}




// nifty addloadevent function by simon willison
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}



addLoadEvent(externaliseLinks);
addLoadEvent(checkFontCookie);
addLoadEvent(showFontSizeControls);



/*
addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
  // more code
});
*/