function AJAX()
{
	try
	{
		xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
		return xmlHttp;
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
			return xmlHttp;
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				return xmlHttp;
			}
			catch (e)
			{
				alert("Your browser does not support AJAX / Tu navegador no soporta AJAX");
				return false;
			}
		}
	}
}

var http = AJAX()



function consultar_precio() 
{

	document.getElementById('rdet_caja_contenido').innerHTML = "<span class=\"nueve\">loading</span> <img class=\"img_centrada\" src=\"imagenes/ajax_loading_peque.gif\" />";

	v = "&r="					+ new Date().getTime().toString() ;	
	v+= "&fecha_desde=" 		+ document.forms[0].res_fecha_desde.value;
	v+= "&fecha_hasta=" 		+ document.forms[0].res_fecha_hasta.value;
	v+= "&form_id_habitacion=" 	+ document.forms[0].res_form_id_habitacion.value;
	v+= "&form_id_suplemento=" 	+ document.forms[0].res_form_id_suplemento.value;
	v+= "&num_adultos=" 		+ document.forms[0].res_num_adultos.value;
	v+= "&num_ninos=" 			+ document.forms[0].res_num_ninos.value;
	v+= "&num_cunas=" 			+ document.forms[0].res_num_cunas.value;
	v+= "&num_hab=" 			+ document.forms[0].res_num_hab.value;
	v+= "&pruebas=" 			+ document.forms[0].res_pruebas.value;
	v+= "&lang=" 				+ document.forms[0].lang.value;
	v+= "&reset_detalles=SI";

	http.open('get', 'hotel_reservas_online.ajax.php?action=cambiar_tarifa_detalle_precio'+v);

	http.onreadystatechange=function() 
	{
		if(http.readyState == 4) 
		{
			var response	= http.responseText;
			var update		= new Array();
			
			//alert(http.responseText)
			//document.getElementById('rdet_caja_contenido').innerHTML = http.responseText;
			
			if(response.indexOf('|' != -1)) 
			{
				update = response.split('|');

				
				
				if ( update[0].length > 0)
				{
					document.getElementById(trim(update[0])).innerHTML = update[1];
				}
				
				
				if ( update[2].length > 0)
				{
					document.getElementById(update[2]).innerHTML = update[3];
				}

				if ( update[4].length > 0)
				{
					document.getElementById(update[4]).innerHTML = update[5];
				}
				
				if ( update[6].length > 0)
				{
					document.getElementById(update[6]).innerHTML = update[7];
				}

				if ( update[8].length > 0)
				{
					document.getElementById(update[8]).innerHTML = update[9];
				}

				if ( update[10].length > 0)
				{
					document.getElementById(update[10]).innerHTML = update[11];
				}


			} else {
				document.getElementById('rdet_caja_contenido').innerHTML = 'Fallo en buscar resultados';		
			}
			
		
		}		
	}

    http.send(null);
}



function pulsa_leido() {
//		return  "<a class=\"botonwebdis\" name=\"rellenar_datos_personales\" id=\"rellenar_datos_personales\" 
//		"href=\"javascript:carga_formulario_cliente('".$this->lang."');\" ><img src=\"imagenes/arrow-small-9x9.gif\" alt=\"\" />" . LABEL_LF_ATRAS . "</a>";				

	if (document.getElementById('form_leido').checked == false)
	{
		document.getElementById('rellenar_datos_personales').disabled = true;
		document.getElementById('rellenar_datos_personales').setAttribute("class", "botonwebdis");
		document.getElementById('rellenar_datos_personales').removeAttribute("href");

//		document.getElementById('rellenar_datos_personales').disabled = true;
//		document.getElementById('rellenar_datos_personales').setAttribute("class", "boton80px-disabled");
	} else {
		document.getElementById('rellenar_datos_personales').disabled = false;	
		document.getElementById('rellenar_datos_personales').setAttribute("class", "botonweb");
		document.getElementById('rellenar_datos_personales').setAttribute("href", "javascript:carga_formulario_cliente();");
//		document.getElementById('rellenar_datos_personales').disabled = false;	
//		document.getElementById('rellenar_datos_personales').setAttribute("class", "boton80px");
	}	   
}



/*

Al recargar este formulario no funciona el script de las fechas, por lo que lo dejamos suspendido

function re_abrir_formulario_1(){
	document.getElementById('contenido').innerHTML = "loading <img src=\"imagenes/ajax_loading_peque.gif\" />";

	http.open('get', 'reservas_html.php?action=re_abrir_formulario_1');
    http.onreadystatechange = re_abrir_formulario_1_handler;
    http.send(null);
}
function re_abrir_formulario_1_handler() {
    if(http.readyState == 4){
		document.getElementById('contenido').innerHTML = http.responseText;
    } else {
		document.getElementById('contenido').innerHTML = "<br /><br />Http readyState not OK on re_abrir_formulario_1_handler. Contact webmaster to inform this error, thanks.<br /><br /> webmaster@hotellalaguna.com ";				
	}
}

*/
var temp_cont_tarifa;

function cambiar_tarifa_detalle(fecha,id_tarifa,lang,cont_tarifa,cont_tarifa_form,indice,cont_precio,cont_tarifa_ori)
{
	http.abort();

	temp_cont_tarifa = document.getElementById(cont_tarifa).innerHTML;

	document.getElementById(cont_tarifa_form).innerHTML = "loading <img src=\"imagenes/ajax_loading_peque.gif\" />";

	http.open('get', 'hotel_reservas_online.ajax.php?action=cambiar_tarifa_detalle&lang='+lang+'&fecha='+fecha+'&id_tarifa='+id_tarifa+'&indice='+indice+'&cont_tarifa='+cont_tarifa+'&cont_tarifa_form='+cont_tarifa_form+'&cont_precio='+cont_precio+'&cont_tarifa_ori='+cont_tarifa_ori);

	http.onreadystatechange=function() 
	{
		if(http.readyState == 4) 
		{
			document.getElementById(cont_tarifa_form).innerHTML  = http.responseText;	   
		}
	}
  
	http.send(null);
}


function cambiar_tarifa_detalle_g(fecha,id_tarifa,lang,cont_tarifa,cont_tarifa_form,indice,cont_precio,cont_tarifa_ori,accion)
{
	var radio_choice = false;

	for (counter = 0; counter < document.forms[1].form_cambiar_detalle_suplemento.length; counter++)
	{
		if (document.forms[1].form_cambiar_detalle_suplemento[counter].checked) {
			radio_choice = true; 
			id_suplemento = document.forms[1].form_cambiar_detalle_suplemento[counter].value;
		}
	}

	var check_choice = false;
	//var complementos = "&complemento0=1";
	var complementos = "";

	indice_nombre_campo = 0;
	for (counter=0; micheckbox=document.forms[1].elements[counter]; counter++)
	{
		if (micheckbox.type=='checkbox') {
			if(micheckbox.checked) {
				check_choice = true; 
				complementos = complementos + '&complemento' + indice_nombre_campo + '=' + micheckbox.value;
				indice_nombre_campo = indice_nombre_campo + 1;
			} 
		}
	}

	//alert(complementos);


	if (accion=='ok' && (radio_choice == true || complementos!='' ) ) 
	{
		http.abort();

		//id_suplemento = document.forms[0].form_cambiar_detalle_suplemento.value;
		

		document.getElementById(cont_tarifa).innerHTML = "checking values <img src=\"imagenes/ajax_loading_peque.gif\" />";

		http.open('get', 'hotel_reservas_online.ajax.php?action=cambiar_tarifa_detalle_g&lang='+lang+'&fecha='+fecha+'&id_tarifa='+id_tarifa+'&id_suplemento='+id_suplemento+'&indice='+indice+'&cont_tarifa='+cont_tarifa+'&cont_tarifa_ori='+cont_tarifa_ori+'&cont_precio='+cont_precio+complementos);
		
		http.onreadystatechange=function() {
			if(http.readyState == 4) {
				var response	= http.responseText;				
				var update		= new Array();
				
				document.getElementById(cont_tarifa_form).innerHTML = "";

				//document.getElementById(cont_tarifa).innerHTML = http.responseText;
		
		
				if(response.indexOf('|' != -1 )) 
				{
					update = response.split('|');
				}

				if ( update[0].length > 0)
				{
					document.getElementById(trim(update[0])).innerHTML = update[1];
				}
												
				if ( update[2].length > 0)
				{
					document.getElementById(update[2]).innerHTML = update[3];
				}

				if ( update[4].length > 0)
				{
					document.getElementById(update[4]).innerHTML = update[5];
				}
				
				if ( update[6].length > 0)
				{
					document.getElementById(update[6]).innerHTML = update[7];
				}

			}//if
		}
	  
		http.send(null);

	} else {
		document.getElementById(cont_tarifa_form).innerHTML			= "";	   	
	}
}



function carga_formulario_cliente()
{
	document.getElementById('res_workarea_margen').innerHTML = "loading <img src=\"imagenes/ajax_loading_peque.gif\" />";

	http.open('get', 'hotel_reservas_online.ajax.php?action=carga_formulario_cliente');
    http.onreadystatechange = carga_formulario_cliente_handler;
    http.send(null);
}


function carga_formulario_cliente_handler() 
{
    if(http.readyState == 4){
		var response	= http.responseText;				
		var update		= new Array();
		
		//document.getElementById('res_workarea_margen').innerHTML = http.responseText;
		document.getElementById('res_workarea_margen').innerHTML = "";
		

		if(response.indexOf('|' != -1 )) 
		{
			update = response.split('|');
		}

		if ( update[0].length > 0)
		{
			document.getElementById(trim(update[0])).innerHTML = update[1];
		}


		if ( update[2].length > 0)
		{
			document.getElementById(trim(update[2])).innerHTML = update[3];
		}
		
		if ( update[4].length > 0)
		{
			document.getElementById(trim(update[4])).innerHTML = update[5];
		}
		

		//document.getElementById('res_workarea_margen').innerHTML = http.responseText;
    } 
}





function abrir_formulario_3() 
{

	document.getElementById('mensajes_titulo').innerHTML = "loading <img src=\"imagenes/ajax_loading_peque.gif\" />";

	params = "&r="					+ new Date().getTime().toString();
	params+= "&revisa_campos=" 		+ 'SI';
	params+= "&cli_nombre=" 		+ document.forms[0].cli_nombre.value;
	params+= "&cli_apellidos=" 		+ document.forms[0].cli_apellidos.value;
	params+= "&cli_id_doc=" 		+ document.forms[0].cli_tipo_doc.value;
	params+= "&cli_docnumber=" 		+ document.forms[0].cli_numdoc.value;
	params+= "&cli_direccion_l1="	+ document.forms[0].cli_direccion_1.value;
	params+= "&cli_direccion_l2="	+ document.forms[0].cli_direccion_2.value;
	params+= "&cli_poblacion=" 		+ document.forms[0].cli_poblacion.value;
	params+= "&cli_zona=" 			+ document.forms[0].cli_zona.value;
	params+= "&cli_cp=" 			+ document.forms[0].cli_cp.value;
	params+= "&cli_email=" 			+ document.forms[0].cli_email.value;
	params+= "&cli_telefono=" 		+ document.forms[0].cli_telefono.value;
	params+= "&cli_observaciones="	+ document.forms[0].cli_observaciones.value;
	
	http.open('post', 'hotel_reservas_online.ajax.php?action=prepara_formulario', true);

	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange=function() 
	{
		if(http.readyState == 4) 
		{
			var response	= http.responseText;				
			var update		= new Array();
			
			//alert(http.responseText);

			if(response.indexOf('|' < 0 )) 
			{
				update = response.split('|');

				container = trim(update[0]);
		
				if ( container.length > 0)
				{
					document.getElementById(container).innerHTML = update[1];
				}

				container = trim(update[2]);

				if ( container.length > 0)
				{
					document.getElementById(container).innerHTML = update[3];
				}

				container = trim(update[4]);

				if ( container.length > 0)
				{
					document.getElementById(container).innerHTML = update[5];
				}

			} else {
				document.getElementById('mensajes_texto').innerHTML = http.responseText;
			}	
			
		}
    }    
	
	http.send(params);
}














function get_foto_habitacion() 
{

	document.getElementById('contenedor_fotohab').innerHTML = "room picture <img src=\"imagenes/ajax_loading_peque.gif\" />";

	v = "&r="					+ new Date().getTime().toString() ;	
	v+= "&form_id_habitacion=" 	+ document.forms[0].res_form_id_habitacion.value;
	v+= "&lang=" 				+ document.forms[0].lang.value;
	
	http.open('get', 'hotel_reservas_online.ajax.php?action=get_foto_hab'+v);

	http.onreadystatechange=function() {
		if(http.readyState == 4) {			
			var response	= http.responseText;
			var update		= new Array();
			
			//alert(http.responseText)
			
			if(response.indexOf('|' >= 0)) {
				update = response.split('|');

				if ( update[0].length > 0)
				{
					document.getElementById(trim(update[0])).innerHTML = update[1];
				}
												
				if ( update[2].length > 0)
				{
					document.getElementById(update[2]).innerHTML = update[3];
				}

				if ( update[4].length > 0)
				{
					document.getElementById(update[4]).innerHTML = update[5];
				}
				
				if ( update[6].length > 0)
				{
					document.getElementById(update[6]).innerHTML = update[7];
				}

				if ( update[8].length > 0)
				{
					document.getElementById(update[8]).innerHTML = update[9];
				}

				if ( update[10].length > 0)
				{
					document.getElementById(update[10]).innerHTML = update[11];
				}
				
				if ( update[12].length > 0)
				{
					document.getElementById(update[12]).innerHTML = update[13];
				}
			} else {
				document.getElementById('contenido').innerHTML = http.responseText;
			}	
		}
    }
    http.send(null);
}



/*********  declarada en my_ajax.js 

function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}


*************/
