if (!codeLang){codeLang = getDirLangFromHtmlAttrib();}

var DispoCalendar = {
    originViewBean: null,
    bookingEngineViewBean: null,
    hotelsPlanningViewBean: null,
    localPrevent: false,
    rewriteOnce: false,
    dateType: new String(),
    paramList : null,
    dateParam : null,
    currentPage : null,
    beanCurrency : null,
    
    /**
     * Liste des noms d'objets à utiliser.
     */
    getBeans: function() {
        return "HotelCalendarViewBean;BookingEngineViewBean;OriginViewBean";
    },
    
    /**
     * Initialisation de la variable JSON
     */
    initJSON: function() {       
       	this.originViewBean = viewBeans["OriginViewBean"];
        this.bookingEngineViewBean = viewBeans["BookingEngineViewBean"];
        this.hotelsPlanningViewBean = viewBeans["HotelCalendarViewBean"];
    },
        
    /**
     * Ecrivez votre code sur l'initialisation des affichage de la page
     * ici.
     * Cette méthode est appelée sur le onload de la page.
     */
    rewrite: function() {
   	
    	if(document.body.id == 'resultat-alternatif-dispo'){
    		this.currentPage = 'alternatif';
    		this.paramList = new Array();
    		this.paramList['currencyCode'] = "";
    		this.paramList["hotelCode"] = this.bookingEngineViewBean.hotelCode;
    	}
    	else{
    		this.currentPage = 'hotels';
				var portions = document.location.href.split("#");
				var params = portions[1].split("&");
				this.paramList = new Array();
				for(i=0; i<params.length; i++){
					var paramData = params[i].split("=");
					this.paramList[paramData[0]] = paramData[1];
				}
			}
    	
    	
    	/**
    	/ Si des dates sont en session, on se base sur ces dates la
    	/ sinon (recherche sans date), on se base sur la date du jour
    	**/
    	if(this.bookingEngineViewBean && this.bookingEngineViewBean.dayIn && this.bookingEngineViewBean.monthIn
  			&& this.bookingEngineViewBean.yearIn && this.bookingEngineViewBean.dayOut && this.bookingEngineViewBean.monthOut
  			&& this.bookingEngineViewBean.yearOut)
  		{
  			this.dateParam = new Date(this.bookingEngineViewBean.yearIn, Number(this.bookingEngineViewBean.monthIn-1), this.bookingEngineViewBean.dayIn);
  			this.dateType = 'user';
  		}
  		/**
    	/ Sinon on prend la date du jour comme reference
    	**/
  		else{
  			this.dateParam = new Date();
  			this.dateType = 'default';
  		}

  		
    	var startMonth = 1+this.dateParam.getMonth();
    	var startYear = this.dateParam.getFullYear();
    	
    	/**
    	/ Si une devise est passee en parametre, on la stocke, sinon la chaine est vide
    	**/
    	if(this.paramList['currencyCode']){
				DC_CAL.devise = this.paramList['currencyCode'];
			}
			else{
				DC_CAL.devise = '';
			}
	   
			/**
    	/ Si le code hotel passe en parametre (donc celui demande) correspond bien au code hotel renvoye par le bean courant
    	**/
      if(this.hotelsPlanningViewBean != null && this.paramList["hotelCode"] == this.hotelsPlanningViewBean.tarsCode 
      		&& (this.hotelsPlanningViewBean.currency == null || DC_CAL.devise == '' || DC_CAL.devise == this.hotelsPlanningViewBean.currency)) {
      		this.launchCalendarInit();
	  	}
	  	/**
    	/ Sinon on relance l'appel du bean en repassant l'ensemble des parametres : mois, annee, code hotel, devise (si elle existe)
    	/ puis on lance dans le callback la fonction launchCalendarInit()
    	**/
	  	else{					
				if(DC_CAL.devise != ''){
					/**
	    		/ Appel avec devise
	    		**/
					RemoteView.getViewBeans("hotelCalendar", "", "&startMonth="+startMonth+"&startYear="+startYear+"&code_hotel="+this.paramList["hotelCode"]+"&currencyCode="+DC_CAL.devise+"&beans=HotelCalendarViewBean;BookingEngineViewBean;OriginViewBean", codeLang, { callback:function(data) {
			        viewBeans = data; 
			        DispoCalendar.hotelsPlanningViewBean = viewBeans["HotelCalendarViewBean"];
			        DispoCalendar.launchCalendarInit();
			        initView(viewBeans); 
			      }, async:false
			      , errorHandler:function(errorString, exception) {
			               
			          if (errorString && errorString.startsWith("Erreur de session")){
			            document.location='/'+ codeLang + '/session/expired.html';
			          }
			              
			          throw exception;            
			        }
			      }, document.referrer      
			    );
			  }
			  else{
			  	/**
	    		/ Appel sans devise
	    		**/
			  	RemoteView.getViewBeans("hotelCalendar", "", "&startMonth="+startMonth+"&startYear="+startYear+"&code_hotel="+this.paramList["hotelCode"]+"&beans=HotelCalendarViewBean;BookingEngineViewBean;OriginViewBean", codeLang, { callback:function(data) {
			        viewBeans = data; 
			        DispoCalendar.hotelsPlanningViewBean = viewBeans["HotelCalendarViewBean"];
			        DispoCalendar.launchCalendarInit();
			        initView(viewBeans); 
			      }, async:false
			      , errorHandler:function(errorString, exception) {
			               
			          if (errorString && errorString.startsWith("Erreur de session")){
			            document.location='/'+ codeLang + '/session/expired.html';
			          }
			              
			          throw exception;            
			        }
			      }, document.referrer      
			    );
			  }
	  	}
  	
  },
  
  /**
	/ Fonction d'initialisation des variables, de l'objet DC_CAL et affichage des nom et logo de l'hotel
	**/
  launchCalendarInit : function(){
  	DC_CAL.hotelCode = this.paramList["hotelCode"];
		DC_CAL.parentPage = this.paramList["parentPage"];
		var hotelBrandCode = this.hotelsPlanningViewBean.hotelBrandCode;
		DC_CAL.hotelBrandCode = hotelBrandCode;
		var hotelName = this.hotelsPlanningViewBean.hotelName;
		
		DC_CAL.maxPeriod = viewBeans.BookingEngineViewBean.maxPeriod;
		DC_CAL.maxStay = viewBeans.BookingEngineViewBean.maxStay;
		
		if(this.currentPage == 'hotels'){
			$('dispo-caleandar').select('h2')[0].innerHTML = '<img src="/imagerie/reservation/picto_'+hotelBrandCode+'.gif" border="0" alt="" /> '+hotelName;
		}
		else{
			$('content').select('h3')[0].innerHTML = '<img src="/imagerie/reservation/picto_'+hotelBrandCode+'.gif" border="0" alt="" /> '+hotelName;
		}
		
		DC_CAL.init(this.dateParam);
  },
  
  
  runHotelsPlanningRequest : function(hotelCode, month, year, devise){
  	if(DC_CAL.dispoNextMonthArray[0] == null){
  		DispoCalendar.getHotelsPlanning(hotelCode, month, year, devise);
  	}
  	else if(DC_CAL.dispoNextMonthArray[0] && Number(DC_CAL.dispoNextMonthArray[0].dateIn.getMonth()+1) != month){
  		DispoCalendar.getHotelsPlanning(hotelCode, month, year, devise);
  	}
  	else{
  		DC_CAL.dispoArray = viewBeans["HotelCalendarViewBean"]["plannings"];
			DC_CAL.bestAvailableRates = viewBeans["HotelCalendarViewBean"]["bestAvailableRates"];
			DC_CAL.monthlyCurrency[year][month] = viewBeans["HotelCalendarViewBean"].currency;
			DC_CAL.createPositionsTabDetails();
  	}
  },
  
  /**
	/ Fonction de "requete" des donnees du bean (pour ecraser le bean en session qui pose souvent probleme)
	/ on va directement, depuis le callback, stocker les tableaux de valeurs retournes dans nos objets locaux
	/ DC_CAL.dispoArray et DC_CAL.bestAvailableRates puis appeler la fonction DC_CAL.createPositionsTabDetails()
	/ en etant sur que les donnes sont bien toutes arrivees
	**/
  getHotelsPlanning: function(hotelCode, month, year, devise) {
		if(devise != ''){
			RemoteView.getViewBeans("hotelCalendar", "", "&startMonth="+month+"&startYear="+year+"&code_hotel="+hotelCode+"&currencyCode="+devise+"&beans=HotelCalendarViewBean;BookingEngineViewBean;OriginViewBean", codeLang, { callback:function(data) {
	        viewBeans = data; 
	        DC_CAL.dispoArray = viewBeans["HotelCalendarViewBean"]["plannings"];
					DC_CAL.bestAvailableRates = viewBeans["HotelCalendarViewBean"]["bestAvailableRates"];
					DC_CAL.monthlyCurrency[year][month] = viewBeans["HotelCalendarViewBean"].currency;
					DC_CAL.createPositionsTabDetails();
	        initView(viewBeans); 
	      }, async:false
	      , errorHandler:function(errorString, exception) {
	               
	          if (errorString && errorString.startsWith("Erreur de session")){
	            document.location='/'+ codeLang + '/session/expired.html';
	          }
	              
	          throw exception;            
	        }
	      }, document.referrer      
	    );
	  }
	  else{
	  	RemoteView.getViewBeans("hotelCalendar", "", "&startMonth="+month+"&startYear="+year+"&code_hotel="+hotelCode+"&beans=HotelCalendarViewBean;BookingEngineViewBean;OriginViewBean", codeLang, { callback:function(data) {
	        viewBeans = data; 
	        DC_CAL.dispoArray = viewBeans["HotelCalendarViewBean"]["plannings"];
					DC_CAL.bestAvailableRates = viewBeans["HotelCalendarViewBean"]["bestAvailableRates"];
					DC_CAL.monthlyCurrency[year][month] = viewBeans["HotelCalendarViewBean"].currency;
					DC_CAL.createPositionsTabDetails();
	        initView(viewBeans); 
	      }, async:false
	      , errorHandler:function(errorString, exception) {
	               
	          if (errorString && errorString.startsWith("Erreur de session")){
	            document.location='/'+ codeLang + '/session/expired.html';
	          }
	              
	          throw exception;            
	        }
	      }, document.referrer      
	    );
	  }
  },
  
  getNextMonthPlanning : function(refererDate, hotelCode){
  	var month = 1+Number(refererDate.getMonth());
  	var year = refererDate.getFullYear();
  	RemoteView.getViewBeans("hotelCalendar", "", "&startMonth="+month+"&startYear="+year+"&code_hotel="+hotelCode+"&beans=HotelCalendarViewBean;BookingEngineViewBean;OriginViewBean", codeLang, { callback:function(data) {
        viewBeans = data; 
        DC_CAL.dispoNextMonthArray = viewBeans["HotelCalendarViewBean"]["plannings"];				
        initView(viewBeans); 
      }, async:false
      , errorHandler:function(errorString, exception) {
               
          if (errorString && errorString.startsWith("Erreur de session")){
            document.location='/'+ codeLang + '/session/expired.html';
          }
              
          throw exception;            
        }
      }, document.referrer      
    );
 	},
 	
 	getPreviousMonthPlanning : function(refererDate, hotelCode){
  	var month = 1+Number(refererDate.getMonth());
  	var year = refererDate.getFullYear();
  	RemoteView.getViewBeans("hotelCalendar", "", "&startMonth="+month+"&startYear="+year+"&code_hotel="+hotelCode+"&beans=HotelCalendarViewBean;BookingEngineViewBean;OriginViewBean", codeLang, { callback:function(data) {
        viewBeans = data; 
        DC_CAL.dispoPreviousMonthArray = viewBeans["HotelCalendarViewBean"]["plannings"];				
        initView(viewBeans); 
      }, async:false
      , errorHandler:function(errorString, exception) {
               
          if (errorString && errorString.startsWith("Erreur de session")){
            document.location='/'+ codeLang + '/session/expired.html';
          }
              
          throw exception;            
        }
      }, document.referrer      
    );
 	}  
}

core.push(DispoCalendar);

if(!DC_CAL){var DC_CAL = null;}
if(!Calendar){var Calendar = function(){}}

DC_CAL = {
	refDate : null,
	refMonth : null,
	refDay : null,
	refYear : null,
	maxPeriod : null,
	maxStay : null,
	todayDate : null,
	dateMaxTime : null,
	dateMax : null,
	dateIn : {set:0,day:null,month:null,year:null,formatedDate:null,date:null,pos:0},
	dateOut : {set:0,day:null,month:null,year:null,formatedDate:null,date:null,pos:0},
	positionsTab : new Array(),
	monthlyCurrency : new Array(),
	nextAvailableDays : 0,
	previousAvailableDays : 0,
	dispoArray : new Array(),
	bestAvailableRates : new Array(),
	dispoNextMonthArray : new Array(),
	dispoPreviousMonthArray : new Array(),
	maxAvailableDate : 0,
	minAvailableDate : -1,
	dateList : new Array(),
	hotelCode : null,
	firstLoad : false,
	lastAction : null,
	parentPage : null,
	hotelBrandCode : null,
	refDateEndMonth : null,
	devise : null,
	minProductCode : null,
	day1 : null,
  daysInMonth : null,
  hasAlreadyClickedOnce : false,
	
	init : function(date){
		
		this.refDate = date;
		this.refMonth = this.refDate.getMonth();
		this.refDay = this.refDate.getDate();
		this.refYear = this.refDate.getFullYear();
		this.todayDate = new Date();	
			
		this.dispoArray = DispoCalendar.hotelsPlanningViewBean.plannings;
		this.bestAvailableRates = DispoCalendar.hotelsPlanningViewBean.bestAvailableRates;
		this.dateList = $('calendar').select('td.date');
		
		this.dateMaxTime = this.todayDate.getTime() + (Date.DAY*(this.maxPeriod ? this.maxPeriod : 405));
		this.dateMax = new Date(this.dateMaxTime);
		
		if($('calendar')){
			DC_CAL.writeMonthTitle();
			DC_CAL.writeShortDayNames();
			DC_CAL.cleanCalendar();
			DC_CAL.writeDates();
			DC_CAL.setNavClickPrev();
			DC_CAL.setNavClickNext();

			this.refDateEndMonth = new Date(this.refYear, this.refMonth, this.refDate.getMonthDays());
			DC_CAL.navigationDisplayManager();
			
			// Si c'est un calendrier avec dates (dates deja choisies par l'internaute) / TD_7496 on ne preselectionne plus les dates sur la page de resultat alternatif
			if(DispoCalendar.dateType == 'user' && DC_CAL.dateIn.set == 0 && DC_CAL.dateOut.set ==  0 && DC_CAL.hasAlreadyClickedOnce == false && DispoCalendar.currentPage != 'alternatif'){
				
				// si mois et annee en cours correspondent aux mois et annee de la dateIn
				if(Number(DispoCalendar.bookingEngineViewBean.monthIn) == Number(DC_CAL.refMonth+1) && Number(DispoCalendar.bookingEngineViewBean.yearIn) == Number(DC_CAL.refYear)){
					var posDateIn = DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][Number(DispoCalendar.bookingEngineViewBean.dayIn)].position;
					//fireEvent($(DC_CAL.dateList[posDateIn]).select('table')[0], 'click');
					var cellIn = $(DC_CAL.dateList[posDateIn]).select('table')[0];
					if(cellIn && !cellIn.hasClassName('closed')){
						this.dateIn.set = 1;
						this.dateIn.day = Number(DispoCalendar.bookingEngineViewBean.dayIn);
						this.dateIn.month = Number(DispoCalendar.bookingEngineViewBean.monthIn-1);
						this.dateIn.year = DispoCalendar.bookingEngineViewBean.yearOut;
						this.dateIn.date = new Date(this.dateIn.year, this.dateIn.month, this.dateIn.day);
						this.dateIn.formatedDate = this.dateIn.date.print(Calendar._TT["SHT_DATE_FORMAT"]);
						$('arrival_date').innerHTML = this.dateIn.formatedDate;
											
						if(cellIn.hasClassName('cheapest')){
							cellIn.addClassName('clicked2');
						}
						
						if(cellIn.hasClassName('open')){
							cellIn.addClassName('clicked1');
						}
						DC_CAL.hasAlreadyClickedOnce = true;
						$('reset').removeClassName('disable');
						
						this.setMaxAvailableDate(this.dateIn.date);
						this.setMinAvailableDate(this.dateIn.date, "begin");
						this.handleMaxAvailableDate('show', $(cellIn.select('span.numJour')[0].innerHTML));
					}
				}
				
				// si mois et annee en cours correspondent aux mois et annee de la dateOut
				if(Number(DispoCalendar.bookingEngineViewBean.monthOut) == Number(DC_CAL.refMonth+1) && Number(DispoCalendar.bookingEngineViewBean.yearOut) == Number(DC_CAL.refYear)){
					var userDayOut = Number(DispoCalendar.bookingEngineViewBean.dayOut);
					var userMonthOut = Number(DispoCalendar.bookingEngineViewBean.monthOut-1);
					var userYearOut = DispoCalendar.bookingEngineViewBean.yearOut;
					var posDateOut = DC_CAL.positionsTab[userYearOut][userMonthOut][userDayOut].position;
					//fireEvent($(DC_CAL.dateList[posDateOut]).select('table')[0], 'click');
					
					if(this.maxAvailableDate == 0 || this.maxAvailableDate >= userDayOut){
						var cellOut = $(DC_CAL.dateList[posDateOut]).select('table')[0];
						if(cellOut && !cellOut.hasClassName('closed')){
							this.dateOut.set = 1;
							this.dateOut.day = Number(DispoCalendar.bookingEngineViewBean.dayOut);
							this.dateOut.month = Number(DispoCalendar.bookingEngineViewBean.monthOut-1);
							this.dateOut.year = DispoCalendar.bookingEngineViewBean.yearOut;
							this.dateOut.date = new Date(this.dateOut.year, this.dateOut.month, this.dateOut.day);
							this.dateOut.formatedDate = this.dateOut.date.print(Calendar._TT["SHT_DATE_FORMAT"]);
							$('departure_date').innerHTML = this.dateOut.formatedDate;
							
							if(cellOut.hasClassName('cheapest')){
								cellOut.addClassName('clicked2');
							}
							
							if(cellOut.hasClassName('open')){
								cellOut.addClassName('clicked1');
							}
							DC_CAL.hasAlreadyClickedOnce = true;
							$('reset').removeClassName('disable');
						}
					}
				}
				// la dateOut n'est pas sur le mois en cours de visualisation
				else{
					var userDayOut = Number(DispoCalendar.bookingEngineViewBean.dayOut);
					var userMonthOut = Number(DispoCalendar.bookingEngineViewBean.monthOut-1);
					var userYearOut = DispoCalendar.bookingEngineViewBean.yearOut;
					var userDateOut = new Date(userYearOut, userMonthOut, userDayOut);
					DispoCalendar.getNextMonthPlanning(userDateOut, DC_CAL.hotelCode);
					
					var newtMonthDispo = true;
					for(var i=0; i<=userDayOut-2; i++){
						if(DC_CAL.dispoNextMonthArray[i]['status'] == 1){
							newtMonthDispo = false;
						}
					}
					
					if(newtMonthDispo == true && (this.maxAvailableDate == 0 || this.maxAvailableDate < this.dateIn.day)){
						this.dateOut.set = 1;
						this.dateOut.day = Number(DispoCalendar.bookingEngineViewBean.dayOut);
						this.dateOut.month = Number(DispoCalendar.bookingEngineViewBean.monthOut-1);
						this.dateOut.year = DispoCalendar.bookingEngineViewBean.yearOut;
						this.dateOut.date = new Date(this.dateOut.year, this.dateOut.month, this.dateOut.day);
						this.dateOut.formatedDate = this.dateOut.date.print(Calendar._TT["SHT_DATE_FORMAT"]);
						$('departure_date').innerHTML = this.dateOut.formatedDate;
						DC_CAL.hasAlreadyClickedOnce = true;
						$('reset').removeClassName('disable');
					}
				}
				
				if(DC_CAL.dateIn.set == 1 && DC_CAL.dateOut.set ==  1) this.highlightStayDates('on');
			}
		}
		
		if($('side_infos')){
			DC_CAL.initResetButton();
			DC_CAL.initSubmitButton();
		}
		DC_CAL.firstLoad = true;
	},
	
	initSubmitButton : function(){
		var button = $("submitLink");
		var aLink = button.select("a")[0];
		
		if(DC_CAL.dateIn.set != 1 || DC_CAL.dateOut.set != 1)
			if(button) button.addClassName('disable');

		Event.observe(
			button,
			"click",
			function(evt){
				Event.stop(evt);
				if(!button.hasClassName('disable')){
					if(DC_CAL.dateIn.set == 1 && DC_CAL.dateOut.set == 1){
						DC_CAL.getMinBarCode(DC_CAL.dateIn, DC_CAL.dateOut);
						
						var productCodeBarRealParam = "";
						var productCodeBarDateInParam = "";
						
						if(DC_CAL.minProductCode != null){
							productCodeBarRealParam = "&productCodeBarReal="+DC_CAL.minProductCode;
						}
						
						if(DC_CAL.positionsTab[DC_CAL.dateIn.year][DC_CAL.dateIn.month][DC_CAL.dateIn.day].productCode){
							productCodeBarDateInParam = "&productCodeBarDateIn="+DC_CAL.positionsTab[DC_CAL.dateIn.year][DC_CAL.dateIn.month][DC_CAL.dateIn.day].productCode;
						}
						var nbNights = DC_CAL.getNbNights();
						
						if(DispoCalendar.currentPage == 'hotels'){
							var lien = "/selectPax.svlt?isCodeTars=1&hotel_ville="+DC_CAL.hotelCode+"&marque="+DC_CAL.hotelBrandCode+"&jour_arrivee="+DC_CAL.dateIn.day+"&mois_arrivee="+parseInt(DC_CAL.dateIn.month+1)+"&annee_arrivee="+DC_CAL.dateIn.year+"&nb_nuit="+nbNights+"&isResaDate=1"+productCodeBarRealParam+productCodeBarDateInParam;
							if(DispoCalendar.hotelsPlanningViewBean.currency != null)
								lien += "&currencyCode="+DispoCalendar.hotelsPlanningViewBean.currency;
						}
						else if(DispoCalendar.currentPage == 'alternatif'){
							var lien = "/availability.svlt?";
							lien += "&jour_arrivee="+DC_CAL.dateIn.day;
							lien += "&mois_arrivee="+parseInt(DC_CAL.dateIn.month+1);
							lien += "&annee_arrivee="+DC_CAL.dateIn.year;
							lien += "&nb_nuit="+nbNights;
							lien += "&nb_personne="+DispoCalendar.bookingEngineViewBean.adultsNb;
							lien += "&nb_enfant="+DispoCalendar.bookingEngineViewBean.childrenNb;
							if(DispoCalendar.hotelsPlanningViewBean.currency != null)
								lien += "&currencyCode="+DispoCalendar.hotelsPlanningViewBean.currency;
							if(DispoCalendar.bookingEngineViewBean.bedding != null)
								lien += "&bedding="+DispoCalendar.bookingEngineViewBean.bedding;
							else
								lien += "&bedding=";
							
							lien += "&rooms_nb="+DispoCalendar.bookingEngineViewBean.roomsNb;
							
							if(DispoCalendar.bookingEngineViewBean.fidelityCardType != null)
								lien += "&type_carte_fidelite="+DispoCalendar.bookingEngineViewBean.fidelityCardType;
							else
								lien += "&type_carte_fidelite=";
							
							if(DispoCalendar.bookingEngineViewBean.fidelityCardNumber != null)
								lien += "&num_carte_fidelite="+DispoCalendar.bookingEngineViewBean.fidelityCardNumber;
							else
								lien += "&num_carte_fidelite=";
							
							if(DispoCalendar.bookingEngineViewBean.preferentialCode != null)
								lien += "&code_avantage="+DispoCalendar.bookingEngineViewBean.preferentialCode;
							else
								lien += "&code_avantage=";
							
							lien += productCodeBarRealParam+productCodeBarDateInParam;
						}
						window.parent.location.href=lien;
					}
					else if((DC_CAL.dateIn.set == 1 && DC_CAL.dateOut.set == 0) || (DC_CAL.dateIn.set == 0 && DC_CAL.dateOut.set == 1)){
						alert(I18N._('calendar', 'mustSelect2Dates'));
					}
				}
			}
		);
	},
	
	/**
	/ Fonction permettant de recuperer le productCode de la date ayant le BAR minimum 
	/ parmi les dates comprises entre la dateIn et la dateOut
	**/
	getMinBarCode : function(dateIn, dateOut){
		if(dateIn && dateOut){
			var minBAR = new Number(0);
			var productCode = new String();
			var barArray = {
				price: new Array(),
				productCode : new Array()
			};
			var currentPrice = new Number();
			DC_CAL.minProductCode = null;
			
			if(dateIn.month != dateOut.month){
				for(var i=dateIn.day; i<= dateIn.date.getMonthDays(); i++){
					if(DC_CAL.positionsTab[dateIn.year][dateIn.month][i] && DC_CAL.positionsTab[dateIn.year][dateIn.month][i].price){
						currentPrice = DC_CAL.positionsTab[dateIn.year][dateIn.month][i].price['priceWithTaxes'];
						productCode = DC_CAL.positionsTab[dateIn.year][dateIn.month][i].productCode;
						barArray['price'].push(currentPrice);
						barArray['productCode'].push(productCode);
					}
				}
				
				for(var i=1; i<= dateOut.day; i++){
					if(DC_CAL.positionsTab[dateOut.year][dateOut.month][i] && DC_CAL.positionsTab[dateOut.year][dateOut.month][i].price){
						currentPrice = DC_CAL.positionsTab[dateOut.year][dateOut.month][i].price['priceWithTaxes'];
						productCode = DC_CAL.positionsTab[dateIn.year][dateIn.month][i].productCode;
						barArray['price'].push(currentPrice);
						barArray['productCode'].push(productCode);
					}
				}
			}
			else if(dateIn.month == dateOut.month){
				for(var i=dateIn.day; i<= dateOut.day; i++){
					if(DC_CAL.positionsTab[dateIn.year][dateIn.month][i] && DC_CAL.positionsTab[dateIn.year][dateIn.month][i].price){
						currentPrice = DC_CAL.positionsTab[dateIn.year][dateIn.month][i].price['priceWithTaxes'];
						productCode = DC_CAL.positionsTab[dateIn.year][dateIn.month][i].productCode;
						barArray['price'].push(currentPrice);
						barArray['productCode'].push(productCode);
					}
				}
			}
			
			if(barArray.price.length > 0){
				minBAR = Number(barArray.price[0]);
				productCode = barArray.productCode[0];
				for(var i=0; i<barArray.price.length; i++){
					if(Number(barArray.price[i]) < minBAR){
						minBAR = Number(barArray.price[i]);
						productCode = barArray.productCode[i];
					}
				}
			}
			
			if(minBAR != 0){
				DC_CAL.minProductCode = productCode;
			}
			
		}
	},
	
	rewriteCalendar : function(date, action){
		this.refDate = date;
		this.refMonth = this.refDate.getMonth();
		this.refDay = this.refDate.getDate();
		this.refYear = this.refDate.getFullYear();
		
		this.refDateEndMonth = new Date(this.refYear, this.refMonth, this.refDate.getMonthDays());
		
		if($('calendar')){
			DC_CAL.writeMonthTitle();
			
			DC_CAL.cleanCalendar();
			DC_CAL.writeDates();
			
			DC_CAL.navigationDisplayManager();
		}
	},
	
	/**
	/  Ecrit le mois et l'annee en cours de visualisation
	**/
	writeMonthTitle : function(){
		var tdTarget = $('calendar').select('td.title');
		if(tdTarget.length > 0) $(tdTarget[0].innerHTML = Calendar._MN[this.refMonth] + " " + this.refYear)
	},
	
	/**
	/  Ecrit les noms abreges des jours de la semaine
	**/
	writeShortDayNames : function(){
		var celList = $('calendar').select('td.day_name');
		for(i=0; i< celList.length; i++){
			$(celList[i]).innerHTML = Calendar._SDN[i+Calendar._FD];
		}
	},
	
	/**
	/  Ecrit les dates du mois en cours
	/  puis selon les infos remontees par le bean affiche la couleur, la devise et le prix pour chaque date.
	**/
	writeDates : function(){
		var beginMonthDate = new Date(this.refYear, this.refMonth, 1);
		this.daysInMonth = this.refDate.getMonthDays();
		this.day1 = (beginMonthDate.getDay() - Calendar._FD) % 7;
		if (this.day1 < 0) this.day1 += 7;
		var numeroJour = 0;
		
		for(i=this.day1; i<this.daysInMonth+this.day1; i++){
		  $(DC_CAL.dateList[i]).innerHTML = '<table cellspacing="0" cellpadding="0" class=""><tr><td class="numDate"><span class="numJour">'+(i-this.day1+1)+'</span></td><td class="devise"><span class="deviseVal"></span></td></tr><tr><td colspan="2" class="price"><span class="priceVal"></span></td></tr></table>';
				if(this.todayDate.getMonth() == this.refMonth && this.todayDate.getFullYear() == this.refYear){
					if((i-this.day1+1) < this.todayDate.getDate()){
						$(DC_CAL.dateList[i]).select('table')[0].addClassName('closed');
					}
					else{
						DC_CAL.initDateClickObserver($(DC_CAL.dateList[i]).select('table')[0]);
					}
				}
				else if(this.dateMax.getMonth() == this.refMonth && this.dateMax.getFullYear() == this.refYear){
					if((i-this.day1+1) > this.dateMax.getDate()){
						$(DC_CAL.dateList[i]).select('table')[0].addClassName('closed');
						if((i-this.day1+1) == this.dateMax.getDate()+1){
							DC_CAL.initDateClickObserver($(DC_CAL.dateList[i]).select('table')[0]);
						}
					}
					else{
						DC_CAL.initDateClickObserver($(DC_CAL.dateList[i]).select('table')[0]);
					}
				}
				else{
					DC_CAL.initDateClickObserver($(DC_CAL.dateList[i]).select('table')[0]);
				}
		}
		
		DC_CAL.setMaskLayer();
		
		if(!DC_CAL.positionsTab[this.refYear]){
			DC_CAL.positionsTab[this.refYear] = new Array();
			DC_CAL.monthlyCurrency[this.refYear] = new Array();		
		}
		
		if(!DC_CAL.positionsTab[this.refYear][this.refMonth]){
			DC_CAL.positionsTab[this.refYear][this.refMonth] = new Array();
			if(DC_CAL.firstLoad == true){
				var startMonth = 1+Number(this.refMonth);
				DispoCalendar.runHotelsPlanningRequest(DC_CAL.hotelCode, startMonth, this.refYear, DC_CAL.devise);
			}
			else{
				if(DispoCalendar.hotelsPlanningViewBean && this.refMonth != DispoCalendar.hotelsPlanningViewBean.plannings[0].dateIn.getMonth()){
					 DispoCalendar.runHotelsPlanningRequest(this.hotelCode, 1+Number(this.refMonth), this.refYear, DC_CAL.devise);
				}
				else{
					DC_CAL.monthlyCurrency[this.refYear][this.refMonth] = viewBeans["HotelCalendarViewBean"].currency;
					this.createPositionsTabDetails();	
				}
			}
		}
		else{
			this.initColoredCalendarTable(DC_CAL.dateList);
		}
	},
	
	/**
	/  Gere l'affichage de la legende "devise", du paragraphe de legende concernant les prix
	/  et la legende du tarif best rates.
	**/
	legendManager : function(currency){
		if(currency != null && currency != ''){
			$('blocDeviseVal').innerHTML = DC_CAL.monthlyCurrency[DC_CAL.refYear][DC_CAL.refMonth];
			$('blocDevise').style.display = "block";
			var note = $('calendar_table').select('p.note')[0];
			if(note) note.style.display = "block";
			var legCheapest = $('bloc-legende').select('ul')[2];
			if(legCheapest) legCheapest.style.display = "block";
		}
		else{
			$('blocDevise').style.display = "none";
			var note = $('calendar_table').select('p.note')[0];
			if(note) note.style.display = "none";
			var legCheapest = $('bloc-legende').select('ul')[2];
			if(legCheapest) legCheapest.style.display = "none";
		} 
	},
	
	createPositionsTabDetails : function(){
		
		DC_CAL.monthlyCurrency[DC_CAL.refYear][DC_CAL.refMonth] = viewBeans["HotelCalendarViewBean"].currency;
		for(i=0; i<DC_CAL.dateList.length; i++){
			if($(DC_CAL.dateList[i]).innerHTML != ''){
				DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][$(DC_CAL.dateList[i]).select('span.numJour')[0].innerHTML] = {
					position: i,
					status:0,
					bestRate:false,
					price:null,
					productCode: null,
					tarsKey : new String()
				}
				
				numeroJour = Number($(DC_CAL.dateList[i]).select('span.numJour')[0].innerHTML);
				
				if(DC_CAL.dispoArray[numeroJour-1] && 
					DC_CAL.dispoArray[numeroJour-1].dateIn.getFullYear() == DC_CAL.refYear &&
					DC_CAL.dispoArray[numeroJour-1].dateIn.getMonth() == DC_CAL.refMonth){
						DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour].status = DC_CAL.dispoArray[numeroJour-1].status;
				}
				
				if(DC_CAL.bestAvailableRates != null && DC_CAL.bestAvailableRates[numeroJour-1] && 
					DC_CAL.bestAvailableRates[numeroJour-1].dateIn.getFullYear() == DC_CAL.refYear &&
					DC_CAL.bestAvailableRates[numeroJour-1].dateIn.getMonth() == DC_CAL.refMonth){
						DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour].bestRate = DC_CAL.bestAvailableRates[numeroJour-1].periodBestAvailableRate;
						DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour].price = DC_CAL.bestAvailableRates[numeroJour-1].price;
						DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour].productCode = DC_CAL.bestAvailableRates[numeroJour-1].productCode;
						DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour].tarsKey = DC_CAL.bestAvailableRates[numeroJour-1].tarsKey;
				}
			}
			else{
				DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][0] = 0;
			}
		}
		
		DC_CAL.initColoredCalendarTable(DC_CAL.dateList);
	},
	
	initColoredCalendarTable : function(dateList){
		
		DC_CAL.legendManager(DC_CAL.monthlyCurrency[DC_CAL.refYear][DC_CAL.refMonth]);
		for(i=DC_CAL.day1; i<DC_CAL.daysInMonth+DC_CAL.day1; i++){
			numeroJour = $(dateList[i]).select('span.numJour')[0].innerHTML;
			if(DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour]){
				
				switch(DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour].status){
					case (0) :
						if(!$(dateList[i]).select('table')[0].hasClassName('closed')) $(dateList[i]).select('table')[0].addClassName('open');
						break;
					
					case (1) :
						if(!$(dateList[i]).select('table')[0].hasClassName('closed')){
							if(DC_CAL.dateIn.set == 1 && DC_CAL.dateOut.set == 1 && DC_CAL.refYear == DC_CAL.dateOut.year && DC_CAL.refMonth == DC_CAL.dateOut.month && parseInt($(dateList[i]).select('span.numJour')[0].innerHTML) == DC_CAL.dateOut.day ){
								$(dateList[i]).select('span')[0].addClassName('open');
							}
							else{
								$(dateList[i]).select('table')[0].addClassName('closed');
							}
						}
						break;
						
					case (2) :
						if(!$(dateList[i]).select('table')[0].hasClassName('closed')) $(dateList[i]).select('table')[0].addClassName('soldout');
						break;
						
					// case (3) :
						// if(!$(dateList[i]).select('span')[0].hasClassName('naDate')) $(dateList[i]).select('span')[0].addClassName('closed');
						// break;
						
					default :
						break;
				}
				
				if(!$(dateList[i]).select('table')[0].hasClassName('closed')
					&& DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour].bestRate == true)
				{
					$(dateList[i]).select('table')[0].removeClassName('open');
					$(dateList[i]).select('table')[0].addClassName('cheapest');
				}
				
				if(!$(dateList[i]).select('table')[0].hasClassName('closed')
					&& DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour].price != null)
				{
					if($(dateList[i]).select('span.deviseVal')[0]){
						$(dateList[i]).select('span.deviseVal')[0].innerHTML = DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour].price['currencyCode'];
					}
					if($(dateList[i]).select('span.priceVal')[0]){
						$(dateList[i]).select('span.priceVal')[0].innerHTML = DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][numeroJour].price['priceWithTaxes'];
					}
				}
				
				if((DC_CAL.refMonth == DC_CAL.dateIn.month && DC_CAL.refYear == DC_CAL.dateIn.year && (i-DC_CAL.day1+1) == DC_CAL.dateIn.day) || (DC_CAL.refMonth == DC_CAL.dateOut.month && DC_CAL.refYear == DC_CAL.dateOut.year && (i-DC_CAL.day1+1) == DC_CAL.dateOut.day)){
					
					if($(dateList[i]).select('table')[0].hasClassName('cheapest')){
						$(dateList[i]).select('table')[0].addClassName('clicked2');
					}
					
					if($(dateList[i]).select('table')[0].hasClassName('open')){
						$(dateList[i]).select('table')[0].addClassName('clicked1');
					}
				}
				
			}
		}

		if(DC_CAL.dateIn.set == 1 && DC_CAL.dateOut.set ==  1){
			if(DC_CAL.refMonth == DC_CAL.dateMax.getMonth() && DC_CAL.refYear == DC_CAL.dateMax.getFullYear()){
					DC_CAL.setMaxAvailableDate(DC_CAL.refDate);
					DC_CAL.handleMaxAvailableDate('show');
			}
			
			if(DC_CAL.dateIn.month != DC_CAL.dateOut.month && DC_CAL.refMonth == DC_CAL.dateOut.month){
				DC_CAL.minAvailableDate = -1;
				DC_CAL.setMaxAvailableDate(DC_CAL.refDate);
				if(DC_CAL.maxAvailableDate == 0){
					DC_CAL.maxAvailableDate = DC_CAL.dateOut.day;
				}
				else{
					DC_CAL.handleMaxAvailableDate('show');
				}
			}
			else if(DC_CAL.dateIn.month != DC_CAL.dateOut.month && DC_CAL.refMonth == DC_CAL.dateIn.month){
				DC_CAL.minAvailableDate = 1;
				DC_CAL.maxAvailableDate = 0;
			}
			//DC_CAL.handleMaxAvailableDate('show');
			DC_CAL.highlightStayDates('on');
		}
		else if(DC_CAL.dateIn.set == 1 || DC_CAL.dateOut.set ==  1){
			if(DC_CAL.dateIn.set == 1 && DC_CAL.dateOut.set ==  0){
				if(DC_CAL.refDate > DC_CAL.dateIn.date){
					DC_CAL.setMaxAvailableDate(DC_CAL.refDate);
					
					if(DC_CAL.refDate.getMonth() > DC_CAL.dateIn.month && DC_CAL.refDate.getFullYear() >= DC_CAL.dateIn.year){
						
						if(DC_CAL.refDate.getMonth() == 0){
							var previousMonth = new Date(Number(DC_CAL.refDate.getFullYear()-1), 11, 1);
						}
						else if(DC_CAL.refDate.getMonth() == 11){
							var previousMonth = new Date(Number(DC_CAL.refDate.getFullYear()+1), 0, 1);
						}
						else{
							var previousMonth = new Date(DC_CAL.refDate.getFullYear(), Number(DC_CAL.refDate.getMonth()-1), 1);
						}
						
						
						if(!DC_CAL.positionsTab[previousMonth.getFullYear()][previousMonth.getMonth()]){
							DispoCalendar.getPreviousMonthPlanning(DC_CAL.refDate, DC_CAL.hotelCode);
							var previousMonthDispo = true;
							for(var i=DC_CAL.dateIn.day; i<=previousMonth.getMonthDays(); i++){
								if(DC_CAL.dispoPreviousMonthArray[i]['status'] == 1){
									previousMonthDispo = false;
								}
							}
						}
						else{
							var previousMonthDispo = true;
							for(var i=DC_CAL.dateIn.day; i<=previousMonth.getMonthDays(); i++){
								if(DC_CAL.positionsTab[previousMonth.getFullYear()][previousMonth.getMonth()][i]['status'] == 1){
									previousMonthDispo = false;
								}
							}
						}
						
						if(previousMonthDispo == true) DC_CAL.handleMaxAvailableDate('show');
					}
					else{
						DC_CAL.handleMaxAvailableDate('show');
					}
					
					if(DC_CAL.maxAvailableDate == 0){
						DC_CAL.minAvailableDate = -1;
					}
					else{
						DC_CAL.setMinAvailableDate(new Date(DC_CAL.refYear, DC_CAL.refMonth, Number(DC_CAL.maxAvailableDate-1)), "begin");
					}
				}
				else if(DC_CAL.refMonth < DC_CAL.dateIn.month && DC_CAL.refYear <= DC_CAL.dateIn.year){
					DC_CAL.setMinAvailableDate(new Date(DC_CAL.refYear, DC_CAL.refMonth, DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth].length-1), "end");
					DC_CAL.maxAvailableDate = 0;
				}
				else{
					DC_CAL.setMaxAvailableDate(DC_CAL.dateIn.date);
					DC_CAL.setMinAvailableDate(DC_CAL.dateIn.date, "begin");
					DC_CAL.handleMaxAvailableDate('show');
				}
			}
			else if(DC_CAL.dateOut.set ==  1 && DC_CAL.dateIn.set == 0){
				if(DC_CAL.dateOut.month == DC_CAL.refMonth){
					DC_CAL.setMinAvailableDate(DC_CAL.dateOut.date, 'begin');
				}
				
				if(DC_CAL.dateOut.month > DC_CAL.refMonth){
					DC_CAL.maxAvailableDate = 0;
				}
				
				if(DC_CAL.refMonth == DC_CAL.dateMax.getMonth() && DC_CAL.refYear == DC_CAL.dateMax.getFullYear()){
					DC_CAL.setMaxAvailableDate(DC_CAL.refDate);
					DC_CAL.handleMaxAvailableDate('show');
				}
				else if(DC_CAL.refMonth == DC_CAL.dateOut.month && DC_CAL.refYear >= DC_CAL.dateOut.year){
					DC_CAL.setMaxAvailableDate(DC_CAL.dateOut.date);
					DC_CAL.handleMaxAvailableDate('show');
					if(DC_CAL.maxAvailableDate == DC_CAL.dateOut.day){
						DC_CAL.setMinAvailableDate(new Date(DC_CAL.dateOut.year, DC_CAL.dateOut.month, Number(DC_CAL.dateOut.day-1)), 'begin');
						if($(DC_CAL.dateList[DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][DC_CAL.maxAvailableDate].position].select('table')[0]).hasClassName('open')) 
							$(DC_CAL.dateList[DC_CAL.positionsTab[DC_CAL.refYear][DC_CAL.refMonth][DC_CAL.maxAvailableDate].position].select('table')[0]).addClassName("clicked1")
					}
				}
				else if(DC_CAL.refDate > DC_CAL.dateOut.date){
					DC_CAL.setMaxAvailableDate(DC_CAL.refDate);
					DC_CAL.handleMaxAvailableDate('show');
				}
			}
		}
		else if(DC_CAL.dateIn.set == 0 && DC_CAL.dateOut.set ==  0){
			DC_CAL.minAvailableDate = -1;
			DC_CAL.maxAvailableDate = 0;
		}
		
		if($('calendar-mask') && $('calendar-mask').style.display == 'block'){
			Effect.Fade('calendar-mask', 0.02);
		}
	},
	
	setMaskLayer : function(){
		if($('calendar-mask')){
			var mask = $('calendar-mask');
			var delta = mask.offsetTop;			
			var height = $('calendar').offsetHeight - delta;
			mask.style.height = height+"px";
			mask.style.display="block";
		}
	},
	
	setNavClickPrev : function(){
		
		Event.observe(
			$('nav_prev'),
			'click',
			function(evt){
				Event.stop(evt);
				if($('calendar-mask').style.display == 'none'){
					//DC_CAL.setMaskLayer();
					if(DC_CAL.refMonth != 0){
							var newMonth = DC_CAL.refMonth - 1;
							var newYear = DC_CAL.refYear;
					}
					else{
						var newMonth = 11;
						var newYear = DC_CAL.refYear - 1;
					}
					DC_CAL.lastAction = "previous";
					var dateParam = new Date(newYear, newMonth, DC_CAL.refDay);
					DC_CAL.rewriteCalendar(dateParam, 'previous');
				}
			}
		);
	},
	
	setNavClickNext : function(){
		
		Event.observe(
			$('nav_next'),
			'click',
			function(evt){
				Event.stop(evt);
				if($('calendar-mask').style.display == 'none'){
					//DC_CAL.setMaskLayer();
					if(DC_CAL.refMonth != 11){
						var newMonth = DC_CAL.refMonth + 1;
						var newYear = DC_CAL.refYear;
					}
					else{
						var newMonth = 0;
						var newYear = DC_CAL.refYear + 1;
					}
					DC_CAL.lastAction = "next";
					var dateParam = new Date(newYear, newMonth, 1);
					DC_CAL.rewriteCalendar(dateParam, 'next');
				}
			}
		);
	},
	
	cleanCalendar : function(){
		var dateList = $('calendar').select('td.date');
		for(i=0; i<dateList.length;i++){
			$(dateList[i]).innerHTML = "";
		}
	},
	
	initDateClickObserver : function(element){
		Event.observe(
			element,
			'click',
			function(event){
				if(!$(element).hasClassName('closed')){

					DC_CAL.dateHandler(element);
				}
			}
		);
	},
	
	navigationDisplayManager : function(){
		
		// si le mois en cours est le mois de la date du jour
		if(this.todayDate.getMonth() == this.refDate.getMonth() && this.todayDate.getFullYear() == this.refDate.getFullYear()){
			$('nav_prev').hide();
		}
		// sinon
		else{
			$('nav_prev').show();
		}
		
		
		// si on visualise le mois de la date max (J+405)
		if(this.refDateEndMonth > this.dateMax){
			$('nav_next').hide();
		}
		else{			
			$('nav_next').show();
		}
	},
	
	dateHandler : function(element){
		if(this.dateIn.set == 1 && this.dateOut.set == 1 && !$(element).hasClassName('clicked1') && !$(element).hasClassName('clicked2')){
			alert(I18N._('calendar', 'date.already.clicked'));
		}
		else{
			if($(element).hasClassName('clicked1') || $(element).hasClassName('clicked2')){ // la date qui vient d'etre cliquee l'etait deja
				this.highlightStayDates('off');
				if(this.dateIn.set == 1 || this.dateOut.set == 1){
					$('submitLink').addClassName('disable');
					switch(Number($(element).select('span.numJour')[0].innerHTML)){
						case (Number(this.dateIn.day)) :
							this.hasAlreadyClickedOnce = true;
							this.dateIn.set = 0;
							DC_CAL.setMinAvailableDate(DC_CAL.dateIn.date, 'begin');
	
							if(this.dateOut.set == 0){
								this.handleMaxAvailableDate('hide', $(element).select('span.numJour')[0].innerHTML);
							}
							else{
								if(this.refMonth == this.dateOut.month){
									DC_CAL.setMaxAvailableDate(DC_CAL.dateOut.date);
								}
							}
						
							if(this.dateOut.set == 0 && this.dateIn.set == 0 && this.todayDate.getMonth() != this.refMonth){
								DC_CAL.minAvailableDate = -1;
							}
	
							this.navigationDisplayManager();
							this.dateIn.day = null;
							this.dateIn.month = null;
							this.dateIn.year = null;
							this.dateIn.formatedDate = '';
							this.dateIn.date = '';
							$('arrival_date').innerHTML = this.dateIn.formatedDate;
							$(element).removeClassName('clicked1');
							$(element).removeClassName('clicked2');
	
							break;
							
						case (Number(this.dateOut.day)) :
							this.hasAlreadyClickedOnce = true;
							this.dateOut.set = 0;
							if(this.refMonth == this.dateIn.month){
								DC_CAL.setMinAvailableDate(DC_CAL.dateIn.date, 'begin');
								DC_CAL.setMaxAvailableDate(DC_CAL.dateIn.date);
							}
							else if(this.refMonth == this.dateOut.month){
								DC_CAL.setMaxAvailableDate(DC_CAL.refDate);
							}
							if(this.dateIn.set == 0){
								this.handleMaxAvailableDate('hide', $(element).select('span.numJour')[0].innerHTML);
							}
							
							if(this.dateOut.set == 0 && this.dateIn.set == 0 && this.todayDate.getMonth() != this.refMonth){
								DC_CAL.minAvailableDate = -1;
							}
							this.navigationDisplayManager();
							
							this.dateOut.day = null;
							this.dateOut.month = null;
							this.dateOut.year = null;
							this.dateOut.formatedDate = '';
							this.dateOut.date = '';
							$('departure_date').innerHTML = this.dateOut.formatedDate;
							$(element).removeClassName('clicked1');
							$(element).removeClassName('clicked2');
	
							break;
							
						default :
							break;
					}
				}
				if(this.dateOut.set == 0 && this.dateIn.set == 0) $('reset').addClassName('disable');
			}
			else{ // la date n'etait pas deja clique
				if(this.dateIn.set == 0 && this.dateOut.set == 0){// si aucune date n'a ete choisi
					this.dateIn.set = 1;
					this.dateIn.day = $(element).select('span.numJour')[0].innerHTML;
					this.dateIn.month = this.refMonth;
					this.dateIn.year = this.refYear;
					this.dateIn.date = new Date(this.dateIn.year, this.dateIn.month, this.dateIn.day);
					this.dateIn.formatedDate = this.dateIn.date.print(Calendar._TT["SHT_DATE_FORMAT"]);
					$('arrival_date').innerHTML = this.dateIn.formatedDate;
	
					if($(element).hasClassName('cheapest')) $(element).addClassName('clicked2');
					if($(element).hasClassName('open')) $(element).addClassName('clicked1');
					$('reset').removeClassName('disable');
					this.setMaxAvailableDate(this.dateIn.date);
					this.setMinAvailableDate(this.dateIn.date, "begin");
					this.handleMaxAvailableDate('show', $(element.select('span.numJour')[0].innerHTML));
					this.navigationDisplayManager();
				}
				else if(this.dateIn.set == 1 && this.dateOut.set == 0){
					this.dateOut.set = 1;
					this.dateOut.day = $(element).select('span.numJour')[0].innerHTML;
					this.dateOut.month = this.refMonth;
					this.dateOut.year = this.refYear;
					
					this.dateOut.date = new Date(this.dateOut.year, this.dateOut.month, this.dateOut.day);
					this.dateOut.formatedDate = this.dateOut.date.print(Calendar._TT["SHT_DATE_FORMAT"]);
					
					if(this.checkChoiceValidity()){
						if(this.checkStayLength()){
							$('departure_date').innerHTML = this.dateOut.formatedDate;
							if($(element).hasClassName('cheapest')) $(element).addClassName('clicked2');
							if($(element).hasClassName('open')) $(element).addClassName('clicked1');
							if(this.refMonth == this.dateIn.month){
								DC_CAL.minAvailableDate = this.dateIn.day;
								DC_CAL.maxAvailableDate = this.dateOut.day;
							}
							else if(this.refMonth == this.dateOut.month && this.dateIn.date < this.dateOut.date){
								DC_CAL.minAvailableDate = -1;
								DC_CAL.maxAvailableDate = this.dateOut.day;
							}
							else if(this.refMonth == this.dateOut.month && this.dateIn.date > this.dateOut.date){
								DC_CAL.minAvailableDate = this.dateOut.day;;
								DC_CAL.maxAvailableDate = 0;
							}
							$('submitLink').removeClassName('disable');
						}
						else{
							this.dateOut.set = 0;
							this.dateOut.day = null;
							this.dateOut.month = null;
							this.dateOut.year = null;
							alert(this.printNightsNb(I18N._('calendar', 'tooManyNights')));
						}
					}
					else{
						this.dateOut.set = 0;
						this.dateOut.day = null;
						this.dateOut.month = null;
						this.dateOut.year = null;
						alert(this.printNightsNb(I18N._('calendar', 'nightNotAvailable')));
					}
	
					this.navigationDisplayManager();
				}
				else if(this.dateIn.set == 0 && this.dateOut.set == 1){
					this.dateIn.set = 1;
					this.dateIn.day = $(element).select('span.numJour')[0].innerHTML;
					
					this.dateIn.month = this.refMonth;
					this.dateIn.year = this.refYear;
					
					this.dateIn.date = new Date(this.dateIn.year, this.dateIn.month, this.dateIn.day);
					this.dateIn.formatedDate = this.dateIn.date.print(Calendar._TT["SHT_DATE_FORMAT"]);
					
					if(this.checkChoiceValidity()){
						if(this.checkStayLength()){
							$('arrival_date').innerHTML = this.dateIn.formatedDate;
							if($(element).hasClassName('cheapest')) $(element).addClassName('clicked2');
							if($(element).hasClassName('open')) $(element).addClassName('clicked1');
							
							if(this.refMonth == this.dateOut.month){
								DC_CAL.maxAvailableDate = this.dateOut.day;	
							}
							DC_CAL.minAvailableDate = this.dateIn.day;
							
							if(this.refMonth == this.dateIn.month && this.refMonth != this.dateOut.month && this.dateIn.date < this.dateOut.date){
								DC_CAL.maxAvailableDate = 0;
							}
							else if(this.refMonth == this.dateIn.month && this.dateIn.date > this.dateOut.date){
								DC_CAL.maxAvailableDate = this.dateIn.day;
							}
							
							this.navigationDisplayManager();
							$('submitLink').removeClassName('disable');
						}
						else{
							this.dateIn.set = 0;
							this.dateIn.day = null;
							this.dateIn.month = null;
							this.dateIn.year = null;
							alert(this.printNightsNb(I18N._('calendar', 'tooManyNights')));
						}
					}
					else{
						this.dateIn.set = 0;
						this.dateIn.day = null;
						this.dateIn.month = null;
						this.dateIn.year = null;
						alert(this.printNightsNb(I18N._('calendar', 'nightNotAvailable')));
					}
					
				}
				
				if(this.dateOut.set != 0 && this.dateIn.set != 0){
					if(this.dateOut.date.getTime() < this.dateIn.date.getTime()){
						if(this.checkChoiceValidity()){
							var tempDay = this.dateIn.day;
							var tempMonth = this.dateIn.month;
							var tempYear = this.dateIn.year;
							this.dateIn.day = this.dateOut.day;
							this.dateIn.month = this.dateOut.month;
							this.dateIn.year = this.dateOut.year;
							
							this.dateIn.date = new Date(this.dateIn.year, this.dateIn.month, this.dateIn.day);
							this.dateIn.formatedDate = this.dateIn.date.print(Calendar._TT["SHT_DATE_FORMAT"]);
							$('arrival_date').innerHTML = this.dateIn.formatedDate;
							this.dateOut.day = tempDay;
							this.dateOut.month = tempMonth;
							this.dateOut.year = tempYear;
							
							this.dateOut.date = new Date(this.dateOut.year, this.dateOut.month, this.dateOut.day);
							this.dateOut.formatedDate = this.dateOut.date.print(Calendar._TT["SHT_DATE_FORMAT"]);
							$('departure_date').innerHTML = this.dateOut.formatedDate;
						}
						else{
							alert(this.printNightsNb(I18N._('calendar', 'nightNotAvailable')));
						}
					}
					if(this.checkStayLength()){
						this.highlightStayDates('on');
					}
				}
			}
		}
	},
	
	setMaxAvailableDate : function(date){
		var year = date.getFullYear();
		var month = date.getMonth();
		var day = date.getDate();
		var max = DC_CAL.positionsTab[year][month].length;
		
		for(i=day; i<max; i++){
			if(DC_CAL.positionsTab[year][month][i].status == 1){
				this.maxAvailableDate = i;
				break;
			}
			else{
				if(year == this.dateMax.getFullYear() && month == this.dateMax.getMonth() && i == this.dateMax.getDate()){
					this.maxAvailableDate = i+1;
					break;
				}
				else{
					this.maxAvailableDate = 0;
				}
			}
		}
	},
	
	setMinAvailableDate : function(date, start){
		var year = date.getFullYear();
		var month = date.getMonth();
		var day = date.getDate();
		if(start == "begin"){
			var min = 1;
			for(i=day; i>=min; i--){
				if(DC_CAL.positionsTab[year][month][i].status == 1){
					this.minAvailableDate = i;
					break;
				}
				else{
					this.minAvailableDate = -1;
				}
			}
		}
		else if(start == "end"){
			var min = DC_CAL.positionsTab[year][month].length-1;
			for(i=min; i>=1; i--){
				if(DC_CAL.positionsTab[year][month][i].status == 1){
					this.minAvailableDate = i;
					break;
				}
			}
		}
	},
	
	handleMaxAvailableDate : function(action){
		if(this.maxAvailableDate != 0){
			if(action == "show"){
				if(this.refMonth == this.dateMax.getMonth() && this.refYear == this.dateMax.getFullYear()){
					$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate].position].select('table')[0]).removeClassName("closed");
					$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate].position].select('table')[0]).addClassName("open");
				}
				else{
					$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate].position].select('table')[0]).removeClassName("closed");
					$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate].position].select('table')[0]).addClassName("open");
					if(DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate+1]){
						if(DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate+1].status != 1){
							$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate+1].position].select('table')[0]).addClassName("closed");
							$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate+1].position].select('table')[0]).removeClassName("open");
						}
					}
				}
			}
			else{
				if(this.refMonth == this.dateMax.getMonth() && this.refYear == this.dateMax.getFullYear()){
					$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate].position].select('table')[0]).removeClassName("open");
					$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate].position].select('table')[0]).addClassName("closed");
				}
				else{
					$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate].position].select('table')[0]).removeClassName("open");
					$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate].position].select('table')[0]).addClassName("closed");
					if(DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate+1]){
						if(DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate+1].status != 1){
							$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate+1].position].select('table')[0]).addClassName("open");
							$(this.dateList[DC_CAL.positionsTab[this.refYear][this.refMonth][this.maxAvailableDate+1].position].select('table')[0]).removeClassName("closed");
						}
					}
				}
				this.maxAvailableDate = 0;
			}
		}
	},
	
	checkStayLength : function(){
		var limitDate = new Date();
		
		if(this.dateOut.date.getTime() < this.dateIn.date.getTime()){
			limitDate.setTime(this.dateIn.date.getTime() - (this.maxStay*Date.DAY));
			if(this.dateOut.date >= limitDate){
				return true;
			}
			else{
				return false;
			}
		}
		else{
				limitDate.setTime(this.dateIn.date.getTime() + (this.maxStay*Date.DAY));
				if(this.dateOut.date <= limitDate){
					return true;
				}
				else{
					return false;
				}
		}
	},
	
	checkChoiceValidity : function(cas){
		if(this.dateOut.date.getTime() < this.dateIn.date.getTime()){
			var yearIn = this.dateOut.year;
			var monthIn = this.dateOut.month;
			var dayIn = this.dateOut.day;
			var yearOut = this.dateIn.year;
			var monthOut = this.dateIn.month;
			var dayOut = this.dateIn.day;
		}
		else{
			var yearIn = this.dateIn.year;
			var monthIn = this.dateIn.month;
			var dayIn = this.dateIn.day;
			var yearOut = this.dateOut.year;
			var monthOut = this.dateOut.month;
			var dayOut = this.dateOut.day;
		}
		
		
		var ko = 0;
		if(monthIn == monthOut && yearIn == yearOut){
			for(i= parseInt(dayIn); i< parseInt(dayOut); i++){
				if(DC_CAL.positionsTab[yearIn][monthIn][i].status == 1){
					ko = 1;
				}
			}
		}
		else{			
			if(DC_CAL.positionsTab[yearIn][monthIn]){
				for(var i=dayIn; i<=DC_CAL.positionsTab[yearIn][monthIn].length-1; i++){
					if(DC_CAL.positionsTab[yearIn][monthIn][i]['status'] == 1){
						ko = 1;
					}
				}
			}
			
			if(ko == 0){
				if(DC_CAL.positionsTab[yearOut][monthOut]){
					for(var i=1; i<=dayOut; i++){
						if(DC_CAL.positionsTab[yearOut][monthOut][i]['status'] == 1){
							ko = 1;
						}
					}
				}
			}			
		}
		if(ko == 0){
			return true;
		}
		else{
			return false;
		}
	},
	
	highlightStayDates : function(mode){
		var dateList = $('calendar').select('td.date');
		if(this.refYear == this.dateIn.year && this.refMonth == this.dateIn.month){
			var indexIn = DC_CAL.positionsTab[this.refYear][this.refMonth][Number(this.dateIn.day)].position;
			var posIn = dateList[indexIn].select('table')[0];
			if(mode == 'on'){
				//$(posIn).addClassName('periodStay');
				if($(posIn.hasClassName('open'))) $(posIn).addClassName('clicked1');
				if($(posIn.hasClassName('cheapest'))) $(posIn).addClassName('clicked2');
			}
			else{
				if($(posIn).hasClassName('periodStay')){
					//$(posIn).removeClassName('periodStay');
				}
			}
		}
		
		if(this.refYear == this.dateOut.year && this.refMonth == this.dateOut.month){
			var indexOut = DC_CAL.positionsTab[this.refYear][this.refMonth][this.dateOut.day].position;
			var posOut = dateList[indexOut].select('table')[0];
			if(mode == 'on'){
				//$(posOut).addClassName('periodStay');
				if($(posOut.hasClassName('open'))) $(posOut).addClassName('clicked1');
				if($(posOut.hasClassName('cheapest'))) $(posOut).addClassName('clicked2');
			}
			else{
				if($(posOut).hasClassName('periodStay')){
					//$(posOut).removeClassName('periodStay');
				}
			}
		}
		
		if(this.dateIn.year == this.dateOut.year && this.dateIn.month == this.dateOut.month && this.refYear == this.dateIn.year && this.refMonth == this.dateIn.month){
			var indexIn = DC_CAL.positionsTab[this.refYear][this.refMonth][Number(this.dateIn.day)].position;
			var indexOut = DC_CAL.positionsTab[this.refYear][this.refMonth][Number(this.dateOut.day)].position;
			for(i=indexIn+1; i<indexOut; i++){
				if(mode == 'on'){
					if($(dateList[i]).select('table')[0].hasClassName('open')){
						$(dateList[i]).select('table')[0].addClassName('periodStayInner');
					}
					
					if($(dateList[i]).select('table')[0].hasClassName('cheapest')){
						$(dateList[i]).select('table')[0].addClassName('periodStayInner2');
					}
				}
				else{
					$(dateList[i]).select('table')[0].removeClassName('periodStayInner');
					$(dateList[i]).select('table')[0].removeClassName('periodStayInner2');
				}
			}
		}
		else{
			if(this.refYear == this.dateIn.year && this.refMonth == this.dateIn.month){
				var indexIn = DC_CAL.positionsTab[this.refYear][this.refMonth][this.dateIn.day].position;
				var indexLastDay = DC_CAL.positionsTab[this.refYear][this.refMonth][this.refDate.getMonthDays()].position;
				for(i=indexIn+1; i<=indexLastDay; i++){
					if(mode == 'on'){
						if($(dateList[i]).select('table')[0].hasClassName('open')){
							$(dateList[i]).select('table')[0].addClassName('periodStayInner');
						}
						
						if($(dateList[i]).select('table')[0].hasClassName('cheapest')){
							$(dateList[i]).select('table')[0].addClassName('periodStayInner2');
						}
						
					}
					else{
						$(dateList[i]).select('table')[0].removeClassName('periodStayInner');
						$(dateList[i]).select('table')[0].removeClassName('periodStayInner2');
					}
				}
			}
			
			if(this.refYear == this.dateOut.year && this.refMonth == this.dateOut.month){
				var indexOut = DC_CAL.positionsTab[this.refYear][this.refMonth][this.dateOut.day].position;
				var indexFirstDay = DC_CAL.positionsTab[this.refYear][this.refMonth][1].position;
				for(i=indexOut-1; i>=indexFirstDay; i--){
					if(mode == 'on'){
						if($(dateList[i]).select('table')[0].hasClassName('open')){
							$(dateList[i]).select('table')[0].addClassName('periodStayInner');
						}
						
						if($(dateList[i]).select('table')[0].hasClassName('cheapest')){
							$(dateList[i]).select('table')[0].addClassName('periodStayInner2');
						}
						
					}
					else{
						$(dateList[i]).select('table')[0].removeClassName('periodStayInner');
						$(dateList[i]).select('table')[0].removeClassName('periodStayInner2');
					}
				}
			}
		}
	},
	
	initResetButton : function(){
		if($('reset')){
			Event.observe(
				$('reset'),
				'click',
				function(evt){
					Event.stop(evt);
					if(!$('reset').hasClassName('disable')){
						DC_CAL.dateIn.set = 0;
						DC_CAL.dateIn.day = null;
						DC_CAL.dateIn.month = null;
						DC_CAL.dateIn.year = null;
						DC_CAL.dateIn.formatedDate = null;
						
						DC_CAL.dateOut.set = 0;
						DC_CAL.dateOut.day = null;
						DC_CAL.dateOut.month = null;
						DC_CAL.dateOut.year = null;
						DC_CAL.dateOut.formatedDate = null;
						DC_CAL.maxAvailableDate = 0;
						DC_CAL.minAvailableDate = -1;
						
						if($('side_infos')){
							$('reset').addClassName('disable');
							$('submitLink').addClassName('disable');
							
							$('arrival_date').innerHTML = '';
							$('departure_date').innerHTML = '';
							
							var dateParam = new Date(DC_CAL.refYear, DC_CAL.refMonth, DC_CAL.refDay);
							DispoCalendar.dateType = "default";
							DC_CAL.rewriteCalendar(dateParam);
						}
					}
					
				}
			);
		}
	},
	
	printNightsNb : function(str){
		var s = {};
		s["%x"] = this.maxStay;
		var re = /%./g;
		if (!Calendar.is_ie5 && !Calendar.is_khtml)
			return str.replace(re, function (par) { return s[par] || par; });

		var a = str.match(re);
		for (var i = 0; i < a.length; i++) {
			var tmp = s[a[i]];
			if (tmp) {
				re = new RegExp(a[i], 'g');
				str = str.replace(re, tmp);
			}
		}

		return str;
	},
	
	getNbNights : function(){
		var dateIn = this.dateIn.date;
		var dateOut = this.dateOut.date;
		return (Math.round((dateOut - dateIn)/Date.DAY));
	}
}

Date.prototype.getMonthDays = function(month) {
	var year = this.getFullYear();
	if (typeof month == "undefined") {
		month = this.getMonth();
	}
	if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
		return 29;
	} else {
		return Date._MD[month];
	}
};

Date._MD = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

Date.SECOND = 1000 /* milliseconds */;
Date.MINUTE = 60 * Date.SECOND;
Date.HOUR   = 60 * Date.MINUTE;
Date.DAY    = 24 * Date.HOUR;
Date.WEEK   =  7 * Date.DAY;

/* Prints the date in a string according to the given format. */
Date.prototype.print = function (str) {
	var m = this.getMonth();
	var d = this.getDate();
	var y = this.getFullYear();
	var wn = this.getWeekNumber();
	var w = this.getDay();
	var s = {};
	var hr = this.getHours();
	var pm = (hr >= 12);
	var ir = (pm) ? (hr - 12) : hr;
	var dy = this.getDayOfYear();
	if (ir == 0)
		ir = 12;
	var min = this.getMinutes();
	var sec = this.getSeconds();
	s["%a"] = Calendar._SDN[w]; // abbreviated weekday name [FIXME: I18N]
	s["%A"] = Calendar._DN[w]; // full weekday name
	s["%b"] = Calendar._SMN[m]; // abbreviated month name [FIXME: I18N]
	s["%B"] = Calendar._MN[m]; // full month name
	// FIXME: %c : preferred date and time representation for the current locale
	s["%C"] = 1 + Math.floor(y / 100); // the century number
	s["%d"] = (d < 10) ? ("0" + d) : d; // the day of the month (range 01 to 31)
	s["%e"] = d; // the day of the month (range 1 to 31)
	// FIXME: %D : american date style: %m/%d/%y
	// FIXME: %E, %F, %G, %g, %h (man strftime)
	s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format)
	s["%I"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format)
	s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366)
	s["%k"] = hr;		// hour, range 0 to 23 (24h format)
	s["%l"] = ir;		// hour, range 1 to 12 (12h format)
	s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m); // month, range 01 to 12
	s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
	s["%n"] = "\n";		// a newline character
	s["%p"] = pm ? "PM" : "AM";
	s["%P"] = pm ? "pm" : "am";
	// FIXME: %r : the time in am/pm notation %I:%M:%S %p
	// FIXME: %R : the time in 24-hour notation %H:%M
	s["%s"] = Math.floor(this.getTime() / 1000);
	s["%S"] = (sec < 10) ? ("0" + sec) : sec; // seconds, range 00 to 59
	s["%t"] = "\t";		// a tab character
	// FIXME: %T : the time in 24-hour notation (%H:%M:%S)
	s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn;
	s["%u"] = w + 1;	// the day of the week (range 1 to 7, 1 = MON)
	s["%w"] = w;		// the day of the week (range 0 to 6, 0 = SUN)
	// FIXME: %x : preferred date representation for the current locale without the time
	// FIXME: %X : preferred time representation for the current locale without the date
	s["%y"] = ('' + y).substr(2, 2); // year without the century (range 00 to 99)
	s["%Y"] = y;		// year with the century
	s["%%"] = "%";		// a literal '%' character

	var re = /%./g;
	if (!Calendar.is_ie5 && !Calendar.is_khtml)
		return str.replace(re, function (par) { return s[par] || par; });

	var a = str.match(re);
	for (var i = 0; i < a.length; i++) {
		var tmp = s[a[i]];
		if (tmp) {
			re = new RegExp(a[i], 'g');
			str = str.replace(re, tmp);
		}
	}

	return str;
};

/* Returns the number of day in the year. */
Date.prototype.getDayOfYear = function() {
	var now = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
	var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0);
	var time = now - then;
	return Math.floor(time / Date.DAY);
};

/* Returns the number of the week in year, as defined in ISO 8601. */
Date.prototype.getWeekNumber = function() {
	var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
	var DoW = d.getDay();
	d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu
	var ms = d.valueOf(); // GMT
	d.setMonth(0);
	d.setDate(4); // Thu in Week 1
	return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
};

//Declanche un evenement
function fireEvent(element,event){
  if (document.createEventObject){
      // dispatch for IE
      var evt = document.createEventObject();
      element.fireEvent('on'+event,evt)
  }
  else{
      // dispatch for firefox + others
      var evt = document.createEvent("HTMLEvents");
      evt.initEvent(event, true, true ); // event type,bubbling,cancelable
       !element.dispatchEvent(evt);
  }
}	