
// module pour les messages error
function NoError() {
     return true;
}
window.onerror=NoError;

window.defaultStatus=' '+langfunc67+' -- http://www.triade-educ.com';

function getInnerText(elt) {
	var _innerText = elt.innerText;
	if (_innerText == undefined) {
  		_innerText = elt.innerHTML.replace(/<[^>]+>/g,"");
	}
	return _innerText;
}

// pour recharger la page //
function reload() {
         history.go(0)
}

// pour afficher une fenetre au centre
function PopupCentrer(page,largeur,hauteur,options,nom_de_la_fenetre) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  window.open(page,nom_de_la_fenetre,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}


function AfficheAttente() {
	document.getElementById('attenteDiv').style.visibility='visible';
	document['imgattente'].src='./image/commun/indicator.gif';
	document.getElementById('imgattente').src='./image/commun/indicator.gif';
	setTimeout("fini()",3000);
}

function fini() {
	document.getElementById('imgattente').src='./image/commun/indicator.gif';
	document['imgattente'].src='./image/commun/indicator.gif';
}


function eregi( chaine, find ) {
  var norm = new RegExp( find );
  return norm.exec( chaine )!=null;
 // x = prompt( 'Test','Chiffre' );
 // alert( eregi( x , "[\.]" ) );

}




// pour afficher une fenetre au centre l'attente
function PopupCentrerAttente(page,largeur,hauteur,options) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  attente=open(page,'attente',"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

// repertoire racine exemple
function attente() {
    PopupCentrerAttente('attente.php','200','120','')
}


function attente_close() {
   attente.close();return true;
}

// ------------------------------------------------
// verif deja clicker 
var nbclic=0 // Initialisation à 0 du nombre de clic
function dejaclicker() {
    nbclic++; // nbclic+1
    if (nbclic>1) { // Plus de 1 clic
             alert(langfunc51);
     	     return false;
    } else { // 1 seul clic
            //alert("Premier Clic.");
	    return true;
    }
}


//fonction de validation d'après la longueur de la chaîne
function ValidLongueur(item,len) {
   drapeau = 1;
   return (item.length >= len);
}



////////////////////////////////////////////////////////
// affiche un message d'alerte
function error1(elem, text) {
// abandon si erreur déjà signalée
   if (errfound) return;
   window.alert(text);
   elem.select();
   elem.focus();
   errfound = true;
}

// verif du champ de recherche
function verif_recherche() {
     errfound = false;
     if (!ValidLongueur(document.recherche.search.value,3)){
      error1(document.recherche.search,langfunc2); }
return !errfound; /* vrai si il ya pas d'erreur */
}
////////////////////////////////////////////////////////
function delay(gap){ /* gap is in millisecs */
var then,now; then=new Date().getTime();
now=then;
while((now-then)<gap)
{now=new Date().getTime();}
}

////////////////////////////////////////////////////////

// fonction imprimer
function imprimer() {
        var ok=confirm(langfunc3);
        if (ok) {
                window.print();
        }
}

////////////////////////////////////////////////////////
// Fonction quitter session
function quitter_session() {
         var confirmation=confirm(langfunc1+langfunc0)
         if (confirmation) {
             location.href='index1.php?deconnexion';
             //parent.window.close();
         }
}

////////////////////////////////////////////////////////
// Fonction quitter avant session
function quitter_avant_session() {
         var confirmation=confirm(langfunc1+langfunc0)
         if (confirmation) {
             parent.window.close();
         }
}

//////////////////////////////////////////////////////
// function pour les bouton
function buttonMagic(value,lien,name,option,actionpossible) {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><a href='#' onclick=\"open('"+lien+"','"+name+"','"+option+"')"+actionpossible+"\"  >"+value+"</a></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}

function buttonMagicSubmitAtt(value,name,attribut) {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=submit "+attribut+" value='"+value+"' name='"+name+"' ></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}

function buttonMagicSubmit(value,name) {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=submit value='"+value+"' name='"+name+"' ></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}

function buttonMagicSubmit2(value,name,action) {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=submit value='"+value+"' name='"+name+"' onclick=\"this.value='"+action+"'\" ></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}


function buttonMagicSubmit3(value,name,action) {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=submit value='"+value+"' name='"+name+"' "+action+"></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}

function buttonMagicSubmit4(value,name,action) {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type='button' value=\""+value+"\" name='"+name+"' onclick=\""+action+"\"></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}


function buttonMagicReactualise() {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=button value='"+langfunc66+"' onclick=\"history.go(0);\"></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}

// test dans le boutont "Modifier" 
function buttonMagicPrecedent() {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=button value='"+langfunc65+"' onclick=\"history.go(-1);\"></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}

// test dans le boutont "Retour" 
function buttonMagicPrecedent2() {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=button value='"+langfunc63+"' onclick=\"history.go(-1);\"></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}


function buttonMagicImprimer() {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=button value='"+langfunc64+"' onclick=\"imprimer();\"></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}



function buttonMagicFermeture() {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=button value='"+langfunc62+"' onclick=\"parent.window.close();\"></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}

function buttonMagicRetour(lien,fen) {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=button value='"+langfunc63+"' onclick=\"open('"+lien+"','"+fen+"','');\"></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}

function buttonMagicRetour2(lien,fen,nom) {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=button value='"+nom+"' onclick=\"open('"+lien+"','"+fen+"','');\"></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}


function buttonMagic3(nom,lien) {
	document.write("<div style='float:left;margin-left:4px;' class='button1'>");
	document.write("<div class='btnleft1'></div>");
	document.write("<div class='btncenter1'><input type=button value='"+nom+"' onclick=\""+lien+"\"></div>");
	document.write("<div class='btnright1'></div>");
	document.write("</div>");
}


// ----------------------------------------------
function ChangeStatus(formulaire,regagree,validation) {
	var1=formulaire+"."+regagree;
	var1=eval(var1);
	var2=formulaire+"."+validation;
	var2=eval(var2);
	if (var1.checked == true ) {
		var2.disabled=false ;
	}
	if (var1.checked == false ) {
		var2.disabled=true ;
	}
}

//------------------------------------------------
// en dessous à verifier avant nouvelle version

function pasdispo(){
	alert(langfunc50); // verifier aussi
}
function pasdispo1(){
	alert(langfunc51); // verifier aussi
}


function motifbulletin(id,val) {
        if (val == "0") {
                val="";
        }
        var motif="document.formulaire.saisie_text_"+id;
        var motif2=eval(motif);
	var text=tab[val];
	if (text == undefined) {
		text="";
	}
        motif2.value=motif2.value+", "+text;
}



function Compter(Target, compteur,nb) {
	//  onkeyup="Compter(this,this.form.CharRestant,'250');"
	var Nombre_Caracteres_Maximum = nb;
	var StrLen;
    	if (StrLen >= Nombre_Caracteres_Maximum ) {
    		Target.value = Target.value.substring(0,Nombre_Caracteres_Maximum);
    	}
    	StrLen = Target.value.length;
    	compteur.value = Nombre_Caracteres_Maximum-StrLen;
}


function compter(f,max,sortie) {
	var txt=f.value;
	var nb=txt.length;
	if (nb>max) { 
		alert("Pas plus de "+max+" caractères dans ce champ");
		f.value=txt.substring(0,max);
		nb=max;
	}
	sortie.value=nb;
}

function timer() {
	compter(document.forms["formulaire"]);
	setTimeout("timer()",100);
}


function verifDate(mot1) {
	erreur=false;
	mot=eval(mot1);
    	if (mot.length!=10){
		alert("Veuillez introduire votre date au format JJ/MM/AAAA (exemple : 12/02/2010)");
		Erreur=true;
		return Erreur;
	}else{
    		motjour=mot.substring(0,2);motmois=mot.substring(3,5);
    		motan=mot.substring(6,10);motsep=mot.charAt(2)+mot.charAt(5);}
	    	if (isNaN(motjour+motmois+motan)|| motan>3000 ||motan<1900 || motsep!="//"){
			alert("Veuillez introduire votre date au format JJ/MM/AAAA (exemple : 12/02/2010)");
			Erreur=true;
			return Erreur;
		}else {
			choix="";    
    			if (motan-(parseInt(motan/4)*4)==0) {choix="bi"};
	    		if (motan-(parseInt(motan/4)*4)==0&&motan-(parseInt(motan/100)*100)==0)	{choix=""};
    			if (motan-(parseInt(motan/4)*4)==0&&motan-(parseInt(motan/400)*400)==0) {choix="bi"}
    			switch (motmois){
    			case "01": if (motjour<1 || motjour>31){
					alert("Le mois de Janvier comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
					Erreur=true;
					return Erreur; 
				    };
    				    break;
		    	case"02": if(choix=="bi"){
					if(motjour<1 || motjour>29){
						alert("Le mois de Février comporte 29 jours car l'année choisie est bissextile.\nVeuillez choisir une date comprise en 1 et 29.");
						Erreur=true;
						return Erreur;
					}
				   }else{
					if(motjour<1 || motjour>28){
						alert("Le mois de Février comporte 28 jours car l'année choisie n'est pas bissextile.\nVeuillez choisir une date comprise en 1 et 28.");
						Erreur=true;
						return Erreur;
					}
				};
		    		break;
	    		case "03" : if(motjour<1 || motjour>31){alert("Le mois de Mars comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						Erreur=true;
						return Erreur;
				     };
		    		     break;
    			case "04":
					if(motjour<1 || motjour>30){
						alert("Le mois de Avril comporte 30 jours, veuillez choisir une date comprise en 1 et 30.");
						Erreur=true;
						return Erreur;
					};
    					break;
    			case "05":
					if(motjour<1 || motjour>31){
						alert("Le mois de Mai comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						Erreur=true;
						return Erreur;
					};
    					break;
    			case "06":
					if(motjour<1 || motjour>30){
						alert("Le mois de Juin comporte 30 jours, veuillez choisir une date comprise en 1 et 30.");
						Erreur=true;
						return Erreur;
					};
    					break;
    			case "07":
					if(motjour<1 || motjour>31){
						alert("Le mois de Juillet comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						Erreur=true;
						return Erreur;
					};
    					break;
    			case "08":
					if(motjour<1 || motjour>31){
						alert("Le mois de Août comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						Erreur=true;
						return Erreur;
					};
    					break;
		    	case "09":
					if(motjour<1 || motjour>30){
						alert("Le mois de Septembre comporte 30 jours, veuillez choisir une date comprise en 1 et 30.");
						Erreur=true;
						return Erreur;
					};
    					break;
    			case "10":
					if(motjour<1 || motjour>31){
						alert("Le mois de Octobre comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						Erreur=true;
						return Erreur;
					};
    					break;
    			case "11":
					if(motjour<1 || motjour>30){
						alert("Le mois de Novembre comporte 30 jours, veuillez choisirune date comprise en 1 et 30.");
						Erreur=true;
						return Erreur;
					};
    					break;
    			case "12":
					if(motjour<1 || motjour>31){
						alert("Le mois de Décembre comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						Erreur=true;
						return Erreur;
					};
    					break;
    			default:
					alert("Le mois que vous avez entré n'est pas valide. Choisissez un mois compris entre 1 et 12.");
					Erreur=true;
					return Erreur;	
		}
		return Erreur;
	}
}

function verifHeure(mot1) {
	erreur=false;
	mot=eval(mot1);
    	if (mot.length!=5){
		alert("Veuillez introduire votre heure au format hh:mm ");
		Erreur=true;
		return Erreur;
	}else{
    		motheure=mot.substring(0,2);motminute=mot.substring(3,5);
		motsep=mot.charAt(2);
	}
	if (isNaN(motheure+motminute) || motsep!=":"){
		alert("Veuillez introduire votre heure au format hh:mm ");
		Erreur=true;
		return Erreur;
	}else {
		if (motminute > 60) {
			alert("Veuillez introduire votre heure au format hh:mm ");
			Erreur=true;
			return Erreur;
		}	
		if (motheure > 24) {
			alert("Veuillez introduire votre heure au format hh:mm ");
			Erreur=true;
			return Erreur;
		}	
	}
	return Erreur;
}

function verifHeure2(mot1,champs,info1) {

   var info=eval(info1);
   var info2=info.options[info.selectedIndex].value;

if (info2 == "retard") {
	var elem=eval(champs);
	mot=eval(mot1);
    	if (mot.length!=5){
		alert("Veuillez introduire votre heure au format hh:mm ");
		elem.select();
		elem.focus();
		return;
	}else{
    		motheure=mot.substring(0,2);motminute=mot.substring(3,5);
		motsep=mot.charAt(2);
	}
	if (isNaN(motheure+motminute) || motsep!=":"){
		alert("Veuillez introduire votre heure au format hh:mm ");
		elem.select();
		elem.focus();
		return;
	}else {
		if (motminute > 60) {
			alert("Veuillez introduire votre heure au format hh:mm ");
			elem.select();
			elem.focus();
			return;
		}	
		if (motheure > 24) {
			alert("Veuillez introduire votre heure au format hh:mm ");
			elem.select();
			elem.focus();
			return;
		}	
	}
}
if (info2 == "absent") {
	var mot=mot1;
	var elem=eval(champs);
    	if (mot.length!=10){
		alert("Veuillez introduire votre date au format JJ/MM/AAAA (exemple : 12/02/2008)");
		elem.select();
		elem.focus();
		return;
	}else{
    		motjour=mot.substring(0,2);motmois=mot.substring(3,5);
    		motan=mot.substring(6,10);motsep=mot.charAt(2)+mot.charAt(5);}
	    	if (isNaN(motjour+motmois+motan)|| motan>3000 ||motan<1900 || motsep!="//"){
			alert("Veuillez introduire votre date au format JJ/MM/AAAA (exemple : 12/02/2007)");
			elem.select();
			elem.focus();
			return;
		}else {
			choix="";    
    			if (motan-(parseInt(motan/4)*4)==0) {choix="bi"};
	    		if (motan-(parseInt(motan/4)*4)==0&&motan-(parseInt(motan/100)*100)==0)	{choix=""};
    			if (motan-(parseInt(motan/4)*4)==0&&motan-(parseInt(motan/400)*400)==0) {choix="bi"}
    			switch (motmois){
    			case "01": if (motjour<1 || motjour>31){
					alert("Le mois de Janvier comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
					elem.select();
					elem.focus();
					return;
				    };
    				    break;
		    	case"02": if(choix=="bi"){
					if(motjour<1 || motjour>29){
						alert("Le mois de Février comporte 29 jours car l'année choisie est bissextile.\nVeuillez choisir une date comprise en 1 et 29.");
						elem.select();
						elem.focus();
						return;
					}
				   }else{
					if(motjour<1 || motjour>28){
						alert("Le mois de Février comporte 28 jours car l'année choisie n'est pas bissextile.\nVeuillez choisir une date comprise en 1 et 28.");
						elem.select();
						elem.focus();
						return;
					}
				};
		    		break;
	    		case "03" : if(motjour<1 || motjour>31){alert("Le mois de Mars comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						elem.select();
						elem.focus();
						return;
				     };
		    		     break;
    			case "04":
					if(motjour<1 || motjour>30){
						alert("Le mois de Avril comporte 30 jours, veuillez choisir une date comprise en 1 et 30.");
						elem.select();
						elem.focus();
						return;
					};
    					break;
    			case "05":
					if(motjour<1 || motjour>31){
						alert("Le mois de Mai comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						elem.select();
						elem.focus();
						return;
					};
    					break;
    			case "06":
					if(motjour<1 || motjour>30){
						alert("Le mois de Juin comporte 30 jours, veuillez choisir une date comprise en 1 et 30.");
						elem.select();
						elem.focus();
						return;
					};
    					break;
    			case "07":
					if(motjour<1 || motjour>31){
						alert("Le mois de Juillet comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						elem.select();
						elem.focus();
						return;
					};
    					break;
    			case "08":
					if(motjour<1 || motjour>31){
						alert("Le mois de Août comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						elem.select();
						elem.focus();
						return;
					};
    					break;
		    	case "09":
					if(motjour<1 || motjour>30){
						alert("Le mois de Septembre comporte 30 jours, veuillez choisir une date comprise en 1 et 30.");
						elem.select();
						elem.focus();
						return;
					};
    					break;
    			case "10":
					if(motjour<1 || motjour>31){
						alert("Le mois de Octobre comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						elem.select();
						elem.focus();
						return;
					};
    					break;
    			case "11":
					if(motjour<1 || motjour>30){
						alert("Le mois de Novembre comporte 30 jours, veuillez choisirune date comprise en 1 et 30.");
						elem.select();
						elem.focus();
						return;
					};
    					break;
    			case "12":
					if(motjour<1 || motjour>31){
						alert("Le mois de Décembre comporte 31 jours, veuillez choisir une date comprise en 1 et 31.");
						elem.select();
						elem.focus();
						return;
					};
    					break;
    			default:
					alert("Le mois que vous avez entré n'est pas valide. Choisissez un mois compris entre 1 et 12.");
					elem.select();
					elem.focus();
					return;
		}
	}
   }
}


// onKeyPress="onlyChar(event.keyCode)"
// N'autorise que [0-9] et / comme saisie
function onlyChar(_code) {
    if ((_code < 47) || (_code > 57))
      event.returnValue=false
}

// onKeyPress="onlyChar2(event.keyCode)"
// N'autorise que [0-9] et : et / comme saisie
function onlyChar2(_code) {
    if ((_code < 47) || (_code > 58))
      event.returnValue=false
}

// onClick="DisplayLigne('tr<?php print $i ?>');"
function DisplayLigne(id) {
	if (document.getElementById(id).style.backgroundColor == '#c0c0c0') {
		document.getElementById(id).style.backgroundColor='';
	}else{
		document.getElementById(id).style.backgroundColor='#C0C0C0';
	}	
}


//onChange="DisplayLigne2('tr<?php print $i ?>',this.value);"
function DisplayLigne2(id,val) {
	if ((document.getElementById(id).style.backgroundColor == '#c0c0c0') && (val == '0')) {
		document.getElementById(id).style.backgroundColor='';
	}else{
		document.getElementById(id).style.backgroundColor='#C0C0C0';
	}	
}


// ------------------------------------------------------------
function MontrerMenu() { 
// Disance par rapport aux bords de la fenetre 
var EspaceDroit = document.body.clientWidth-event.clientX; 
var EspaceBas = document.body.clientHeight-event.clientY; 

// Affichage du menu suivant la position du curseur 
if (EspaceDroit < CMenu.offsetWidth) 
CMenu.style.left = document.body.scrollLeft + event.clientX - CMenu.offsetWidth; 
else 
CMenu.style.left = document.body.scrollLeft + event.clientX; 

if (EspaceBas < CMenu.offsetHeight){ 
CMenu.style.top = document.body.scrollTop + event.clientY - CMenu.offsetHeight; } 
else{ 
CMenu.style.top = document.body.scrollTop + event.clientY; } 

// Affichage du menu 
CMenu.style.visibility = "visible"; 
return false; 
} 

function MasquerMenu(){ 
CMenu.style.visibility = "hidden"; 
} 
//------------------------------------------------------------
