function formvalidator()
{
  var txtname  = trimAll(document.getElementById('txtname').value);
  var txtemail = trimAll(document.getElementById('txtemail').value);
  var txtmess  = trimAll(document.getElementById('txtmessage').value);
  
    if(txtmess==0 || txtemail==0 || txtname==0)
       {
         alert("all fields are required.");
         return false;
       }
    else
      {
         txtemail = document.getElementById('txtemail').value;
         if(validate(txtemail)==true)
            document.getElementById('form_contact').submit();
         else
            alert("Invalid Email format");
      }

}


//-------------- SUPPPORTING FUNCTIONS -------------------------------------------------

function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}

return sString.length;

}


// Email validator
function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false)
      {
        return false;
      }
   else
       return true;
}

// --------------------- END OF SUPPORTING FUNCTIONS -------------------------------------------