// WE REQUIRE THE CALENDAR.JS TO BE INCLUDED
var at = /\@/i;
var period = /\./i;

function checkForm(whatForm){
	errorMessage = "";
	if (whatForm.check_required){
		requiredList = whatForm.check_required.value.split(',');
		for (i=0;i<requiredList.length;i++){
			subitem = requiredList[i].split(':');
			if (whatForm[subitem[1]].value.length < 1) errorMessage += subitem[0]+" requires a value.\n";
		}
	}
	if (whatForm.check_special){
		specialList = whatForm.check_special.value.split(',');
		for (i=0;i<specialList.length;i++){
			subitem = specialList[i].split(':');
			if (whatForm[subitem[1]].value.length)
				switch (subitem[2]){
					case 'date':
						if (!ValidateDateForm(whatForm[subitem[1]])) errorMessage += subitem[0]+" is an invalid date (it should be in the format MM/DD/YYYY).\n";	
						break;
					case 'time':
						if (!ValidateTimeForm(whatForm[subitem[1]].value)) errorMessage += subitem[0]+" is an invalid time (it should be in the format HH:MM AM).\n";			
						break;
					case 'email':
						if ((!at.test(whatForm[subitem[1]].value)) || (!period.test(whatForm[subitem[1]].value))) 
							errorMessage += "You must enter a valid email address for "+subitem[0]+".\n";
						break;
				}
		}
	}
	if (errorMessage){
		alert("There was an error with this form:\n"+errorMessage);
		return false;
	}
	return true;
}
