/*
Utilisés sur toutes les pages
(fonctions Dreamweaver)
*/
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

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 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_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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function ouvrir(z,p){mywin=window.open(z,'winname',p);}
/* fin fonctions dreamweaver */
/* * initialisation de la zone z-editor (htmlarea) * */
// load htmlarea
var ver_ie_min = 5.5		//version min de IE pour afficher editeur V2
var ver_ie_min_2 = 5.0		//version min de IE pour afficher Z-editor
var win_ie_ver = parseFloat(navigator.appVersion.split('MSIE')[1]);
var agent = navigator.userAgent.toLowerCase();
if (agent.indexOf('mac')        >= 0) { win_ie_ver = 0;}
if (agent.indexOf('windows ce') >= 0) { win_ie_ver = 0;}
if (agent.indexOf('opera')      >= 0) { win_ie_ver = 0;}
var is_gecko = 0;
if ((navigator.product == 'Gecko')) {
	is_gecko = 1;
	if (navigator.productSub < 20021201) {
		is_gecko = 0;
		alert("You need at least Mozilla-1.3 Alpha.\nSorry, your Gecko is not supported.");
	}
	if (navigator.productSub < 20030210) {
		is_gecko = 0;
		alert("Mozilla < 1.3 Beta is not supported!\nI'll try, though, but it might not work.");
	}
}

if (win_ie_ver >= ver_ie_min) {
 _editor_url = 'include/htmlarea/';                     // URL to htmlarea files
 document.write('<script src="' +_editor_url+ 'editor.js" language="Javascript1.2"></script>');  

} else if (win_ie_ver >= ver_ie_min_2) { 
	//utilise Z-Editor, donc rien a initialiser

} else if (is_gecko == 1) { 
 _editor_url = 'include/htmlareav3/';                     // URL to htmlarea files
 _editor_lang = 'fr';                     // Language of htmlarea files
document.write('<script src="' +  _editor_url + 'htmlarea.js"  type="text/javascript" language="Javascript1.2"></script>');
} 


/* ** verification des formulaires ** */
// Fonction pour verifier la validite d'une date
function check_date(field){
  var checkstr = "0123456789";
  var DateField = field;
  var Datevalue = "";
  var DateTemp = "";
  var seperator = "/";
  var day;
  var month;
  var year;
  var leap = 0;
  var err = 0;
  var i;
  err = 0;
  DateValue = DateField.value;
  /* Delete all chars except 0..9 */
  for (i = 0; i < DateValue.length; i++) {
    if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
      DateTemp = DateTemp + DateValue.substr(i,1);
	}
  }
  DateValue = DateTemp;
  /* Always change date to 8 digits - string*/
  /* if year is entered as 2-digit / always assume 20xx */
  if (DateValue.length == 6) {
    DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
  if (DateValue.length != 8) {
     err = 19;}
  /* year is wrong if year = 0000 */
  year = DateValue.substr(4,4);
  if (year == 0) {
     err = 20;
  }
  /* Validation of month*/
  month = DateValue.substr(2,2);
  if ((month < 1) || (month > 12)) {
     err = 21;
  }
  /* Validation of day*/
  day = DateValue.substr(0,2);
  if (day < 1) {
    err = 22;
  }
  /* Validation leap-year / february / day */
  if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
     leap = 1;
  }
  if ((month == 2) && (leap == 1) && (day > 29)) {
     err = 23;
  }
  if ((month == 2) && (leap != 1) && (day > 28)) {
     err = 24;
  }
  /* Validation of other months */
  if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
     err = 25;
  }
  if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
     err = 26;
  }
  /* if 00 ist entered, no error, deleting the entry */
  if ((day == 0) && (month == 0) && (year == 00)) {
     err = 0; day = ""; month = ""; year = ""; seperator = "";
  }
  /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
  if (err == 0) {
     DateField.value = day + seperator + month + seperator + year;
  }
  /* Error-message if err != 0 */
  else {
      return -1;
  }
}
function validite(controle,format,mini,maxi,scale) {
	var retour = true;
// Les differents tests possibles :
// On affecte a la variable 'RE' le test d'expression reguliere souhaite

   // On ne fera les tests que si le champ est rempli d au moins un caractere (pas vide)
	if (controle.value.length > 0) {
      //	I	: Integer
   	if ( format == "I" ) {
   	   RE = /^\d+([\.]|[\,])*\d*$/;
   	   // Si on ne trouve pas dans le champ l expression reguliere recherchee
      	if (format != "C" && !RE.test(controle.value)) {
            // Envoi d'une alerte
            alert('Veuillez saisir un nombre svp.');
            controle.focus();
            controle.select();
            retour = false;
         } else {
            if (scale>0) {
            	controle.value = controle.value.replace(",",".");
		    	if ((controle.value.indexOf(".")!=-1 && (controle.value.substring(0,controle.value.indexOf(".")).length>(maxi-scale-1) || controle.value.substring((controle.value.indexOf(".")+1),controle.value.length).length>scale))
		    		|| (controle.value.indexOf(".")==-1 && controle.value.length>(maxi-scale-1))) {
		        	// Envoi d une alerte
        	   		alert('Veuillez saisir un nombre avec '+(maxi-scale-1)+' chiffres avant la virgule et '+scale+' chiffres après la virgule svp.');
        			controle.focus();
	           		controle.select();
		            retour = false;
		        }
			}
       		if (scale==0) {
            	controle.value = controle.value.replace(",",".");
		    	if (controle.value.indexOf(".")!=-1 ) {
		        	// Envoi d une alerte
        	   		alert('Veuillez saisir un nombre sans chiffres après la virgule svp.');
        			controle.focus();
	           		controle.select();
		            return false;
    	       	}
	       	}
         }
      }
      //	D	: Date (xx/xx/xx ou xx/xx/xxxx ou xx-xx-xx ou xx-xx-xxxx)
   	if ( format == "D" ) {
   	   if (check_date(controle)) {
            // Envoi d une alerte
            alert('Veuillez saisir une date svp.');
            controle.focus();
            controle.select();
            retour = false;
   	   }
   	}
    // Tests de longueur du champ (nombre de caracteres saisis)
      // Si il a ete specifie 0, le test n'est pas effectue
	  if ( mini != 0 ) {

         // Si la longueur de la saisie est inferieure au minimum demande
			if ( controle.value.length < mini ) {
               alert('Le champ est obligatoire. Veuillez saisir au moins ' + mini + ' caractères svp.');
               controle.focus();
               controle.select();
	           retour = false;
			}
      }

      // Si la longueur de la saisie est superieure au maximum demande
		if ( maxi != 0 ) {
			//Si on a un champ File, on ne contrôle que le nom du fichier, pas tout le chemin...
			if (controle.type == "file") {taille = controle.value.substr(Math.max(controle.value.lastIndexOf("\\"),controle.value.lastIndexOf("/"))+1).length;}
			else {taille = controle.value.length;}
			if ( taille > maxi ) {
	   			alert('Vous ne devez pas saisir plus de ' + maxi + ' caractères svp.');
    	        controle.focus();
        	    controle.select();
	            retour = false;
			}
		}
	}
	else{
	   if (mini > 0){
         alert('Ce champ est obligatoire. Veuillez saisir au moins ' + mini + ' caractères svp.');
         controle.focus();
         controle.select();
         retour = false;
	   	}
	}

	return retour;
}

	/* ** test des champs vides lors de la soummission ** */
function getLstFields(myForm){
	var AllIsOk=0;
    var chp = "";

	for (var i=0; i<myForm.elements.length; i++) {
		var inp = myForm.elements[i]; //on recupere le champ dans une variable 
		if (inp.className.match("required","gi")) { //on check si l element a la classe required.
			var myEditor = 'tampon';
			// s il a la classe on regarde son type et on sort une erreur en fonction de son type
			if(inp.type=="text" || inp.type=="file" || inp.type=="password"){
					if (inp.value=="") {
						chp = chp + inp.id +','; 
						AllIsOk++;
					}
				}
				if(inp.type=="textarea"){
					var myf = null;
					if(is_ie6){
						myf = document.getElementById('_'+inp.id+'_editor');
						if(myf){myf=myf.contentWindow.document;}
						if(myf){
							if(myf.body.innerText=='' || myf.body.innerText.split("\n").join().replace(/\,/g,'')==''){
								myEditor='';
							}
						}
					}else{
						myf = document.getElementById('frame'+inp.id);
						if(myf){myf=myf.contentDocument;}
						if(myf){
							if(myf.body.textContent=='' || myf.body.textContent.split("\n").join().replace(/\,/g,'')==''){
								myEditor='';
							}
						}
					}
					
					if ( (inp.value=="" && myf==null) || (myEditor=='' && myf)) {
						chp = chp + inp.id +','; 
						AllIsOk++;
					}
				}
				if(inp.type=="checkbox" || inp.type== "radio"){
					if (!inp.checked) {
						chp= chp+inp.id +',';
						AllIsOk++;
					}
				}
				if(inp.type== "select" || inp.type== "select-multiple" || inp.type== "select-one"){
					if(inp.selectedIndex==-1 || inp.value=="") {
						chp = chp+inp.id +',';
						AllIsOk++;
					}
				}
		}
	}
	return chp;
}
	/* * affichage des messages d alerte et modification du style des champs vides * */
function dspFormAlert(lstField){
	if(lstField!=''){
		var objField = null;
		var strLabel = '';
		var objLabel = null;
		tabField=lstField.split(',');
		for (var i=0; i<tabField.length; i++) {
			objLabel = document.getElementById('label_'+tabField[i]);
			if(objLabel){
				strTemp = objLabel.childNodes[0].nodeValue;
				strLabel = strLabel + strTemp +'\n'; /* liste libelles des champs vides */
			}
			objField = document.getElementById(tabField[i]);
			if(objField){
				objField.style.backgroundColor ="#FADC4B"; /* champ vide surligne en jaune */
				var myf = null;
				if(is_ie6){
					myf = document.getElementById('_'+objField.id+'_editor');
					if(myf){myf=myf.contentWindow.document;}
				}else{
					myf = document.getElementById('frame'+objField.id);
					if(myf){myf=myf.contentDocument;}
				}
				
				if(myf){
					myf.body.bgColor='#FADC4B';/* iframe z-editor vide surligne en jaune */
				}
				
			}
		}
		if(strLabel!=''){
			alert('Attention, la liste de champs suivante est obligatoire : \n'+strLabel+'');
			return false;
		}
	}
	return true;
}
/* * pour la surcharge du onsubmit du formulaire */
var precedentOnSubmit;
	/* * fonction de verification d un formulaire */
function verifierDataFormulaire(strForm){
	var lchp = '';
	var retour = true;
	
	var resLien = verifierFichierLie();
	if(resLien==false){
		return false;
	}
			
	
	/*alert(myForm); */
	myForm=document.getElementById(strForm)
	lchp = getLstFields(myForm);
	//
	
	retour = dspFormAlert(lchp);
	
	if(retour==false){return false};
	
	if (precedentOnSubmit !== undefined) {
		precedentOnSubmit;
	}
	return true;
}
/* ** fin verification des formulaires ** */

/* test si la fiche est publiee */
function isEtatCorrect(chpEtat, condition){
	var etat = document.getElementById(chpEtat);
	if(etat){
		if(etat.value==condition){
			return true;
		}
	}
	return false;
}

/* ouverture logiciel email */
function creerMailTo(destinataire,chpEtat,condition){
	if(isEtatCorrect(chpEtat,condition)){
		if(destinataire!=''){
			window.location='mailto:'+destinataire;
		}
	}
}

/* recuperation d un parametre de l url */
function extractUrlParam(leParam){	

	var t = location.search.substring(1).split('&');
	var f = [];
	for (var i=0; i<t.length; i++){
		var x = t[ i ].split('=');
		f[x[0]]=x[1];
	}

	return f[leParam];

}

/* fonction de recuperation de la valeur d un bouton radio */
function get_radio_value(radioButton) {
	value = "";
	for (var i=0; i < radioButton.length; i++) {
		if (radioButton[i].checked) {
			var value = radioButton[i].value;
		}
	}
	return value;
}

/* fonction permettant de deplacer des elements dans un champ de type SELECT 
	maDirection	: deplacement => -1 = monter (l index diminue) / +1 = descendre (l index augmente) */
function switchValue(monChamp, maDirection){
	var champmax = monChamp.length -2;
	var monElement = monChamp.selectedIndex;
	
	// Gestion des bornes
	if ((monElement < 0) || (monElement < 1 && maDirection == -1) || (monElement > champmax && maDirection == 1)) { return false; }

	// Deplacement
	monOption = new Option( monChamp.options[monElement+maDirection].text, monChamp.options[monElement+maDirection].value );
	
	monChamp.options[monElement+maDirection].text = monChamp.options[monElement].text; 
	monChamp.options[monElement+maDirection].value = monChamp.options[monElement].value; 
	monChamp.options[monElement+maDirection].selected = true;
	
	monChamp.options[monElement].text = monOption.text; 						
	monChamp.options[monElement].value = monOption.value;
	monChamp.options[monElement].selected = false;
	return true;
}
/* fonction permettant d ajouter un element a un champ SELECT */
function addValue(monChamp, maValeur, monLibelle){
	if(maValeur==''){return false}
	var monCompteur = monChamp.length;
	var monOption = new Option( monLibelle, maValeur );
	
	monChamp.options[monCompteur]= monOption;
	monChamp.options[monCompteur].selected = false;
	return true;
}
/* fonction permettant de supprimer un element a un champ SELECT */
function removeValue(monChamp){
	var maTaille = monChamp.length;
	for(j=0; j<maTaille; j++){
		if (monChamp.options[j].selected) {
			monChamp.remove(j);
			maTaille = maTaille-1;
			j = j-1;
		}
	}
	return true;
}