// validate.js
// simple form validation | modified Feb 2005 for Hotwater Beach
// richard morris
// november 2005

// Main function recieves results from all check functions, concatenates the error message and generates an alert
function checkForm(myForm) {
	
	// Get entered values
	var name = myForm.name.value;
	var email = myForm.email.value;
	var message = myForm.message.value;
	var error = "";
		
	// Checks if name field is empty
		if (name.length <= 0) {
			error += "* Name field is incomplete.\n";	
		}
	// Checks if message field is empty
		if (message == "") {
   		error += "* Message field is incomplete.\n";
		}
	// Firstly, checks if email field is empty, if there is a value - the value is checked for correct syntax and invalid chars
		if (email == "") {
   		error += "* Email field is incomplete.\n";
		} else {
			var emailFilter=/^.+@.+\..{2,3}$/;
    		if (!(emailFilter.test(email))) { 
       		error += "* Entered email is invalid.\n";
    		} else {
	 			var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         	if (email.match(illegalChars)) {
          		error += "* Entered email features invalid characters.\n";
       		}
    		}
		}
		if (error != "" ) {
			alert ("The following errors were found:\n" + error);
			return false;
		}
return true;
}
