function validateFormOnSubmit(theForm) 
{
	var reason = "";

	reason += validateEmpty(theForm.Name);
	reason += validateEmail(theForm.Email);
	reason += validateEmpty(theForm.Message);

	if (reason != "") 
	{
		alert("Some fields need correction:\n" + reason);
		return false;
	}

	return true;
}

function validateEmpty(fld) 
{
    var error = "";
 
    if (fld.value.length == 0) {
         error = "* The required field " + fld.name + " is empty.\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 = "* The required field Email is empty.\n"
    } else if (!emailFilter.test(tfld)) {
        error = "* The required field Email is invalid.\n"
    } else if (fld.value.match(illegalChars)) {
        error = "* The required field Email contains illegal characters.\n"
    }
    return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "* The required field " + fld.name + " is empty.\n"
    } else if (isNaN(parseInt(stripped))) {
        error = "* The required field " + fld.name + " contains illegal characters.\n"
    }
    return error;
}