function validEmail(str) {
//Function downloaded from http://www.webreference.com/js/tips/000310.html
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
    return true;
  }
  return false;
}

//// PHONE NUMBER VALIDATION
var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
//////

 

function validateForm(){
        
theForm = document.forms["contact"];

var msg = "";
var focusField = "";

if (theForm.FNAME.value == ""){
msg += "  - First name\n";
focusField = (focusField == "") ? "FNAME" : focusField;
}

if (theForm.LNAME.value == ""){
msg += "  - Last name\n";
focusField = (focusField == "") ? "LNAME" : focusField;
}

if(theForm.EMAIL1.value != ""){
	if (validEmail(theForm.EMAIL1.value)){
	//Do nothing
	} else {
	 msg += "  - Invalid email\n";
	focusField = (focusField == "") ? "EMAIL1" : focusField;
	}
}else{
	msg += "  - Email\n";
	focusField = (focusField == "") ? "EMAIL1" : focusField;
}

if(theForm.EMAIL1.value != theForm.EMAIL2.value){
	msg += "  - Different emails\n";
	focusField = (focusField == "") ? "EMAIL2" : focusField;
}

if ((theForm.PHONE1.value==null)||(theForm.PHONE1.value=="")){
msg += "  - Daytime phone\n";
focusField = (focusField == "") ? "PHONE1" : focusField;
}else{
	if (checkInternationalPhone(theForm.PHONE1.value)==false){
		msg += "  - Valid 10 digit phone number\n";
		focusField = (focusField == "") ? "PHONE1" : focusField;
	}
}


if (theForm.ZIP.value == ""){
msg += "  - Zip code\n";
focusField = (focusField == "") ? "ZIP" : focusField;
}

/*
if (theForm["STUDENTS"][0].selected==true){
msg += "  - Number of students or children\n";
focusField = (focusField == "") ? "STUDENTS" : focusField;
}else{
 if ((theForm.STUDENTS_NAMES.value == "")&&(theForm["STUDENTS"][1].selected!=true)){
  msg += "  - children/students names/ages\n";
  focusField = (focusField == "") ? "STUDENTS_NAMES" : focusField;
 }
}
*/


if (msg == ""){
//Everything is OK submit the form
return true;
} else {
//Display errors:
msgAll = "Please provide or correct the following information:\n";
msgAll += "\n"+msg;
msgAll += "\nClick OK to make corrections.";
alert(msgAll);
eval("theForm." + focusField + ".focus()");
eval("theForm." + focusField + ".select()");
return false;
}

return false;
}