// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateEmail(addr,man,db) {
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
if(addr == ""){
return true;	
}
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('adresse e-mail contient des caractères incorrects');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("adresse e-mail contient des caractères d'ASCII.");
      return false;
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('adresse e-mail doit contenir un @');
   return false;
}
if (atPos == 0) {
   if (db) alert('adresse e-mail ne doit pas commencer par @');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('adresse e-mail doit contenir un seul @');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('adresse e-mail doit contenir une période dans le nom de domaine');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('période ne doit pas immédiatement suivre @ dans l adresse e-mail');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('période ne doit pas précéder immédiatement @ dans l adresse e-mail');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('deux périodes ne doit pas être adjacent à l adresse e-mail');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('invalide domaine principal dans l adresse e-mail');
   return false;
}
return true;
}

function multiEmail(email_field) {
var email = email_field.split(',');
for (var i = 0; i < email.length; i++) {
   if (!validateEmail(email[i], 1, 0)) {
      alert('une ou plusieurs adresses e-mail indiquée est incorrecte');
      return false;
   }
}
return true;
}
