//********************* Test du Champ s'il est vide ********************
function vide(s)
{
 if(s=="")
  { return true; }
}
//********************* Test de la taille du champ **********************
function taille(s,t)
{
 if(s.length>t)
  { return true; }
}
//********************* Caracteres speciaux **************************
function carasp(s, b)
  {  
    var i;
    for (i = 0; i < s.length; i++)
    {   
      var c = s.charAt(i);
      if (b.indexOf(c) == -1) return false;
    }
    return true;
  }
//************************** Verification de l'adresse E-mail ************************************
 function Email1(s)
       {
           var i=0;
           var cpt=0;
           var sLength = s.length;
           while (i < sLength)
           { 
             if (s.charAt(i)=="@") {cpt++;}
           i++;
            }
            
             if (cpt==1) return false;
           else   return true;
        }
 function Email2(s)
       {
         var sLength = s.length;
         if ((s.charAt(sLength-4)==".") || (s.charAt(sLength-3)==".")) return false;
            else return true;
       }
/********************************** Test sur pwd=pwd2 ********************************/

function confpwd(s1,s2)
{
 if ( s1 != s2 )
  {
   return(true);
  }
}

/********************************** Test sur la date *********************************/

function tdate(s)
{
if(!carasp(s,"0123456789/")||s.length<10) return true;
  else if((s.charAt(2)!="/")||(s.charAt(5)!="/")) return true;
          else return false;
}


/************************************ ajouter un praragraphe **************************/
function fct_pragraphe()
{
document.forms[fct_pragraphe.arguments[0]].elements[fct_pragraphe.arguments[1]].focus();
valeur=document.forms[fct_pragraphe.arguments[0]].elements[fct_pragraphe.arguments[1]].value;
document.forms[fct_pragraphe.arguments[0]].elements[fct_pragraphe.arguments[1]].value=valeur+"\n<p>\n";
document.forms[fct_pragraphe.arguments[0]].elements[fct_pragraphe.arguments[1]].focus();
}
/************************************ ajouter un retour à la ligne **************************/

function fct_ligne()
{
document.forms[fct_ligne.arguments[0]].elements[fct_ligne.arguments[1]].focus();
valeur=document.forms[fct_ligne.arguments[0]].elements[fct_ligne.arguments[1]].value;
document.forms[fct_ligne.arguments[0]].elements[fct_ligne.arguments[1]].value=valeur+"\n<br>\n";
document.forms[fct_ligne.arguments[0]].elements[fct_ligne.arguments[1]].focus();
}
 /****************************//////////////////////////
function fct_email(a){
if ( a.indexOf(".")==-1 ||  a.indexOf("@")==-1 ||  a.lastIndexOf(".")<a.length-5 ||a.lastIndexOf(".")>=a.length-2)
return true
else
return false
}
// la date 
/*function fct_date(a){

if(!carasp(a, '0123456789/') || a.length>10  || (a.indexOf("/")!=2 && a.indexOf("/")!=1)|| (a.lastIndexOf("/")!=5 &&a.lastIndexOf("/")!=4 &&a.lastIndexOf("/")!=3 ))
return true ;

else

return false;
}*/
// le nombre
function fct_nombre(a){
if (isNaN(a))
return true;
else
return false;
}
function fct_retour(){
history.back();
}
function fct_fichier(a){
if (a.length<3||(a.lastIndexOf(".")!=a.length-3 && a.lastIndexOf(".")!=a.length-4 && a.lastIndexOf(".")!=a.length-5)|| a.lastIndexOf(".")==-1 )
   return true ;
else
return false
}
//**************************************************************************************************
//**************************************************************************************************
// fct_pasplus permet d'enlever le focus à une textearea quand le nombre de caractere est plus que un 
// nombre y a determinéé
// f num de formulaire
// n num d'element 
function fct_pasplus(f,n,y){
var numform;
var numelement;
var nombre_caractere;
    numform=fct_pasplus.arguments[0];
	numelement=fct_pasplus.arguments[1];
	nombre_caractere=(fct_pasplus.arguments[2]-1);
if(document.forms[numform].elements[numelement].value.length > nombre_caractere)
  {
   document.forms[numform].elements[numelement].blur();
   alert('Seulement'+y+' caractères');
  }

}

function fct_date(a){
	 
   var Expression="^[0-9]{1,2}[/]{1}[0-9]{1,2}[/]{1}([0-9]{2}$|[0-9]{4}$)";
   var Verif=new RegExp("\/" ,"g");
   var ExpressionDate=new RegExp(Expression, "g");
  if(!ExpressionDate.test(a))
      {  return true}
	  
  else 
  {// debut else
    var tableau=a.split(Verif);
	var annee=parseInt(tableau[2]); 
	var mois=parseInt(tableau[1]);
	var jour=parseInt(tableau[0]);
	if( mois > 12 ||  jour <1 ||  jour>31|| jour<1 || annee<1){  return true;}
	annee=(annee<10)?annee+2000:annee;
	annee=(annee>10&&annee<100)?1900+annee:annee;
	
//Est-ce que l'année est divisible par 4 et pas 
    vingtNeuf =((annee % 4 ==0 && annee % 100 !=0) || (annee % 400 ==0))?true:false;
	
	if(mois==2 && vingtNeuf &&jour>29){return true;}
	if(mois==2 &&!vingtNeuf&&jour>28){return true;}
   
	
	// moi paire inferieur à 8
	   if(mois%2==0 && mois<8 && jour>30){ return true ;  
	   }
	   
	// moi impaire superieur au moi 8
	 if(mois%2!=0 && mois>8 && jour>30){  return true ; 
	 }

  }// fin else
   return false;
  }
  function Choisir(choix,ou){
    if(choix.options.selectedIndex>=0)
    	{
	    	Element = new Option(choix.options[choix.options.selectedIndex].text,choix.options[choix.options.selectedIndex].value);
			ou.options[ou.options.length]=Element;
			 choix.options[choix.options.selectedIndex]=null;
		}else{
			alert(" Sélectionnée un ou plusieurs personnes ");
		}
	}
//------------------------------------------------------------------------//
//----------------------------------//--------------------//-------------------------------------------------------
function ToutDeplacer(choix,ou){
  var k = choix.options.length ;
		    if(k > 0)
			{
			  for(i=0;i<k;i++){
			  Element=new Option(choix.options[0].text,choix.options[0].value);
			  ou.options[ou.options.length]=Element;
			  choix.options[0]=null;
			 }
			 }
	}
/////////
function isDateValid(chaineDate) {
   if (chaineDate != "") return false
   var ladate = (chaineDate).split("/")
   if ((ladate.length != 3) || isNaN(parseInt(ladate[0])) || isNaN(parseInt(ladate[1])) || isNaN(parseInt(ladate[2]))) return false
   var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]))
   var annee = unedate.getYear()
   if ((Math.abs(annee)+"").length < 4) annee = annee + 1900
   return ((unedate.getDate() == eval(ladate[0])) && (unedate.getMonth() == eval(ladate[1])-1) && (annee == eval(ladate[2])))
}
//----------------------------------------------------------------------------------------------------------
function init(formulaire,nbAnnee,anneeDepart){
	formulaire = "document." + formulaire; 
	document.write('<select name="annee" OnChange="afficheJours('+formulaire+'.mois,this,'+formulaire+'.jours)" style="width:55"><option value=""> Année</option></select>');
	document.write('<select name="mois" OnChange="afficheJours(this,'+formulaire+'.annee,'+formulaire+'.jours)" style="width:55"><option value="">Mois</option></select>');
	document.write('<select name="jours" style="width:55"> <option value="Liste des jours"> Jour</option></select>');
    tabJours = new Array("dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi");
    tabMois = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
    tabAnnee = new Array();
    for(var i = 0 ; i<nbAnnee ; i++)tabAnnee[i] = anneeDepart+i;
    for(var i in tabAnnee)eval(formulaire).annee.options[eval(formulaire).annee.options.length] = new Option(tabAnnee[i],tabAnnee[i]);
    for(var i in tabMois)eval(formulaire).mois.options[eval(formulaire).mois.options.length] = new Option(tabMois[i],i);
}
//------------------------------------------------------------------------------------------------------------
function afficheJours(mois,annee,jours){
	if(annee.options.selectedIndex != 0 && mois.options.selectedIndex != 0){
		jours.options.length = 0;
		currentYear = annee.options[annee.options.selectedIndex].value;
		currentMonth = mois.options[mois.options.selectedIndex].value;
		afficheJourDuMois(jours,currentYear,currentMonth);
	}
}
function afficheJourDuMois(list,currentYear,currentMonth){
	var moisSuivant = 0;	
	var timeMoisCourant = Date.UTC(currentYear, currentMonth, 1);
	if(currentMonth == 11)
	{
		moisSuivant=0;
		annneeSuivante = parseInt(currentYear) + 1;
	}else{
		moisSuivant = parseInt(currentMonth)+1;
		annneeSuivante = currentYear;
	}
	var timeMoisSuivant = Date.UTC(annneeSuivante, moisSuivant, 1);
	var intervalle = timeMoisSuivant - timeMoisCourant;
	var nbJours = intervalle/(24*60*60*1000);
	dt = new Date();
	for(var i = 0; i<nbJours ; i++){
		dt.setTime(timeMoisCourant);
		list.options[list.options.length] = new Option(dt.getDate(),dt.getDate());
		timeMoisCourant = timeMoisCourant + (24*60*60*1000);
	}
}
//----------------------------------------------------------------------------------------------------------------111111
function init1(formulaire,nbAnnee,anneeDepart){
	formulaire = "document." + formulaire; 
	document.write('<select name="annee1" OnChange="afficheJours1('+formulaire+'.mois1,this,'+formulaire+'.jours1)" style="width:55"><option value=""> Année</option></select>');
	document.write('<select name="mois1" OnChange="afficheJours1(this,'+formulaire+'.annee1,'+formulaire+'.jours1)" style="width:55"><option value="">Mois</option></select>');
	document.write('<select name="jours1" style="width:55"><option value="Liste des jours"> Jour</option></select>');
    tabJours = new Array("dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi");
    tabMois = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
    tabAnnee = new Array();
    for(var i = 0 ; i<nbAnnee ; i++)tabAnnee[i] = anneeDepart+i;
    for(var i in tabAnnee)eval(formulaire).annee1.options[eval(formulaire).annee1.options.length] = new Option(tabAnnee[i],tabAnnee[i]);
    for(var i in tabMois)eval(formulaire).mois1.options[eval(formulaire).mois1.options.length] = new Option(tabMois[i],i);
}
function afficheJours1(mois1,annee1,jours1){
	if(annee1.options.selectedIndex != 0 && mois1.options.selectedIndex != 0){
		jours1.options.length = 0;
		currentYear = annee1.options[annee1.options.selectedIndex].value;
		currentMonth = mois1.options[mois1.options.selectedIndex].value;
		afficheJourDuMois1(jours1,currentYear,currentMonth);
	}
}
function afficheJourDuMois1(list,currentYear,currentMonth){
	var moisSuivant = 0;	
	var timeMoisCourant = Date.UTC(currentYear, currentMonth, 1);
	if(currentMonth == 11)
	{
		moisSuivant=0;
		annneeSuivante = parseInt(currentYear) + 1;
	}else{
		moisSuivant = parseInt(currentMonth)+1;
		annneeSuivante = currentYear;
	}
	var timeMoisSuivant = Date.UTC(annneeSuivante, moisSuivant, 1);
	var intervalle = timeMoisSuivant - timeMoisCourant;
	var nbJours = intervalle/(24*60*60*1000);
	dt = new Date();
	for(var i = 0; i<nbJours ; i++){
		dt.setTime(timeMoisCourant);
		list.options[list.options.length] = new Option(dt.getDate(),dt.getDate());
		timeMoisCourant = timeMoisCourant + (24*60*60*1000);
	}
}

//---------------------------------------------------
function init2(formulaire,nbAnnee,anneeDepart){
	formulaire = "document." + formulaire; 
	document.write('<select name="annee2" OnChange="afficheJours2('+formulaire+'.mois2,this,'+formulaire+'.jours2)" style="width:55"><option value=""> Année</option></select>');
	document.write('<select name="mois2" OnChange="afficheJours2(this,'+formulaire+'.annee2,'+formulaire+'.jours2)" style="width:55"><option value="">Mois</option></select>');
	document.write('<select name="jours2" style="width:55"><option value="Liste des jours"> Jour</option></select>');
    tabJours = new Array("dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi");
    tabMois = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
    tabAnnee = new Array();
    for(var i = 0 ; i<nbAnnee ; i++)tabAnnee[i] = anneeDepart+i;
    for(var i in tabAnnee)eval(formulaire).annee2.options[eval(formulaire).annee2.options.length] = new Option(tabAnnee[i],tabAnnee[i]);
    for(var i in tabMois)eval(formulaire).mois2.options[eval(formulaire).mois2.options.length] = new Option(tabMois[i],i);
}
function afficheJours2(mois2,annee2,jours2){
	if(annee2.options.selectedIndex != 0 && mois2.options.selectedIndex != 0){
		jours2.options.length = 0;
		currentYear = annee2.options[annee2.options.selectedIndex].value;
		currentMonth = mois2.options[mois2.options.selectedIndex].value;
		afficheJourDuMois2(jours2,currentYear,currentMonth);
	}
}
function afficheJourDuMois2(list,currentYear,currentMonth){
	var moisSuivant = 0;	
	var timeMoisCourant = Date.UTC(currentYear, currentMonth, 1);
	if(currentMonth == 11)
	{
		moisSuivant=0;
		annneeSuivante = parseInt(currentYear) + 1;
	}else{
		moisSuivant = parseInt(currentMonth)+1;
		annneeSuivante = currentYear;
	}
	var timeMoisSuivant = Date.UTC(annneeSuivante, moisSuivant, 1);
	var intervalle = timeMoisSuivant - timeMoisCourant;
	var nbJours = intervalle/(24*60*60*1000);
	dt = new Date();
	for(var i = 0; i<nbJours ; i++){
		dt.setTime(timeMoisCourant);
		list.options[list.options.length] = new Option(dt.getDate(),dt.getDate());
		timeMoisCourant = timeMoisCourant + (24*60*60*1000);
	}
}
//------
//---------------------------------------------------
function init3(formulaire,nbAnnee,anneeDepart){
	formulaire = "document." + formulaire; 
	document.write('<select name="annee3" OnChange="afficheJours3('+formulaire+'.mois3,this,'+formulaire+'.jours3)" style="width:55"><option value=""> Année</option></select>');
	document.write('<select name="mois3" OnChange="afficheJours3(this,'+formulaire+'.annee3,'+formulaire+'.jours3)" style="width:55"><option value="">Mois</option></select>');
	document.write('<select name="jours3" style="width:55"><option value="Liste des jours"> Jour</option></select>');
    tabJours = new Array("dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi");
    tabMois = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
    tabAnnee = new Array();
    for(var i = 0 ; i<nbAnnee ; i++)tabAnnee[i] = anneeDepart+i;
    for(var i in tabAnnee)eval(formulaire).annee3.options[eval(formulaire).annee3.options.length] = new Option(tabAnnee[i],tabAnnee[i]);
    for(var i in tabMois)eval(formulaire).mois3.options[eval(formulaire).mois3.options.length] = new Option(tabMois[i],i);
}
function afficheJours3(mois3,annee3,jours3){
	if(annee3.options.selectedIndex != 0 && mois3.options.selectedIndex != 0){
		jours3.options.length = 0;
		currentYear = annee3.options[annee3.options.selectedIndex].value;
		currentMonth = mois3.options[mois3.options.selectedIndex].value;
		afficheJourDuMois3(jours3,currentYear,currentMonth);
	}
}
function afficheJourDuMois3(list,currentYear,currentMonth){
	var moisSuivant = 0;	
	var timeMoisCourant = Date.UTC(currentYear, currentMonth, 1);
	if(currentMonth == 11)
	{
		moisSuivant=0;
		annneeSuivante = parseInt(currentYear) + 1;
	}else{
		moisSuivant = parseInt(currentMonth)+1;
		annneeSuivante = currentYear;
	}
	var timeMoisSuivant = Date.UTC(annneeSuivante, moisSuivant, 1);
	var intervalle = timeMoisSuivant - timeMoisCourant;
	var nbJours = intervalle/(24*60*60*1000);
	dt = new Date();
	for(var i = 0; i<nbJours ; i++){
		dt.setTime(timeMoisCourant);
		list.options[list.options.length] = new Option(dt.getDate(),dt.getDate());
		timeMoisCourant = timeMoisCourant + (24*60*60*1000);
	}
}