function checkForm()
{
   var cname, cemail, cphone, cstatecountry, cmessage;
   with(window.document.msgform)
   {
      cname = name;
      cemail = email;
      cphone = phone;
      cstatecountry = statecountry;
      cmessage = comments;
      
   }

   if(trim(cname.value) == '')
   {
      alert('Please enter your name');
      cname.focus();
      return false;
   }
   else if(trim(cemail.value) == '')
   {
      alert('Please enter your email');
      cemail.focus();
      return false;
   }
   else if(!isEmail(trim(cemail.value)))
   {
      alert('Email address is not valid');
      cemail.focus();
      return false;
   }
    else if(trim(cphone.value) == '')
   {
      alert('Please enter your Phone number');
      return false;
   }
   else if(trim(cstatecountry.value) == '')
   {
      alert('Please enter state/country');
      cstatecountry.focus();
      return false;
   }
   else if(trim(cmessage.value) == '')
   {
      alert('Please enter your Comments');
      cmessage.focus();
      return false;
   }
   else
   {
      cname.value    = trim(cname.value);
      cemail.value   = trim(cemail.value);
      cphone.value   = trim(cphone.value);
      cstatecountry.value = trim(cstatecountry.value);
      cmessage.value = trim(cmessage.value);
      return true;
   }
}

function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}
function isEmail(str) {

                var at="@"
                var dot="."
                var lat=str.indexOf(at)
                var lstr=str.length
                var ldot=str.indexOf(dot)
                if (str.indexOf(at)==-1){
                   alert("Invalid E-mail ID")
                   return false
                }

                if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
                   alert("Invalid E-mail ID")
                   return false
                }

                if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
                    alert("Invalid E-mail ID")
                    return false
                }

                 if (str.indexOf(at,(lat+1))!=-1){
                    alert("Invalid E-mail ID")
                    return false
                 }

                 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
                    alert("Invalid E-mail ID")
                    return false
                 }

                 if (str.indexOf(dot,(lat+2))==-1){
                    alert("Invalid E-mail ID")
                    return false
                 }

                 if (str.indexOf(" ")!=-1){
                    alert("Invalid E-mail ID")
                    return false
                 }

                  return true
        }