
<!-- BEGIN CHECK REQUIRE FUNCTION -->

function checkReq(thisForm,checkChar)
{ //this was used inside form, can be passed to function
for(x=0; x<thisForm.length; x++)
{
var thisElement = thisForm.elements[x];
var myCheck = 0;
	if(thisElement.name.charAt(0) == checkChar)
	{//first char == checkChar means required element!
		var tempName = "";  //stores removed char version
		if(thisElement.type == "select-one" && thisElement.selectedIndex==0)
		{//single select opt	
			tempName = processName(thisElement.name); //temp name, rem x, add spaces
			alert("Please select one: " + tempName);	
			thisElement.focus();
			return false;
		}else{
			
			switch(thisElement.type)
			{
				case "select-multiple":
					for(y=0;y<thisElement.options.length; y++)
					{
						if(thisElement.options[y].selected)
						{
							myCheck = 1;
						}
						if(myCheck == 0)
						{
							tempName = processName(thisElement.name);
							alert("Please make selections: " + tempName);	
							thisElement.focus();
							return false;
						}
					}//end mult for
					break;
				case "radio":
				case "checkbox":
					var myLength = 1; //start at one
					var myStart = x;  //will change x
					while(thisElement.name == thisForm.elements[x + 1].name)
					{//calc number of radio/checkboxes
						myLength++;
						x++
					}
					for(y=myStart;(y<myStart + myLength);y++)
					{
						if(thisForm.elements[y].checked == true)//add x to offset
						{
							myCheck++;
						}
					}//end for
					if(myCheck == 0)
					{
						tempName = processName(thisElement.name);
						alert("Please check one: " + tempName);	
						thisForm.elements[myStart].focus(); //focus back to first element
						return false;
					}
					break;
				case "text":
				case "textarea":
				case "password":
					if(thisElement.value == "")
					{	
						tempName = processName(thisElement.name);
						alert("Please enter required field: " + tempName);	
						thisElement.focus();
						return false;
					}
					break;
			}//end switch
		}//end select-one check		
	}//end of charAt()
}//end of for
return true; //if passed all checks, submit form
}

function processName(str)
{//Removes checkChar, adds space before capitalized words in field name
	var newStr = "";
	var leftStr = "";
	var myChar = "";
	var myPos = "";
	var prevChar = "";
	var myCounter = 0;
	var rePattern = /\B[A-Z]\B/; //any capital letter \B is not on a word boundary
	str = str.substring(1) //remove first char
	do
	{
		myChar = str.match(rePattern);//find first RegEx pattern match
		if(myChar == null && myCounter == 0){return str;} //no match, abort!
		myPos = str.indexOf(myChar); //find first char of pattern
		leftStr = str.substring(0,myPos); //grab left str
		str = str.substring(myPos + 1) //right side of str
		if(myChar != null)
		{
			if(newStr == "") //start of new string
			{
				newStr = leftStr; //add left side of string
				prevChar = myChar;  //store old char for next round
			}else{
				newStr += " " + prevChar + leftStr; //prev. stored char, + left side
				prevChar = myChar;
			}
		}
		myCounter++;
		if(myChar == null){myPos = -1;} //no more chars to search for, finis!
	}while(myPos > -1);
	newStr += " " + prevChar + str; //add remaining bit to end
	return newStr;
}

<!-- BEGIN CAPFIRST FUNCTION -->

function processForm(thisForm)
{
	thisForm.myText.value = capFirst(thisForm.myText.value);  //capitalize & rem spaces
	return false;  //change to true to test submitted version
}
function capFirst(str)
{//accepts a string, strips spaces, capitalizes first letter of each word
	str = stripSpaces(str); //get rid o' extra spaces!
	var myStart = "";
	var myEnd = "";
	var nameStr = ""; //to store name
	capArray = str.split(" ");
	for (x=0; x<capArray.length;x++)
	{
		myStart = capArray[x].substr(0,1); //grab first char
		myEnd = capArray[x].substr(1,capArray[x].length - 1); //grab rest
		myStart	= myStart.toUpperCase();  //capitalize first letter
		myEnd = myEnd.toLowerCase();  //lowercase the rest
		if(nameStr == "")
		{
			nameStr += myStart + myEnd;
		}else{
			nameStr += " " + myStart + myEnd;  //add back ONE space between words!!
		}
	}
	return nameStr;
}

function stripSpaces(str)
{
	myMarker = "";
	for(x=0;x<str.length;x++)
	{
		myMarker = str.substr(0,1);
		if(myMarker == " ")
		{
			str = str.substr(1,str.length - 1);// grab rest
		}else{
			break; //exit loop if no more beginning spaces
		}
	
	}
	for(x=0;x<str.length;x++)
	{
		myMarker = str.slice(str.length-1,str.length);
		if(myMarker == " ")
		{
			str = str.slice(0,str.length - 1);// grab rest
		}else{
			break; //exit loop if no more beginning spaces
		}
	}
	var blnSpace = false;
	for(x=0;x<str.length;x++)
	{
		myMarker = str.substr(x,1); //one char at a time
		if(myMarker == " ")
		{
			if (blnSpace == true) //2 zeros, remove 1!
			{
			str = str.slice(0,x) + str.slice(x+1,str.length);//concat both ends around space
			x--  //adjust for removal!
			}else{
				blnSpace = true;
			}
		}else{
			blnSpace = false;
		}
			
	}
	return str;
}

<!-- BEGIN ZIP CODE FUNCTION -->

function regExZip(eObj) 
{//uses regular expression for zip code check
   var rePattern = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
   if(rePattern.test(eObj.value))
     {
     return true; //will return for submittal
     //alert("Valid Zip Code: " + eObj.value); //testing only
     //return false; //testing only
     }else{
     alert("Please enter a valid zip code.");
     eObj.value = "";
     eObj.focus();
     return false;
     }
}

<!-- BEGIN EMAIL FUNCTION -->

function regExEmail(eObj)
{//Uses regular expression for email check
var rePattern = /^[a-zA-Z0-9\-]+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3})$/;
 if(rePattern.test(eObj.value))
 {
 	return true;
 }else{
    alert("Please enter a valid email address");
	eObj.value = "";
	eObj.focus();
	return false;
 }
}

<!-- BEGIN CHECK ALL FUNCTION -->

function toggle(myCheck){
	for(var x=0; x<myCheck.length; x++){
		myCheck[x].checked = document.myForm.checkAll.checked;
	}	
}

function showAid(myCheck){	
	var showAlert = "Aid Checked:\n";
	for(var x=0; x<myCheck.length; x++){
		if(myCheck[x].checked){
			showAlert += myCheck[x].value + "\n";	
		}	
	}
	alert(showAlert);		
}	


<!-- BEGIN MAXLENGTH FUNCTION -->

function maxLength(myText) 
{
   return myText.value.length != myText.getAttribute("maxlength");
}

<!-- BEGIN PASSWORD FUNCTION-->

function regExPassword(eObj)
{//Uses regular expression for password check
var rePattern = /^[a-zA-Z0-9]+$/;
 if(rePattern.test(eObj.value))
 {
 	return true;  //will return for submittal
	//alert("Valid Password: " + eObj.value); //testing only
	//return false; //testing only
 }else{
    alert("Please enter alphanumerics only for password");
	eObj.value = "";
	eObj.focus();
	return false;
 }
}