// test si champs est une url correcte
function url_correcte(champs) {
  var urlt = /^http:\/\/[\w.%\/?=&#:;+-]{5,}$/;
  
  reponse = urlt.test(champs.value);
  return reponse;
}

// test si champs est un numero de telephone correct
function tel_correcte(champs) {
  var tel = /^[+]{0,1}[0-9]{8,12}$/;
  
  reponse = tel.test(champs.value);
  return reponse;
}

// test si champs est une adresse e-mail correcte
function mail_correcte(champs) {
  var mail = /^[a-zA-Z0-9]+[a-zA-Z0-9\.-_]+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
  
  reponse = mail.test(champs.value);
  return reponse;
}

// test des champs d'un formulaire
function verif_formulaire(nom_formulaire, nom_langue) {
  var ok = true;

  // test les differents champ du formulaire
  if (nom_formulaire.nom.value == "") {
    if (nom_langue == 'FR') {
      alert("Vous devez saisir : Nom");
    }
    else {
      alert("You must enter : First Name");
    }
    ok = false;
  }
  else if (nom_formulaire.prenom.value == "") {
    if (nom_langue == 'FR') {
      alert("Vous devez saisir : Prénom");
    }
    else {
      alert("You must enter : Last Name");
    }
    ok = false;
  }
  else if (nom_formulaire.societe.value == "") {
    if (nom_langue == 'FR') {
      alert("Vous devez saisir : Société");
    }
    else {
      alert("You must enter : Company");
    }
    ok = false;
  }
  else if (nom_formulaire.email.value != "" && mail_correcte(nom_formulaire.email) == false) {
    if (nom_langue == 'FR') {
      alert("Vous devez saisir une adresse E-mail correct");
    }
    else {
      alert("You must enter an correct E-mail address");
    }
    ok = false;
  }
  else if (tel_correcte(nom_formulaire.tel) == false) {
    if (nom_langue == 'FR') {
      alert("Vous devez saisir un numéro de Téléphone correct");
    }
    else {
      alert("You must enter a correct Telephone number");
    }
    ok = false;
  }
//  else if (url_correcte(nom_formulaire.web) == false) {
//    if (nom_langue == 'FR') {
//      alert("Vous devez saisir un site Web correct");
//    }
//    else {
//      alert("You must enter a correct Web site");
//    }
//    ok = false;
//  }
//  else if (nom_formulaire.categorie.value == 'formulaire' && (nom_formulaire.precision.value == "" || nom_formulaire.precision.value == "                                                                             Espace libre ou vous avez la possibilit&eacute; de mettre votre souhait ou vos attentes")) {
//    if (nom_langue == 'FR') {
//      alert("Vous devez saisir : Votre message");
//    }
//    else {
//      alert("You must enter : Your message");
//    }
//    ok = false;
//  }
  
  return ok;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function openLien(lien, nom, larg, haut, loc, menu, size, asc, stat, tool) {
  if (nom == "") nom = "newWindow";
  param="height="+haut+", width="+larg+", location="+loc+", menubar="+menu+", resizable="+size+", scrollbars="+asc+", status="+stat+", toolbar="+tool;
  var newWindow=window.open(lien, nom, param);
}

function modif(type, id, langue) {
  if (type == "rubrique") {
    fichier = "modif_rubrique";
    id_rubrique = id;
    param="height=550, width=820, location=no, menubar=no, resizable=no, scrollbars=yes, status=yes, toolbar=no";
    var newWindow=window.open("<? print(CHEMIN); ?>./root/index.php?fichier="+fichier+"&id_rubrique="+id_rubrique+"&langue="+langue, '_blank', param);
  }
  if (type == "paragraphe"){
    fichier = "modif_paragraphe";
    id_paragraphe = id;
    param="height=550, width=820, location=no, menubar=no, resizable=no, scrollbars=yes, status=yes, toolbar=no";
    var newWindow=window.open("<? print(CHEMIN); ?>./root/index.php?fichier="+fichier+"&id_paragraphe="+id_paragraphe+"&langue="+langue, '_blank', param);
  }
}

