

//**********************************************************************************		 
  //Teste l'équivalence des valeurs de deux objets, le txtType sert à indiquer dans le message d'erreur de quel type
  // de données il s'agit
function coherence(valeur1, valeur2, txtType)
{
  alert('test coherence');

  if (valeur1.value == "")
  {
    alert (valeur1.name+" ne doit pas être vide");
    return false;
  }
  if (valeur2.value == "")
  {
    alert (valeur2.name+" ne doit pas être vide");
    return false;
  }
  if (valeur1.value == valeur2.value)
  {
    return true;
  }
  else
  {
    alert("Les "+txtType+" ne sont pas identiques !");
    return false;
  }
}
//**********************************************************************************  
// Vérifie un format de numéro de tél. (00.00.00.00.00)
function formatTelephone(valeur)
{
  var resultat = 0;
  if (valeur.value.length != 14)
  {
    resultat++;
  }
  else
  {
    var num = valeur.value;
    var subs = new Array();
    subs[0] = num.substring(0,2);
    subs[1] = num.substring(3,5);
    subs[2] = num.substring(6,8);
    subs[3] = num.substring(9,11);
    subs[4] = num.substring(12,14);
    
    for (i = 0; i < subs.length; i++)
    {
      if (isNaN(subs[i]))
      {
        resultat++;
        break;
      }
    }
  }
  alert(subs[0]+"\n"+subs[1]+"\n"+subs[2]+"\n"+subs[3]+"\n"+subs[4]);
  if (resultat > 0)
  {
    alert("Le numéro de "+valeur.name+" est incorrect\nIl doit suivre le format :\n00.00.00.00.00");
    return false;
  }
  else
  {
    return true;
  }
}
//**********************************************************************************	
//Vérifie si un code postal est valide
function checkCP(valeur)
{
  var num = valeur.value;
  if (isNaN(num)){alert('code postal non valide');return false;}
  if (num == 0){return true;}
  if (valeur.value.length != 5){alert('code postal non valide');return false;}
}
//**********************************************************************************   
  // Cette fonction modifie la couleur de fond 
  // et de police d'une cellule de tableau
function changeCouleur(cellule,couleurFond,couleurPolice) {
  cellule.style.backgroundColor = couleurFond;
  cellule.style.color=couleurPolice;
}	   
//**********************************************************************************
// Redirige vers l'url passé en paramètre
function redirection(url) {
document.location.href=url;
}						
//**********************************************************************************
// affiche 'message' et redirige sur url1 en cas de oui
// et url2 en cas de non
function confirmation (message, url1, url2)
{
	$question = confirm (message);
	if ($question) {
		document.location=url1;
	} else {
		document.location=url2;
	}
} 
//********************************************************************************** 
// Ferme la fenètre en cours du navigateur
function ferme(){
close();
}				
// Retour historique
function retour_histo(){
history.back(1);
}


//**********************************************************************************		 
// Ouvre un popup centré par rapport à la page
function popupcentrer(page,largeur,hauteur,options) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}			  
//**********************************************************************************
//REMPLACE UN CARACTERE PAR UN AUTRE
String.prototype.remplacerTousles=stringCreerremplacerTousles;
function stringCreerremplacerTousles(strChercher,strRemplacement)
	{
	    //if (this.length==0) return ''
		if ((this=="") || (strChercher=="")) return false;
		valeur = this.indexOf(strChercher);
		if (valeur==-1) return this;
		strFinale="";
		strTmp = this;
		while (valeur!= -1)
	{
		strFinale=strFinale.concat(strTmp.substring(0,valeur)).concat(strRemplacement);
		strTmp=strTmp.substr(valeur+strChercher.length);
		valeur=strTmp.indexOf(strChercher);
	}
		strFinale = strFinale.concat(strTmp);
		return strFinale;
	}
//**********************************************************************************	
	String.prototype.estRempli=StringCreerestRempli;
	function StringCreerestRempli()
	{
	texte=this;
	if (texte.length==0){return false;}
	//texte=texte.supprEspaceGauche();
//	if (texte.length==0){return false;}	
	if (texte.length==0)
	{
	//alert (nom.estRempli())
	return false;
	}
	else{
	return true;
	}}

   String.prototype.estEntier=StringCreerEstEntier
   function StringCreerEstEntier()
   {
   if (this==parseInt(this))
  	 {
   return true;
  	 }
   else
  	 {
   return false;
  	 }
   }
    String.prototype.estDecimal=StringCreerEstDecimal
   function StringCreerEstDecimal()
   {
   if (this==parseFloat(this))
  	 {
   return true;
  	 }
   else
  	 {
   return false;
  	 }
   }
   
   String.prototype.estUnNumeroSerie=StringCreernumeroSerie
   function StringCreernumeroSerie()
   {
 strTmp=this;
   if (strTmp.length==8)
  	 {
   return true;
  	 }
   else
  	 {
   return false;
  	 }
   }
   
   
   
      //String.prototype.estDate=verifierDate
	     function verifierDate(d) {
      // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
      // Le séparateur est défini dans la variable separateur
      var amin=1900; // année mini
      var amax=2100; // année maxi
      var separateur="/"; // separateur entre jour/mois/annee
      var j=(d.substring(0,2));
      var m=(d.substring(3,5));
      var a=(d.substring(6));
      var ok=1;
      if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) ) {
         //alert("Le jour n'est pas correct."); 
		 ok=0;
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) ) {
        // alert("Le mois n'est pas correct."); 
		 ok=0;
      }
      if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) ) {
        // alert("L'année n'est pas correcte."); 
		 ok=0;
      }
      if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) ) {
        // alert("Les séparateurs doivent être des "+separateur); 
		 ok=0;
      }
      if (ok==1) {
         var d2=new Date(a,m-1,j);
         j2=d2.getDate();
         m2=d2.getMonth()+1;
         a2=d2.getFullYear();
         if (a2<=100) {a2=1900+a2}
         if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
         //   alert("La date "+d+" n'existe pas !");
            ok=0;
         }
      }
      return ok;
   }

   String.prototype.estMail=verifierMail
   function verifierMail() {
      if ((this.indexOf("@")>=0)&&(this.indexOf(".")>=0)) {
         return true 
      } else {
         alert("Mail !");
         return false
      }
   }
String.prototype.estJpg=verifierJpg
   function verifierJpg() {
      if  ((this.indexOf("JPG")>=0)||(this.indexOf("jpg")>=0)) {
         return true 
      } else {
         alert("type de Fichier invalide !");
         return false
      }
   }
//**************************************************************************************	
String.prototype.estPdf=verifierPdf
   function verifierPdf() {
      if  ((this.indexOf("PDF")>=0)||(this.indexOf("pdf")>=0)) {
         return true 
      } else {
         alert("type de Fichier invalide !");
         return false
      }
   } 
//**************************************************************************************	
String.prototype.estPdfHtmHtml=verifierPdfHtmHtml
   function verifierPdfHtmHtml() {
      if  ((this.indexOf("PDF")>=0)||(this.indexOf("pdf")>=0)||(this.indexOf("htm")>=0)||(this.indexOf("HTM")>=0)||(this.indexOf("html")>=0)||(this.indexOf("HTML")>=0)) {
         return true 
      } else {
         alert("type de Fichier invalide !");
         return false
      }
   }	
//Controle si une date respecte le calendrier 
  function DateIsValid_val(jj, mm, aaaa) {
    if (jj < 1 || jj > 31 || mm < 1 || mm > 12)
      return false;
    if (mm == 2) {
      if (jj == 30 || jj == 31)
        return false;
      if (jj == 29)
        return ((aaaa % 4 == 0 && aaaa % 100 != 0) || aaaa % 400 == 0);
    }
    else if (jj == 31)
      return !( mm == 4 || mm == 6 || mm == 9 || mm == 11 );
    return true;
  }
//**************************************************************************************	
// Vérifie si une date est valide
  function chk_date_format(jj_mm_aaaa) {
    //Declarations
    var delim_char;
    var tab_jma;
    var msg1;
    var msg2;
    var ctrlOK;

    //Corps de la fonction
    //Initialisations
    delim_char = '/';
    msg1 = 'ERREUR :\n- Cette date n\'est pas au format jj/mm/aaaa.\n- Veuillez saisir une date valide.';
    msg2 = 'ERREUR :\n- Cette date n\'est pas valide.\n- Veuillez saisir une date valide.';

    //Verification de la longueur du param
    if (jj_mm_aaaa.value.length !== 10 && jj_mm_aaaa.value.length !== 8) {
      if (jj_mm_aaaa.value != '') {
        window.alert(msg1);
        jj_mm_aaaa.value = '';
        jj_mm_aaaa.focus();
        return false;
      }
    }
    else {
      //Decoupage de la date en jj, mm, aaaa
      tab_jma = jj_mm_aaaa.value.split(delim_char);
      //Verification de la longueur du tableau (3 cases) :
      // [jj][mm][aaaa]
      if (tab_jma.length !== 3) {
        window.alert(msg1);
        jj_mm_aaaa.value = '';
        jj_mm_aaaa.focus();
        return false;
      }
      else {
        //Adaptation des dates en jj/mm/aa en jj/mm/aaaa (pivot 60)
        if (tab_jma[2].length == 2 && !(isNaN(tab_jma[2]))) {
          var _pivot = 60;
          tab_jma[2] = (Number(tab_jma[2])>_pivot) ? (Number(tab_jma[2])+1900).toString() : (Number(tab_jma[2])+2000).toString();
          jj_mm_aaaa.value = tab_jma[0] + delim_char + tab_jma[1] + delim_char + tab_jma[2];
        }
        //Verification de la validite des chaines de caracteres
        //jj, mm, aaaa
        if ((tab_jma[0].length !== 2) || (tab_jma[1].length !== 2) || (tab_jma[2].length !== 4 && tab_jma[2].length !== 2) ||
          (isNaN(tab_jma[0])) || (isNaN(tab_jma[1])) || (isNaN(tab_jma[2])) || (tab_jma[2] <= 0)) {
          window.alert(msg1);
          jj_mm_aaaa.value = '';
          jj_mm_aaaa.focus();
          return false;
        }
        else {
          //Verification de la date dans le calendrier
          ctrlOK = DateIsValid_val(tab_jma[0], tab_jma[1], tab_jma[2]);
          if (! ctrlOK) {
            window.alert(msg2);
            jj_mm_aaaa.value = '';
            jj_mm_aaaa.focus();
            return false;
          }
        }
      }
    }
    return true;
  }
//**************************************************************************************	
// ?
  function evalDate(_date) {
    //Declarations
    var delim_char;
    var tab_jma;

    //Corps de la fonction
    //Initialisations
    delim_char = '/';
    //Decoupage de la date en jj, mm, aaaa
    tab_jma = _date.split(delim_char);
    // Pas besoin de verif, car la fonction precedente l'a deja faite
    return (tab_jma[2]+tab_jma[1]+tab_jma[0]);
  }	
  
//**************************************************************************************	
//N'autorise que [0-9] et / comme saisie
function onlyChar(_code) 
{
if ((_code < 47) || (_code > 57))
event.returnValue=false
}
//**************************************************************************************	
// donne le focus à un champ
 function prendre_focus(form,champ)
{
document.form.elements[champ].focus();
}
//**************************************************************************************	
// Ajoute la page aux favoris
function ajouter_favoris(){
	if (document.all) 
	{ 
	window.external.AddFavorite(location.href, document.title); 
	} 
	else 
	{ 
	alert('Vous pouvez faire CTRL + D pour ajouter cette page dans vos signets, ou favoris.') 
	} 
}
//**************************************************************************************	
// Ferme la page en cours
function fermer(){
close();
}
//**************************************************************************************	
function FormatUpload(fichier,ext_ok){
	if(fichier=="") return true;		
	var ok = false;
	fichier_ext_pos = fichier.lastIndexOf(".");
	fichier_ext = fichier.substring(fichier_ext_pos);
	fichier_ext = fichier_ext.toLowerCase();
	for (var i = 0; i < ext_ok.length; i++) {
		if (ext_ok[i] == fichier_ext){ ok = true; break; }
	}
	if (ok){
		return true;
	}else{
		alert("Le fichier founis n'est pas de type 'jpg' ou 'jpeg'");
		return false;
	}
}
