// FCT.JS

// Fonctions pour vérifier les formulaires
// testées et approuvées - merci à toutjavascript.com

// Téléphone en 10 chiffres
function is_tel(chaine) {
      var chiffres = new RegExp("^[0-9]{10}$","");
      if (chiffres.test(chaine)) { return 1; }
      else { return 0; }
}

// Caractères alphabétiques majuscules et minuscules et caractères accentués en un seul mot
function is_txt_only_sw(chaine) {
      var txt_only_sw = new RegExp("^[a-zéèâêîôäëïö]+$","i");
      if (txt_only_sw.test(chaine)) { return 1; }
      else { return 0; }
}

// nom ou prénom avec les accents composé ou non (séparé par espace ou tiret)
function is_nom(chaine) {
      var nom = new RegExp("^[a-zéèâêîôûäëïöü]+[ |-]?[a-zéèâêîôûäëïöü]*$","i");
      if (nom.test(chaine)) { return 1; }
      else { return 0; }
}

// adresse mail (courtesy of rOblOche)
function is_mail(chaine) {
      var mail = new RegExp("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)*\\.[\\w-]{2,}$","i");
      if (mail.test(chaine)) { return 1; }
      else { return 0; }
}

// nombre
function is_nombre(chaine) {
      var nombre = new RegExp("^[0-9]+$","");
      if (nombre.test(chaine)) { return 1; }
      else { return 0; }
}

// montant
function is_montant(chaine) {
      var nombre = new RegExp("^[0-9]+([\.|,][0-9]{2})?$","");
      if (nombre.test(chaine)) { return 1; }
      else { return 0; }
}

// Code postal
function is_CP(chaine) {
      var nombre = new RegExp("^[0-9]{5}$","");
      if (nombre.test(chaine)) { return 1; }
      else { return 0; }
}

// date : jj/mm/aaaa
function is_date(chaine) {
      var t_time = new Array();
      var ok=true;
      t_date=chaine.split("/");
      if (t_date.length>3) { ok=false; }
      if ((t_date[0]<1) || (t_date[0]>31)) { ok=false; }
      if ((t_date[1]<1) || (t_date[1]>12)) { ok=false; }
      if ((t_date[2]<2005) || (t_date[2]>2050)) { ok=false; }

      if (ok) { return 1; }
      else { return 0; }

}

// heure : hh:mm
function is_time(chaine) {
      var t_time = new Array();
      var ok=true;
      t_time=chaine.split(":");
      if (t_time.length>2) { ok=false; }
      if ((t_time[0]<0) || (t_time[0]>23)) { ok=false; }
      if ((t_time[1]<0) || (t_time[1]>59)) { ok=false; }
      if (ok) { return 1; }
      else { return 0; }
}

// Fonction pour ouvrir un popup
function popup(title,w,h) {
      var windim="width="+w+",height="+h+",screenX=100,screenY=100,";
      var winopt="directories=no,hotkeys=no,location=no,menubar=no,personalbar=no,scrollbars=no";
      var winopts=windim+winopt;
      var actpopup=window.open('','curpop',winopts);
}
