
// Function opens link in new window
//
function openInNewWindow(address) {
var newWindow = window.open(address, 'newWindow');
newWindow.focus();
return false;
}

// Function turns spam-bot protected e-mail addresses
// into functioning e-mail links
//
function emailCloak() {
	if (document.getElementById) {
		//var alltags = document.all? document.all : document.getElementsByTagName("*");
		var alltags = document.all? document.all : document.getElementsByTagName("span");
		for (i=0; i < alltags.length; i++) {
		  var strClassName = "cloak";
		  strClassName = strClassName.replace(/\-/g, "\\-");
		  var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
		  if (oRegExp.test(alltags[i].className)) {
			var oldText = alltags[i].firstChild;
			var emailAddress = alltags[i].firstChild.nodeValue;
			var user = emailAddress.substring(0, emailAddress.indexOf("("));
			var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
			var newText = user+"@"+website;
			var a = document.createElement("a");
			a.href = "mailto:"+newText;
			var address = document.createTextNode(newText);
			a.appendChild(address);
			alltags[i].replaceChild(a,oldText);
		  }
		}
	}
}

// Function checks for mandatory fields in form
//
function frmChecker() {
	var frm; frm=document.form; 
	if (frm.name.value == "") { 
		alert("Please enter your name."); 
		frm.name.focus(); return false; 	
	}
	if (frm.email.value == "") { 
		alert("Please enter your e-mail address."); 
		frm.email.focus(); return false; 	
	}
	if (frm.comments.value == "") { 
		alert("Please enter a question or comment."); 
		frm.comments.focus(); return false; 
	}
	return true 
} 

// Function runs on window load, going through link tags looking for rel="external".
// These links receive onclick events that cause the link to open in a new window.
//
function initLinker()
{
	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		
		// rel="external"
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external")){
			anchor.onclick = function () {openInNewWindow(this.getAttribute("href")); return false;}
		}
		// rel="print"
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "print")){
			anchor.onclick = function () {window.print(); return false;}
		}
	}
}
function initForm() {
	if(pageForm = document.getElementById('form')) {
		pageForm.onsubmit = function() { return frmChecker(); }
	}
}
//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}


addLoadEvent(initLinker);	// run initLinker onLoad
addLoadEvent(initForm);	// run initForm onLoad
addLoadEvent(emailCloak);