function validateFormOnSubmit(theForm) {
var reason = "";
	reason += validateName(theForm.name);
	reason += validateHoneypot(theForm.hihuni);
	reason += validatePhone(theForm.phone);
	reason += validateEmail(theForm.email);
	//reason += validateWebsite(theForm.website);
	reason += validateComments(theForm.comments);

      
  if (reason != "") {
	  
	  
    $('#errorli').show('fast');
	$('#errorul').html("").html(reason);
   // alert("Some fields need correction:\n" + reason);
    return false;
  }
  //alert("All fields are filled correctly");
 // return false;
}

function validateHoneypot(fld) {
    var error = "";
 
    if (fld.value.length != "") {
        error = "<li>You Stuck your hand in the honeypot!!</li>"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}


function validateName(fld) {
    var error = "";
 
    if (fld.value.length <= 3) {
        fld.style.background = '#97BFD6'; 
        error = "<li>Please Enter your Name.</li>"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validatePhone(fld) {
    var error = "";
 
    if (fld.value.length <= 3) {
        fld.style.background = '#97BFD6'; 
        error = "<li>Please Enter your Phone Number.</li>"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}


function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#97BFD6';
        error = "<li>Please Enter your Email Address.</li>";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#97BFD6';
        error = "<li>Please check that the email address is correctly formed.</li>";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#97BFD6';
        error = "<li>The email address contains illegal characters.</li>";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateComments(fld) {
    var error = "";
 
    if (fld.value.length <= 3) {
        fld.style.background = '#97BFD6'; 
        error = "<li>Please Enter a Question or Comment.</li>"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}