//////////////////////////////////////////////////////////////
// Librairie   : date.js
// Description : gestion des dates
//
// Date de creation     :   18/09/2001		Auteur : DUCLOS
//         
//////////////////////////////////////////////////////////////
// variables globales
var VGjj;
var VGmm;
var VGaa;
var VGss;
var VGssaa;
var VGdateok = true;
var VGpivot = 80;
var VGmoisarray = new Array(13);
var l_champ;
/*************************************************************
* FinitDateDuJour : initialise le champ a la date du jour
* VPchamp : champ du formulaire de type date
**************************************************************/
function FinitDateDuJour(VPchamp)
{ var jj, mm, aa, ssaa, VLdateFormate;
  var VLdate = new Date();
  jj =  String(VLdate.getDate());
  if (jj.length < 2) jj = '0' + jj;
  mm = String((VLdate.getMonth())+ 1);
  if (mm.length < 2) mm = '0' + mm;
  aa =  VLdate.getYear();
//  ssaa = 1900 + aa;
//  VLdateFormate = jj+"/"+mm+"/"+ssaa;

if (navigator.appName.indexOf("Netscape") != -1) {
		aa = aa - 100;
		if (aa < 10) {
                     aa = "200" + aa;
                           }else{
                     aa = "20" + aa;}        
              }
        
  VLdateFormate = jj+"/"+mm+"/"+aa;
  VPchamp.value = VLdateFormate;
  return true;
}

/*************************************************************
* FreturnDateDuJour : renvoie la date du jour
**************************************************************/
function FreturnDateDuJour()
{ var jj, mm, aa, ssaa, VLdateFormate;
  var VLdate = new Date();
  jj =  String(VLdate.getDate());
  if (jj.length < 2) jj = '0' + jj;
  mm = String((VLdate.getMonth())+ 1);
  if (mm.length < 2) mm = '0' + mm;
  aa =  VLdate.getYear();
  //  ssaa = 1900 + aa;
  //  VLdateFormate = jj+"/"+mm+"/"+ssaa;
if (navigator.appName.indexOf("Netscape") != -1) {
		aa = aa - 100;
		if (aa < 10) {
                     aa = "200" + aa;
                           }else{
                     aa = "20" + aa;}        
              }       
  VLdateFormate = jj+"/"+mm+"/"+aa;
  return VLdateFormate;
}


/*************************************************************
* FrepriseDate : verifie si le champ est une date valide
* VPchampSrc : element du formulaire source
* VPchampDst : element du formulaire destination
**************************************************************/
function FrepriseDate(VPchampSrc, VPchampDst)
{ if ( VPchampDst.value != "" ) return false;
  if ( ! FvaliderDate(VPchampSrc) ) return false;
  VPchampDst.value = VPchampSrc.value;
  return true;
}


/**************************************************************
* FvaliderDate : validation du format date de (VPchamp)         
* l annee pivot (VPpivot/passage an 2000 d'ou pivot=20) est passee en parametre et le nom du champ (Champ)
**************************************************************/
function FvaliderDate(VPchamp,VPpivot,Champ) 
{ 
l_champ=Champ;
VGpivot = VPpivot;
// initialisation du tableau du nb de jours par mois
Finitialisertableau()
 
// variables locales
var VLvaleurChampDate = String (VPchamp.value);
var VLlongueurdate = VLvaleurChampDate.length;

// determinantion du format de la date saisie. si
// la date n'a pas une longueur valide --> message d'erreur.
{ 
if ( VLlongueurdate == 0) return
else
if ( VLlongueurdate == 6)
 { Ftrtlong6(VPchamp)
 }
   else {if ( VLlongueurdate == 7)
           { Ftrtlong7(VPchamp);
           } 
      else {if ( VLlongueurdate == 8)
          { Ftrtlong8(VPchamp);
          } 
         else { if ( VLlongueurdate == 9)
                   { Ftrtlong9(VPchamp);
                   }
                else { if ( VLlongueurdate == 10)
                     { Ftrtlong10(VPchamp);
                     }
                       else
                         {VGdateok = false;
                         FmessageDate(VPchamp,1);}
                     }   
               }
	   }
      }
 
} 

{ 

// test de numericite sur annee mois jour. si non numerique --> message erreur
if (VGdateok == true) 
  {
FvaliderDateEntier(VPchamp, VGssaa);
  }
if (VGdateok == true) 
  {
FvaliderDateEntier(VPchamp, VGmm);
  }
if (VGdateok == true) 
  {
FvaliderDateEntier(VPchamp, VGjj);
  }

// determinantion de la bissextilite de l annee
if (VGdateok == true) 
  {
Fbissextile();

// validation du numero de jour du numero de mois et coherence des deux
FValidation(VPchamp);
  }
}

// mise en forme du champ date au format jj/mm/ssaa
{if (VGdateok == true) 
    { VPchamp.value = VGjj + "/" + VGmm + "/" + VGssaa ;
      return true ;
    }

   else {
   VGdateok = true;
   return false;
        }  ;
}
}

/* Validation de la date si saisie (date non obligatoire)*/
function FvaliderDateNonOblig(VPchamp,VPpivot,Champ)
	{ 
	var VPchamp2 = VPchamp.value.trim();
	if (VPchamp2 != "")
		{FvaliderDate(VPchamp,VPpivot,Champ);}
	}

/****************************************************************
* Ftrtlong6() : verification de numericite des champs de la date
*               j/m/aa ou jjmmaa 
*****************************************************************/
function Ftrtlong6(VPchamp)
{
 var VLvaleurChampDate = String (VPchamp.value);
 {if ((VLvaleurChampDate.charAt(1) == " " && VLvaleurChampDate.charAt(3) == " ") ||
     (VLvaleurChampDate.charAt(1) == "/" && VLvaleurChampDate.charAt(3) == "/") ||
     (VLvaleurChampDate.charAt(1) == "-" && VLvaleurChampDate.charAt(3) == "-"))
 {VGjj = "0" +  VLvaleurChampDate.charAt(0);
  VGmm = "0" +  VLvaleurChampDate.charAt(2);
  VGaa = VLvaleurChampDate.charAt(4) +  VLvaleurChampDate.charAt(5);
 } 
else
 {VGjj = VLvaleurChampDate.charAt(0) +  VLvaleurChampDate.charAt(1);
  VGmm = VLvaleurChampDate.charAt(2) +  VLvaleurChampDate.charAt(3);
  VGaa = VLvaleurChampDate.charAt(4) +  VLvaleurChampDate.charAt(5);
 }
}
Fpivot();
return;
}

/*****************************************************************
* Ftrtlong7(VPchamp) : j/mm/aa ou jj/m/aa
*               
******************************************************************/
function Ftrtlong7(VPchamp)
{
 var VLvaleurChampDate = String (VPchamp.value);
 {if ((VLvaleurChampDate.charAt(1) == " " && VLvaleurChampDate.charAt(4) == " ") ||
     (VLvaleurChampDate.charAt(1) == "/" && VLvaleurChampDate.charAt(4) == "/") ||
     (VLvaleurChampDate.charAt(1) == "-" && VLvaleurChampDate.charAt(4) == "-"))
    {VGjj = "0" +  VLvaleurChampDate.charAt(0);
     VGmm = VLvaleurChampDate.charAt(2) +  VLvaleurChampDate.charAt(3);
     VGaa = VLvaleurChampDate.charAt(5) +  VLvaleurChampDate.charAt(6);
    } 
  else
   { if
    ((VLvaleurChampDate.charAt(2) == " " && VLvaleurChampDate.charAt(4) == " ") ||
     (VLvaleurChampDate.charAt(2) == "/" && VLvaleurChampDate.charAt(4) == "/") ||
     (VLvaleurChampDate.charAt(2) == "-" && VLvaleurChampDate.charAt(4) == "-"))
     {VGjj = VLvaleurChampDate.charAt(0) +  VLvaleurChampDate.charAt(1);
     VGmm = "0" +  VLvaleurChampDate.charAt(3);
     VGaa = VLvaleurChampDate.charAt(5) +  VLvaleurChampDate.charAt(6);
     }
     else 
     { FmessageDate(VPchamp,0);
     }   
   }
 }
Fpivot();
return;
}

/*****************************************************************
* Ftrtlong8(VPchamp) : analyse du type de date traite et redirection
*               vers les procedures voulues
*           Ftrtlong8Sep(): date de type jj/mm/aa
*           Ftrtlong8SansSep() : date du type jjmmssaa
******************************************************************/
function Ftrtlong8(VPchamp)
{
var VLvaleurChampDate = String (VPchamp.value);
if ((VLvaleurChampDate.charAt(2) == " " && VLvaleurChampDate.charAt(5) == " ") ||
    (VLvaleurChampDate.charAt(2) == "/" && VLvaleurChampDate.charAt(5) == "/") ||
    (VLvaleurChampDate.charAt(2) == "-" && VLvaleurChampDate.charAt(5) == "-"))
    Ftrtlong8Sep(VPchamp, VLvaleurChampDate);
else {if 
      ((VLvaleurChampDate.charAt(1) == " " && VLvaleurChampDate.charAt(3) == " ") ||
       (VLvaleurChampDate.charAt(1) == "/" && VLvaleurChampDate.charAt(3) == "/") ||
       (VLvaleurChampDate.charAt(1) == "-" && VLvaleurChampDate.charAt(3) == "-")) 
	    Ftrtlong8AveSep(VPchamp, VLvaleurChampDate);
      else Ftrtlong8SansSep(VPchamp, VLvaleurChampDate);
     }
return;
} 

/****************************************************************
* Ftrtlong8Sep(VPchamp) : traitement date du type jj/mm/aa 	*
*           							*
*****************************************************************/
function Ftrtlong8Sep(VPchamp, VPvaleurChampDate)
{
VGjj = VPvaleurChampDate.charAt(0) +  VPvaleurChampDate.charAt(1);
VGmm = VPvaleurChampDate.charAt(3) +  VPvaleurChampDate.charAt(4);
VGaa = VPvaleurChampDate.charAt(6) +  VPvaleurChampDate.charAt(7);
 Fpivot();
 return;
}

/****************************************************************
* Ftrtlong8Sep(VPchamp) : traitement date du type j/m/ssaa 	*
*           							*
*****************************************************************/
function Ftrtlong8AveSep(VPchamp, VPvaleurChampDate)
{
VGjj = "0" + VPvaleurChampDate.charAt(0);
VGmm = "0" + VPvaleurChampDate.charAt(2);
VGssaa = VPvaleurChampDate.charAt(4) +  VPvaleurChampDate.charAt(5) +  VPvaleurChampDate.charAt(6) +  VPvaleurChampDate.charAt(7);
return;
}

/****************************************************************
* Ftrtlong8SansSep(VPchamp) : traitement date du type jjmmssaa  *
*****************************************************************/
function Ftrtlong8SansSep(VPchamp, VPvaleurChampDate)
{

VGjj = VPvaleurChampDate.charAt(0) +  VPvaleurChampDate.charAt(1);
VGmm = VPvaleurChampDate.charAt(2) +  VPvaleurChampDate.charAt(3);
VGssaa = VPvaleurChampDate.charAt(4) +  VPvaleurChampDate.charAt(5) + VPvaleurChampDate.charAt(6) +  VPvaleurChampDate.charAt(7);
 return;
}



/*****************************************************************
* Ftrtlong9(VPchamp) : j/mm/ssaa ou jj/m/ssaa
*               
******************************************************************/
function Ftrtlong9(VPchamp)
{
 var VLvaleurChampDate = String (VPchamp.value);
 {if ((VLvaleurChampDate.charAt(1) == " " && VLvaleurChampDate.charAt(4) == " ") ||
      (VLvaleurChampDate.charAt(1) == "/" && VLvaleurChampDate.charAt(4) == "/") ||
      (VLvaleurChampDate.charAt(1) == "-" && VLvaleurChampDate.charAt(4) == "-"))
    {VGjj = "0" +  VLvaleurChampDate.charAt(0);
     VGmm = VLvaleurChampDate.charAt(2) +  VLvaleurChampDate.charAt(3);
     VGssaa = VLvaleurChampDate.charAt(5) +  VLvaleurChampDate.charAt(6) +  VLvaleurChampDate.charAt(7) +  VLvaleurChampDate.charAt(8);
    } 
  else
    { if
    ((VLvaleurChampDate.charAt(2) == " " && VLvaleurChampDate.charAt(4) == " ") ||
     (VLvaleurChampDate.charAt(2) == "/" && VLvaleurChampDate.charAt(4) == "/") ||
     (VLvaleurChampDate.charAt(2) == "-" && VLvaleurChampDate.charAt(4) == "-"))
      {VGjj = VLvaleurChampDate.charAt(0) +  VLvaleurChampDate.charAt(1);
      VGmm = "0" +  VLvaleurChampDate.charAt(3);
      VGssaa = VLvaleurChampDate.charAt(5) +  VLvaleurChampDate.charAt(6) +  VLvaleurChampDate.charAt(7) +  VLvaleurChampDate.charAt(8);
      }
      else 
      { FmessageDate(VPchamp,0);
      }   
    }
 }
return;
}

/****************************************************************
* Ftrtlong10(VPchamp) : traitement date du type jj/mm/ssaa      *
*****************************************************************/
function Ftrtlong10(VPchamp)
{
var VLvaleurChampDate = String (VPchamp.value);
if ((VLvaleurChampDate.charAt(2) == " " && VLvaleurChampDate.charAt(5) == " ") ||
    (VLvaleurChampDate.charAt(2) == "/" && VLvaleurChampDate.charAt(5) == "/") ||
    (VLvaleurChampDate.charAt(2) == "-" && VLvaleurChampDate.charAt(5) == "-"))

{ VGjj = VLvaleurChampDate.charAt(0) +  VLvaleurChampDate.charAt(1);
  VGmm = VLvaleurChampDate.charAt(3) +  VLvaleurChampDate.charAt(4);
  VGssaa = VLvaleurChampDate.charAt(6) +  VLvaleurChampDate.charAt(7) + VLvaleurChampDate.charAt(8) +  VLvaleurChampDate.charAt(9);
 return;
}
else 
{
  FmessageDate(VPchamp,4);
  
  }
}

/*****************************************************************
* Fpivot : fenetrage de VGaa par rapport a VGpivot               * 
*****************************************************************/
function Fpivot()
{
var VLaanumerique = Math.round(VGaa)
if (VLaanumerique > VGpivot)
    { VGssaa = "19" + VGaa}
 else {VGssaa = "20" + VGaa};
 return; 
}

/****************************************************************************
* Fbissextile() : determination du nombre de jours du mois de fevrier * 
*****************************************************************************/
function Fbissextile()
{var VLannee
 var VLsiecle
 
 VLannee = VGssaa.charAt(2) + VGssaa.charAt(3);
 VLsiecle = VGssaa.charAt(0) + VGssaa.charAt(1);
 VGmoisarray[2][2] = "28"
{ if (VLannee == "00")
    {var VLresult = VGssaa/400
     var VLrentier = Math.floor(VLresult) 
     if (VLresult == VLrentier )
        VGmoisarray[2][2] = "29";
     }
  else 
     { VLresult = VGssaa/4;
       VLrentier = Math.floor(VLresult)
         if (VLresult == VLrentier )
          VGmoisarray[2][2] = "29";
         
     }
 
}
// return
}

/****************************************************************************
* FValidation() : validation de la date saisie                              * 
*****************************************************************************/
function FValidation(VPchamp)
// on valide ici le nombre de jours/ au mois ds lequel on se trouve
{ var VLjour
 
for (var j = 0; j < 13; j++)
   { 
   if  (VGmm == VGmoisarray[j][1]) 
        VLjour = VGmoisarray[j][2];
        VLvalid = true 
        
   }

 
if ((VGjj < "01" || VGjj > VLjour  || (VGmm < "01" || VGmm > "12" ))  )
   {
 FmessageDate(VPchamp,3);       
   }
else return true ;
}


/**************************************************************************
* Finitialisertableau() : initialise le tableau des nb jour/mois          * 
***************************************************************************/
function Finitialisertableau()
{
for (var j = 0; j < VGmoisarray.length; j++)  {  // Prépare le remplissage du tableau 
     var VLLigne = new Array(2);  // Crée une ligne.
    for (var i = 0; i < VLLigne.length; i++)  {  // Prépare le remplissage  
    VLLigne[i] = (" ");  // initialise le tableau à blanc.
    }
 VGmoisarray[j] = VLLigne;  // Place la ligne remplie dans le tableau.
}

// initialisation du nombre de jours par mois.
//janvier
VGmoisarray[1][1] = "01";
VGmoisarray[1][2] = "31";

//fevrier bissextile
VGmoisarray[2][1] = "02";
 
//mars
VGmoisarray[3][1] = "03";
VGmoisarray[3][2] = "31";

//avril
VGmoisarray[4][1] = "04";
VGmoisarray[4][2] = "30";

//mai
VGmoisarray[5][1] = "05";
VGmoisarray[5][2] = "31";

//juin
VGmoisarray[6][1] = "06";
VGmoisarray[6][2] = "30";

//juillet
VGmoisarray[7][1] = "07";
VGmoisarray[7][2] = "31";

//aout
VGmoisarray[8][1] = "08";
VGmoisarray[8][2] = "31";

//septembre
VGmoisarray[9][1] = "09";
VGmoisarray[9][2] = "30";

//octobre
VGmoisarray[10][1] = "10";
VGmoisarray[10][2] = "31";

//novembre
VGmoisarray[11][1] = "11";
VGmoisarray[11][2] = "30";

//decembre
VGmoisarray[12][1] = "12";
VGmoisarray[12][2] = "31";

return;
}


/*************************************************************
* FvaliderDateEntier : verifie si le champ ne contient que des chiffres
* VPchamp : element du formulaire
**************************************************************/
function FvaliderDateEntier(VPchamp, VPentier)
{
var VLentier = "0123456789"
var VLvalidation = false
var VLvalidOk = true
var j = 0
var i = 0

do 
   { 
     VLcaractere = VPentier.charAt(j);
    do 
     {if  (VLentier.charAt(i) ==  VLcaractere)
     {VLvalidation = true};
     i++    
     }
   while ((VLvalidation == false) && i < VLentier.length);
   if (VLvalidation == false)
   {VLvalidOk = false};
   j++ ;
   i = 0;
   VLvalidation = false;
  }
while ((j < VPentier.length) && (VLvalidOk == true) );
 
if (VLvalidOk == false)
   {  FmessageDate(VPchamp,0);
       
   }
else return true; 
}
  


/*********************************************************************************
* fonction des anomalies
**********************************************************************************/
function FmessageDate(VPchamp, VPnumMsg)
{ switch (VPnumMsg)
  { case 0 :
    case 1 :  
     alert(l_champ+" doit être au format JJ/MM/AAAA.");
     reponse_format_publication=false;
     reponse_deb_publication=false;
     reponse_fin_publication=false;
     break;
    case 3 : 
      alert(l_champ+" est incorrecte (incohérence jour/mois)."  );
      reponse_format_publication=false;
      reponse_deb_publication=false;
      reponse_fin_publication=false;
      break;
    case 4 : 
      alert("Attention : Les caractères séparateurs pour "+l_champ+" doivent être identiques et sont / ou - ou Espace." );
      reponse_format_publication=false;
      reponse_deb_publication=false;
      reponse_fin_publication=false;
      break;
    default : alert("ERREUR DANS LE CODE MESSAGE.");
    reponse_format_publication=false;
    reponse_deb_publication=false;
    reponse_fin_publication=false;
  }
 VPchamp.focus();   
 VGdateok = false;
 return false ;
 }


/**********************************************************************************/
// fonction qui permet de comparer deux date au format jj/mm/aaaa: renvoie true si date2 > date1
function comparerLesDates(date1, date2) {
if (date1.length == 10  &&  date2.length == 10)
	{
	var dateISO2 = date2.substring(6,10) + "-" + date2.substring(3,5) + "-" + date2.substring(0,2); 
	var dateISO1 = date1.substring(6,10) + "-" + date1.substring(3,5) + "-" + date1.substring(0,2); 
	if (dateISO2 >= dateISO1){return true;}
		else {return false;}
	}
else {return true;}
}


/**********************************************************************************/
// fonction qui permet de comparer deux date time au format jj/mm/aaaa hh/mm: 
// renvoie true si date2 heure2 > date1 heure1
function comparerLesDatesHeures(date1, date2, heure1, heure2)
{
	
if (date1.length == 10  &&  date2.length == 10 
	&& heure1.length == 5 && heure2.length == 5)
	{
	var dateISO2 = date2.substring(6,10) + "-" + date2.substring(3,5) + "-" + date2.substring(0,2); 
	var dateISO1 = date1.substring(6,10) + "-" + date1.substring(3,5) + "-" + date1.substring(0,2); 
	var heure1ISO = heure1.substring(0,2);
	var heure2ISO = heure2.substring(0,2);
	var minute1ISO = heure1.substring(3,5);
	var minute2ISO = heure2.substring(3,5);
	
	if ( (dateISO2 > dateISO1) || (dateISO2 == dateISO1
	&& (heure2ISO > heure1ISO  || (heure2ISO == heure1ISO && minute2ISO > minute1ISO)) ))
		{return true;}
	else {return false;}
	}
else {return true;}
}


/*********************************************************************************
* fonction des anomalies
**********************************************************************************/
/*
function FmessageDate(VPchamp, VPnumMsg)
{ switch (VPnumMsg)
  { case 0 : 
      alert("ERREUR DANS LE FORMAT DE LA DATE");
      break;
    case 1 : 
      alert("ERREUR: LE LONGUEUR DU CHAMP DATE NE CORRESPOND PAS A UNE LONGUEUR DE DATE VALIDE");
      break;
    case 3 : 
      alert("ERREUR INCOHERENCE JOUR/MOIS"  );
      break;
    case 4 : 
      alert("ERREUR : LES CARACTERES SEPARATEURS DOIVENT IDENTIQUES ET SONT / - OU L'ESPACE " );
      break;
    default : alert("ERREUR DANS LE CODE MESSAGE.");
  }
 VPchamp.focus();   
 VGdateok = false;
 return false ;
 }
*/
/*

           if (VPchamp.name == "DateDeb")
              {alert("LA DATE DU DEBUT DE CE CHANGEMENT EST INCORRECTE.\nELLE DOIT ETRE COMPOSEE DU JOUR (JJ), DU MOIS (MM) ET DE L'ANNEE (AA OU SSAA) AVEC OU SANS SEPARATEURS.");
                     break;
              } 
           if (VPchamp.name == "Date")
              {alert("LA DATE DE SIGNATURE DU FORMULAIRE EST INCORRECTE.\nELLE DOIT ETRE COMPOSEE DU JOUR (JJ), DU MOIS (MM) ET DE L'ANNEE (AA OU SSAA) AVEC OU SANS SEPARATEURS.");
                     break;
              } 
           if (VPchamp.name == "DMariage")
              {alert("LA DATE DU MARIAGE EST INCORRECTE.\nELLE DOIT ETRE COMPOSEE DU JOUR (JJ), DU MOIS (MM) ET DE L'ANNEE (AA OU SSAA) AVEC OU SANS SEPARATEURS.");
                     break;
              } 
           if (VPchamp.name == "DConcubin")
              {alert("LA DATE DU DEBUT DU CONCUBINAGE EST INCORRECTE.\nELLE DOIT ETRE COMPOSEE DU JOUR (JJ), DU MOIS (MM) ET DE L'ANNEE (AA OU SSAA) AVEC OU SANS SEPARATEURS.");
                     break;
              } 
           if (VPchamp.name == "DNaissance")
              {alert("LA DATE DE NAISSANCE EST INCORRECTE.\nELLE DOIT ETRE COMPOSEE DU JOUR (JJ), DU MOIS (MM) ET DE L'ANNEE (AA OU SSAA) AVEC OU SANS SEPARATEURS.");
                     break;
              } 
*/




/**************************************************************
* FvaliderHeure : validation du format heure de (heureChamp)         
**************************************************************/
function FvaliderHeure(heureChamp) 
{ 

// variables locales
var valeurHeureChamp = String (heureChamp.value);
var VLlongueurHeure = valeurHeureChamp.length;

// determinantion du format de l'heure saisie. si
// l'heure n'a pas une longueur valide (5) --> message d'erreur.
if (VLlongueurHeure != 0 && VLlongueurHeure != 5) {
	alert('L\'heure doit être au format hh:mm');
	  heureChamp.focus();
	  return(false);	
	  }
else{
	// test de la présence d'un : au centre
	// si on trouve un espace ou . ou /, ou -, on remplace par :	
	if (valeurHeureChamp.charAt(2) == " "  ||
	    valeurHeureChamp.charAt(2) == "."  ||
    	valeurHeureChamp.charAt(2) == "/"  ||
    	valeurHeureChamp.charAt(2) == ","  ||
    	valeurHeureChamp.charAt(2) == "-" )
		{
		valeurHeureChamp = valeurHeureChamp.substring(0,2) + ":" + valeurHeureChamp.substring(3);
		}
	if(valeurHeureChamp.charAt(2) != ":"){
		alert('L\'heure doit être au format hh:mm');
	  	heureChamp.focus();
	  	return(false);
		}
 	else{
 		var champDateReformat = valeurHeureChamp;
 		heureChamp.value = champDateReformat;
 		
 		// test de numericite : heure de 00 à 23 et minutes de 00 à 59		
 		var heure = valeurHeureChamp.charAt(0) +  valeurHeureChamp.charAt(1);
 		var minute = valeurHeureChamp.charAt(3) +  valeurHeureChamp.charAt(4);
 		if (heure < "00" || heure > "23"  || minute < "00" || minute > "59")	
 			{
 			alert('Les heures doivent être comprises entre 00 et 23 et les minutes entres 00 et 59');
	  		heureChamp.focus();
	  		return(false);
 			}
 		else{return(true);}
	    }
    } 
}

/**************************************************************
* FvaliderHeure : validation du format heure de (heureChamp)         
**************************************************************/
function FvaliderHeureNonOblig(heureChamp) 
{ 

// variables locales
var valeurHeureChamp = String (heureChamp.value);
var VLlongueurHeure = valeurHeureChamp.length;

if (VLlongueurHeure == 0){
	return (true);
}
else{

// déterminantion du format de l'heure saisie. si
// l'heure n'a pas une longueur valide (5) --> message d'erreur.
if (VLlongueurHeure != 5) {
	  alert('L\'heure doit être au format hh:mm');
	  heureChamp.focus();
	  return(false);	
	  }
else{
	// test de la présence d'un : au centre
	// si on trouve un espace ou . ou /, ou -, on remplace par :	
	if (valeurHeureChamp.charAt(2) == " "  ||
	    valeurHeureChamp.charAt(2) == "."  ||
    	valeurHeureChamp.charAt(2) == "/"  ||
    	valeurHeureChamp.charAt(2) == ","  ||
    	valeurHeureChamp.charAt(2) == "-" )
		{
		valeurHeureChamp = valeurHeureChamp.substring(0,2) + ":" + valeurHeureChamp.substring(3);
		}
	if(valeurHeureChamp.charAt(2) != ":"){	
		alert('L\'heure doit être au format hh:mm');
	  	heureChamp.focus();
	  	return(false);
		}
 	else{
 		var champDateReformat = valeurHeureChamp;
 		heureChamp.value = champDateReformat;
 		
 		// test de numericite : heure de 00 à 23 et minutes de 00 à 59		
 		var heure = valeurHeureChamp.charAt(0) +  valeurHeureChamp.charAt(1);
 		var minute = valeurHeureChamp.charAt(3) +  valeurHeureChamp.charAt(4);
 		if (heure < "00" || heure > "23"  || minute < "00" || minute > "59")	
 			{
 			alert('Les heures doivent être comprises entre 00 et 23 et les minutes entres 00 et 59');
	  		heureChamp.focus();
	  		return(false);
 			}
 		else{return(true);}
	    }
    } 
   }
}

/**************************************************************
* FajouterJour : ajouter des jours à une date         
**************************************************************/

function FajouterJour(old_date, delta_days)
{
    // Date plus plus quelques jours
    var split_date = old_date.split('/');
    // Les mois vont de 0 a 11 donc on enleve 1, cast avec *1
    var new_date = new Date(split_date[2], split_date[1]*1 - 1, split_date[0]*1 + delta_days);
    var new_day = new_date.getDate();
        new_day = ((new_day < 10) ? '0' : '') + new_day; // ajoute un zéro devant pour la forme  
    var new_month = new_date.getMonth() + 1;
        new_month = ((new_month < 10) ? '0' : '') + new_month; // ajoute un zéro devant pour la forme  
    var new_year = new_date.getYear();
        new_year = ((new_year < 200) ? 1900 : 0) + new_year; // necessaire car IE et FF retourne pas la meme chose  
    var new_date_text = new_day + '/' + new_month + '/' + new_year;
    return new_date_text;
}
