// JavaScript Document
function checkIt(evt) { //allow only numbers into certain input fields
	evt = (evt) ? evt : window.event 
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		status = "This field accepts numbers only."
		return false
	}
	status =""
	return true
}
//address validator allows only numbers and characters
function letterCheck(field) { 
var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
var ok = true;
var temp;
for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = false;
	}
	if (ok == false) {
	alert("Only letters are accepted in this field");
	field.focus();
	field.select();
	}
}
//Email validator
function validateEmail(temp) { 
	var emailOk  = true
	var temp     = document.diningForm.EmailAddress
	var atSym    = temp.value.indexOf('@')
	var period   = temp.value.lastIndexOf('.')
	var space    = temp.value.indexOf(' ')
	var length   = temp.value.length - 1  
if ((atSym < 1) ||                     
    (period <= atSym+1) ||             
    (period == length ) ||             
    (space  != -1))                    
   {  
      EmailOk = false
      alert('You need to enter a valid email address to proceed!\n\nTry inserting the @ symbol, a comma,\n\nor remove any unnecesary spaces...')
      temp.focus()
	  temp.select();
   }
return emailOk
}
//check to make sure all fields are filled
function isblank(s) {
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ')&& (c != '\n')&& (c != '\t')) return false;
	}
	return true;
}
//form verification invoked from onSubmit() event handler
function verify(f)	{
var msg;
var emptyFields = "";
var errors = "";
	for(var i = 0; i < f.length; i++) {
		var e = f.elements[i];
		if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
			//check for empty field
			if ((e.value == null) || (e.value == "") || isblank(e.value)) {
				emptyFields += "\n          " + e.name;
				continue;
			}
			//check for numeric fields
			if (e.numeric || (e.min != null) || (e.max != null)) { 
				var v = parseFloat(e.value);
				if (isNaN(v) || 
				((e.min != null) && (v < e.min)) || 
				((e.max != null) && (v > e.max))) {
				errors += "- The field " + e.name + " must be a number";
				if (e.min != null)
					errors += " that is greater than " + e.min;
				if (e.max != null && e.min != null)
					errors += " and less than " + e.max;
				else if (e.max != null)
					errors += " that is less than " + e.max;
				errors += ".\n";
			}
		}
	}
}
if (!emptyFields && !errors) return true;
msg = "___________________________________________________________\n\n"
msg += "The form was not submitted because of the following error(s).\n";
msg += "Please correct these error(s) and re-submit.\n";
msg += "___________________________________________________________\n\n"
	if (emptyFields) {
		msg += "- The following required field(s) are empty:"
			+ emptyFields + "\n";
		if (errors) msg += "\n";
	}
	msg += errors;
	alert(msg);
	return false;
}