 function trim(chaine) { 
     // espaces au debut 
     while (chaine.substring(0,1) == ' ') 
         chaine = chaine.substring(1, chaine.length);
 
     // espaces a la fin 
     while (chaine.substring(chaine.length-1,chaine.length) == ' ')
         chaine = chaine.substring(0, chaine.length-1);
    return chaine;
 }

function valide_syntaxe_email(champ)
{
    champ.value = trim(champ.value);
    var checkOK = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-@_.'";
    var checkStr = champ.value;
    var allValid = true;
    var i = 0;
    while ((i < checkStr.length) && (allValid)) {
       allValid = (checkOK.indexOf(checkStr.charAt(i)) == -1)?false:true;
       i ++;
    }
    
    if (!allValid) {
        alert("Ne tapez que lettres, chiffres, et les caractères -@_.'  dans le champ 'Adresse e-mail'.");
        champ.focus() ;
        return (false);
    }
    
    var posiA = checkStr.indexOf('@');
    var posiP = checkStr.lastIndexOf('.');
    if ((posiA < 1) || (posiP < posiA+3) || (checkStr.length < 5) || (posiP > checkStr.length - 3)) {
        alert("Vous avez indiqué une adresse e-mail invalide.");
        champ.focus() ;
        return (false);
    }
    
    return (true);
}

function valide_syntaxe_password(champ)
{
      var longueur = champ.value.length ;
      if (longueur < 4) {
         alert("Le champ Mot de Passe doit comporter plus de 3 caractères");
         champ.focus() ;
      return false;
      }
      var checkOK = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
      var checkStr = champ.value;
      var allValid = true;
      var i = 0;
      var invalid = "";
      var unCar = '';
      while (i < checkStr.length) {
         unCar = checkStr.charAt(i) ;
         if(-1 == checkOK.indexOf(unCar))
         {
            allValid = false;
            if(-1 == invalid.indexOf(unCar))
              invalid += unCar ;
         }
         i ++;
      }
      
      if (!allValid) {
         alert("Les caractères suivant sont interdits dans le mot de passe: " + invalid);
         champ.focus() ;
         return (false);
      }
    
    return (true);
}


