var myConn = new XHConn();

if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");

var showCalendar = function (oXML) 
{ 
		document.getElementById('calendar').innerHTML = oXML.responseText;
};

function changeDateCalendar(page,idProd){
	
	value_year=document.getElementById('cboYear').value;
	value_month=document.getElementById('cboMonth').value;

	url="cboMonth="+value_month+"&cboYear="+value_year+"&id="+idProd;

	myConn.connect(page,"GET",url,showCalendar);
	document.getElementById('calendar').innerHTML = "<br /><img src='./imagenes/attente.gif' />";
}

function hours(idDate,idProd){
	cadena=idDate+","+idProd;
	//alert(cadena);
	for(x=0; x < 2; x++) {	
		document.getElementById("idHours").options[0]= null;
	}
	document.getElementById("showHours").style.display="none";
	
	for(x=0; x < 6; x++) {	
		document.getElementById("idTarifs").options[0]= null;
	}
	document.getElementById("showTarifs").style.display="none";
	
	document.getElementById("idDate").value=idDate;
	
	var url="idDate="+idDate+"&idProd="+idProd;
	myConn.connect("hours.php","GET",url,end_hours);
}

var end_hours = function (oXML) 
{ 
	datos=oXML.responseText.split("|");
	
	id=datos[0].split(",");
	nb=datos[1].split(",");
	
	cid=id.length;
	
	long=document.getElementById('idHours').length;
	
	for(x=0; x < long; x++) {	
		document.getElementById("idHours").options[0]= null;
	}
	
	for(x=0; x < cid-1; x++) {
		otraopcion=new Option(nb[x],id[x]);
		document.getElementById("idHours").options[x]= otraopcion;
	}
	
	document.getElementById("showHours").style.display="";
	document.getElementById("txt_cantidad2").value="";
	document.getElementById("txt_stotal").value="";
	
	document.getElementById("numPlaces").style.display="none";
	document.getElementById("tr_prixSubtotal").style.display="none";
};


function show_tarifs(idHour){
	if(document.getElementById("idHours").value==0){
		for(x=0; x < 6; x++) {	
			document.getElementById("idTarifs").options[0]= null;
		}
		document.getElementById("showTarifs").style.display="none";
		document.getElementById("numPlaces").style.display="none";
	}else{
		idHour=document.getElementById("idHours").value;
		idProd=document.getElementById("prodid").value;
		
		var url="idHour="+idHour+"&idProd="+idProd;
		myConn.connect("tarifs.php","GET",url,end_tarifs);
		
	}
}


var end_tarifs = function (oXML) 
{ 
	datos=oXML.responseText.split("|");
	
	id=datos[0].split(",");
	nb=datos[1].split(",");
	
	cid=id.length;
	long=6;
	
	for(x=0; x < long; x++) {	
		document.getElementById("idTarifs").options[0]= null;
	}
	
	var idn=new Array();
	var nbn=new Array();
	var c=0;
	for(i=0; i<5; i++){
		if(nb[i]=="[Choisir...]"){
			idn[c]=id[i];
			nbn[c]=nb[i];
			c++;
		}else{			
			if(id[i]!="0" && id[i]!="0.00"){				
				idn[c]=id[i];
				nbn[c]=nb[i];
				c++;
			}
		}
	}
	
	for(x=0; x<c; x++){
		otraopcion=new Option(nbn[x],idn[x]);		
		document.getElementById("idTarifs").options[x]= otraopcion;	
	}
	
	/*for(x=0; x < 5; x++) {		
		otraopcion=new Option(nb[x],id[x]);		
		document.getElementById("idTarifs").options[x]= otraopcion;		
	}*/
	
	document.getElementById("showTarifs").style.display="";
}

function show_numPlaces(){
	document.getElementById("numPlaces").style.display="";
	document.getElementById("tr_prixSubtotal").style.display="";
	document.getElementById("txt_cantidad2").value="";	
	document.getElementById("txt_stotal").value="";	
}
