var resultatAlternatif = {
	
  bookingEngineViewBean : null,
  alternativeHotelsViewBean : null,  
    
    /**
     * Liste des noms d'objets à utiliser.
     */
		getBeans: function() {
        return "BookingEngineViewBean;AlternativeHotelsViewBean";
    },
    
    /**
     * Initialisation de la variable JSON
     */
    initJSON: function() {
      this.alternativeHotelsViewBean = viewBeans["AlternativeHotelsViewBean"];
	  this.bookingEngineViewBean = viewBeans["BookingEngineViewBean"];
    },
        
    /**
     * 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() {
        var hotels = this.alternativeHotelsViewBean.hotels;
        if(hotels && hotels.length > 0){
        	this.writeHotelsList(hotels);
        }
        else{
        	$('hotels_proxi').style.display = "none";
        }
                
        this.writeGivenDates();       
        //Si l'on ne peut pas changer les dates, on masque le calendreir de dispo        
        if(bookingEngineViewBean.modifDate)
        	$("calendar_dispo").show();
        
        this.fillInListeHotelForm();
		
		if(bookingEngineViewBean.hotelsListUrl==null)
			$("launchSearch").up().style.display = "none";
    },
    
    writeHotelsList : function(hotels){
    	if($('liste')){
    		var listeUl = $('liste');
    		for(var i=0; i < hotels.length; i++){
    			var li = document.createElement('li');
    			li.innerHTML = "<img src='/imagerie/reservation/picto_"+ hotels[i].brand+".gif' border='0' />";
    			li.innerHTML += "<a href='/selectPax.svlt?isCodeTars=1&hotel_ville="+hotels[i].code+"&marque="+hotels[i].brand+"'>"+hotels[i].name+"</a>";
    			li.innerHTML += " ("+hotels[i].distance+" km)";
    			listeUl.appendChild(li);
    		}
    	}
    },
    
    writeGivenDates : function(){
    	if($('given_dates') && this.alternativeHotelsViewBean.period.dayIn != null
    											&& this.alternativeHotelsViewBean.period.monthIn != null
    											&& this.alternativeHotelsViewBean.period.yearIn != null
    											&& this.alternativeHotelsViewBean.period.dayOut != null
    											&& this.alternativeHotelsViewBean.period.monthOut != null
    											&& this.alternativeHotelsViewBean.period.yearOut != null){
    		var givenDateIn = new Date(this.alternativeHotelsViewBean.period.yearIn, Number(this.alternativeHotelsViewBean.period.monthIn-1), this.alternativeHotelsViewBean.period.dayIn);
    		var givenDateOut = new Date(this.alternativeHotelsViewBean.period.yearOut, Number(this.alternativeHotelsViewBean.period.monthOut-1), this.alternativeHotelsViewBean.period.dayOut);
    		$('given_dates').innerHTML = givenDateIn.print(Calendar._TT["SHT_DATE_FORMAT"]) +" - "+ givenDateOut.print(Calendar._TT["SHT_DATE_FORMAT"]);
    	}
    },
    
    fillInListeHotelForm : function(){
    	if(this.alternativeHotelsViewBean.period.dayIn != null
				&& this.alternativeHotelsViewBean.period.monthIn != null
				&& this.alternativeHotelsViewBean.period.yearIn != null
				&& this.alternativeHotelsViewBean.period.nbDay != null
				&& this.alternativeHotelsViewBean.geoZone.geoName != null){
					$('nom_ville').value = this.alternativeHotelsViewBean.geoZone.geoName;
					$('jour_arrivee').value = this.alternativeHotelsViewBean.period.dayIn;
					$('mois_arrivee').value = this.alternativeHotelsViewBean.period.monthIn;
					$('annee_arrivee').value = this.alternativeHotelsViewBean.period.yearIn;
					$('nb_nuit').value = this.alternativeHotelsViewBean.period.nbDay;
					
					if($('launchSearch')){
						Event.observe(
							$('launchSearch'),
							'click',
							function(evt){
								Event.stop(evt);
								document.bookingEngine.submit();
							}
						);
					}
    	}
    }
}

core.push(resultatAlternatif);