function checkMail()
{
  ok = true
  if (document.getElementById("EPOS").value=="")
  {
    alert ("Tik asb jou e-pos adres in.");
    document.getElementById("EPOS").focus();
    ok = false;
  }
  else
  {
    smail = document.getElementById("EPOS").value;
    at_pos = smail.indexOf("@");
    dot_pos = smail.indexOf(".");
    www_pos = smail.indexOf("www.");
    if (at_pos<1 || dot_pos<1 || www_pos>=0)
    {
      alert ("Tik asb 'n geldige e-pos adres in.");
      document.getElementById("EPOS").focus();
      ok = false;
    }
    else
    {
      smail = document.getElementById("EPOS").value;
      condition = "yes";
      var at_count = 0;
      var dot_count = 0;
      var temp = 0;
      for (var i=0;i<smail.length;i++)
      {
         //alert (smail.charCodeAt(i) + '  ' +  smail.charAt(i));
        if ((smail.charCodeAt(i)>0 && smail.charCodeAt(i)<48)||(smail.charCodeAt(i)>57 && smail.charCodeAt(i)<65)||(smail.charCodeAt(i)>91 && smail.charCodeAt(i)<97)||smail.charCodeAt(i)>122||smail.charCodeAt(i)==45||smail.charCodeAt(i)==95)
        {
          if(smail.charAt(i)=="@"||smail.charAt(i)==".")
          {
            // counts the no. of times @ and . appears in EPOS
            if(smail.charAt(i)=="@")
            {
              at_count++;
            }
            else
            {
              dot_count++;
            } 

            if(dot_count>=1)
            {
              dot_pos = i;
              if ((dot_pos>at_pos) && temp==0)
              {
                pos = dot_pos - at_pos;
                temp++;
              }
            }
          }
          else
          {
            if (smail.charCodeAt(i)!=45 && smail.charCodeAt(i)!=95)
            {
              condition = "no";
              i = smail.length;
            }
          }
        }
      }
      if(condition=="no")
      {
        alert ("Tik asb 'n geldige e-pos adres in.");
        document.getElementById("EPOS").focus();
        ok = false;
      }
      else
      {
        if(at_count>1)
        {
          alert ("Tik asb 'n geldige e-pos adres in.");
          document.getElementById("EPOS").focus();
          ok = false;
        }
        else
        {
          if(pos<2)
          {
            alert ("Tik asb 'n geldige e-pos adres in.");
            document.getElementById("EPOS").focus();
            ok = false;
            i = smail.length;
          }
          else
          {
            count = dot_pos + 1;
            domain = "";
            for(count;count<smail.length;count++)
            {
              domain = domain + smail.charAt(count);
            }
            dom=new Array("au","com","net","org","edu","in","mil","gov","arpa","biz","aero","name","coop","info","pro","museum");
            Error = "yes";
            for(var k=0;k<dom.length;k++)
            {
              if(domain==dom[k])
              {
                k = dom.length;
                Error = "no";
              }
            }
            if((Error=="yes" && (domain.length>2)) || (domain.length<2))
            {
              alert ("Tik asb 'n geldige e-pos adres in.");
              document.getElementById("EPOS").focus();
              ok = false;
            }
          }
        }
      }
    }
  }
  return ok;
}

