function cal_reservation(id_du_jour,id_du_mois,id_du_annee,id_du_retour,object_cal,ref_vpc,id_du_retour_resultat,id_du_logement,id_du_codfc)  {
	
	this.duree_selection="";
	this.id_du_jour=id_du_jour;
	this.id_du_mois=id_du_mois;
	this.id_du_annee=id_du_annee;
	this.id_du_retour=id_du_retour;
	this.id_du_retour_resultat=id_du_retour_resultat;
	this.object_cal=object_cal;
	this.ref_vpc=ref_vpc;
	this.id_du_logement=id_du_logement;
	this.id_du_codfc=id_du_codfc;
	this.nb_personne="";
	this.compo_personnes="";
	this.id_dates_naissances="";
	
	this.cal_init = function(jour,mois,annee,duree){
		this.duree_selection=duree;
		document.getElementById(this.id_du_jour).value=jour;
		document.getElementById(this.id_du_mois).value=mois;
		document.getElementById(this.id_du_annee).value=annee;
		this.cal_afficher("",mois,annee,this.duree_selection);
		if(jour!=""){			
			setTimeout(this.object_cal+".cal_selection_jour("+jour+","+mois+","+annee+")",1000);	
		}
	}
	
	this.cal_afficher= function(jour,mois,annee,duree){ 
		var req = createXHR();
		req.onreadystatechange = function(){ 
			if(req.readyState == 4){
				if(req.status == 200){
					document.getElementById(id_du_retour).innerHTML=req.responseText;
				}	
			} 
		}; 
		req.open("GET", "include/calendrier_resa.php?jour="+jour+"&mois="+mois+"&annee="+annee+"&duree="+duree+"&object_cal="+this.object_cal+"&ref_vpc="+this.ref_vpc, true); 
		req.send(null);	
		//setTimeout("affiche_calendrier()", 2000); 
	}
	
	this.cal_afficher_resultat= function(jour,mois,annee,id_du_retour_resultat_bis){ 
		var req = createXHR();
		req.onreadystatechange = function(){ 
			if(req.readyState == 4){
				if(req.status == 200){
					if(id_du_retour_resultat_bis){
						document.getElementById(id_du_retour_resultat_bis).innerHTML=req.responseText;
					}else{
						document.getElementById(id_du_retour_resultat).innerHTML=req.responseText;
					}
				}	
			} 
		}; 
		if(id_du_retour_resultat_bis){
			document.getElementById(id_du_retour_resultat_bis).innerHTML='<br><img src="images/indicator2.gif" border="0" />';
		}else{
			document.getElementById(id_du_retour_resultat).innerHTML='<br><img src="images/indicator2.gif" border="0" />';
		}		
		req.open("GET", "include/calendrier_resultat.php?jour="+jour+"&mois="+mois+"&annee="+annee+"&duree="+this.duree_selection+"&object_cal="+this.object_cal+"&ref_vpc="+this.ref_vpc+"&compo_personnes="+this.compo_personnes, true); 
		req.send(null);	
	}
	
	this.cal_affiche_cache_region= function(jour,mois,annee){ 
		var req = createXHR();
		req.onreadystatechange = function(){ 
			if(req.readyState == 4){
				if(req.status == 200){
					r=req.responseText.split("!!");
					
					for(i=0; i<tab_region.length; i++){
						document.getElementById("reg_"+tab_region[i][0]).style.display="none";						
						document.getElementById("chk_reg_"+tab_region[i][0]).setAttribute("reserv_impossible","1");
						//alert("c region : " + tab_region[i][0] + " - " + document.getElementById("chk_reg_"+tab_region[i][0]).getAttribute("reserv_impossible"));
					}
					
					for(i=0; i<r.length; i++){
						if(r[i]!="" && document.getElementById("reg_"+r[i])){
							document.getElementById("reg_"+r[i]).style.display="";
							document.getElementById("chk_reg_"+r[i]).setAttribute("reserv_impossible","0");
							//alert("a region : " + r[i]+ " - " + document.getElementById("chk_reg_"+r[i]).getAttribute("reserv_impossible"));
						}						
					}
					maj_region("");
					possibilite_critere("");
				}	
			} 
		}; 		
		req.open("GET", "include/calendrier_regions.php?jour="+jour+"&mois="+mois+"&annee="+annee+"&duree="+this.duree_selection, true); 
		req.send(null);	
	}
	
	this.cal_mois_suivant = function(mois,annee){
		document.getElementById(this.id_du_jour).value='';
		document.getElementById(this.id_du_mois).value=mois;
		document.getElementById(this.id_du_annee).value=annee;
		this.cal_afficher('',mois,annee,this.duree_selection);
	}
	
	this.cal_mois_precedent = function(mois,annee){
		document.getElementById(this.id_du_jour).value='';
		document.getElementById(this.id_du_mois).value=mois;
		document.getElementById(this.id_du_annee).value=annee;
		this.cal_afficher('',mois,annee,this.duree_selection);
	}
	
	this.cal_selection_jour = function(jour,mois,annee){
		document.getElementById(this.id_du_jour).value=jour;
		document.getElementById(this.id_du_mois).value=mois;
		document.getElementById(this.id_du_annee).value=annee;
		this.cal_afficher(jour,mois,annee,this.duree_selection);		
		if(this.ref_vpc!=""){		
			this.cal_afficher_resultat(jour,mois,annee);
		}else{			
			if(document.getElementById("chk_reg_1")){
				this.cal_affiche_cache_region(jour,mois,annee);
			}			
		}
	}
	
	this.cal_deselection_jour = function(jour,mois,annee){
		document.getElementById(this.id_du_jour).value="";
		document.getElementById(this.id_du_mois).value=mois;
		document.getElementById(this.id_du_annee).value=annee;
		this.cal_afficher("",mois,annee,this.duree_selection);		
		if(this.ref_vpc!=""){		
			document.getElementById(id_du_retour_resultat).innerHTML="";
		}else{			
			if(document.getElementById("chk_reg_1")){
				for(i=0; i<tab_region.length; i++){
					document.getElementById("reg_"+tab_region[i][0]).style.display="none";						
					document.getElementById("chk_reg_"+tab_region[i][0]).setAttribute("reserv_impossible","0");					
				}
				maj_region("");
			}			
		}
	}
	
	this.cal_selection_logement = function(codelog,codfc){
		document.getElementById(this.id_du_logement).value=codelog;
		document.getElementById(this.id_du_codfc).value=codfc;
		if(document.reservation.nb_personne.value==0){
			alert("Veuillez sélectionner le nombre de personne souhaitant venir au séjour.");
			document.reservation.nb_adulte.focus();
		}else{
			for(i=1; i<=this.nb_personne; i++){				
				if(document.getElementById(this.id_dates_naissances + "jj_" + i).value=="" || document.getElementById(this.id_dates_naissances + "mm_"  + i).value=="" || document.getElementById(this.id_dates_naissances + "aa_"  + i).value==""){
					document.getElementById(this.id_dates_naissances + "jj_" + i).selectedIndex=0;
					document.getElementById(this.id_dates_naissances + "mm_" + i).selectedIndex=0;
					document.getElementById(this.id_dates_naissances + "aa_" + i).selectedIndex=0;
				}
			}
			this.nb_personne++;
			while(document.getElementById(this.id_dates_naissances + "jj_" + this.nb_personne)){
				document.getElementById(this.id_dates_naissances + "jj_" + this.nb_personne).selectedIndex=0;
				document.getElementById(this.id_dates_naissances + "mm_" + this.nb_personne).selectedIndex=0;
				document.getElementById(this.id_dates_naissances + "aa_" + this.nb_personne).selectedIndex=0;
				this.nb_personne++;
			}
			document.reservation.submit();	
		}
	}
	
	this.cal_change_duree = function(duree){
		document.getElementById(this.id_du_jour).value='';
		this.duree_selection=duree;
		this.cal_afficher('',document.getElementById(this.id_du_mois).value,document.getElementById(this.id_du_annee).value,this.duree_selection);
		if(id_du_retour_resultat!=""){
			document.getElementById(id_du_retour_resultat).innerHTML="";
		}
	}
	
	this.cal_change_nb_personne = function(nb,id_dates_naissances){
		this.id_dates_naissances=id_dates_naissances;
		this.nb_personne=nb;
		this.compo_personnes="";
		for(i=1; i<=nb; i++){
			if(i!=1){
				this.compo_personnes+="-";
			}
			if(document.getElementById(id_dates_naissances+"jj_"+i).value=="" || document.getElementById(id_dates_naissances+"mm_"+i).value=="" || document.getElementById(id_dates_naissances+"aa_"+i).value==""){
				this.compo_personnes+=" ";
			}else{
				this.compo_personnes+=document.getElementById(id_dates_naissances+"jj_"+i).value+"/"+document.getElementById(id_dates_naissances+"mm_"+i).value+"/"+document.getElementById(id_dates_naissances+"aa_"+i).value;
			}			
		}
		document.getElementById(this.id_du_jour).value='';
		this.cal_afficher('',document.getElementById(this.id_du_mois).value,document.getElementById(this.id_du_annee).value,this.duree_selection);
		if(id_du_retour_resultat!=""){
			document.getElementById(id_du_retour_resultat).innerHTML="";		
		}
	}
}

//création de l'objet XMLHTTP en fonction du navigateur
function createXHR(){
	var request = false;
	try{
		request = new ActiveXObject('Msxml2.XMLHTTP');
	}catch (err2) {
		try {
			request = new ActiveXObject('Microsoft.XMLHTTP');
		}catch (err3) {
			try {
				request = new XMLHttpRequest();
			}catch (err1){
				request = false;
			}
		}
	}
	return request;
}

//envoi de requete en POST
function Write(url, content){	// url is the script and data is a string of parameters
	var xhr = createXHR();
	xhr.onreadystatechange=function(){ 
		if(xhr.readyState == 4){
			// nothing for now
			// alert("sent " + url + " " + content);
		}
	}; 
	xhr.open("POST", url, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(content); 
} 

Array.prototype.remove=function(s){
	for(i=0;i<this.length; i++){
		if(s==this[i]) this.splice(i, 1);
	}
};
