/*[ Copyright 2006 Sean Colombo and Motive Force LLC.]*/
////
// Author: Sean Colombo
// Date: 20060326
//
// Extracted from signUp.js to validate any form using some basic conventions.
// If the form has an error, it will be set to class formErr, then back to formOkay if no errors are found.
////

////
// Checks the validity of every item in the rules array.
// Each item will itself be an array with the following key mappings (0: object id, 1: regex to match, 2: string to display for errors).
//
// Returns true on success, false on failed validation.
//
// TODO: Make this form focus() the first field with an error in it.
////
function validateForm(rules){
	var errClass = 'formErr';
	var okayClass = 'formOkay';
	var errString = '';
	var retVal = true;
	
	for(var cnt=0; cnt<rules.length; cnt++){
		var currRule = rules[cnt];
		var id = currRule[0];
		var reg = new RegExp(currRule[1]);
		var msg = currRule[2];

		var val = el(id).value;
		if(val.match(reg)){
			el(id).className = okayClass;
		} else {
			el(id).className = errClass;
			if(errString != ''){errString += '\n';}
			errString += msg;
			retVal = false;
		}
	}
	
	if((retVal == 0) && (errString != '')){
		alert(errString);
	}
	return retVal;
}

