function validateFormOnSubmit(theForm) {
var reason = "";
	reason += validateName(theForm.name);
	reason += validateEmail(theForm.email);
	reason += validateMessage(theForm.message);
	reason += validateSpamTrap(theForm.url);

      
  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 validateName(fld) {
    var error = "";
 
    if (fld.value.length <= 3) {
        fld.style.background = '#a0c5be'; 
        error = "<li>Please enter your name.</li>"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}



function validateSpamTrap(fld) {
    var error = "";
 
    if (fld.value.length != "") {
        error = "<li>Sorry, no Spam Allowed.</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 = '#a0c5be';
        error = "<li>Please enter your email address.</li>";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#a0c5be';
        error = "<li>Please check that the email address is correctly formatted.</li>";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#a0c5be';
        error = "<li>The email address contains illegal characters.</li>";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


function validateMessage(fld) {
    var error = "";
 
    if (fld.value.length <= 3) {
        fld.style.background = '#a0c5be'; 
        error = "<li>Please enter a message.</li>"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
