function validateForm(thisForm)
{
	//Here's a hook to disable form validation
	//If there is a variable "skipValidation" defined globally and its value is set to
	//the number 1, then we skip validation and return true
	if(typeof skipValidation != "undefined"){
		if(skipValidation == 1){
			return true;
		}
	}
	
	var errMsg ="";
	
	//Loops through each MetaData object and runs the appropriate tests
	//if one failure condition is found, the remainder of the code for the loop
	//is skipped and the next MetaData object is checked ... (We don't want
	//to print out multiple error messages for the same field)
	for(var x=0; x<validationDescriptor.length; x++)
	{
		var cur = validationDescriptor[x];
		
		//A little hack here ....
		//If a developer gets sloppy when building the validationDescriptor in the Servlet
		//and accidentally puts a trailing comma in the declaration of validationDescriptor,
		//the length property reports an extra row in the array ... so this just checks
		//for that special case and bails if it occurs
		if(typeof cur == "undefined")
			break;
		
		var formField = eval("thisForm." + cur.fieldName);
		
		if(cur.minlength > 0 && formField.value.length < cur.minlength){
			errMsg += cur.fieldNamePretty;
			
			if(cur.minlength > 1)
				errMsg += " cannot be less than " + cur.minlength + " characters long.\n";
			else
				errMsg += " is required.\n";
				
			continue;
		}

		if(cur.maxlength > 0 && formField.value.length > cur.maxlength){
			errMsg += cur.fieldNamePretty + " cannot be more than " + cur.maxlength + " character(s) long.\n";
			continue;
		}
		
		if(cur.minlength > 0 && cur.fieldType == "INTEGER" && isNaN(parseInt(formField.value))){
			errMsg += cur.fieldNamePretty + " must be an integer value\n";
			continue;
		}
		
		if(cur.minlength > 0 && cur.fieldType == "FLOAT" && isNaN(parseInt(formField.value))){
			errMsg += cur.fieldNamePretty + " must be a numeric value.\n";
			continue;
		}
		
		//Check to make sure that there is a field in the datastruct called "filter" first
		if(typeof cur.filter != "undefined")
		{
			//If the field isn't blank
			if(cur.filter != "" && formField.value.length > 0)
			{
				re = new RegExp(cur.filter);
				
				//Test it against the reg exp
				if(!re.test(formField.value)){
					errMsg += cur.fieldNamePretty + " is not in the proper format.\n";
					continue;
				}
				
			}
		}
	}
	
	//Check to see if there is a method called extraValidation() defined on the form, if so, call it
	//extraValidation = eval("extraValidation");
	if(typeof extraValidation != "undefined")
	{
		errMsg += extraValidation(thisForm);
	}
	
	if(errMsg.length == 0)
	{
		//alert("All is well");
		return true;
	}
	else
	{	
		alert("The following error(s) need to be fixed before the form can be submitted:\n\n" + errMsg);
		return false;
	}
}

//Workaround for "double-click" problem
function onSubmitButton(inForm, buttonName){

	var button = event.srcElement;

	if(validateForm(inForm)){
		button.disabled = true;
		inForm.button.value = buttonName;
		inForm.submit();
	}
}
