/*DEBUT*/infMois=0;supMois=11;spDOffer=null;posSDay=null;prValD=null;derValD=null;diffAn=0;retDay=null,retMonth=null,retYear=null;bBord=false;isNav=false;isIE=false;
if (navigator.appName == "Netscape") { isNav=true; } else { isIE=true; }
codeMarche="";
libClik=new Array();
selDate=new Date();
moisChoisi="";
longWeekDays="";
shortWeekDays="";
calDocRight="";
calDocLeft="";
calDocTop="";
calDBas="";
calBaCFen="";
calCCRFen="";
calHtCFen="";
calEnd="";
function writeCalendar() {   
    var calDBas=top.newWin.frames['fenDroit'].genCalBas();     
    top.newWin.frames['calBas'].document.open();   
    top.newWin.frames['calBas'].document.write(cLink1);
    top.newWin.frames['calBas'].document.write(cLink2);
    top.newWin.frames['calBas'].document.write(calDBas); 
    top.newWin.frames['calBas'].document.close();          
    top.newWin.frames['calBas'].document.dateLibelleForm.dateLibelle.value="";
}

/***************************************************************/
/* Rajout de variables pour tests sur les listes jours et mois */
/***************************************************************/

/* Variables utilisees pour le controle des dates */
var aller = "D_Month";
var retour = "R_Month";

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
var NSX = (navigator.appName == "Netscape");
var IE4 = (document.all) ? true : false;

var monthday = new Array('31','28','31','30','31','30','31','31','30','31','30','31');

var shortWeekDays = new Array(
'Dom ', 
'Seg ', 
'Ter ', 
'Qua ', 
'Qui ', 
'Sex ', 
'Sab '
);
var longWeekDays = new Array(
'Domingo', 
'Seg ', 
'Ter ', 
'Quarta  ', 
'Qui ', 
'Sex ', 
'Sabado '
);

/* Fonction controlant si l annee en cours est bissextile ou non */
function verifAnneeBissextile(a) {
  var num = a - 1900;
  if( (num == 100) || (num % 4 == 0 && num % 100 != 0) || (num % 400 == 0) ) {
	return(29);
  } else {
	return(28);
  }
}

/*
idj l'objet du select du jour
month la valeur du mois
year la valeur de l'annee
*/
function updateListJour(idj,month,year) {
  var mois=month;
  var jour=$voir(idj);
  var annee=year;
   
  /* On recupere l annee en cours, on teste si elle est bissextile pour avoir le nb de jours en fevrier */
  var nbJours = verifAnneeBissextile(annee);

  /* On recupere la longueur de la liste des jours */
  var selLength = jour.length;
  /* update du tableau de max de jours pour fÃ©vrier*/
  monthday[1]=nbJours;

  /* On vide toute la liste non commune Ã  tous les mois*/
  /*Save the latest select value*/
  selected = jour.options[jour.selectedIndex].value;

  if (IE4) {
    for(i=Number(selLength); i > 27; i--) {
      jour.remove(i);
    }
  } else
    jour.options.length=monthday[mois-1];
	
  for(i=29; i < Number(monthday[mois-1])+1; i++) {
    if (IE4) {
      var newOpt = document.createElement("OPTION");
      newOpt.text=i;
      newOpt.value=i;
      if(selected==i) {
        newOpt.selected=true;
      }
      jour.add(newOpt);
    } else {	  		
      jour.options.length=monthday[mois-1];
      var newOpt = new Option(i,i);
      if(selected==i) {
        newOpt.selected=true;
      }
      jour.options[i-1] = newOpt;
    }
  }
}


/* 
 * Fonction appelee lorsque l utilisateur selectionne un mois dans la liste deroulante - met a jour la liste des jours 
 * Utilise les noms des inputs par defaut : D_Day, D_Month, R_Day, R_Month
 */
function changeOption(p) {
   /* Test sur la liste selectionnee - on recupere les elements */
   if (p == "D_Month") {
      changeOptionByObject("D_Day", "D_Month");
   } else {
      /* Sinon la liste selectionnee est R_Month */
      changeOptionByObject("R_Day", "R_Month");
   }

}

/* Fonction appelee lorsque l utilisateur selectionne un mois dans la liste deroulante - met a jour la liste des jours */
function changeOptionByObject(dayList, monthList) {

   /* on recupere les elements */
   var mois = $voir(monthList);
   var jour = $voir(dayList);

   /* On recupere le mois selectionne */   
  if(mois.options==null) // visiblement IE ne charge pas tout de suite tous les objets
     var moisSelected = document.forms[0].elements[RechercherIndiceElt(monthList)].value.substring(4,6);
  else
     var moisSelected = mois.options[mois.selectedIndex].value.substring(4,6);


   /* On recupere l annee en cours, on teste si elle est bissextile pour avoir le nb de jours en fevrier */
   var d = new Date();
   annee=d.getFullYear();
   var nbJours = verifAnneeBissextile(annee);

   /* On recupere la longueur de la liste des jours */
   var selLength = jour.length;

   /* Test sur le mois selectionne */
   if (moisSelected =='01' || moisSelected == '03' || moisSelected == '05' ||  moisSelected == '07' || moisSelected == '08' || 
moisSelected == '10' || moisSelected == '12') {
      /* Tests sur la longueur de la liste et rajout des options pour avoir les 31 jours du mois */
      if(selLength == 28) {
         /* Test sur le navigateur */
         if (IE4){
	    var newOpt = document.createElement("OPTION");
	    newOpt.text="29";
	    newOpt.value="29";
	    jour.add(newOpt);
        } else if(NSX){
	    var newOpt = new Option("29", "29");
	    jour.options[selLength] = newOpt;
        }
        /* On met a jour la longueur de la liste */
	selLength = jour.length;
     }
     
     if (selLength > 28 && selLength<30){
        if(IE4){
	   var newOpt = document.createElement("OPTION");
	   newOpt.text="30";
	   newOpt.value="30";
	   jour.add(newOpt);
	} else if(NSX){
	   var newOpt = new Option("30", "30");
	   jour.options[selLength] = newOpt;
        }
	selLength = jour.length;
     }

     if (selLength > 29 && selLength<31) {
        if(IE4){
           var newOpt = document.createElement("OPTION");
	   newOpt.text="31";
	   newOpt.value="31";
	   jour.add(newOpt);
        } else if (NSX) {
	   var newOpt = new Option("31", "31");
	   jour.options[selLength] = newOpt;
        }
        selLength = jour.length;
     }

   }

   /* Tests sur la longueur de la liste et rajout des options pour avoir les 30 jours du mois */
   if (moisSelected =='04' || moisSelected =='06' || moisSelected =='09' || moisSelected =='11'){
      
      if(selLength == 28){
         if(IE4) {
	   var newOpt = document.createElement("OPTION");
	   newOpt.text="29";
	   newOpt.value="29";
	   jour.add(newOpt);
	 }
	 else if (NSX) {
	   var newOpt = new Option("29", "29");
	   jour.options[selLength] = newOpt;
	 }
         selLength = jour.length;
      }

      if (selLength > 28 && selLength<30){
         if (IE4){
	   var newOpt = document.createElement("OPTION");
	   newOpt.text="30";
	   newOpt.value="30";
	   jour.add(newOpt);
	  }
	  else if (NSX) {
	    var newOpt = new Option("30", "30");
	    jour.options[selLength] = newOpt;
	  }
	  selLength = jour.length;

	}

      /* Si la liste contient 31 elements, on en supprime un pour avoir 30 jours dans le mois*/

      if (selLength>30){
         if (IE4) {
	   jour.remove(selLength-1);
	 }
	 else if (NSX) {
           jour.options[selLength-1]=null;
	   if (NS4) history.go(0);
	 }
	 selLength = jour.length;
      }
	
   }
        

   /* Si le mois selectionne est fevrier */	

   if (moisSelected =='02'){

      /* Tests sur la longueur de la liste et suppression des options pour avoir les 28/29 jours du mois selon annee bissextile ou pas */

      /* Si l'annee en cours a 28 jours*/
      if (nbJours==28){

         /* Si la liste a 30 elements, on en supprime 2 */
         if (selLength == 30){
           if (IE4){
             jour.remove(selLength-1);
	     jour.remove(selLength-2);
	   }
	   else if(NSX){
             jour.options[selLength-1]=null;
             jour.options[selLength-2]=null;
	     if (NS4) history.go(0);
	   }
	   selLength = jour.length;
	 }
			

         /* Si la liste a 31 elements, on en supprime 3 */
         if (selLength == 31){
	   if (IE4){
	     jour.remove(selLength-1);
             jour.remove(selLength-2);
	     jour.remove(selLength-3);
	   }
	   else if(NSX){
	     jour.options[selLength-1]=null;
             jour.options[selLength-2]=null;
             jour.options[selLength-3]=null;
	     if (NS4) history.go(0);
	   }
	   selLength = jour.length;
	  }
      } 


      /* Si l'annee en cours a 29 jours */
      if (nbJours==29){

         /* Si la liste a 30 elements, on en supprime 1 */
         if (selLength == 30){
	   if (IE4){
	     jour.remove(selLength-1);
	   }
	   else if(NSX){
             jour.options[selLength-1]=null;
	     if (NS4) history.go(0);
	   }
	   selLength = jour.length;
         }

         /* Si la liste a 31 elements, on en supprime 2 */
	 if (selLength == 31){
	   if (IE4){
	     jour.remove(selLength-1);
	     jour.remove(selLength-2);
	   }
	   else if(NSX){
             jour.options[selLength-1]=null;
             jour.options[selLength-2]=null;
	     if (NS4) history.go(0);
	   }
           selLength = jour.length;
	  }
      }
   }
}


/* Fonction appelee lorsque l utilisateur modifie le menu deroulant de la date aller */
/* Si la date aller modifiee est posterieure a la date retour affichee, alors la date retour affichee prend la valeur de la date aller */
/* Utilise les noms des inputs par defaut : D_Day, D_Month, R_Day, R_Month */
function dateRetourPosterieure()
{
	dateRetourPosterieureByObject("D_Day", "D_Month", "R_Day", "R_Month");
}

/* Fonction appelee lorsque l utilisateur modifie le menu deroulant de la date aller */
/* Si la date aller modifiee est posterieure a la date retour affichee, alors la date retour affichee prend la valeur de la date aller */
function dateRetourPosterieureByObject(outboundDayList, outboundMonthList, inboundDayList, inboundMonthList)
{

    var outboundDayObj = $voir(outboundDayList);
    var outboundMonthObj = $voir(outboundMonthList);
    var inboundDayObj = $voir(inboundDayList);
    var inboundMonthObj = $voir(inboundMonthList);
    if(isNaN(outboundDayObj.selectedIndex)) // cas de IE qui ne fonctionne pas sur certains navigateur
    {      
        outboundDayObj = document.forms[0].elements[outboundDayList];
        outboundMonthObj = document.forms[0].elements[outboundMonthList];
        inboundDayObj = document.forms[0].elements[inboundDayList];
        inboundMonthObj = document.forms[0].elements[inboundMonthList];
    }

    outboundDaySelectedIndex = outboundDayObj.selectedIndex;
    outboundMonthSelectedIndex = outboundMonthObj.selectedIndex;
    inboundDaySelectedIndex = inboundDayObj.selectedIndex;
    inboundMonthSelectedIndex = inboundMonthObj.selectedIndex;


    var moisAllerTmp = 0;
    var moisRetourTmp = 0;
    var jourAllerTmp = 0;
    var jourRetourTmp = 0;

    moisAllerTmp = parseInt(outboundMonthSelectedIndex);
    moisRetourTmp = parseInt(inboundMonthSelectedIndex);
    jourAllerTmp = parseInt(outboundDaySelectedIndex);
    jourRetourTmp = parseInt(inboundDaySelectedIndex);

    if (moisAllerTmp > moisRetourTmp) 
    {  
       inboundMonthObj.selectedIndex = outboundMonthObj.selectedIndex;
       changeOptionByObject(inboundDayList, inboundMonthList);
       inboundDayObj.selectedIndex = outboundDayObj.selectedIndex;
    }

    if (moisAllerTmp == moisRetourTmp && jourAllerTmp > jourRetourTmp) 
    {
       inboundDayObj.selectedIndex = outboundDayObj.selectedIndex;
    }
}



/* Fonction appelee lorsque l utilisateur modifie le menu deroulant de la date retour */
/* Si la date retour modifiee est anterieure a la date aller affichee, alors */
/*    - si le champ R_Day a ete modifie, le champs R_Month est incremente de 1 */
/*    - si le champ R_Month a ete modifie, la date retour affichee prend la valeur de la date aller */
/* Utilise les noms des inputs par defaut : D_Day, D_Month, R_Day, R_Month */
function dateAllerAnterieure(jourRetourModifie)
{
   dateAllerAnterieureByObject(jourRetourModifie, "D_Day", "D_Month", "R_Day", "R_Month");
}



/* Fonction appelee lorsque l utilisateur modifie le menu deroulant de la date retour */
/* Si la date retour modifiee est anterieure a la date aller affichee, alors */
/*    - si le champ R_Day a ete modifie, le champs R_Month est incremente de 1 */
/*    - si le champ R_Month a ete modifie, la date retour affichee prend la valeur de la date aller */
function dateAllerAnterieureByObject(jourRetourModifie, outboundDayList, outboundMonthList, inboundDayList, inboundMonthList)
{
    var outboundDayObj = $voir(outboundDayList);
    var outboundMonthObj = $voir(outboundMonthList);
    var inboundDayObj = $voir(inboundDayList);
    var inboundMonthObj = $voir(inboundMonthList);
    if(isNaN(outboundDayObj.selectedIndex)) // cas de IE qui ne fonctionne pas sur certains navigateur
    {      
        outboundDayObj = document.forms[0].elements[outboundDayList];
        outboundMonthObj = document.forms[0].elements[outboundMonthList];
        inboundDayObj = document.forms[0].elements[inboundDayList];
        inboundMonthObj = document.forms[0].elements[inboundMonthList];
    }

    outboundDaySelectedIndex = outboundDayObj.selectedIndex;
    outboundMonthSelectedIndex = outboundMonthObj.selectedIndex;
    inboundDaySelectedIndex = inboundDayObj.selectedIndex;
    inboundMonthSelectedIndex = inboundMonthObj.selectedIndex;

    var moisAllerTmp = 0;
    var moisRetourTmp = 0;
    var jourAllerTmp = 0;
    var jourRetourTmp = 0;

    moisAllerTmp = parseInt(outboundMonthSelectedIndex);
    moisRetourTmp = parseInt(inboundMonthSelectedIndex);
    jourAllerTmp = parseInt(outboundDaySelectedIndex);
    jourRetourTmp = parseInt(inboundDaySelectedIndex);

    if (moisAllerTmp > moisRetourTmp || (moisAllerTmp == moisRetourTmp && jourAllerTmp > jourRetourTmp)) { 

       if (jourRetourModifie) {
           /* incremente le champ R_Month si possible */
           if (parseInt(inboundMonthSelectedIndex) < inboundMonthObj.options.length - 1) { 
               inboundMonthObj.selectedIndex = parseInt(inboundMonthSelectedIndex) + 1;
               changeOptionByObject(inboundDayList, inboundMonthList);

           }
       } else {
           /* met a jour la date aller */
           outboundMonthObj.selectedIndex = inboundMonthSelectedIndex;
           changeOptionByObject(outboundDayList, outboundMonthList);
           outboundDayObj.selectedIndex = inboundDaySelectedIndex;

       }
    }
}

/**
 * Met Ã  jour la champ divDay, contenant le jour de la semaine, en fonction de la date selectionnÃ©e
 * divDay: id du champ contenant le jour de la semaine
 * selectDay: id du champ jour
 * selectMonth: id du champ annee/mois
 */
function updateDay(divDay, selectDay, selectMonth, isShort) {
	var inpDay = $voir(selectDay);
	var inpMonth = $voir(selectMonth);

	if (!inpDay.value || !inpMonth.value) {
		inpDay = document.forms[0].elements[selectDay];
		inpMonth = document.forms[0].elements[selectMonth];
	}

	var day = inpDay.value;
	var month = inpMonth.value.substring(4, 6);
	var year = inpMonth.value.substring(0, 4);
	
	// CrÃ©e l'objet date
	var dateJavaScript = new Date(year, month-1, day);
	// on vÃ©rifie que la date est valide
	var jourJavaScript = dateJavaScript.getDate();
        jourJavaScript = parseInt(jourJavaScript,10);
	var moisJavaScript = dateJavaScript.getMonth()+1;
	moisJavaScript = parseInt(moisJavaScript);
	var anneeJavaScript = dateJavaScript.getFullYear();
	anneeJavaScript = parseInt(anneeJavaScript,10);
	
	var iWeekDay; 
	if ((day == jourJavaScript) && (month == moisJavaScript) && (year == anneeJavaScript)) {
		iWeekDay = dateJavaScript.getDay();
          if (isShort) {
			$voir(divDay).innerHTML = shortWeekDays[iWeekDay]+"<span>&nbsp;&nbsp;</span> "; 
		} else {
			$voir(divDay).innerHTML = longWeekDays[iWeekDay]; 
		}
	} else {
		// date invalide
		$voir(divDay).innerHTML = "xxx";
	}
}

function updateDayByObject(divDay, selectDay, selectMonth, isShort) {

	var inpDay = $voir(selectDay);
	var inpMonth = $voir(selectMonth);
	var day = inpDay.value;
	var month = inpMonth.value.substring(4, 6);
	var year = inpMonth.value.substring(0, 4);
	// CrÃ©e l'objet date
	var dateJavaScript = new Date(year, month-1, day);
	
	// on vÃ©rifie que la date est valide
	var jourJavaScript = dateJavaScript.getDate();
        jourJavaScript = parseInt(jourJavaScript,10);
	var moisJavaScript = dateJavaScript.getMonth()+1;
	moisJavaScript = parseInt(moisJavaScript);
	var anneeJavaScript = dateJavaScript.getFullYear();
	anneeJavaScript = parseInt(anneeJavaScript,10);
	
	var iWeekDay; 
	if ((day == jourJavaScript) && (month == moisJavaScript) && (year == anneeJavaScript)) {
		iWeekDay = dateJavaScript.getDay();

                if (isShort) {
			$voir(divDay).innerHTML = shortWeekDays[iWeekDay]; 
		} else {
			$voir(divDay).innerHTML = longWeekDays[iWeekDay]; 
		}
	} else {
		// date invalide
		$voir(divDay).innerHTML = "xxx";
	}
}


function dateAllerChanged(isShort, jourMax, moisAnneeMax, pasDeRetour) {
	var atteintMax = false;   /* indique si la date selectionnÃ©e atteint ou dÃ©passe la date max */

	// VÃ©rifie que la date ne dÃ©passe pas le max
	if (jourMax && moisAnneeMax) {
		var inpDay = getElement('D_Day');
		var inpMonth = getElement('D_Month');
		if (inpMonth.value > moisAnneeMax) {
			selectOption(inpMonth, moisAnneeMax);
                        atteintMax = true;
		}
		if (atteintMax || (inpDay.value > jourMax && inpMonth.value == moisAnneeMax)) {
			selectOption(inpDay, jourMax);
                        atteintMax = true;
		}
	}
	
	changeOption(aller);
	updateDay('jourSemAller','D_Day','D_Month', isShort);
	
	/********** bloc ajouté : date deb et retour sont egales *************/
	dateRetourPosterieureByObject('D_Day','D_Month','R_Day','R_Month');
	updateDay('jourSemRetour','R_Day', 'R_Month', isShort);
	/********** fin bloc ajouté ******************************************/

	if (atteintMax) {
		return "MAX";	
	}
}

function dateAllerChangedByObject(isRoundTrip, isShort, outboundDivDay, outboundDayList, outboundMonthList, inboundDivDay, inboundDayList, inboundMonthList) {

	changeOptionByObject(outboundDayList, outboundMonthList);
	if($voir(isRoundTrip).value == "true") {
		dateRetourPosterieureByObject(outboundDayList, outboundMonthList, inboundDayList, inboundMonthList);	
	}
	changeOptionByObject(inboundDayList, inboundMonthList);
	updateDay(outboundDivDay,outboundDayList, outboundMonthList, isShort);
	updateDay(inboundDivDay, inboundDayList, inboundMonthList, isShort);
}


function dateRetourChanged(moisChanged, isShort, jourMin, moisAnneeMin, pasDAller) {
	var atteintMin = false;   /* indique si la date selectionnÃ©e atteint ou dÃ©passe la date min */

	// VÃ©rifie que la date ne dÃ©passe pas le min
	if (jourMin && moisAnneeMin) {
		var inpDay = getElement('R_Day');
		var inpMonth = getElement('R_Month');
		if (inpMonth.value < moisAnneeMin) {
			selectOption(inpMonth, moisAnneeMin);
			atteintMin = true;
		}
		if (atteintMin|| (inpDay.value < jourMin && inpMonth.value == moisAnneeMin)) {
			selectOption(inpDay, jourMin);
			atteintMin = true;
		}
	}
       
        if (!pasDAller) {
		dateRetourChangedByObject(moisChanged, isShort, 'jourSemAller','D_Day','D_Month','jourSemRetour','R_Day','R_Month');
	} else { /* pas d'input pour l'aller, on fait le strict necessaire pour le retour */
		
		changeOptionByObject('R_Day','R_Month');
		updateDay('jourSemRetour','R_Day','R_Month', isShort);
	}

	if (atteintMin) {
		return "MIN";	
	}
}

function dateRetourChangedByObject(moisHasChanged, isShort, outboundDivDay, outboundDayList, outboundMonthList, inboundDivDay, inboundDayList, inboundMonthList) {
	changeOptionByObject(inboundDayList, inboundMonthList)	
	dateAllerAnterieureByObject(!moisHasChanged, outboundDayList, outboundMonthList, inboundDayList, inboundMonthList)
	changeOptionByObject(outboundDayList, outboundMonthList);
	changeOptionByObject(inboundDayList, inboundMonthList);  /* le mois peut avoir change, apres l'appel a dateAllerAnterieure */
	updateDay(inboundDivDay, inboundDayList, inboundMonthList, isShort);
	updateDay(outboundDivDay,outboundDayList, outboundMonthList, isShort);
}

function getDiv(divId) {
	if (document.getElementById) {
		return document.getElementById(divId);
	} else if (document.all) {
		return document.all[divId];
	} else if (document.layers)	{
		return document.layers[divId];
	}
}
function selectOption(inpSelect, value) {
	var len = inpSelect.options.length;
	for (var i = 0; i < len; i++) {
		if (inpSelect.options[i].value == value) {
			inpSelect.selectedIndex = i;
			break;
		}
	}
}

/** ------------------------------------------------------ **/
/**    Fonctions pour le mini-calendrier en page          **/
/** ------------------------------------------------------ **/

function showCalendrier(idInputMois, idInputJour, openerButton, top, left, onShow, onClose) {
	if (openBy) { 
		/* le calendrier est dÃ©jÃ  ouvert :
		     soit on a cliquÃ© sur le meme bouton calendrier : on ferme le calendrier
		     soit on a cliquÃ© sur un autre bouton calendrier : on le rÃ©initialise (ie on le ferme, puis on rÃ©ouvre).
		 */
		var sameButton = (openBy == openerButton);
		/* ferme le calendrier */
		closeCalendrier();
		/*  si on ne rÃ©ouvre pas le calendrier, on quitte */
                if (sameButton) {
			return;
		}
	}
	openBy = openerButton;


	/* Handlers pour fermer le calendrier si on clique en dehors du calendrier.
	   L'algorithme de "bubbling" est majoritairement utilisÃ© par les navigateurs pour gÃ©rer les Ã©vÃ¨nements.
	   Ainsi, lorsqu'on clique sur le calendrier, le handler attachÃ© au calendrier est dÃ©clenchÃ© *avant* celui
	   sur le document. On utilise cette propriÃ©tÃ© pour mettre un flag indiquant qui ne faut pas fermer le 
	   calendrier lorsqu'on a cliquÃ© sur le calendrier.
	*/
	isClickInsideCal = true; 
	var captureClickDoc = function() {if (!isClickInsideCal){closeCalendrier();};isClickInsideCal=false;}
	var captureClickCal = function() {isClickInsideCal=true;}
	var captureEscape = function(e) {var keyID=(window.event)?event.keyCode:e.keyCode; if (keyID==27){closeCalendrier();}}
	
	document.onclick = captureClickDoc;
	$voir('idCalendrier').onclick = captureClickCal;
	document.onkeyup = captureEscape;


	/* Handler Ã  exÃ©cuter l'ouverture du calendrier */
	if (onShow) {
		onShow();
	} 
	handlerOnClose = onClose;  /* sauvegarde l'action a effectuer Ã  la fermeture du calendrier */

	/* DÃ©finit la plage de selection du calendrier */
	var D_DayOrigin = $voir('D_DayOrigin').value;
	var D_MonthOrigin = $voir('D_MonthOrigin').value;
	var R_DayFin = $voir('R_DayFin').value;
	var R_MonthFin = $voir('R_MonthFin').value;

	CAL_MIN_DATE = D_DayOrigin;
	CAL_MIN_MONTH = parseInt(D_MonthOrigin.substring(4,6), 10) - 1;
	CAL_MIN_YEAR = D_MonthOrigin.substring(0,4);
	CAL_MAX_DATE = R_DayFin;
	CAL_MAX_MONTH = parseInt(R_MonthFin.substring(4,6), 10) - 1;
	CAL_MAX_YEAR = R_MonthFin.substring(0,4);

	if (!top) {
		top = 0;
	}
	if (!left) {
		left = 0;
	} 

	/* les inputs associÃ©s au calendrier */
	inputYearMonth = $voir(idInputMois);
	inputDate = $voir(idInputJour);

  
	/* la date sÃ©lectionnÃ©e */
	var yearMonth = inputYearMonth.options[inputYearMonth.selectedIndex].value;

	selectedYear = yearMonth.substr(0, 4);
	selectedMonth = yearMonth.substr(4, 2) - 1;
	selectedDate = inputDate.options[inputDate.selectedIndex].value;

	/* le mois affichÃ© */
	calendarMonth = selectedMonth;
	calendarYear = selectedYear;
	/* construit le calendrier */
	buildCalendrier();
	/* positionne le calendrier */
	var divCalendrier = $voir("idCalendrier");
	divCalendrier.style.top = getPosY(openerButton) + top + "px";
	divCalendrier.style.left = getPosX(openerButton) + left+ "px";
	/* affiche le calendrier */
	divCalendrier.style.display="block";
}

function buildCalendrier() {
	var premierJourMois = (new Date(calendarYear, calendarMonth, 1).getDay()-deltaFirstDayOfWeek+7)%7;  /* colonne (0-based) du premier jour du mois, Ã  partir de lundi */
	var nbJoursDansLeMois= nbJourDansMois(calendarYear, calendarMonth);
	/* Met a jour le titre du calendrier */
	$voir("labelCalendar").innerHTML = monthLabel[calendarMonth] + " " + calendarYear;
	var nbCols = 7; /* 7 jours par semaine */
	/* Construit le calendrier */
	var r = 1; 
	for (var row = $voir('tableCalendar').rows[1]; row != null; row = row.nextSibling) {
        if (row.nodeType == 1) { /* not text */
			c = 0;
			for (var td = row.firstChild, i = 0; td != null; td = td.nextSibling) {
				if (td.nodeType == 1) { /* not text */
					var indexCell = (r-1)*nbCols + c;
					var date = indexCell - premierJourMois + 1;
					if (date >= 1 && date <= nbJoursDansLeMois) {
						if (   compareDate(calendarYear, calendarMonth, date, CAL_MIN_YEAR, CAL_MIN_MONTH, CAL_MIN_DATE) == -1
							|| compareDate(calendarYear, calendarMonth, date, CAL_MAX_YEAR, CAL_MAX_MONTH, CAL_MAX_DATE) == 1) {
								/* non selectionnable */
								td.className= 'disabled';
								td.innerHTML = date;
						} else {
								/* selectionnable */
								td.innerHTML='<a href="javascript:void(0);" onclick="javascript:selectDate(this,'+calendarYear+','+calendarMonth+','+date+');">'+date+'</a>';
								
								if (selectedYear == calendarYear && selectedMonth == calendarMonth && selectedDate == date) {
									td.className="selected";
								} else {
									td.className="";
								}
						}
					} else {
						td.className='';
						td.innerHTML='&nbsp;';
					}
					c++;
				}
			} /* fin foreach cell */
			r++;
		}		
	} /* fin foreach row; */

	/* Masque ou affiche les fleches de next/previous month */
	showOrHideShiftMonth();
}
function showOrHideShiftMonth() {
     if (compareDate(CAL_MIN_YEAR, CAL_MIN_MONTH, CAL_MIN_DATE, calendarYear, calendarMonth, 1) >= 0) {
        /* masque previous month si la date min  >= 1er du mois affichÃ© */
        $voir('idCalPreviousMonth').style.visibility = "hidden";
     } else {
        /* affiche previous month */
        $voir('idCalPreviousMonth').style.visibility = "visible";
     }
     if (compareDate(CAL_MAX_YEAR, CAL_MAX_MONTH, CAL_MAX_DATE, calendarYear, calendarMonth, 31) <= 0) {
        /* masque next month si la date max  >= 31 du mois affichÃ© (mÃªme si ce mois ne comporte que 28 ou 30j)*/
        $voir('idCalNextMonth').style.visibility = "hidden";
     } else {
        /* affiche next month */
        $voir('idCalNextMonth').style.visibility = "visible";
     }
}
function previousMonth() {
	/* backup */
	var saveYear = calendarYear, saveMonth = calendarMonth;  
	/* on recule d'un mois */
	calendarMonth--;
	if (calendarMonth < 0) {
		calendarMonth = 11;
		calendarYear--;
	}
	/* on reconstruit le calendrier */
	if (compareDate(calendarYear, calendarMonth, 31, CAL_MIN_YEAR, CAL_MIN_MONTH, CAL_MIN_DATE) >= 0) {
		buildCalendrier();
	} else {
		calendarYear = saveYear;
		calendarMonth = saveMonth; 
	}
}
function nextMonth() {
	/* backup */
	var saveYear = calendarYear, saveMonth = calendarMonth;  
	/* on avance d'un mois */
	calendarMonth++;
	if (calendarMonth > 11) {
		calendarMonth = 0;
		calendarYear++;
	}
	/* on reconstruit le calendrier */
	if (compareDate(calendarYear, calendarMonth, 1, CAL_MAX_YEAR, CAL_MAX_MONTH, CAL_MAX_DATE) <= 0) {
		buildCalendrier();
	} else {
		calendarYear = saveYear;
		calendarMonth = saveMonth; 
	}
}
function nbJourDansMois(annee, mois) {
	if (mois == 1) {
		return verifAnneeBissextile(annee);
	} else if (mois == 3 || mois == 5 || mois == 8 || mois == 10) {
		return 30;	
	} else {
		return 31;
	}
}
function selectDate(anchorTag, year, month, date) {
	selectOption(inputYearMonth, concatYearMonth(year,month));
	selectOption(inputDate, date);
	
	if (inputYearMonth.onchange) {
            inputYearMonth.onchange();
        }
	
	/* masque le calendrier */
	closeCalendrier()
}
function closeCalendrier(closeForthisId) {
	/* 
           si closeForthisId est renseignÃ©, on ferme le calendrier seulement si openBy.id == closeForthisId 
           sinon, on ferme le calendrier dans tous les cas
         */ 
	if (closeForthisId && openBy != null && closeForthisId != openBy.id) {
             return;  /* on ne ferme pas le calendrier */
        }

	/* supprime les handlers */
	document.onclick = null;
	$voir('idCalendrier').onclick = null;
	document.onkeyup = null;

	/* handler sur la fermeture du calendrier */
	if (handlerOnClose) {
		handlerOnClose();
	}

	$voir("idCalendrier").style.display="none";

	openBy = null; 
}
function concatYearMonth(year, month) {
	month = month + 1;  /* les mois commencent Ã  1; */
	if (month <= 9) {
		month = '0' + month;
	}
	return '' + year + month;
}
/**
 *  Compare 2 dates. retourne -1,0,1 si la date1 est respectivement infÃ©rieure/Ã©gale/supÃ©rieure Ã  date2
 */
function compareDate(year1, month1, date1, year2, month2, date2) {
	if (year1 == year2 && month1 == month2 && date1 == date2) {
		return 0;
	} else if (	 year1 < year2 || 
				(year1 == year2 && month1 < month2) ||
				(year1 == year2 && month1 == month2 && date1 < date2)  ) {
		return -1			
	} else {
		return 1;
	}
}
function getPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}
function getPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

/** ------------------------------------------------------ **/
/**     Fin Fonctions pour le mini-calendrier en page      **/
/** ------------------------------------------------------ **/
/*FIN*/

