function actualizaFechaEntradaPaquete(fechaEntrada) {
	var vueltas = fechasPaquetes[fechaEntrada]['vueltas'];
	removeSelectContent(document.getElementById('selectFechaSalida'));
	
	for (var fecha in vueltas) {
		if(typeof(vueltas[fecha]) != 'function') {
			addSelectOption(document.getElementById('selectFechaSalida'), vueltas[fecha], fecha);
		}
	}
	
	partesFecha = fechaEntrada.split('-');
	formulariohotel.fecha_entrada.value = partesFecha[2]+'-'+partesFecha[1]+'-'+partesFecha[0];
	
	
	actualizaFechaSalidaPaquete(document.getElementById('selectFechaSalida').value);
}

function actualizaFechaSalidaPaquete(fechaSalida) {
	partesFecha = fechaSalida.split('-');
	formulariohotel.fecha_salida.value = partesFecha[2]+'-'+partesFecha[1]+'-'+partesFecha[0];
}

function removeSelectContent(theSel){
	theSel.length = 0;
}

function addSelectOption(theSel, text, value) {
	theSel.options[theSel.length] = new Option(text, value);
}


function marcarRadioButtonBuscador(valor){
	temp = document.formulariohotel.tipoBusqueda;
	
	for(i=0;i<temp.length;i++){
		if(temp[i].value==valor){
			temp[i].checked = true;
			temp[i].onclick();
		}
	}
	
}

function recargarSelectBuscador(tipo,idLoc,select,idArea,mostrar){	
	temp = document.getElementById(select);	
	if(tipo=='localidad'){
		for (i=0;i<temp.length;i++){
			if(temp[i].value==idLoc){
				temp[i].selected = true;
			}else{
				temp[i].selected = false;
			}
		}
	}else if (tipo=='area'){		
		for (i=0;i<temp.length;i++){
			if(temp[i].value==idArea){				
				temp[i].selected = true;
			}else{
				temp[i].selected = false;
			}
		}				
		actualizarSelectLocalidad(idArea,idLoc);		
		if(!mostrar){
			document.getElementById('div_costa').style.display='none';
		}
	}
	
}

function actualizarSelectLocalidad(id,marcado){
	FAjax('js/ajax.php', 'div_costa', 'q='+id+'&marcado='+marcado, 'POST');
}


function insertarEnBuscadorDesdeMapa(nombre,tipo,tipoBusquedaGeneral){
	if((tipo==1 ) || (tipo==2)){
		// 	Caso de que el tipo sea hotel o alojamiento lo marcamos
		for(i=0;i<formulariohotel.search_hal.length;i++){
			if(formulariohotel.search_hal[i].value==tipo){
				formulariohotel.search_hal[i].checked = true;
			}else{
				formulariohotel.search_hal[i].checked = false;
			}
		}
		// Funcion que cambia los iconos del filtro
		cambiarTipoAlojamiento(tipo);
	}else{
		for(i=0;i<formulariohotel.search_hal.length;i++){
			if(formulariohotel.search_hal[i].value==0){
				formulariohotel.search_hal[i].checked = true;
			}else{
				formulariohotel.search_hal[i].checked = false;
			}
		}
		// Funcion que cambia los iconos del filtro
		cambiarTipoAlojamiento('1');
	}

	
	
	// cambiamos ahora el tipo de busqueda y ponemos busqueda por hotel
	for(i=0;i<formulariohotel.tipoBusqueda.length;i++){
		if((formulariohotel.tipoBusqueda[i].value=='hotel') && ((tipoBusquedaGeneral=='serhs') || (tipoBusquedaGeneral=='propio'))){
			formulariohotel.tipoBusqueda[i].checked = true;
		}else if((formulariohotel.tipoBusqueda[i].value=='localidad') && (tipoBusquedaGeneral!='serhs') && (tipoBusquedaGeneral!='propio')){
			formulariohotel.tipoBusqueda[i].checked = true;
		}else{
			formulariohotel.tipoBusqueda[i].checked = false;
		}
	}
	// mostramos el div de hotel nombre
	if((tipoBusquedaGeneral=='serhs') || (tipoBusquedaGeneral=='propio')){
		document.getElementById("hotelName").value = nombre;
		document.getElementById("hotelName").style.display= '';
		document.getElementById("localidadName").value = '';
		document.getElementById("localidadName").style.display= 'none';
	}else{
		document.getElementById("hotelName").value = '';
		document.getElementById("hotelName").style.display= 'none';
		document.getElementById("localidadName").value = nombre;
		document.getElementById("localidadName").style.display= '';
	}
	document.getElementById("tipoHidden").value=tipoBusquedaGeneral;
	

}


var ajaxTemporal = null;
function buscarSimilares(tipo,elemento,clase){
	/* limpiamos el tipoHidden */
	document.getElementById('tipoHidden').value='';
	if(ajaxTemporal){
		ajaxTemporal.transport.abort();
	}
	
	ajaxTemporal = new Ajax.Updater(divElementos, 'temp/mostrarParecidos.php?tipo='+tipo+'&valor='+elemento.value, { method: 'GET' , encoding:'ISO-8859-1'});
	document.getElementById('divContenedorElementos').style.display='';
	if(clase=='lateral'){
		document.getElementById('divContenedorElementos').style.left='360';
	}else{
		document.getElementById('divContenedorElementos').style.left='625';
		document.getElementById('divContenedorElementos').style.top='200';
	}
} 
function desmarcar(id,valor){
	// Comprobamos todos los checkbox
	valor5 = document.getElementById('categoria5').checked;
	valor4 = document.getElementById('categoria4').checked;
	valor3 = document.getElementById('categoria3').checked;
	valor2 = document.getElementById('categoria2').checked;
	valor1 = document.getElementById('categoria1').checked;
	if(!valor1 & !valor2 && !valor3 && !valor4 && !valor5){
		document.getElementById(id).checked = true;
	}else if (valor1 && valor2 && valor3 && valor4 && valor5){
		document.getElementById(id).checked = true;
		document.getElementById('categoria5').checked = false;
		document.getElementById('categoria4').checked = false;
		document.getElementById('categoria3').checked = false;
		document.getElementById('categoria2').checked = false;
		document.getElementById('categoria1').checked = false;
		
	}else{
		document.getElementById(id).checked = false;
	}

}
function marcarTodas(nombre1,nombre2,nombre3,nombre4,nombre5,valor){
		document.getElementById(nombre1).checked=false;
		document.getElementById(nombre2).checked=false;
		document.getElementById(nombre3).checked=false;
		document.getElementById(nombre4).checked=false;
		document.getElementById(nombre5).checked=false;
		document.getElementById(valor).checked= true;
	
}
function cambiarTipoAlojamiento(valor){
	if((valor=='0') ||(valor=='1')){
		icono = "imagenes/estrellita.gif";			
	}else{
		icono = "imagenes/llave.gif";			
	}
	$$('.imagenCategoria').each(function(objeto){
		objeto.src = icono;
	});
	/*document.getElementById('imagenCategoria5').src = icono;
	document.getElementById('imagenCategoria4').src = icono;
	document.getElementById('imagenCategoria3').src = icono;
	document.getElementById('imagenCategoria2').src = icono;
	document.getElementById('imagenCategoria1').src = icono;*/
	
	
}
	
