USERNAME = /^[A-Za-z\d]{3,12}$/;
PASSWORD = /^[a-zA-Z\d]{3,24}$/;

function checkString(testString, stringPattern) {
   return stringPattern.test(testString);
}//checkString

function errorMsg(msg, thisElem) {
	alert(msg);
	if (thisElem != null) {
		thisElem.focus();
	}
}//errorMsg(msg, thisElem)

function formRegExpValidate(thisForm) {
	if ((thisForm == null)||(thisForm == '')) {
		return true;
	}

	var thisElem = null;
	var elemName = "";
	var elemType = "";
	var elemValue = "";
	var regExp = null;
	
	msg = "";
	firstElem = null;

	for (var i=0; i<thisForm.length; i++) {
		thisElem = thisForm.elements[i]
		elemName = thisForm.elements[i].name;
		elemType = thisForm.elements[i].type;
		elemValue = "";
		regExp = null;
		
		if (thisElem.disabled) {
			continue;
		}

		switch(elemType) {
		case "password"://just go down to text case
		case "select-one":
		case "text":
			if (thisForm["rExp_"+elemName]) {
				regExp = eval(thisForm["rExp_"+elemName].value);
				if (!checkString(thisElem.value, regExp)) {
					if (firstElem == null) {
						firstElem = thisElem;
					}
					if (thisForm["rExpErr_"+elemName]) {
						msg += "    - " + thisForm["rExpErr_"+elemName].value + "\n";
					}
				}
			}
			break;
		case "radio":
			break;
		case "select-multiple":
			break;
		case "checkbox":
			break;
		default:
			//then we don't process b/c it's a hidden field, form button,etc, 
			//so we continue from the top of the for loop
			continue;
			break;
		}//end switch(elemType)
		
		//alert(elemName + ": " + thisForm["req_"+elemName]);
		if (thisForm["req_"+elemName]) {
			//var isFormOk = eval(thisForm["req_"+elemName].value+ "(thisForm, elemName)");
			//if not ok, throw an error msg back and return
			var reqCheck = thisForm[elemName].value;
			if ( reqCheck.length == 0 ) {
				if (firstElem == null) {
					firstElem = thisElem;
				}
				msg += "    - " + thisForm["req_"+elemName].value + "\n";
			}
		}//end if
	}//end for loop

	if (firstElem != null) {
		//need to do this b/c for some stupid reason the \n and \t in hidden text element values
		//does not get picked up correctly so we replace with \n and spaces to indent for each, respectively
		msg = msg.replace(/\\n/g, "\n");
		msg = msg.replace(/\\t/g, "      ");
		msg = "The following field(s) are incomplete or invalid.\n\n" + msg + 
				"\nComplete or correct these fields and re-submit the form.";
		errorMsg(msg, firstElem);
		return false;
	}

	return true;
}//end formRegExpValidate(thisForm)
