	function stripTrailingSpace(theStr) {
		var iStr;
		iStr = theStr;
	 	if (iStr.charAt(0) == " ") {
			iStr = iStr.substring(1,iStr.length)
		}
		if (iStr.charAt(iStr.length) == " ") {
			iStr = iStr.substring(0,iStr.length-1)
		}
		return iStr;
	}
	function validate(theform) {
		if (!theform.required) {
			alert("Required fields not registered!");
			return false;
		}
		var reqfields = theform.required.value;
		var reqErrMsg = theform.requiredErrMsg.value;
		var reqfieldsAry = reqfields.split(",");
		var reqErrMsgAry = reqErrMsg.split("\n");
		var tmpStr = "";
		var strEmails = "";
		var strConfEmails = "";
		var bEntered = false;
		var bIsSingle = false;
		if (reqfieldsAry.length != reqErrMsgAry.length) {
			if (reqfieldsAry.length < reqErrMsgAry.length) {
				alert("Error in form configuration.There are more error messages than required fields.");
			} else {
				alert("Error in form configuration. There are more required fields than error messages.");
			}
			return false;
		}
		for (i=0;i<reqfieldsAry.length;i++){
			reqfieldsAry[i] = stripTrailingSpace(reqfieldsAry[i]);
		}
		for (i=0;i<reqfieldsAry.length;i++){
			if (reqfieldsAry[i].indexOf('(',0) >= 0) {
				// check grouped items
				bEntered = false;
				tmpStr = reqfieldsAry[i].substring(1,reqfieldsAry[i].length-1);
				var tmpAry = tmpStr.split("|");
				for (j=0;j<tmpAry.length;j++){
					tmpAry[j] = stripTrailingSpace(tmpAry[j]);
					if (!theform.elements[tmpAry[j]]) {
						alert("An extra required field was encountered: " + tmpAry[j]);
						return false;
					}
				}
				for (j=0;j<tmpAry.length;j++){
					// if there are multiple items with the same name then we have to deal with this in a completely different way
					if (theform.elements[tmpAry[j]].length) {
						if (theform.elements[tmpAry[j]].length == 1) {
							bIsSingle = true;
						} else {
							bIsSingle = false;
						}
					} else {
						bIsSingle = true;
					}
					if (bIsSingle) {
						if ((theform.elements[tmpAry[j]].type == "text")||(theform.elements[tmpAry[j]].type == "textarea")) {
							if (theform.elements[tmpAry[j]].value.length > 0) {
								bEntered = true;
							}
						} else if (theform.elements[tmpAry[j]].type == "select-multiple") {
							var numSelected = 0;
							for (k=0;k<theform.elements[tmpAry[j]].options.length;k++){
								if (theform.elements[tmpAry[j]].options[k].selected == true) {
									numSelected++;
								}
							}
							if (numSelected > 0) {
								bEntered = true;
							}
						} else if (theform.elements[tmpAry[j]].type == "checkbox") {
							if (theform.elements[tmpAry[j]].checked == true) {
								bEntered = true;
							}
						} else if (theform.elements[tmpAry[j]].type == "select-one") {
							if (theform.elements[tmpAry[j]].selectedIndex > 0) {
								bEntered = true;
							}
						}
					} else {
						if (theform.elements[tmpAry[j]][0].type == "checkbox") {
							var numSelected = 0;
							for (k=0;k<theform.elements[tmpAry[j]].length;k++){
								if (theform.elements[tmpAry[j]][k].checked == true) {
									numSelected++;
								}
							}
							if (numSelected > 0) {
								bEntered = true;
							}
						}
					}
				}
				if (!bEntered) {
					alert(reqErrMsgAry[i]);
					if (bIsSingle) {
						theform.elements[tmpAry[0]].focus();
					} else {
						theform.elements[tmpAry[0]][0].focus();
					}
					return false;
				}
			} else {
				// check to make sure field exists
				if (!theform.elements[reqfieldsAry[i]]) {
					alert("An extra required field was encountered: " + reqfieldsAry[i]);
					return false;
				}
				if (theform.elements[reqfieldsAry[i]].length) {
					if (theform.elements[reqfieldsAry[i]].length == 1) {
						bIsSingle = true;
					} else {
						bIsSingle = false;
					}
				} else {
					bIsSingle = true;
				}
				if (bIsSingle) {
					if ((theform.elements[reqfieldsAry[i]].type == "text")||(theform.elements[reqfieldsAry[i]].type == "textarea")) {
						if (theform.elements[reqfieldsAry[i]].value.length < 1) {
							alert(reqErrMsgAry[i]);
							theform.elements[reqfieldsAry[i]].focus();
							return false;
						}
						tmpStr = reqfieldsAry[i].toLowerCase();
						if (tmpStr.indexOf('email',0) >= 0) {
							if (!validEmail(theform.elements[reqfieldsAry[i]].value)) {
								alert("Please make sure that the email address provided is valid.");
								theform.elements[reqfieldsAry[i]].focus();
								return false;
							}
						}
					} else if (theform.elements[reqfieldsAry[i]].type == "select-one") {
						if (theform.elements[reqfieldsAry[i]].selectedIndex < 1) {
							alert(reqErrMsgAry[i]);
							theform.elements[reqfieldsAry[i]].focus();
							return false;
						}
					} else if (theform.elements[reqfieldsAry[i]].type == "select-multiple") {
						var numSelected = 0;
						for (j=0;j<theform.elements[reqfieldsAry[i]].options.length;j++){
							if (theform.elements[reqfieldsAry[i]].options[j].selected == true) {
								numSelected++;
							}
						}
						if (numSelected == 0) {
							alert(reqErrMsgAry[i]);
							return false;
						}
					} else if (theform.elements[reqfieldsAry[i]].type == "checkbox") {
						if (theform.elements[reqfieldsAry[i]].checked != true) {
							alert(reqErrMsgAry[i]);
							theform.elements[reqfieldsAry[i]].focus();
							return false;
						}
					} else {
						bEntered = false;
						for (j=0;j<theform.elements[reqfieldsAry[i]].length;j++){
							if (theform.elements[reqfieldsAry[i]][j].checked == true) {
								bEntered = true;
							}
						}
						if (!bEntered) {
							alert(reqErrMsgAry[i]);
							theform.elements[reqfieldsAry[i]][0].focus();
							return false;
						}
					}
				} else {
					if (theform.elements[reqfieldsAry[i]][0].type == "checkbox") {
						numSelected = 0;
						for (j=0;j<theform.elements[reqfieldsAry[i]].length;j++){
							if (theform.elements[reqfieldsAry[i]][j].checked == true) {
								numSelected++;
							}
						}
						if (numSelected == 0) {
							alert(reqErrMsgAry[i]);
							theform.elements[reqfieldsAry[i]][0].focus();
							return false;
						}
					}
				}
			}
		}
		// check confirmation emails
		for (i=0;i<reqfieldsAry.length;i++){
			tmpStr = reqfieldsAry[i].toLowerCase();
			if (tmpStr.indexOf('email_confirm',0) >= 0) {
				strConfEmails += reqfieldsAry[i] + ",";
			} else if (tmpStr.indexOf('email',0) >= 0) {
				strEmails += reqfieldsAry[i] + ",";
			}
		}
		if ((strEmails.length > 0) && (strConfEmails.length > 0)){
			strEmails = strEmails.substring(0,strEmails.length-1);
			strConfEmails = strConfEmails.substring(0,strConfEmails.length-1);
			var emailsAry = strEmails.split(",");
			var confEmailsAry = strConfEmails.split(",");
			for (i=0;i<confEmailsAry.length;i++){
				for (j=0;j<emailsAry.length;j++){
					if ((confEmailsAry[i].substring(0,confEmailsAry[i].length-8) == emailsAry[j])||(confEmailsAry[i].substring(0,confEmailsAry[i].length-13) == emailsAry[j])) {
						if (theform.elements[confEmailsAry[i]].value != theform.elements[emailsAry[j]].value) {
							alert("Please make sure your confirmation email address matches you email address.");
							theform.elements[confEmailsAry[i]].focus();
							return false;
						}
					}
				}
			}
		}
		return true;
	}
	function validStartDate(thestr) {
	 	if (thestr.match("^[0-9]{1,2}\/[0-9]{4}$") == null) {
			return false;
		} else {
			return true;
		}
	}
	function validCompDate(thestr) {
	 	if (thestr.match("^([1-9]|[0][1-9]|[1][012])[/]([1-9]|[0][1-9]|[12][0-9]|[3][01])[/]([1][9]|[2][0])[0-9][0-9]$") == null) {
			return false;
		} else {
			return true;
		}
	}
	function validEmail(thestr) {
	 	if (thestr.match("^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$") == null) {
			return false;
		} else {
			return true;
		}
	}
