function validateFormOnSubmit(theForm) {

var reason = "";
	
	reason += validateName(theForm.name);
	reason += validatePhone(theForm.phone);
	reason += validateEmail(theForm.email);
	reason += validateMonth(theForm.month);
	reason += validateDay(theForm.day);
	reason += validateMonthb(theForm.monthb);
	reason += validateDayb(theForm.dayb);
	reason += validateParty(theForm.party);
	
      
  	if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
}

  	alert("Your reservation request has been submitted.  We will contact you promptly.  Thank you!");
  	return true;
}

function validateName(fld) {
var error = "";

	if (fld.value == "") {
	error = "Please enter your name.\n";
}
	return error;
}
  
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   	if (fld.value == "") {
	error = "You didn't enter a phone number.\n";
    
} 	else if (isNaN(stripped)) {
	error = "The phone number contains illegal characters.\n";
    
} 	else if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
}
    return error;
}


function trim(s) {
	return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
	var error="";
    var tfld = trim(fld.value);
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
	error = "You didn't enter an email address.\n";

} 	else if (!emailFilter.test(tfld)) {
	error = "Please enter a valid email address.\n";
    
} 	else if (fld.value.match(illegalChars)) {
	error = "The email address contains illegal characters.\n";
	
}
    return error;
}


function validateMonth(fld) {
	var error = "";

	if (fld.selectedIndex == 0) {
	error = "Please indicate an arrival month.\n";
}
	return error;
}

function validateDay(fld) {
	var error = "";

	if (fld.selectedIndex == 0) {
	error = "Please indicate an arrival day.\n";
}
	return error;
}

function validateMonthb(fld) {
	var error = "";

	if (fld.selectedIndex == 0) {
	error = "Please indicate a departure month.\n";
}
	return error;
}

function validateDayb(fld) {
	var error = "";

	if (fld.selectedIndex == 0) {
	error = "Please indicate a departure day.\n";
}
	return error;
}

function validateParty(fld) {
var error = "";

	if (fld.value == "") {
	error = "Please indicate the size of your party.\n";
}
	return error;
}
// JavaScript Document