function isset(variable_name)
{
    try {
         if (typeof(eval(variable_name)) != 'undefined')
         if (eval(variable_name) != null)
         return true;
     } catch(e) { }
    return false;
}
/*****************************************************************************/
function abrirXY(capa,x,y){
    ReconoceCapas(capa);
    eval(capa+".style.top  = '"+y+"px';");
    eval(capa+".style.left = '"+x+"px';");
    eval(capa+".style.visibility = 'visible';");
}//abrirXY

/******************************************************************************/
function setInner(capa, texto){
    ReconoceCapas(capa);
    eval(capa+".innerHTML = '"+texto+"';");
}//setInner

/*****************************************************************************************************/
function ayudarFija(capa, textoAyuda, Evento)
{
	if(document.all)
	{
	PosX = window.event.clientX + document.documentElement.scrollLeft;
	PosY = window.event.clientY + document.documentElement.scrollTop;
	}
	else
	{
	PosX = Evento.pageX;
	PosY = Evento.pageY;
	}

	PosX = PosX + 20;
	PosY = PosY + 5;


    setInner(capa, textoAyuda);
    abrirXY(capa,PosX,PosY);
}//ayudarFija


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

function cerrarLaCapa(laCapa){
	eval(laCapa+".style.visibility='hidden'");
}

/*****************************************************************************************************/
function mostrarHabitacion(totalCapas){
	var capasSeleccionadas = document.getElementById('tiposHabitaciones').value;

	for (i=1; i<=totalCapas; i++)
	{
		nombreCapa = 'tipoHabitacion_'+i;

		if (i <= capasSeleccionadas) document.getElementById(nombreCapa).style.display='block';
		else document.getElementById(nombreCapa).style.display='none';
	}
}


/*****************************************************************************************************/
function mostrarMenores(habitacion){
	var menoresSeleccionados = document.getElementById('menores_'+habitacion).value;

	for (i=1; i<=5; i++)
	{
		nombreCapa = 'capaEdadMenor_'+habitacion+'_'+i;

		if (i <= menoresSeleccionados) document.getElementById(nombreCapa).style.display='block';
		else document.getElementById(nombreCapa).style.display='none';
	}
}
function mostrarBebes(habitacion){
	var bebesSeleccionados = document.getElementById('bebes_'+habitacion).value;

	for (i=1; i<=5; i++)
	{
		nombreCapa = 'capaEdadBebe_'+habitacion+'_'+i;

		if (i <= bebesSeleccionados) document.getElementById(nombreCapa).style.display='block';
		else document.getElementById(nombreCapa).style.display='none';
	}
}




/*****************************************************************************************************/
function validarFormulario()
{
	var error=0;
	var arrayHabitaciones =  new Array;

	document.formularioBusqueda.target="";

	document.getElementById('errorciudades').style.display='none';
	document.getElementById('errorhabitaciones').style.display='none';
	document.getElementById('errorhabitacionesdistintas').style.display='none';


	//CIUDAD VACIA
	if ((document.formularioBusqueda.destino.value=='') || (document.formularioBusqueda.destino.value=='*') || (document.formularioBusqueda.destino.value=='0'))
	{
		error=1;
		document.getElementById('errorciudades').style.display='block';
	}

	//NUMERO DE HABITACIONES Y OCUPACION
	var totalHabitaciones=0;
	for (i=1; i<4; i++)
	{
		campoCantidad = 'cantidadHabitacion_'+i;
		totalHabitaciones += document.getElementById(campoCantidad).value;
	}
	if (totalHabitaciones==0)
	{
		error=1;
		document.getElementById('errorhabitaciones').style.display='block';
	}
	else
	{
		//si hay habitaciones seleccionadas ver que hay ocupacion por cada una de ellas
		for (i=1; i<4; i++)
		{
			campoCantidad = 'cantidadHabitacion_'+i;

			campoAdultos = 'adultos_'+i;
			campoMenores = 'menores_'+i;
			campoBebes = 'bebes_'+i;
			arrayHabitaciones[i] = new Array;
			arrayHabitaciones[i]['cantidad'] = document.getElementById(campoCantidad).value
			arrayHabitaciones[i]['adultos'] = document.getElementById(campoAdultos).value
			arrayHabitaciones[i]['menores'] = document.getElementById(campoMenores).value
			arrayHabitaciones[i]['bebes'] = document.getElementById(campoBebes).value

			if (document.getElementById(campoCantidad).value!=0)
			{
				if (document.getElementById(campoAdultos).value==0)
				{
					error=1;
					document.getElementById('errorhabitaciones').style.display='block';
				}
			}
		}

		//ver si piden dos lineas con mismo tipo de habitacion

		//tipos habitaciones 1..3
		if (arrayHabitaciones[1]['cantidad']!=0) hayHabitaciones1 = 1; else hayHabitaciones1 = 0;
		if (arrayHabitaciones[2]['cantidad']!=0) hayHabitaciones2 = 1; else hayHabitaciones2 = 0;
		if (arrayHabitaciones[3]['cantidad']!=0) hayHabitaciones3 = 1; else hayHabitaciones3 = 0;

		//ver combinaciones posibles
		var errorHabitacionesRepetidas = false;

		//1º, 2º y 3º
		if (hayHabitaciones1 && hayHabitaciones2 && hayHabitaciones3)
		{

			if (((arrayHabitaciones[1]['adultos']==arrayHabitaciones[2]['adultos']) && (arrayHabitaciones[2]['adultos']==arrayHabitaciones[3]['adultos']) && (arrayHabitaciones[1]['menores']==arrayHabitaciones[2]['menores']) && (arrayHabitaciones[2]['menores']==arrayHabitaciones[3]['menores']) && (arrayHabitaciones[1]['bebes']==arrayHabitaciones[2]['bebes']) && (arrayHabitaciones[2]['bebes']==arrayHabitaciones[3]['bebes']))
			|| ((arrayHabitaciones[1]['adultos']==arrayHabitaciones[2]['adultos']) && (arrayHabitaciones[1]['menores']==arrayHabitaciones[2]['menores']) && (arrayHabitaciones[1]['bebes']==arrayHabitaciones[2]['bebes']))
			|| ((arrayHabitaciones[1]['adultos']==arrayHabitaciones[3]['adultos']) && (arrayHabitaciones[1]['menores']==arrayHabitaciones[3]['menores']) && (arrayHabitaciones[1]['bebes']==arrayHabitaciones[3]['bebes']))
			|| ((arrayHabitaciones[2]['adultos']==arrayHabitaciones[3]['adultos']) && (arrayHabitaciones[2]['menores']==arrayHabitaciones[3]['menores']) && (arrayHabitaciones[2]['bebes']==arrayHabitaciones[3]['bebes'])) 	)
			{
				errorHabitacionesRepetidas = true;
			}
		}
		else
			//1º y 2º
			if (hayHabitaciones1 && hayHabitaciones2)
			{
				if ((arrayHabitaciones[1]['adultos']==arrayHabitaciones[2]['adultos']) && (arrayHabitaciones[1]['menores']==arrayHabitaciones[2]['menores']) && (arrayHabitaciones[1]['bebes']==arrayHabitaciones[2]['bebes']))
				{
					errorHabitacionesRepetidas = true;
				}
			}
			else
				//1º y 3º
				if (hayHabitaciones1 && hayHabitaciones3)
				{
					if ((arrayHabitaciones[1]['adultos']==arrayHabitaciones[3]['adultos']) && (arrayHabitaciones[1]['menores']==arrayHabitaciones[3]['menores']) && (arrayHabitaciones[1]['bebes']==arrayHabitaciones[3]['bebes']))
					{
						errorHabitacionesRepetidas = true;
					}
				}
				else
					//2º y 3º
					if (hayHabitaciones2 && hayHabitaciones3)
					{
						if ((arrayHabitaciones[2]['adultos']==arrayHabitaciones[3]['adultos']) && (arrayHabitaciones[2]['menores']==arrayHabitaciones[3]['menores']) && (arrayHabitaciones[2]['bebes']==arrayHabitaciones[3]['bebes']))
						{
							errorHabitacionesRepetidas = true;
						}
					}

		if (errorHabitacionesRepetidas)
		{
			error=1;
			document.getElementById('errorhabitacionesdistintas').style.display='block';
		}
	}




	if (error==0) {
		document.getElementById('errorBusqueda').style.display='none';
		var nombreCiudad='';
		indiceSelectCiudad = document.getElementById('destino').selectedIndex;
		nombreCiudad=document.getElementById('destino').options[indiceSelectCiudad].text;
		document.getElementById('nombreCiudad').value = nombreCiudad;
		document.formularioBusqueda.submit();
	}
	else{
		document.getElementById('errorBusqueda').style.display='block';
	}
}


function ocultaErroresBusqueda()
{
	document.getElementById('errorBusqueda').style.display='none';
	document.getElementById('errorciudades').style.display='none';
	document.getElementById('errorhabitaciones').style.display='none';
	document.getElementById('errorhabitacionesdistintas').style.display='none';

}


/*****************************************************************************************************/
function verMas(capa){
	var nombreCapa = 'capaMasInfo_'+capa;
	var nombreDesde = 'desde_'+capa;
	if (document.getElementById(nombreCapa).style.display=="none")
	{
		document.getElementById(nombreCapa).style.display="block";
		document.getElementById(nombreDesde).style.display="none";
	}
	else
	{
		document.getElementById(nombreCapa).style.display="none";
		document.getElementById(nombreDesde).style.display="block";
	}
}


/*****************************************************************************************************/
function restringirRegimenes(h, r)
{
	var r=1;//ver que valor de regimen esta cogido en la primera habitacion. Las demas seran iguales

	//si hay varios radiobuttons tratarlos como un array
	if (eval('document.formularioResultados.habitacion_'+h+'_'+r).length != undefined)
	{
		for (j=0; j<eval('document.formularioResultados.habitacion_'+h+'_'+r).length; j++)
		{
			if (eval('document.formularioResultados.habitacion_'+h+'_'+r+'[j]').checked == true)
			{
				indice = j;
				valorSelectPrincipal = eval('document.formularioResultados.regimen_'+h+'_'+r+'[j]').value;
			}
		}
	}
	else //si hay un solo radiobutton trabajar directamente con el
	{
		if (eval('document.formularioResultados.habitacion_'+h+'_'+r).checked == true)
		{
			indice = 0;
			valorSelectPrincipal = eval('document.formularioResultados.regimen_'+h+'_'+r).value;
		}
	}

	auxRegimen = valorSelectPrincipal.split("_");
	codigosRegimen = auxRegimen[0];
	auxRegimen2 = codigosRegimen.split("#");
	regimenPrincipal = auxRegimen2[0];


	aux = 'numeroHabitaciones_'+h;
	habitaciones = document.getElementById(aux).value;

	//recorrer cada habitacion y cada regimen de habitacion para igualar al seleccionado
	for(r=1; r<=habitaciones; r++)
	{
		if (eval('document.formularioResultados.habitacion_'+h+'_'+r).length != undefined)
		{
			for (j=0; j<eval('document.formularioResultados.habitacion_'+h+'_'+r).length; j++)
			{
				campoSelect = eval('document.formularioResultados.regimen_'+h+'_'+r+'[j]');

				valorSelect = campoSelect.value;
				auxRegimen = valorSelect.split("_");
				codigosRegimen = auxRegimen[0];
				auxRegimen2 = codigosRegimen.split("#");
				regimen = auxRegimen2[0];


				for(i=0;i<campoSelect.options.length;i++)
				{
					valorOption = campoSelect.options[i].value;

					auxOptions = valorOption.split("_");
					codigosRegimenOptions = auxOptions[0];
					auxOptions2 = codigosRegimenOptions.split("#");
					opcion = auxOptions2[0];

//					alert('comparar regimen principal '+regimenPrincipal +' con regimen en curso '+opcion)

					if (regimenPrincipal == opcion)
					{
						campoSelect.options[i].selected=true;
					}
				}
			}
		}
		else //si hay un solo radiobutton trabajar directamente con el
		{
			campoSelect = eval('document.formularioResultados.regimen_'+h+'_'+r);
			valorSelect = campoSelect.value;
			auxRegimen = valorSelect.split("_");
			codigosRegimen = auxRegimen[0];
			auxRegimen2 = codigosRegimen.split("#");
			regimen = auxRegimen2[0];
//			alert('comparar regimen principal '+regimenPrincipal+ ' con regimen en curso '+regimen)



			for(i=0;i<campoSelect.options.length;i++)
			{
				valorOption = campoSelect.options[i].value;

				auxOptions = valorOption.split("_");
				codigosRegimenOptions = auxOptions[0];
				auxOptions2 = codigosRegimenOptions.split("#");
				opcion = auxOptions2[0];

//				alert('comparar regimen principal '+regimenPrincipal +' con regimen en curso '+opcion)
				if (regimenPrincipal == opcion)
				{
					campoSelect.options[i].selected=true;
				}
			}
		}
	}
}


function calcularOpcionMasBarata()
{
	var hoteles = document.getElementById('numeroHoteles').value;

	for (h=0; h<hoteles; h++)
	{
		var totalOpcionMasBarata = 0;

		aux = 'numeroHabitaciones_'+h;
		habitaciones = document.getElementById(aux).value;
		for(r=1; r<=habitaciones; r++)
		{
			//si hay varios radiobuttons tratarlos como un array
			if (eval('document.formularioResultados.habitacion_'+h+'_'+r).length != undefined)
			{
				j=0; //opcion mas barata: primer tipo con primer regimen
				valorSelect = eval('document.formularioResultados.regimen_'+h+'_'+r+'[j]').value;
			}
			else //si hay un solo radiobutton trabajar directamente con el
			{
				valorSelect = eval('document.formularioResultados.regimen_'+h+'_'+r).value;
			}
			auxPrecio = valorSelect.split("_");
			precio = parseFloat(auxPrecio[1]);

			//cantidad de habitaciones del mismo tipo
			cantidadHabitaciones = parseInt(eval('document.formularioResultados.cantidadHabitacion_'+h+'_'+r).value);

			totalOpcionMasBarata += (precio*cantidadHabitaciones);
		}

		eval('document.formularioResultados.opcionMasBarata_'+h).value = totalOpcionMasBarata.toFixed(2);
	}
}

/*****************************************************************************************************/
function recalcularPrecio()
{
	var hoteles = document.getElementById('numeroHoteles').value;
	var cadena = '';
	for (h=0; h<hoteles; h++)
	{
		var total = 0;
		aux = 'numeroHabitaciones_'+h;
		habitaciones = document.getElementById(aux).value;

		for(r=1; r<=habitaciones; r++)
		{
			var importeOfertas = parseFloat(eval('document.formularioResultados.importeOfertas_'+h+'_'+r).value);
			var importeSuplementos = parseFloat(eval('document.formularioResultados.importeSuplementos_'+h+'_'+r).value);

			//si hay varios radiobuttons tratarlos como un array
			if (eval('document.formularioResultados.habitacion_'+h+'_'+r).length != undefined)
			{
				for (j=0; j<eval('document.formularioResultados.habitacion_'+h+'_'+r).length; j++)
				{
					codHabitacion=eval('document.formularioResultados.codHabitacion_'+h+'_'+r+'[j]').value;
					valorSelect = eval('document.formularioResultados.regimen_'+h+'_'+r+'[j]').value;

					eval('document.formularioResultados.habitacion_'+h+'_'+r+'[j]').value = codHabitacion + '_'+ valorSelect;
					auxPrecio = valorSelect.split("_");
					precio = parseFloat(auxPrecio[1]);
					comision = auxPrecio[2];
					contadorRegimen = parseInt(auxPrecio[3]);

					if (eval('document.formularioResultados.habitacion_'+h+'_'+r+'[j]').checked == true)
					{
						precio = precio + importeOfertas + importeSuplementos;

						//cantidad de habitaciones del mismo tipo
						cantidadHabitaciones = parseInt(eval('document.formularioResultados.cantidadHabitacion_'+h+'_'+r).value);

						total = total + (precio*cantidadHabitaciones);

						//guardar valores de la tarifa y regimen seleccionados para las ofertas
						eval('document.formularioResultados.tarifaOfertas_'+h+'_'+r).value = j;
						eval('document.formularioResultados.regimenOfertas_'+h+'_'+r).value = contadorRegimen;

					}

					if (comision=='N/D') simboloEuro = '';
					else simboloEuro = ' €';
					eval('document.formularioResultados.comision_'+h+'_'+r+'_'+j).value = comision+simboloEuro;
					eval('document.formularioResultados.precio_'+h+'_'+r+'_'+j).value = precio;
				}
			}
			else //si hay un solo radiobutton trabajar directamente con el
			{
				codHabitacion=eval('document.formularioResultados.codHabitacion_'+h+'_'+r).value;
				valorSelect = eval('document.formularioResultados.regimen_'+h+'_'+r).value;

				eval('document.formularioResultados.habitacion_'+h+'_'+r).value = codHabitacion + '_'+ valorSelect;
				auxPrecio = valorSelect.split("_");
				precio = parseFloat(auxPrecio[1]);
				comision = auxPrecio[2];
				contadorRegimen = parseInt(auxPrecio[3]);

				if (eval('document.formularioResultados.habitacion_'+h+'_'+r).checked == true)
				{
					precio = precio + importeOfertas + importeSuplementos;

					//cantidad de habitaciones del mismo tipo
					cantidadHabitaciones = parseInt(eval('document.formularioResultados.cantidadHabitacion_'+h+'_'+r).value);
					total = total + (precio * cantidadHabitaciones);

					//guardar valores de la tarifa y regimen seleccionados para las ofertas
					eval('document.formularioResultados.tarifaOfertas_'+h+'_'+r).value = 0;
					eval('document.formularioResultados.regimenOfertas_'+h+'_'+r).value = contadorRegimen;
				}

				if (comision=='N/D') simboloEuro = '';
				else simboloEuro = ' €';
				eval('document.formularioResultados.comision_'+h+'_'+r+'_0').value = comision+simboloEuro;
				eval('document.formularioResultados.precio_'+h+'_'+r+'_0').value = precio.toFixed(2);
			}
		}

		eval('document.formularioResultados.total_'+h).value = total.toFixed(2);
	}

}


function reiniciarOfertasSuplementos(h, r)
{
	eval('document.formularioResultados.importeOfertas_'+h+'_'+r).value = 0;
	eval('document.formularioResultados.importeSuplementos_'+h+'_'+r).value = 0;
}

function reiniciarOfertasSuplementosHotel(h, numeroTiposHabitaciones)
{
	for (r=1; r<=numeroTiposHabitaciones; r++) reiniciarOfertasSuplementos(h, r)
}


function aplicarOferta(h, r, elemento)
{
	//ver si estamos aplicando la oferta o quitándola
	if (elemento.checked == true) aplicandoOferta = true;
	else aplicandoOferta = false;

	var valorOferta = parseFloat(elemento.value);
	var nuevoPrecio = parseFloat(eval('document.formularioResultados.importeOfertas_'+h+'_'+r).value);

	if (eval('document.formularioResultados.habitacion_'+h+'_'+r).length != undefined)
	{
		for (j=0; j<eval('document.formularioResultados.habitacion_'+h+'_'+r).length; j++)
		{
			if (eval('document.formularioResultados.habitacion_'+h+'_'+r+'[j]').checked == true)
			{
				//aplicar o quitar las ofertas
				if (aplicandoOferta) nuevoPrecio = nuevoPrecio - valorOferta;
				else nuevoPrecio = nuevoPrecio + valorOferta;
			}
		}
	}
	else
	{
		if (eval('document.formularioResultados.habitacion_'+h+'_'+r).checked == true)
		{
			//aplicar o quitar la oferta
			if (aplicandoOferta) nuevoPrecio = nuevoPrecio - valorOferta;
			else nuevoPrecio = nuevoPrecio + valorOferta;
		}
	}

	eval('document.formularioResultados.importeOfertas_'+h+'_'+r).value = nuevoPrecio;
	recalcularPrecio();
}



function aplicarSuplemento(h, r, elemento)
{
	//ver si estamos aplicando el suplemento o quitándolo
	if (elemento.checked == true) aplicandoSuplemento = true;
	else aplicandoSuplemento = false;

	var valorSuplemento = parseFloat(elemento.value);
	var nuevoPrecio = parseFloat(eval('document.formularioResultados.importeSuplementos_'+h+'_'+r).value);

	if (eval('document.formularioResultados.habitacion_'+h+'_'+r).length != undefined)
	{
		for (j=0; j<eval('document.formularioResultados.habitacion_'+h+'_'+r).length; j++)
		{
			if (eval('document.formularioResultados.habitacion_'+h+'_'+r+'[j]').checked == true)
			{
				//aplicar o quitar los suplementos
				if (aplicandoSuplemento) nuevoPrecio = nuevoPrecio + valorSuplemento;
				else nuevoPrecio = nuevoPrecio - valorSuplemento;
			}
		}
	}
	else
	{
		if (eval('document.formularioResultados.habitacion_'+h+'_'+r).checked == true)
		{
			//aplicar o quitar el suplemento
			if (aplicandoSuplemento) nuevoPrecio = nuevoPrecio + valorSuplemento;
			else nuevoPrecio = nuevoPrecio - valorSuplemento;
		}
	}

	eval('document.formularioResultados.importeSuplementos_'+h+'_'+r).value = nuevoPrecio;
	recalcularPrecio();
}


/*****************************************************************************************************/
function abrirMasInfo(elemento, idHotel, ChainCode, CategoryCode, CityCode){
	urlMasInfo = 'includes/masInfo.php?elemento='+elemento+'&idHotel='+idHotel+'&ChainCode='+ChainCode+'&CategoryCode='+CategoryCode+'&CityCode='+CityCode+'&';
	window.open(urlMasInfo, 'info', 'width=700, height=550, scrollbars=yes');
}

/*****************************************************************************************************/
function reservar(hotel, idHotel, ChainCode)
{
	document.getElementById('hotelSeleccionado').value = hotel;
	document.getElementById('idHotelSeleccionado').value = idHotel;
	document.getElementById('centralHotelSeleccionado').value = ChainCode;
	document.formularioResultados.action="prereserva.php";

	//guardar ofertas seleccionadas

	numeroHabitaciones = eval('document.formularioResultados.numeroHabitaciones_'+hotel).value;
	for (r=1; r<=numeroHabitaciones; r++)
	{
		var ofertasSeleccionadas = '';
		if (isset(eval('document.formularioResultados.numeroOfertas_'+hotel+'_'+r)))
			numeroOfertas = eval('document.formularioResultados.numeroOfertas_'+hotel+'_'+r).value;
		else
			numeroOfertas = 0;

		for (j=0; j<numeroOfertas; j++)
		{
			if (eval('document.formularioResultados.oferta_'+hotel+'_'+r+'_'+j).checked == true)
				ofertasSeleccionadas += '1#';
			else
				ofertasSeleccionadas += '0#';
		}

		var suplementosSeleccionados = '';
		if (isset(eval('document.formularioResultados.numeroSuplementos_'+hotel+'_'+r)))
			numeroSuplementos = eval('document.formularioResultados.numeroSuplementos_'+hotel+'_'+r).value;
		else
			numeroSuplementos = 0;

		for (j=0; j<numeroSuplementos; j++)
		{
			if (eval('document.formularioResultados.suplemento_'+hotel+'_'+r+'_'+j).checked == true)
				suplementosSeleccionados += '1#';
			else
				suplementosSeleccionados += '0#';
		}

		eval('document.formularioResultados.ofertasSeleccionadas_'+hotel+'_'+r).value = ofertasSeleccionadas;
		eval('document.formularioResultados.suplementosSeleccionados_'+hotel+'_'+r).value = suplementosSeleccionados;

		if (ChainCode==8)
		{
			//GO GLOBAL GUARDAR habitacion_h_i en campos ocultos de goglobal
			if (eval('document.formularioResultados.habitacion_'+hotel+'_'+r).length != undefined)
			{
				for (i=0; i<eval('document.formularioResultados.habitacion_'+hotel+'_'+r).length; i++)
				{
					if (eval('document.formularioResultados.habitacion_'+hotel+'_'+r+'[i]').checked == true)
					{
						valorGoGlobal = eval('document.formularioResultados.habitacion_'+hotel+'_'+r+'[i]').value;
					}
				}
			}
			else //si hay un solo radiobutton trabajar directamente con el
			{
				campoRadio = 'habitacion_'+hotel+'_'+r;
				valorGoGlobal = document.getElementById(campoRadio).value;
			}
			eval('document.formularioResultados.GOGLOBAL_habitacion_'+hotel+'_'+r).value = valorGoGlobal;
		}
	}


	document.formularioResultados.submit();
}

/*****************************************************************************************************/
function evaluarPago()
{
	//si hay varios radiobuttons tratarlos como un array
	if (eval('document.formularioReserva.pago').length != undefined)
	{
		for (j=0; j<eval('document.formularioReserva.pago').length; j++)
		{
			if (eval('document.formularioReserva.pago[j]').checked == true)
				modoPago = eval('document.formularioReserva.pago[j]').value;
		}
	}
	else //si hay un solo radiobutton trabajar directamente con el
		modoPago = eval('document.formularioReserva.pago').value;


	switch (modoPago)
	{
		//$pagoPrepago	$pagoCredito  $pagoBonoTalon  $pagoDirectoHotel  $pagoDirectoHotel  $pagoDirectoMomento
		case 'prepago':
		case 'credito':
		case 'bonoTalon':		document.getElementById('mensajePagoDirectoHotel').style.display='none';
								document.getElementById('mensajePagoDirectoMomento').style.display='none';
								document.getElementById('capaTarjetas').style.display='none';
								break;

		case 'directoHotel':
								document.getElementById('mensajePagoDirectoHotel').style.display='block';
								document.getElementById('mensajePagoDirectoMomento').style.display='none';
								document.getElementById('capaTarjetas').style.display='block';
								break;

		case 'directoMomento': 	document.getElementById('mensajePagoDirectoHotel').style.display='none';
								document.getElementById('mensajePagoDirectoMomento').style.display='block';
								document.getElementById('capaTarjetas').style.display='block';
								break;
	}
}

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

// Valida que en los campos que le digamos sólo se puedan introducir números
function ValidarNumeros(e){

		/*
			Teclas permitidas aparte de todos los números:
			8 = tecla borrar
			0 = tecla supr
		*/

		// Para netscape o mozilla
		if (!document.all){
			//event = Evento;
			if((e.which < 48 || e.which > 57) && e.which != 8 && e.which != 0 )
				e.preventDefault();
		}
		// Para IE
		else{
			if((e.keyCode < 48 || e.keyCode > 57) && e.keyCode != 8 && e.keyCode != 0 )
				e.returnValue = false;
		}

}



function emailValido(cadena)
{
	var RegExPattern = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
	if ((cadena.match(RegExPattern)) && (cadena!='')) return true;
	else return false;
}


function formatoValidoFechaCaducidad(cadena)
{
	var RegExPattern = /^\d{2}\/\d{2}$/;
	if ((cadena.match(RegExPattern)) && (cadena!='')) {
		//si el formato es valido comprobar que no este caducada
		var hoy = new Date();
		var mesHoy = hoy.getMonth()+1;
		var anyoHoy = hoy.getYear();
		if (anyoHoy<1900) anyoHoy+=1900;

		var arrayFecha = new Array;
		arrayFecha = cadena.split('/');
		var mes = arrayFecha[0];
		var anyo = arrayFecha[1];
		anyo = '20'+anyo;



		//anyo anterior al actual
		if (anyo < anyoHoy) return false;
		else
			//mes no valido
			if ((mes<1) || (mes>12)) return false;
			else
			{
				//si es el actual mirar el mes
				if (anyo == anyoHoy)
				{
					if (mes < mesHoy) return false;
					else return true;
				}
				else return true;
			}
	}
	else return false;

}

function ocultaErrores()
{
	document.getElementById('erroresReserva').style.display='none';
	document.getElementById('errorCamposVacios').style.display='none';
	document.getElementById('errorFormatoEmail').style.display='none';
	document.getElementById('errorTarjeta').style.display='none';
	document.getElementById('errorCondiciones').style.display='none';
}

function validarFormularioReserva()
{
	//comprobar datos no vacios
 	var datosVacios=false;
	ocultaErrores();


 	if ((document.getElementById('nombre').value == '') || (document.getElementById('apellidos').value == '') || (document.getElementById('telefono').value == '') || (document.getElementById('email').value == '') || (document.getElementById('direccion').value == '') || (document.getElementById('ciudad').value == '') || (document.getElementById('cp').value == ''))
 	{
 		datosVacios=true;
 	}



 	//si es pago con tarjeta comprobar datos no vacios
 	var pagoTarjeta = false;

 	//si hay varios radiobuttons tratarlos como un array
	if (eval('document.formularioReserva.pago').length != undefined)
	{
 	 	for (var i=0; i<eval('document.formularioReserva.pago').length; i++)
		{
			if (((eval('document.formularioReserva.pago[i]').value == 'directoHotel') && (eval('document.formularioReserva.pago[i]').checked == true)) || ((eval('document.formularioReserva.pago[i]').value == 'directoMomento') && (eval('document.formularioReserva.pago[i]').checked == true))) pagoTarjeta=true;
		}
	}
	else
	{
		if (((eval('document.formularioReserva.pago').value == 'directoHotel') && (eval('document.formularioReserva.pago').checked == true)) || ((eval('document.formularioReserva.pago').value == 'directoMomento') && (eval('document.formularioReserva.pago').checked == true))) pagoTarjeta=true;
	}

	if (pagoTarjeta && ((document.getElementById('ccnombre').value == '') || (document.getElementById('ccnumero').value == '') || (document.getElementById('cvc').value == '') ))	datosVacios=true;





	if (datosVacios)
	{
		document.getElementById('erroresReserva').style.display='block';
		document.getElementById('errorCamposVacios').style.display='block';
	}
	else
	{
		//aceptar condiciones
		if (document.getElementById('aceptarCondiciones').checked == false)
		{
			document.getElementById('erroresReserva').style.display='block';
			document.getElementById('errorCondiciones').style.display='block';
		}
		else
		{
			//validar email
			if (!(emailValido(document.getElementById('email').value)))
			{
				document.getElementById('erroresReserva').style.display='block';
				document.getElementById('errorFormatoEmail').style.display='block';
			}
			else
			{
				if (pagoTarjeta)
				{
					//validar datos de tarjeta
					mes = document.getElementById('mes').value;
					anyo = document.getElementById('anyo').value;

					if (mes<10) mes='0'+mes;
					anyo = anyo.substr(2,2);
 					fechaCaducidad = mes+'/'+anyo;

 					numeroTarjeta = document.getElementById('ccnumero').value

					if ((numeroTarjeta.length!=16) || (!formatoValidoFechaCaducidad(fechaCaducidad)))
					{
						document.getElementById('erroresReserva').style.display='block';
						document.getElementById('errorTarjeta').style.display='block';
					}
					else
					{
						document.formularioReserva.submit();
					}
				}
				else
				{
					document.formularioReserva.submit();
				}
			}
		}


	}

}




/*****************************************************************************************************/
var NS7=(document.getElementById && !document.all)?1:0;

function ReconoceCapas2(capitas){
 var cadena="";
    if (NS7)  {
          cadena=capitas+"=document.getElementById('"+capitas+"')";
		  eval (cadena);
    }
}

function MostrarPestanya(capa, color)
{
	var cadena="";
    if (NS7)
    {
    	var caracteristicas = "caracteristicas";
    	var galeria = "galeria";
    	var situacion = "situacion";
      	var condiciones = "condiciones";
    	ReconoceCapas2(caracteristicas);
    	ReconoceCapas2(galeria);
    	ReconoceCapas2(situacion);
      	ReconoceCapas2(condiciones);

    }


	document.getElementById("pest_caracteristicas").style.background='#FFFFFF';
	document.getElementById("pest_caracteristicas").style.color='#9B9B9B';

	document.getElementById("pest_galeria").style.background='#FFFFFF';
	document.getElementById("pest_galeria").style.color='#9B9B9B';

	document.getElementById("pest_situacion").style.background='#FFFFFF';
	document.getElementById("pest_situacion").style.color='#9B9B9B';

	document.getElementById("pest_condiciones").style.background='#FFFFFF';
	document.getElementById("pest_condiciones").style.color='#9B9B9B';

	document.getElementById("pest_"+capa).style.background=color;
	document.getElementById("pest_"+capa).style.color='#555555';

	eval ("document.getElementById('caracteristicas').style.display = 'none'");
	eval ("document.getElementById('galeria').style.display = 'none'");
	eval ("document.getElementById('situacion').style.display = 'none'");
	eval ("document.getElementById('condiciones').style.display = 'none'");

	eval ("document.getElementById('"+capa+"').style.display = 'block'");
}

function VerImagen(Archivo,Capa)
{
	document.getElementById(Capa).src = Archivo;
}


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


function recuperacionReservas()
{
	var busqueda='';

	switch (document.getElementById('tipoRecuperacion').value)
	{
		case 'localizador':	busqueda = document.getElementById('localizador').value;
							break;

		case 'apellido':	busqueda = document.getElementById('apellido').value;
							break;

	}

	if (busqueda != '') document.formularioRecuperacion.submit();
}

/*****************************************************************************************************/
function confirmarCancelacion()
{
	var r = confirm("Confirmar cancelación");
	if (r==true)
	{
//		url="cancelacion.php";
//	    window.open(url, 'cancelacion', 'top=200, left=200, width=400,height=200');
		location.href="cancelacion.php";
	}
}


/*****************************************************************************************************/
function verCondiciones(ChainCode){
	url = 'condiciones.php?ChainCode='+ChainCode+'&';
	window.open(url, 'condiciones', 'top=100, left=150, width=700, height=550, toolbar=no, scrollbars=yes');
}



/*****************************************************************************************************/
function mostrarFiltros(){
	if (document.getElementById('filtros').style.display == "block")
		document.getElementById('filtros').style.display = "none";
	else
		document.getElementById('filtros').style.display = "block";
}

function filtrarBusqueda(){

	document.getElementById('paginaActual').value='1';
	document.getElementById('primeraBusqueda').value='NO';
	document.formularioResultados.submit();
}

function verTodosResultados()
{
	document.getElementById('paginaActual').value='1';
	document.getElementById('primeraBusqueda').value='NO';
	document.getElementById('filtroHotel').value='';
	document.getElementById('filtroCategoria').value='';
	document.getElementById('filtroProveedor').value='';
	document.getElementById('filtroPrecioMinimo').value='';
	document.getElementById('filtroPrecioMaximo').value='';
	document.getElementById('filtroLocalidad').value='';
	document.formularioResultados.submit();
}


function comprobarRangosFiltros(tipo)
{
	var valorMinimo = parseInt(document.getElementById('filtroPrecioMinimo').value);
	var valorMaximo = parseInt(document.getElementById('filtroPrecioMaximo').value);

	//si se modifica el minimo ajustar el maximo
	switch (tipo)
	{
		case 'min':		if (valorMaximo < valorMinimo) document.getElementById('filtroPrecioMaximo').value = valorMinimo;
						break;
		case 'max':		if (valorMinimo > valorMaximo) document.getElementById('filtroPrecioMinimo').value = valorMaximo;
						break;
	}
}




function validarSugerencias()
{
	var error=0;

	ocultaErroresSugerencias();
	document.getElementById('errorEmail').style.display='none';


	//CAMPOS VACIOS
	if ((document.formularioSugerencias.asunto.value=='') || (document.formularioSugerencias.email.value=='') || (document.formularioSugerencias.comentario.value==''))
	{
		error=1;
		document.getElementById('errorCamposVacios').style.display='block';
	}
	else
		if (!emailValido(document.formularioSugerencias.email.value))
		{
			error=1;
			document.getElementById('errorEmail').style.display='block';
		}



	if (error==0) {
		document.getElementById('errorSugerencias').style.display='none';
		document.getElementById('formularioValido').value='1';
		document.formularioSugerencias.submit();
	}
	else{
		document.getElementById('errorSugerencias').style.display='block';
	}
}

function ocultaErroresSugerencias()
{
	document.getElementById('errorSugerencias').style.display='none';
	document.getElementById('errorCamposVacios').style.display='none';
	document.getElementById('errorEmail').style.display='none';
}



function DesplegarInfoRegimen(Evento, texto)
{
	var ayudaText = document.getElementById('ayudaText');
	if(document.all)
	{
		PosX = window.event.clientX + document.documentElement.scrollLeft;
		PosY = window.event.clientY + document.documentElement.scrollTop;
	}
	else
	{
		PosX = Evento.pageX;
		PosY = Evento.pageY;
	}

	PosX = PosX + 15;
	PosY = PosY + 5;

	ayudaText.style.left = PosX+"px";
	ayudaText.style.top = PosY+"px";
	ayudaText.innerHTML = texto;
	ayudaText.style.visibility = 'visible';
}

function OcultarInfoRegimen()
{
	document.getElementById('ayudaText').style.visibility = 'hidden';
}


//inicializar ofertas en TODOS los hoteles
function inicializarOfertas(numeroHoteles, numeroTiposHabitaciones, correspondenciaHabitacionesRoomstays)
{
	var var1=ObjetoAjax()
	hotelInicial = 0;
	habitacionInicial = 1;
	mostrarOfertasRecursivo(numeroHoteles, numeroTiposHabitaciones, var1, true, mostrarOfertas, mostrarOfertasRecursivo, hotelInicial, habitacionInicial, correspondenciaHabitacionesRoomstays);
}

//inicializar ofertas en UN HOTEL EN CONCRETO
function inicializarOfertasHotel(hotel, numeroTiposHabitaciones, correspondenciaHabitacionesRoomstays)
{
	var var2=ObjetoAjax()
	numeroHoteles = parseInt(hotel)+1; //para hacerlo 1 sola vez, justo para ese hotel
	hotelInicial = hotel;
	habitacionInicial = 1;

	mostrarOfertasRecursivo(numeroHoteles, numeroTiposHabitaciones, var2, true, mostrarOfertas, mostrarOfertasRecursivo, hotelInicial, habitacionInicial, correspondenciaHabitacionesRoomstays);
}





/*****************************************************************************************************/
function evaluarGoGlobal(h, numeroHabitacion, totalHabitaciones)
{
	evaluarGoGlobalRegimen(h, numeroHabitacion, totalHabitaciones)

	//distinguir si son varios radiobuttons o solo uno
	if (eval('document.formularioResultados.habitacion_'+h+'_'+numeroHabitacion).length != undefined)
	{
		for (i=0; i<eval('document.formularioResultados.habitacion_'+h+'_'+numeroHabitacion).length; i++)
		{
			if (eval('document.formularioResultados.habitacion_'+h+'_'+numeroHabitacion+'[i]').checked == true)
			{
				valorSelectPrincipal = eval('document.formularioResultados.regimen_'+h+'_'+numeroHabitacion+'[i]').value;

				valor = eval('document.formularioResultados.habitacion_'+h+'_'+numeroHabitacion+'[i]').value;
			}
		}
	}
	else //si hay un solo radiobutton trabajar directamente con el
	{
		valorSelectPrincipal = eval('document.formularioResultados.regimen_'+h+'_'+numeroHabitacion).value;

		campoRadio = 'habitacion_'+h+'_'+numeroHabitacion;
		valor = document.getElementById(campoRadio).value;
	}

	var auxRegimenSelect = valorSelectPrincipal.split('_');
	var regimenSelect = auxRegimenSelect[0];
	var auxCodeSearchSelect = regimenSelect.split('#');
	var HotelSearchCodeSelect = auxCodeSearchSelect[1];
//	alert(HotelSearchCodeSelect)

	var auxRegimen = valor.split('_');
	var regimenHabitacion = auxRegimen[1];
	var auxCodeSearch = regimenHabitacion.split('#');
	var HotelSearchCode = auxCodeSearch[1];

//alert('radio '+HotelSearchCode+ '  select '+HotelSearchCodeSelect)

	//Para el resto de habitaciones deshabilitar las que no tengan el mismo codigo
	for (i=2; i<=totalHabitaciones; i++)
	{
		//recorrer cada radio
		if (eval('document.formularioResultados.habitacion_'+h+'_'+i).length != undefined)
		{
			for (j=0; j<eval('document.formularioResultados.habitacion_'+h+'_'+i).length; j++)
			{
				valorRadio = eval('document.formularioResultados.habitacion_'+h+'_'+i+'[j]').value;
				auxRegimenRadio = valorRadio.split('_');
				regimenHabitacionRadio = auxRegimenRadio[1];
				auxCodeSearchRadio = regimenHabitacionRadio.split('#');
				HotelSearchCodeRadio = auxCodeSearchRadio[1];

				if (HotelSearchCodeRadio == HotelSearchCode)
				{
					eval('document.formularioResultados.habitacion_'+h+'_'+i+'[j]').checked=true;
				}
				else
				{
					eval('document.formularioResultados.habitacion_'+h+'_'+i+'[j]').checked=false;
				}
				eval('document.formularioResultados.habitacion_'+h+'_'+i+'[j]').disabled=true;
				eval('document.formularioResultados.regimen_'+h+'_'+i+'[j]').disabled=true;
			}
		}
		else
		{
			valorRadio = eval('document.formularioResultados.habitacion_'+h+'_'+i).value;
			auxRegimenRadio = valorRadio.split('_');
			regimenHabitacionRadio = auxRegimenRadio[1];
			auxCodeSearchRadio = regimenHabitacionRadio.split('#');
			HotelSearchCodeRadio = auxCodeSearchRadio[1];

			if (HotelSearchCodeRadio == HotelSearchCode)
			{
				eval('document.formularioResultados.habitacion_'+h+'_'+i).checked=true;
			}
			else
			{
				eval('document.formularioResultados.habitacion_'+h+'_'+i).checked=false;
			}
			eval('document.formularioResultados.habitacion_'+h+'_'+i).disabled=true;
			eval('document.formularioResultados.regimen_'+h+'_'+i).disabled=true;
		}
	}

	recalcularPrecio();
}


function evaluarGoGlobalRegimen(h, numeroHabitacion, totalHabitaciones)
{
	//distinguir si son varios radiobuttons o solo uno
	if (eval('document.formularioResultados.habitacion_'+h+'_'+numeroHabitacion).length != undefined)
	{
		for (i=0; i<eval('document.formularioResultados.habitacion_'+h+'_'+numeroHabitacion).length; i++)
		{
			if (eval('document.formularioResultados.habitacion_'+h+'_'+numeroHabitacion+'[i]').checked == true)
			{
				valorSelectPrincipal = eval('document.formularioResultados.regimen_'+h+'_'+numeroHabitacion+'[i]').value;

				valor = eval('document.formularioResultados.habitacion_'+h+'_'+numeroHabitacion+'[i]').value;
			}
		}
	}
	else //si hay un solo radiobutton trabajar directamente con el
	{
		valorSelectPrincipal = eval('document.formularioResultados.regimen_'+h+'_'+numeroHabitacion).value;

		campoRadio = 'habitacion_'+h+'_'+numeroHabitacion;
		valor = document.getElementById(campoRadio).value;
	}

	var auxRegimenSelect = valorSelectPrincipal.split('_');
	var regimenSelect = auxRegimenSelect[0];
	var auxCodeSearchSelect = regimenSelect.split('#');
	var HotelSearchCodeSelect = auxCodeSearchSelect[1];
//	alert(HotelSearchCodeSelect)

	var auxRegimen = valor.split('_');
	var regimenHabitacion = auxRegimen[1];
	var auxCodeSearch = regimenHabitacion.split('#');
	var HotelSearchCode = auxCodeSearch[1];

//alert('radio '+HotelSearchCode+ '  select '+HotelSearchCodeSelect)

	//Para el resto de habitaciones deshabilitar las que no tengan el mismo codigo
	for (i=2; i<=totalHabitaciones; i++)
	{
		//recorrer cada radio
		if (eval('document.formularioResultados.habitacion_'+h+'_'+i).length != undefined)
		{
			//	Primero seleccionar mismo regimen para que coja su codigo
			for (j=0; j<eval('document.formularioResultados.regimen_'+h+'_'+i).length; j++)
			{
				campoSelect = eval('document.formularioResultados.regimen_'+h+'_'+i+'[j]');
				for(k=0;k<campoSelect.options.length;k++)
				{
					valorOption = campoSelect.options[k].value;
					auxRegimen = valorOption.split("_");
					codigosRegimen = auxRegimen[0];
					auxRegimen2 = codigosRegimen.split("#");
					selectCode = auxRegimen2[1];

					if (selectCode == HotelSearchCode)
					{
						campoSelect.options[k].selected=true;
					}
					else
					{
						campoSelect.options[k].selected=false;
					}
				}
			}
		}
		else
		{
			//	Primero seleccionar mismo regimen para que coja su codigo
			campoSelect = eval('document.formularioResultados.regimen_'+h+'_'+i);
			for(k=0;k<campoSelect.options.length;k++)
			{
				valorOption = campoSelect.options[k].value;
				auxRegimen = valorOption.split("_");
				codigosRegimen = auxRegimen[0];
				auxRegimen2 = codigosRegimen.split("#");
				selectCode = auxRegimen2[1];

				if (selectCode == HotelSearchCode)
				{
					campoSelect.options[k].selected=true;
				}
				else
				{
					campoSelect.options[k].selected=false;
				}
			}
		}
	}

	recalcularPrecio();
}

