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;
}


function validateForm(){
        
theForm = document.forms["contact"];

var msg = "";
var focusField = "";

if (theForm.name.value == ""){
msg += "  - Name\n";
focusField = (focusField == "") ? "name" : focusField;
}

if(theForm.email.value != ""){
	if (validEmail(theForm.email.value)){
	//Do nothing
	} else {
	 msg += "  - Invalid email\n";
	focusField = (focusField == "") ? "email" : focusField;
	}
}else{
	msg += "  - Email\n";
	focusField = (focusField == "") ? "email" : focusField;
}

if (theForm.phone.value == ""){
msg += "  - Telephone\n";
focusField = (focusField == "") ? "phone" : focusField;
}

if (theForm.comments.value == ""){
msg += "  - Comments\n";
focusField = (focusField == "") ? "comments" : 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;
}