// General browser functions Author: Anthony Booth May 2006 Company: Do Media Ltd
addLoadEvent(prepareCloseWindow);
addLoadEvent(preparePrint);
addLoadEvent(prepareNewWindow);
addLoadEvent(viewAddress);

// Close opened window
function prepareCloseWindow(){
	if(!document.getElementById("close")) return false;
	var closewindow = document.getElementById("close").getElementsByTagName("a");
	closewindow[0].onclick = function(){
		parent.window.close();
		return false;
	}
}
// Print page
function preparePrint(){
	if(!document.getElementById("print")) return false;
	var printpage = document.getElementById("print").getElementsByTagName("a");
	printpage[0].onclick = function(){
		window.print();
		return false;
	}
}
// New window for external links
function prepareNewWindow(){
	if(!document.getElementsByTagName) return false;
	var arrayhref = document.getElementsByTagName("a");
	for(i = 0; i<arrayhref.length; i++){
    	if(arrayhref[i].getAttribute("rel") && arrayhref[i].getAttribute("rel") == "external"){
			arrayhref[i].onclick = function(){
				window.open(this.getAttribute("href"));
				return false;
			}
		}
	}
}
// hide email links from spam
function viewAddress() {
	if (document.getElementsByTagName) {
		var a = document.getElementsByTagName("a")
		var i
		for (i = 0; i < a.length; i++) {
			if (a[i].className && a[i].className == "email") {
				var address_to_replace = a[i].firstChild;
				var real_address = address_to_replace.nodeValue.replace("*atsymbol*", "@");
				address_to_replace.nodeValue = real_address;
				address_to_replace.parentNode.setAttribute("href", "mailto:" + real_address);
			}
		}
	}
}  