// functions for write-aid site
window.onload = onLoadBody;

function onLoadBody() {
	// debugger;
	var nodeNav = document.getElementById("leftNav");
	var arrNavNode = nodeNav.getElementsByTagName("a");
	for (var i=0;i<arrNavNode.length;i++) {
		arrNavNode[i].onmouseover=function() {
			if (this.firstChild.className!="selectedLink") this.firstChild.className="hoverLink";
		}
		arrNavNode[i].onmouseout = function() {
			if (this.firstChild.className!="selectedLink") this.firstChild.className="";
		}
		arrNavNode[i].onmousedown = function() {
			if (this.firstChild.className!="selectedLink") this.firstChild.className="activeLink";
		}
	}
	
	var sLoc = window.location.pathname;
	sLoc = sLoc.slice(sLoc.lastIndexOf("/")+1);
	sLoc = sLoc.substr(0,sLoc.indexOf("."));
	sLoc = "link_img_" + sLoc;
	// alert(sLoc);
	var objLink = document.getElementById(sLoc);
	if (objLink) {
		objLink.className="selectedLink";
	}
}

function validateForm(objForm) {
	var re = /\s*((\S+\s*)*)/;
	var msg="Please fill in all required fields";
	var fields=objForm.getElementsByTagName("input");
	var labels=objForm.getElementsByTagName("label");
	for (var i=0;i<fields.length;i++) {
		if (fields[i].className=="required" && fields[i].value.replace(re, "$1")=="") {
			for (var j=0; j<labels.length; j++) {
				if (labels[j].htmlFor == fields[i].name) {
					msg = "You must fill in the \""+labels[j].firstChild.nodeValue+"\" field.";
					break;
				}
			}
			alert(msg);
			fields[i].focus();
			return false;
		}
	}
	return true;
}
