<!-- // Generic Form Validation: Web JavaScript

// requires in form
/*
<input type="hidden" name="reqFlds" value=",fieldToValidate,fieldToValidate,fieldToValidate,"> 
<input type="hidden" name="disSub" value="dis">
<input type="hidden" name="disSubVal" value="Sending Message ...">
<input type="hidden" name="disSubWidth" value="140">
*/


function gnrcFormVal( FNform )
	{
		var valI, FNform, FNrequiredFields, FNdisSub, FNgnrcHl, totalFields, requiredSTR, erMes, isMissing, firstFocus;
			// get validation values from form
				FNrequiredFields = document.forms[FNform].elements["reqFlds"].value;
				FNdisSub = document.forms[FNform].elements["disSub"].value;
				FNdisSubVal = document.forms[FNform].elements["disSubVal"].value;
				FNdisSubWidth = document.forms[FNform].elements["disSubWidth"].value;
				FNgnrcHl = document.forms[FNform].elements["REMgnrcHl"];
				
			// format for JS function
				requiredSTR = new String(FNrequiredFields);
				totalFields = document.forms[FNform].elements.length;
				erMes = "";
				firstFocus = "";
			for (valI=0; valI<totalFields; valI++)
				{
				thisField = document.forms[FNform].elements[valI];
				thisFieldName = thisField.name;
				thisFieldVal = thisField.value;
				thisFieldTitle = thisField.title;
				isRequired = requiredSTR.indexOf(""+thisFieldName+"");
					if (isRequired>0)
						{
			// doublecheck is actual fld name
				var endChar = requiredSTR.substring(isRequired+thisFieldName.length, (isRequired+thisFieldName.length)+1);
					if (endChar == "," || endChar == null) {
							//alert(endChar);
							//alert(thisFieldVal);
							
							var lc_thisFieldTitle = thisFieldTitle.toLowerCase();
								// highlight obj (reset)
									var currGnrcHl = document.getElementById(thisFieldName+ "_Hl");
										currGnrcHl.className = "reqFldHl";
							if (lc_thisFieldTitle.indexOf("email")>-1 ) {
								// set boolean to false for valid email
									var isValidEmail = false;
								// start by finding @ symbol at least 2 characters after start
									if (thisField.value.indexOf("@")>1) {
									// seperate into box and domain
										var thisFieldEmailBox = thisField.value.substring(0, (thisField.value.indexOf("@")) );
										var thisFieldEmailDomain = thisField.value.substring( (thisField.value.indexOf("@")), thisField.value.length);
									// set new vars
										var thisFieldAt = thisFieldEmailDomain.indexOf("@");
										var thisFieldPeriod = thisFieldEmailDomain.indexOf(".");
										var thisFieldLen = thisFieldEmailDomain.length;
									// determine if valid domain for box 
									//(if at least a two character domain with two character extenstion)
										if ( (thisFieldPeriod-thisFieldAt > 2) && (thisFieldLen-thisFieldPeriod > 2 ) ) {
											isValidEmail = true;
										}
											/*
											alert("" + 
												"[thisFieldEmailBox] " +thisFieldEmailBox+ "\t\n" + 
												"[thisFieldEmailDomain] " +thisFieldEmailDomain+ "\t\n" + 
												"\n" +
												"[thisFieldAt] " +thisFieldAt+ "\t\n" +
												"[thisFieldPeriod] " +thisFieldPeriod+ "\t\n" +
												"[thisFieldLen] " +thisFieldLen+ "\t\n" +
												"\n" +
												"[thisFieldPeriod-thisFieldAt] " +(thisFieldPeriod-thisFieldAt)+ "\t\n" +
												"[thisFieldLen-thisFieldPeriod] " +(thisFieldLen-thisFieldPeriod)+ "\t\n" +
												"\n" +
												"[isValidEmail] " +(isValidEmail)+ "\t\n" +
												"\n" +
												"");
											*/
									}
									if (isValidEmail == false) {
										isMissing = "yes";
										erMes = erMes + "  * A valid Email address in \"" + thisFieldTitle + "\"\n";
											if (firstFocus == "") {
												firstFocus = valI;
											}
										// highlight errors
											currGnrcHl.className = "reqFldHl reqFldHlErr";
									}
								} else {
									if (thisField.value == "") {
										isMissing = "yes";
										erMes = erMes + "  * " + thisFieldTitle + "\n";
											if (firstFocus == "") {
												firstFocus = valI;
											}
										// highlight errors
											currGnrcHl.className = "reqFldHl reqFldHlErr";
									}
								}
								
							}
						}
				}
				if (isMissing == "yes")
					{
						// set alert message
							var genAlertMsg = ""; 
								//genAlertMsg = "You have missed the required fields listed below:\n\n"+
								//	"" + erMes + "\nPlease enter values in the fields marked with an asterix *\t\t";
								genAlertMsg = "You have missed the required fields listed below:\t\t\n\n"+
									"" + erMes + "\n";
								alert(genAlertMsg);
						// set focus
							var fieldToFocusObj = document.forms[FNform].elements[firstFocus];
								if  (fieldToFocusObj.type == "hidden")
									{
										//document.forms[FNform].elements[0].focus();
									}
								else
									{
										document.forms[FNform].elements[firstFocus].focus();
									}
							return (false);
					}
				else
					{
						if (FNdisSub == "dis")
							{
								
								document.forms[FNform].elements["disHere"].disabled = true;
								document.forms[FNform].elements["disHere"].value = FNdisSubVal;
								document.forms[FNform].elements["disHere"].style.width = FNdisSubWidth+'px';
							}
						//alert("sub");
						document.forms[FNform].submit();
					}
	}	


// -->