function ereg_words(car, data){
   var err = false;
   var cnt = data.length;
   len = car.length;
   for(i=0;i<cnt;i++){
       errm = false;
       chrm = data.charAt(i).toLowerCase();
       for(k=0;k<len;k++) if(car.charAt(k)==chrm) errm = true;
       if(!errm) err = true;
   }
   return err;
} // End ereg_words() -----------

function check_mail(mail){

   // car -> list acceptable words
   var car = "0123456789.abcdefghijklmnopqrstuvwxyz_@-";
   // ext -> list extension domain words
   var ext = "abcdefghijklmnopqrstuvwxyz";

   /**
   * if you not use return(), is necesary to put elseif()
   */
	
   if(ereg_words(car, mail)) return "01"; // contain invalid caracter(s)
   expMail = mail.split("@");
  
   if(expMail.length==1) return "02"; // invalid format
   if(expMail.length>2) return "03"; // contain multi @ caracters
   else{
       if(expMail[0]=="") return "04"; // begin at @ is empty
       if(expMail[1].length<3) return "05"; // after @ invalid format
       expSep = expMail[1].split(".");
       if(expSep.length==1) return "06"; // invalid format domain host
       else{
           if(expSep[expSep.length-2]=="") return "07"; // domain name is empty
           if(expSep[expSep.length-1].length < 2 || expSep[expSep.length-1].length > 4) return "08"; // invalid extension domain
           if(ereg_words(ext, expSep[expSep.length-1])) return "09"; // extension domain contain invalid caracter(s)
       }
   }

   return mail;

} 
