//Esta linea hay que definirla en cada plantilla para que funcione correctamente.
//var url = "http://www.ecoturismorural.com/www/ControlCasasRuralesXML.php?Evento=DISPONIBILIDAD_EST"; /*La URL donde está el script generador de XML*/

/**
* Este metodo recoge los valores del servidor XML y actua en consecuencia
*/
function handleHttpResponse() 
{
	if (http.readyState == 4) 
	{
		if (http.responseText.indexOf("invalid") == -1) 
		{
			// Use the XML DOM to unpack data 
			var xmlDocument = http.responseXML; 
			var numero_dias = xmlDocument.getElementsByTagName("numero_dia").length;
			for (Cont=0; Cont<numero_dias; ++Cont)
			{
				numero_dia = xmlDocument.getElementsByTagName('numero_dia').item(Cont).firstChild.data;
				estado = xmlDocument.getElementsByTagName('estado').item(Cont).firstChild.data;			
				fecha_completo_entrada = xmlDocument.getElementsByTagName('fecha_completo_entrada').item(Cont).firstChild.data;			
				fecha_completo_salida = xmlDocument.getElementsByTagName('fecha_completo_salida').item(Cont).firstChild.data;				
				fecha_entrada = xmlDocument.getElementsByTagName('fecha_inicio').item(Cont).firstChild.data;			
				fecha_salida = xmlDocument.getElementsByTagName('fecha_final').item(Cont).firstChild.data;				

				
				Estilo = "bloque_dia_libre";
				switch(estado)
				{
					default:
					case "L":/*Día libre*/
						Estilo = "bloque_dia_libre";
					break;
					case "S":/*Día solicitado */
						//Estilo = "bloque_dia_solicitado";
                        Estilo = "bloque_dia_reservado";
					break;
					case "R":/*Día reservado */
						if (fecha_entrada==0 && fecha_salida==0)
						{
							Estilo = "bloque_dia_reservado";
						}
						else
						{
							if (fecha_entrada!=0 && fecha_salida!=0)
							{
								//Estilo = "bloque_dia_reserva_entrada_salida";
								Estilo = "bloque_dia_reservado";
							}
							else
							{
								if (fecha_entrada != 0)
								{
									//Estilo = "bloque_dia_reserva_entrada";
									Estilo = "bloque_dia_reservado";
								}
								else
								{
									//Estilo = "bloque_dia_reserva_salida";
									Estilo = "bloque_dia_reservado";
								}
							}
						}
					break;
					case "P":/*Plazas libres*/
						Estilo = "bloque_dia_plazas_libres";
                                                //Estilo = "bloque_dia_libre";
					break;					
					case "X":/*Utilizado para indicar día anterior al día de hoy*/
						Estilo = "bloque_dia_pasado";
					break;
					
				}
				document.getElementById(numero_dia).className = Estilo;
			}
		}
		isWorking = false;
	}
}

var isWorking = false;

/**
* Disparador recoge los datos necesarios y efectua la llamada
*/
function Disparador(IdEstablecimiento, Mes, Anyo)
{
	if (!isWorking && http) 
	{
		/* Envio por GET
		http.open("GET", url+"?"+"Evento=CONFIRMAR&" + "Usuario="+escape(Usuario) + "&" + "Clave="+escape(Clave), true);
		http.onreadystatechange = handleHttpResponse;
		isWorking = true;
		http.send(null);
		*/

		//Envio por post
		http.open("POST", url, true); 
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http.onreadystatechange = handleHttpResponse;
		isWorking = true;
		CadenaEnvio = "&IdEstablecimiento="+escape(IdEstablecimiento)+"&Mes="+escape(Mes)+"&Anyo="+escape(Anyo);
		http.send(CadenaEnvio);
	}
}


/**
* Script genérico para las comunicaciones ajax.
*
*/		
function getHTTPObject() 
{
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
	try 
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		try 
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E) 
		{
			xmlhttp = false;
		}
	}
	@else
		xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != "undefined") 
	{
		try 
		{
			xmlhttp = new XMLHttpRequest();
			xmlhttp.overrideMimeType("text/xml"); 
		} 
		catch (e) 
		{
			xmlhttp = false;
		}
	}
	return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
