function checkForm()
{
   var cname, cemail, cphone, csubject, cmessage, ccaptcha;
   with(window.document.msgform)
   {
      cname = Name;
      cemail = Email;
      cphone = Phone;
      csubject = Subject;
      cmessage = Comments;
      ccaptcha = captcha
   }

   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(csubject.value) == '')
   {
      alert('Please enter message subject');
      csubject.focus();
      return false;
   }
   else if(trim(cmessage.value) == '')
   {
      alert('Please enter your Comments');
      cmessage.focus();
      return false;
   }
    else if(trim(ccaptcha.value) == '')
   {
      alert('Please enter Image Code');
      ccaptcha.focus();
      return false;
   }
   else
   {
      cname.value    = trim(cname.value);
      cemail.value   = trim(cemail.value);
      cphone.value   = trim(cphone.value);
      csubject.value = trim(csubject.value);
      cmessage.value = trim(cmessage.value);
      ccaptcha.value = trim(ccaptcha.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
        }
