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_servicios(id){
	if(id=='hotel'){
		$('#servicios_hotel').show();
		$('#servicios_clientes').hide();
		$('#a_servicios_hotel').addClass('selected');
		$('#a_servicios_clientes').removeClass('selected');
		$('#a_servicios_clientes').children().show();
	}else{
		$('#servicios_clientes').show();
		$('#servicios_hotel').hide();
		$('#a_servicios_clientes').addClass('selected');
		$('#a_servicios_hotel').removeClass('selected');
		$('#a_servicios_hotel').children().show();
	}
}
function cambia_eventos(id){
	if(id=='convenciones'){
		$('#eventos_convenciones').show();
		$('#eventos_celebraciones').hide();
		$('#a_convenciones').addClass('selected');
		$('#a_celebraciones').removeClass('selected');
		$('#a_celebraciones').children().show();
	}else{
		$('#eventos_celebraciones').show();
		$('#eventos_convenciones').hide();
		$('#a_celebraciones').addClass('selected');
		$('#a_convenciones').removeClass('selected');
		$('#a_convenciones').children().show();
	}
}
function cambia_entorno(id){
	if(id=='visiten'){
		$('.servicios').hide();
		$('#entorno_visiten').show();
		$('.ico_entorno').removeClass('selected');
		$('.ico_entorno').children().show();
		$('#a_visiten').addClass('selected');
		$('#a_visiten').children().hide();
	}
	if(id=='compras'){
		$('.servicios').hide();
		$('#entorno_compras').show();
		$('.ico_entorno').removeClass('selected');
		$('.ico_entorno').children().show();
		$('#a_compras').addClass('selected');
		$('#a_compras').children().hide();
	}
	if(id=='noches'){
		$('.servicios').hide();
		$('#entorno_noches').show();
		$('.ico_entorno').removeClass('selected');
		$('.ico_entorno').children().show();
		$('#a_noches').addClass('selected');
		$('#a_noches').children().hide();
	}
	if(id=='festivales'){
		$('.servicios').hide();
		$('#entorno_festivales').show();
		$('.ico_entorno').removeClass('selected');
		$('.ico_entorno').children().show();
		$('#a_festivales').addClass('selected');
		$('#a_festivales').children().hide();
	}
	if(id=='ferias'){
		$('.servicios').hide();
		$('#entorno_ferias').show();
		$('.ico_entorno').removeClass('selected');
		$('.ico_entorno').children().show();
		$('#a_ferias').addClass('selected');
		$('#a_ferias').children().hide();
	}
	if(id=='ocio'){
		$('.servicios').hide();
		$('#entorno_ocio').show();
		$('.ico_entorno').removeClass('selected');
		$('.ico_entorno').children().show();
		$('#a_ocio').addClass('selected');
		$('#a_ocio').children().hide();
	}
}

var map=null;
var ruta=null;
var iniQuery=0;
function google_map(){
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("mapa"));		
		map.setCenter(new GLatLng(41.9817957, 2.8236999), 9);

		Icono = new GIcon(G_DEFAULT_ICON);	
		Icono.image = base_url+"templates/css/imagenes/icono_google_map.png";
		Icono.iconSize = new GSize(38,46);
		Icono.shadow="";		
		markerOptions = { icon:Icono};
		var geocoder = new GClientGeocoder();
		geocoder.getLatLng(
			"Pla&ccedil;a Major, 17214, Regenc&oacute;s, Girona,ES",
			function(point) {
			  if (!point) {
				alert(address + " not found");
			  } else {
				var marker = new GMarker(point,markerOptions);
				crea_evento(marker);
				map.addOverlay(marker);
			  }
			}
		  );
		map.setUIToDefault();
		map.disableScrollWheelZoom();
	}
}
function crea_evento(marker,cont,imagen)
{
	GEvent.addListener(marker, "click", function (){												  
		var html=LeeInfoOpenInfoWindowHtml();
		marker.openExtInfoWindow(
		  map,
		  "simple_example_window",
		  html,
		  {beakOffset: 3}
		); 
	
	});		
}
function LeeInfoOpenInfoWindowHtml()
{
	var sReturn='';
	sReturn='<div class="google_map_content">';
	sReturn+='	<div class="google_map_content_foto"><img src="'+base_url+'templates/css/imagenes/foto.png"></div>';
	sReturn+='	<div class="google_map_content_datos">';
	sReturn+='		<div class="google_map_content_title">Hotel del Teatre</div>';
	sReturn+='		<div class="google_map_content_info">Pla&ccedil;a Major, s/n<br>17214 Regenc&oacute;s (Girona)<br>Tel: (+34) 972 30 62 70</div>';
	sReturn+='	</div>';
	sReturn+="</div>";	
	return sReturn;
}
function comoLlegar(){
	desde=$('#desdeRuta').val();
	hasta="Pla&ccedil;a Major, 17214, Regenc&oacute;s, Girona,ES";
	tipo="d";
	
	CreaRuta(desde,hasta,"",errorMapa,ImprimirMapa,tipo);
}
function ImprimirMapa(){ 
}
function errorMapa(){
	alert("No se ha encontrado la ruta.")
}
function CreaRuta(from,to,result_div,error_func,callback_func,travelmode)
{
	travel=G_TRAVEL_MODE_DRIVING;
	
	if(ruta==null){
		ruta = new GDirections(this.map);
		
        //Función de error
		if(typeof error_func=="undefined") GEvent.addListener(ruta, "error", error_func);
		else GEvent.addListener(ruta, "error", error_func);
	}
	//Función de respuesta
	if(typeof callback_func!="undefined"){
		GEvent.addListener(ruta, "load", callback_func);
	}
	ruta.load("from: " + from + " to: " + to,{ "locale": "es","travelMode":travel});
}

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_email(){
	email=$('#contacto_email').val();

	error=false;
	if(!validarEmail(email)) {
		error=true;
		$('#error_form').show();
		
	}
	if(error==false){
		$('#error_form').hide();
		document.form_contacto.submit();
	}
}
function comprobar_email_newsletter(){
	email=$('#newsletter_email').val();

	error=false;
	if(!validarEmail(email)) {
		error=true;
		$('#error_form').show();
		
	}
	if(error==false){
		$('#error_form').hide();
		if($('#acepto').is(':checked')){
			document.form_newsletter.submit();
		}
		else{
			$('#id_condiciones').css("color","#CC3333");
		}
	}
}
