function ValidateForm(myform) {
	var elementname;						// name attribute
	var elementvalue						// value attribute
	var valid = true;						// becomes false when any error is encountered
	var errData = "";						// names of bad Data fields
	var errReq = "";						// names of missing required fields
	var id, arrid;							// array with contents of form element's id attribute
	var req;								// temp variable for required field check
	var friendly;							// friendly field name string
	var datatype;							// data type, string, eg txt, num, eml, dte
	var strError = "";
	var iTmp1;
	var sTmp1;
	var sTmp2;
	var sTmp3;
	var arremail;
	var LightBody = "#ddddff"

	for (j = 0; j < myform.elements.length; j++) {
		
		elementname = myform.elements[j].name;
		elementvalue = myform.elements[j].value;
		
		req = false;
		friendly = "";
		datatype = "";
		
		// check for an id attribute, and draw out friendly name, etc.
		if (myform.elements[j].id != "") {
			id = myform.elements[j].id;
			arrid = id.split(",")
			friendly = arrid[0];
			if (parseInt(arrid[1])) req = true;
			datatype = arrid[2];
		}

		// reset borders in case they were already highlighted
		//myform.elements[j].style.borderWidth = "";
		//myform.elements[j].style.borderStyle = "";
		//myform.elements[j].style.borderColor = "";
		myform.elements[j].style.backgroundColor = "";

		// check for invalid data type if type was specified and field is not blank
		// as this will be handled later.

		if ((datatype != "") && !(elementvalue == "")) {
			if (datatype == "pwd") {
				if (elementvalue.length < 6) {
					valid = false;
					errData += " -  " + friendly + " Password must be at least 6 characters in length.\n";
					myform.elements[j].style.backgroundColor =LightBody;
				}else if (myform.elements["cmdPasswordConfirm"].value !="" ) {
					if(myform.elements["cmdPasswordConfirm"].value != elementvalue){
						valid = false;
						errData += " -  " + friendly + " Your passwords do not match.\n";
						myform.elements[j].style.backgroundColor =LightBody;
						myform.elements["cmdPasswordConfirm"].style.backgroundColor =LightBody;
					}
				}
			}
			if (datatype == "num") {
				elementvalue = elementvalue.replace("$", "");
				elementvalue = elementvalue.replace(",", "");
				if (isNaN(elementvalue)) {
					valid = false;
					errData += " -  " + friendly + " must be numeric.\n";
					// highlight this problem field
					//myform.elements[j].style.borderWidth = "2px"; 
					//myform.elements[j].style.borderStyle = "solid";
					//myform.elements[j].style.borderColor = "#000000"; 
					myform.elements[j].style.backgroundColor =LightBody; 
				}
			}
			if (datatype == "dte") {
				if (isNaN(Date.parse(elementvalue))) {
					valid = false;
					errData += " -  " + friendly + " must be a valid date.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = LightBody; 
				}
			}
			if (datatype == "eml") {
				// put into an array to enable test for multiple email addresses
				arremail = elementvalue.split(",")
				for (var loop=0; loop < arremail.length; loop++) { 
					// new and improved RegExp
					myRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (arremail[loop].search(myRegExp) == -1  && arremail[loop] !='') {
						valid = false;
						errData += " -  " + friendly + " has an invalid e-mail address:'" + arremail[loop] + "'\n";
						if (loop > 0) {
							errData += "    (separate multiple addresses with ',')\n";
						}
						// highlight this problem field
						myform.elements[j].style.backgroundColor = LightBody; 
					}
				} 
			}
			if (datatype == "tme") {
  				iTmp1 = elementvalue.indexOf(":") 
  				if (iTmp1 == -1) { 
					valid = false;
					errData += " -  " + friendly + " must be a valid time.\n";
					// highlight this problem field
					myform.elements[j].style.backgroundColor = LightBody; 
				}
  				else { 
					sTmp1 = elementvalue.substr(0 , iTmp1) 
					sTmp2 = elementvalue.substr(iTmp1 + 1, 2) 
					sTmp3 = elementvalue.substr(iTmp1 + 4, 2) 
					sTmp4 = elementvalue.substr(iTmp1 + 7)
  				  	if (!((!isNaN(sTmp1)) && (!isNaN(sTmp2)) && (!isNaN(sTmp3)) && (sTmp1>=0) && (sTmp1<24) && (sTmp2>=0) && (sTmp2<60) && (sTmp3>=0) && (sTmp3<60))) {
						valid = false;
						errData += " -  " + friendly + " must be a valid time.\n";
						// highlight this problem field
						myform.elements[j].style.backgroundColor = LightBody; 
					}
				} 
			}
		}
		// check for required field being blank
		if (req && (elementvalue == "")) {
			valid = false;
			errReq += " -  " + friendly + " is required.\n";
			// highlight this problem field
			myform.elements[j].style.backgroundColor = LightBody; 
		}
	}

	if (!valid) {	// if an error occurred, generate the error report display
		
		strError = "The data in these fields are invalid:\n\n"
		if (errReq != "") strError += errReq;
		if (errData != "") strError += errData;
		strError += "\nThe fields requiring attention have been highlighted.\n";
		
		alert(strError);
	}
	return valid;
}

function confirmdelete() {
	return confirm('Deleting this entry can not be undone. Continue?');
}

function openBrWindow(theURL,winName,features) { //v2.0
	winName = window.open(theURL,winName,features);
	winName.focus()
}