//touchless javascript (no event handlers in html)window.onload = kickOff;function kickOff() {    //set behavior to show parent fields based on number of parents    document.getElementById("parentq").onchange = showFields;    // set behavior to copy child's address to parent(s) if it's the same    for (var i=1; i<=5; i++) {    	if (i==5) i="y"; //py payer match address		document.getElementById("p" + i + "match1").onclick = copyAddress;    }    //set behavior to clear child's address from parent(s) if it's different    for (var i=1; i<=5; i++) {    	if (i==5) i="y"; //py payer clear address		document.getElementById("p" + i + "match0").onclick = clearAddress;    }        	//set behavior to check required fields for no or too much content	document.getElementById("appform").onsubmit = checkField;	//set behavior to clear an error hilight when user instigates a correction in the field	var formElements = document.getElementById("appform").elements;	for (var i=1; i<formElements.length; i++) {		formElements[i].onmousedown = clearHilite;	    }}function showFields() {    //show parent fields based on number of parents    document.getElementById("instruct").style.display = "none";    for (var i=1; i<=4; i++) {        document.getElementById("parent"+i).style.display = "none";    }    var parentq = document.getElementById("parentq").selectedIndex;    for (var i=1; i<=parentq; i++) {        document.getElementById("parent"+i).style.display = "block";    }}function copyAddress() {    //copy child's address to parent(s) if it's the same    var whichParent =  this.id.substr(0,2);    document.getElementById("appform")[whichParent + "address"].value = document.getElementById("appform").caddress.value;    document.getElementById("appform")[whichParent + "city"].value = document.getElementById("appform").ccity.value;    document.getElementById("appform")[whichParent + "state"].value = document.getElementById("appform").cstate.value;    document.getElementById("appform")[whichParent + "zip"].value = document.getElementById("appform").czip.value;    document.getElementById("appform")[whichParent + "hometel"].value = document.getElementById("appform").chometel.value;}function clearAddress() {    //clear child's address from parent(s) if it's different    var whichParent =  this.id.substr(0,2);    document.getElementById("appform")[whichParent + "address"].value = "";    document.getElementById("appform")[whichParent + "city"].value = "";    document.getElementById("appform")[whichParent + "state"].value = "";    document.getElementById("appform")[whichParent + "zip"].value = "";    document.getElementById("appform")[whichParent + "hometel"].value = "";}var requiredFields = new Array("cnamelast","cnamefirst","bdaymm","bdaydd","bdayyy","grade","caddress","ccity","cstate","czip","chometel","clang","cschoolname","parentq","p1namelast","p1namefirst","pyname","textseeking","textinterests","textstrengths","textneeds");function checkField() {	//check required fields for no or too much content	var notEmpty = /^s*\w+/; //anything but alphanumeric content (a field with only word space(s) does not count as content)	var isWord = /\b(\w+)\b/ig;	//begins and end with alphanumeric content, case insensitive, all occurances								//apostrophe'd words count as two words; will fix later	var didFail = false;	//check required fields for no content	for (var i=0; i<requiredFields.length; i++) {		if (!notEmpty.test(document.getElementById("appform")[requiredFields[i]].value)) {			document.getElementById("appform")[requiredFields[i]].style.backgroundColor = "#ffff00";			didFail = true;		}	}	//check required textarea fields for too much content	for (var i=0; i<requiredFields.length; i++) {		if (document.getElementById("appform")[requiredFields[i]].name.indexOf("text") != -1) {			var userEntered = document.getElementById("appform")[requiredFields[i]].value;			var wordsUsed = userEntered.match(isWord);			var wordCount = 0;			if (wordsUsed != null) wordCount = wordsUsed.length;			if (wordCount > 500) {				document.getElementById("appform")[requiredFields[i]].style.backgroundColor = "#ffff00";				var newP = document.createElement("p");				newP.className = "message";				newP.appendChild(document.createTextNode("You entered " + wordCount + " words. Please limit to 500."));				document.getElementById("appform")[requiredFields[i]].parentNode.appendChild(newP);				didFail = true;			}		}	}	//stop submit and create message if errors	if (didFail) {		var newSpan = document.createElement("span");		newSpan.className = "message";		newSpan.appendChild(document.createTextNode("Error: please review any hilighted fields before sending."));		document.getElementById("submit").parentNode.appendChild(newSpan);		return false;	}	return true;}function clearHilite() {	//clear an error hilight when user instigates a correction in the field	this.style.backgroundColor = "#ffffff";	if (document.getElementById("submit").parentNode.lastChild.className == "message") {		document.getElementById("submit").parentNode.removeChild(document.getElementById("submit").parentNode.lastChild)	}	if (this.parentNode.lastChild.className) {		if (this.parentNode.lastChild.className == "message") {			this.parentNode.removeChild(this.parentNode.lastChild)		}	}}
