// JavaScript creado para la verificacion del correo electronico de la forma de preregistro edl CESSA
// Ene 2008. Martha
// Tomado del ejemplo de Stephen Chapman, Felgall Pty Ltd

function validateEmail(addr,man,db) {
if (addr == '' && man) {
   if (db) alert('Debes escribir una direccion de correo valida');
   return false;
}
if (addr == '') return true;
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('Lo siento, la direccion de correo tiene caracteres invalidos.');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("La direccion de correo tiene caracteres invalidos.");
      return false;
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('La direccon de correo debe tener una  @');
   return false;
}
if (atPos == 0) {
   if (db) alert('La direccion de correo NO debe comenzar con  @');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('La direccion de correo debe tener solo una  @');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('La direccion de correo debe tener un punto para dividir el nombre del dominio');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('el punto no debe estas junto a la  @');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('el punto no debe estas junto a la  @');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('No puedes escribir dos puntos consecutivos');
   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' && suffix != 'mx') {
   if (db) alert('La direccion de correo tiene  un domino invalido');
   return false;
}
return true;
}
