function arregla_fechas()
{
	desdetemp=$('#desdetemp').val();
	desdetemp1=desdetemp.substr(0,6);
	desdetemp2=desdetemp.substr(8,2);
	hastatemp=$('#hastatemp').val();
	hastatemp1=hastatemp.substr(0,6);
	hastatemp2=hastatemp.substr(8,2);
	$('#desde').val(desdetemp1+desdetemp2);
	$('#hasta').val(hastatemp1+hastatemp2);
}
function cambia_tab_pack_tematico(nombre)
{
	$('.tabs_packs .tab_pack').removeClass('selected').addClass('noselected');
	$('#tab_'+nombre).removeClass('noselected').addClass('selected');
	$('.tabs_packs_center .tab_pack_content').removeClass('selected').addClass('noselected');
	$('#tab_content_'+nombre).removeClass('noselected').addClass('selected');
}
function cambia_tab_pack(nombre)
{
	$('.packs').removeClass('selected').addClass('noselected');
	$('#tab_'+nombre).removeClass('noselected').addClass('selected');	
}

function crea_selector_zonas(){
	var contenido;
	contenido='<select onchange="crea_selector_poblacions(this.value)">';
	for (i=0;i<zonas.length;i++)
	{
		if(i==0)
			contenido+="<option value='' selected>" + todas[idioma_base] + "</option>"; 
		else
		if(zonas[i][0]=='1068')
		   contenido+="<option value='"+zonas[i][0]+"' selected>" + zonas[i][1] + "</option>"; 
		else
		   contenido+="<option value='"+zonas[i][0]+"'>" + zonas[i][1] + "</option>"; 	
	}
	contenido+='</select>';
	$('#div_select_zona').html(contenido);
	$('#zonaid').val(zonas[0][0]);
}

function crea_selector_poblacions(pos)
{
	if(pos==0){
		contenido='<select name="destinoid"><option value="">' + todas[idioma_base] + '</option></select>';
		$('#zonaid').val('');
	}
	else
	{
		for (i=0;i<zonas.length;i++)
			if(zonas[i][0]==pos)
				$('#zonaid').val(zonas[i][0]);
		var contenido;
		contenido='<select name="destinoid">';
		contenido+="<option value=''>"+ todas[idioma_base] +"</option>"; 		
		for (i=0;i<poblacio[pos].length;i++)
			   contenido+="<option value='"+poblacio[pos][i][0]+"'>" + poblacio[pos][i][1] + "</option>"; 	
		contenido+='</select>';
	}
	$('#div_select_poblacion').html(contenido);	
}
function PreparaEnlace(cont)
{
	return link_hoteles[cont];
}
function LeeInfoOpenInfoWindowHtml(cont,imagen)
{
	var sReturn='';
	url=PreparaEnlace(cont);	
	sReturn='<div class="google_map_content">';
	sReturn+='<div class="google_map_content_title"><a href="'+url+'">'+nombres_hoteles[cont]+"</a></div>";
	sReturn+='<div class="google_map_content_title_right">';
	sReturn+='<div class="google_map_content_title_estrellas"><div class="estrellas estrellas'+estrellas_hoteles[cont]+'"></div></div>';
	sReturn+='<div class="google_map_content_title_marca"><img src="'+imagen+'"></div>';	
	sReturn+='<div style="clear:both"></div>';
	sReturn+='</div>';
	sReturn+='<div class="google_map_content_bottom">';
	if(imagenes_hoteles[cont]!=""){	
	sReturn+="<div class='google_map_content_imagen'>";
		sReturn+="<img src='"+imagenes_hoteles[cont]+"' width='80' height='80'>";		
	sReturn+="</div>";
	}
	if(imagenes_hoteles[cont]=="")		
		sReturn+="<div class='google_map_content_desc' style='width:285px'>"+texto_hoteles[cont]+"</div>";
	else
		sReturn+="<div class='google_map_content_desc'>"+texto_hoteles[cont]+"</div>";
//	sReturn+="<a style='font-size:12px' onclick='' href='"+url+"'>Ver</a></center>";
	sReturn+='<div style="clear:both"></div>';
	sReturn+='</div>';
	sReturn+='</div>';
	
	return sReturn;
}	
function LeeInfoOpenInfoWindowHtml_hotel(imagen)
{
	var sReturn='';
	sReturn='<div class="google_map_content">';
	sReturn+='<div class="google_map_content_title">'+nombre_hotel+"</div>";
	sReturn+='<div class="google_map_content_title_right">';
	sReturn+='<div class="google_map_content_title_estrellas"><div class="estrellas estrellas'+estrellas_hotel+'"></div></div>';
	sReturn+='<div class="google_map_content_title_marca"><img src="'+imagen+'"></div>';	
	sReturn+='<div style="clear:both"></div>';
	sReturn+='</div>';
	sReturn+='<div class="google_map_content_bottom">';
	if(imagen_hotel!=""){
	sReturn+="<div class='google_map_content_imagen'>";
		sReturn+="<img src='"+imagen_hotel+"' width='80' height='80'>";		
	sReturn+="</div>";
	}	
	if(imagen_hotel=="")
		sReturn+="<div class='google_map_content_desc' style='width:285px'>"+texto_hotel+"</div>";	
	else
		sReturn+="<div class='google_map_content_desc'>"+texto_hotel+"</div>";
	sReturn+='<div style="clear:both"></div>';
	sReturn+='</div>';
	sReturn+='</div>';
	
	return sReturn;
}	
function crea_evento(marker,cont,imagen)
{
	GEvent.addListener(marker, "click", function (){												  
		var html=LeeInfoOpenInfoWindowHtml(cont,imagen);
		marker.openExtInfoWindow(
		  map,
		  "simple_example_window",
		  html,
		  {beakOffset: 3}
		); 
	
	});		
}
function crea_evento_hotel(marker,imagen)
{
	GEvent.addListener(marker, "click", function (){												  
		var html=LeeInfoOpenInfoWindowHtml_hotel(imagen);
		marker.openExtInfoWindow(
		  map,
		  "simple_example_window",
		  html,
		  {beakOffset: 3}
		); 
	});
}
function google_map(){
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("mapa"));		
		map.setCenter(new GLatLng(41.730330, 1.669921), 7);
		
		for(cont=0;cont<latitudes_hoteles.length;cont++)
		{
			if(latitudes_hoteles[cont]==0.000000 && longitudes_hoteles[cont]==0.000000)
			{
				var bounds = map.getBounds();
				var southWest = bounds.getSouthWest();
				var northEast = bounds.getNorthEast();
				var lngSpan = northEast.lng() - southWest.lng();
				var latSpan = northEast.lat() - southWest.lat();
				latitudes_hoteles[cont]=southWest.lat() + latSpan * Math.random()/1.5;
				longitudes_hoteles[cont]=southWest.lng() + lngSpan * Math.random()/1.5;
			}
			Icono = new GIcon(G_DEFAULT_ICON);	

			if(tipo_hoteles[cont]==1) Icono.image = base_url+"templates/css/imagenes/iconos/icono_hotel_costa.gif";
			else
			if(tipo_hoteles[cont]==2) Icono.image = base_url+"templates/css/imagenes/iconos/icono_hotel_blau.gif";
			else Icono.image = base_url+"templates/css/imagenes/iconos/icono_hotel_petit.gif";
			Icono.iconSize = new GSize(25,26);
			Icono.shadow="";
			
			markerOptions = { icon:Icono,title:nombres_hoteles[cont] };
			var latlng = new GLatLng(latitudes_hoteles[cont], longitudes_hoteles[cont]);
			var marker = new GMarker(latlng,markerOptions);
			crea_evento(marker,cont,Icono.image);
			markers_hoteles.push(marker);
		}
		var markerCluster = new MarkerClusterer(map, markers_hoteles,{maxZoom:12,gridSize:45,styles:[{
			url: base_url+'templates/css/imagenes/googlemap/google.png',
			height: 45,
			width: 45
		  },
		  {
			url: base_url+'templates/css/imagenes/googlemap/google.png',
			height: 45,
			width: 45
		  },
		  {
			url: base_url+'templates/css/imagenes/googlemap/google.png',
			height: 45,
			width: 45
		}]});
		Icono = new GIcon(G_DEFAULT_ICON);	
		Icono.image = base_url+"templates/css/imagenes/googlemap/icono_aeropuerto.png";
		Icono.shadow="";		
		markerOptions = { icon:Icono};
		var geocoder = new GClientGeocoder();
		geocoder.getLatLng(
			"aeropuerto girona",
			function(point) {
			  if (!point) {
				alert(address + " not found");
			  } else {
				var marker = new GMarker(point,markerOptions);
				map.addOverlay(marker);
			  }
			}
		  );
		map.setUIToDefault();
	}
}

function google_map_hotel(){
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("mapa_hotel"));		
		map.setCenter(new GLatLng(41.730330, 1.669921), 7);
		Icono = new GIcon(G_DEFAULT_ICON);	

		if(tipo_hotel==1) Icono.image = base_url+"templates/css/imagenes/iconos/icono_hotel_costa.gif";
		else
		if(tipo_hotel==2) Icono.image = base_url+"templates/css/imagenes/iconos/icono_hotel_blau.gif";
		else Icono.image = base_url+"templates/css/imagenes/iconos/icono_hotel_petit.gif";
		Icono.iconSize = new GSize(25,26);
		Icono.shadow="";

		markerOptions = { icon:Icono,title:nombre_hotel };				
		var latlng = new GLatLng(latitud_hotel, longitud_hotel);		
		var marker = new GMarker(latlng,markerOptions);
		
		crea_evento_hotel(marker,Icono.image);
		map.addOverlay(marker);
		map.setCenter(new GLatLng(latitud_hotel, longitud_hotel), 9);
		map.setUIToDefault();
	}
}
function envia_formulario_filtro(){
	estrellas='';
	if ($('input[name=estrellas_todas]').attr('checked')) {
		estrellas=0;
		$('input[name=bus_estrellas]').val(estrellas);
	}
	else
	{
		if ($('input[name=estrellas_1]').attr('checked')) estrellas=estrellas+"|1";
		if ($('input[name=estrellas_2]').attr('checked')) estrellas=estrellas+"|2";
		if ($('input[name=estrellas_3]').attr('checked')) estrellas=estrellas+"|3";
		if ($('input[name=estrellas_4]').attr('checked')) estrellas=estrellas+"|4";	
		if ($('input[name=estrellas_5]').attr('checked')) estrellas=estrellas+"|5";
		$('input[name=bus_estrellas]').val(estrellas.substring(1));
	}
	$('input[name=bus_nombre]').val("");
	$('input[name=bus_poblacion]').val("");
	document.form_numero_items.submit();	
}
function envia_formulario_filtro_zona(){
	zona='';
	if ($('input[name=zona_todas]').attr('checked')) {
		zona=0;
		$('input[name=bus_zona]').val(zona);
	}
	else
	{
		if ($('input[name=zona_bar]').attr('checked')) zona=zona+"|08";
		if ($('input[name=zona_tar]').attr('checked')) zona=zona+"|43";
		if ($('input[name=zona_lle]').attr('checked')) zona=zona+"|25";
		if ($('input[name=zona_gir]').attr('checked')) zona=zona+"|17";
		$('input[name=bus_zona]').val(zona.substring(1));		
	}
	$('input[name=bus_nombre]').val("");
	$('input[name=bus_poblacion]').val("");
	document.form_numero_items.submit();	
}
function envia_formulario_shotel(){
	shotel='';
	if ($('input[name=servicio_hotel_todas]').attr('checked')) {
		shotel=0;
		$('input[name=bus_servicios_hotel]').val(shotel);
	}
	else
	{	
		$(".shotel").each(
			function() {
				if($(this).attr('checked'))
					 shotel=shotel+"|"+$(this).attr('name').substr(15);
			}
		);
		$('input[name=bus_servicios_hotel]').val(shotel.substring(1));
	}
	$('input[name=bus_nombre]').val("");
	$('input[name=bus_poblacion]').val("");
	document.form_numero_items.submit();
}
function envia_formulario_shabitacion(){
	shabitacion='';
	if ($('input[name=servicio_habitacion_todas]').attr('checked')) {
		shabitacion=0;
		$('input[name=bus_servicios_habitacion]').val(shabitacion);
	}
	else
	{	
		$(".shabitacion").each(
			function() {
				if($(this).attr('checked'))
					 shabitacion=shabitacion+"|"+$(this).attr('name').substr(20);
			}
		);
		$('input[name=bus_servicios_habitacion]').val(shabitacion.substring(1));
	}
	$('input[name=bus_nombre]').val("");
	$('input[name=bus_poblacion]').val("");
	document.form_numero_items.submit();
}
function validarEmail(valor) {
	if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test(valor)){
		return (true)
	} else {
		return (false);
	}
}
function comprobar_newsletter(){
	error=false;
	if ($('#nnombre').val()=='') {
		$('#nnombre_texto').html($('#nnombre_error_texto').html());
		error=true;
	} else $('#nnombre_texto').html('');
	if ($('#nemail').val()=='') {
		$('#nemail_texto').html($('#nemail_error_texto').html());
		error=true;
	} else	if(!validarEmail($('#nemail').val())) {
		$('#nemail_texto').html($('#nemail_error2_texto').html());
		error=true;
	} else $('#nemail_texto').html('');
	if(!error) document.form_newsletters.submit();
}

function comprueba_area_clientes(){
	error=false;
	if ($('#localizador').val()=='') {
		$('#texto_localizador').html($('#error_texto_localizador').html());
		error=true;
	} else $('#texto_localizador').html('');
	if ($('#email').val()=='') {
		$('#texto_email').html($('#error_texto_email1').html());
		error=true;
	} else	if(!validarEmail($('#email').val())) {
		$('#texto_email').html($('#error_texto_email2').html());
		error=true;
	} else $('#texto_email').html('');
	if(!error) document.form_area_clientes.submit();	
}
function cambia_idioma(idioma,selfurl)
{
	if(selfurl.substr(1,8)=='festival'){
		selfurl="/"+url[idioma];
	}
	if(idioma!='es')
		{
		if(idioma=='ge')			
			$("#form_cambiar_idioma").attr("action",'http://de.reservashoteles.net'+selfurl);
			else
			$("#form_cambiar_idioma").attr("action",'http://'+idioma+'.reservashoteles.net'+selfurl);
		}
	else
		$("#form_cambiar_idioma").attr("action",'http://www.reservashoteles.net'+selfurl);	
	document.form_cambiar_idioma.submit();
}
function enviar_formulario_email()
{
	cnombre=$("#cnombre").val();
	ctelefono=$("#ctelefono").val();	
	cemail=$("#cemail").val();
	cmensaje=$("#cmensaje").val();
	error=false;
	if (cnombre=='') {
		$('#cnombre_texto').html($('#nnombre_error_texto').html()+"<br><br>");
		error=true;
	} else $('#cnombre_texto').html('');
	if (ctelefono=='') {
		$('#ctelefono_texto').html($('#ntelefono_error_texto').html()+"<br><br>");
		error=true;
	} else $('#ctelefono_texto').html('');
	if (cemail=='') {
		$('#cemail_texto').html($('#nemail_error_texto').html()+"<br><br>");
		error=true;
	} else	if(!validarEmail(cemail)) {
		$('#cemail_texto').html($('#nemail_error2_texto').html()+"<br><br>");
		error=true;
	} else $('#cemail_texto').html('');
	if (cmensaje=='') {
		$('#cmensaje_texto').html($('#nmensaje_error_texto').html()+"<br><br>");
		error=true;
	} else $('#cmensaje_texto').html('');	
	if(!error) {
		$('#formulario_texto').html($('#mensaje_contacto_enviando').html());
		$.get("enviar_email.php", { nombre: cnombre, telefono: ctelefono, email: cemail, mensaje: cmensaje},
			function(data){
				$('#formulario_texto').html($('#mensaje_contacto_enviado').html());
		});
	}
}