function TesteChaine(champ, nom_champ, longueur, pas_vide) {
        if (nom_champ != "") {
                nom_champ = "'" + nom_champ + "' ";
        }

        if ((pas_vide) && (champ.value == "")) {
                alert("Le champ " + nom_champ + "est vide.");
                champ.focus();
                champ.select();
                return false;
        }

        if (longueur != 0) {
                if (champ.value.length > longueur) {
                        alert("Le champ " + nom_champ + "doit contenir " + longueur + " caractères au maximum.");
                        champ.focus();
                        champ.select();
                        return false;
                }
        }

        return true;
}

// Verification de la validite de la date
function CheckDate (LeChampDate) {
        if (LeChampDate.value != "") {
          LaDate = LeChampDate.value;
          NewDate = LaDate.replace(/[\\ \-\.\:\|*\+\/]+/g, '/');
          if (NS4) {
                  TabVal = NewDate.split(/\b(0?[1-9]|[12][0-9]|3[01])\b\/\b(0?[1-9]|1[0-2])\b\/\b((19|20)[0-9]{2}|[0-9]{2}|[0-9])\b/);
                  Jour = parseInt(TabVal[1], 10);
                  Mois = parseInt(TabVal[2], 10);
                  Annee = parseInt(TabVal[3], 10);
          } else {
                  // Comment faire complique !!!
                  TabVal = NewDate.split('/');
                  Jour = parseInt(TabVal[0], 10);
                  Mois = parseInt(TabVal[1], 10);
                  Annee = parseInt(TabVal[2], 10);
          /*        // Annee de 0 a 99 et de 1950 a 2050
                  if ((Annee < 0) || ((Annee > 99) && (Annee < 1950)) || (Annee >= 2050)) {
                          return false;
                  }*/
          }

          if ((Jour == 0) || (Mois == 0)) {
                  return false;
          }

          if ((Annee >= 0) && (Annee < 99)) {
                  Annee += 2000;
          }

          ChkDate = new Date(Annee, Mois-1, Jour);
          if ((ChkDate.getDate() != Jour) ||
              (ChkDate.getMonth() != Mois-1)) {
                  return false;
          }

          // Vivement l'an 2000
          Annee = ChkDate.getYear();

          if (NS4) {        // 1999 <=> 99 et 2000 <=> 100
                  Annee += 1900;
          } else {        // 1999 <=> 99 et 2000 <=> 2000
                  if ((Annee >= 0) && (Annee <= 99)) {
                          Annee += 1900;
                  }
          }

          LeChampDate.value = Jour+'/'+Mois+'/'+Annee;
        }

        return true;
}

// Verification d'un champ numerique
function TesteNombre(champ, nom_champ, longueur, pas_vide) {
        if (nom_champ != "") {
                nom_champ = "'" + nom_champ + "' ";
        }

        if ((pas_vide) && (champ.value == "")) {
                alert("Le champ " + nom_champ + "est vide.");
                champ.focus();
                champ.select();
                return false;
        }

        champ.value = champ.value.replace(/,/, '.');

        if (isNaN(champ.value)) {
                alert("Le champ " + nom_champ + "doit contenir des chiffres.");
                champ.focus();
                champ.select();
                return false;
        }

        //champ.value = champ.value.replace(/\./, ',')

        var chaine_champ = String(champ.value);
        if ((longueur) && (chaine_champ.length > longueur)) {
                alert("Le champ " + nom_champ + "doit contenir " + longueur + " caractères au maximum.");
                champ.focus();
                champ.select();
                return false;
        }

        return true;
}

// Verification d'un champ email
function TesteEMail(email, longueur, non_vide) {
        if ((email.value == "") && (non_vide)) {
                alert('Le champ de votre adresse email doit être rempli.');
                email.focus();
                email.select();
                return(false);
        }

        if (email.value != "") {
                if (email.value.length <= longueur) {
                        var At = 0;
                        var Point = 0;
                        var I = email.value.length - 3;

                        while (I >= 1) {
                                if (!Point && email.value.charAt(I) == '.') {
                                        Point = 1;
                                } else {
                                        if (Point && (!At && ((email.value.charAt(I) == '@')))) {
                                                At = 1;
                                        } else {
                                                if (email.value.charAt(I) == ' ') {
                                                        I = 0;
                                                }
                                        }
                                }
                                I--;
                        }
                        if ((At != 1) || (Point != 1)) {
                                alert('Vérifiez votre adresse email\nElle ne semble pas valide.');
                                email.focus();
                                email.select();
                                return(false);
                        }
                } else {
                        alert('Le champ de votre adresse email doit contenir au maximum ' + longueur + ' caractères.');
                        email.focus();
                        email.select();
                        return false;
                }
        }

        return true;
}


// fonction permettant l'affichage d'un nombre avec deux chiffres après la virgule
function AfficheFlottant(Nombre) {
        NombreInt = parseInt(Nombre, 10);

        // teste si on a un entier
        if (Nombre == NombreInt) {      // Entier
                Nombre = Nombre + '.00';
        }
        
        // teste si on a un seul chiffre après la virgule
        if (((Nombre - NombreInt) > 0) && ((Nombre - NombreInt) < 1)) {
                Nombre = Nombre + '0';
        }
        
        // variable contenant la troisième décimale pour un éventuel arrondi
        decimal3 = String(Nombre).replace(/((\.|,)\d\d\d).*$/, '$1');
        decimal3 = String(decimal3).substr(String(decimal3).length-1);

        Nombre = String(Nombre).replace(/((\.|,)\d\d).*$/, '$1');
        
        if ((decimal3 >= 5.0) && (decimal3 <= 9.0)) {   // on arrondi à la valeur supérieure
                Nombre = Nombre * 1 + 0.01;
        }
        Nombre = String(Nombre)+'000';
       	Nombre = Nombre.replace(/((\.|,)\d)$/, '$1'+'0');
        Nombre = String(Nombre).replace(/((\.|,)\d\d).*$/, '$1');
       
        return Nombre;
}

