function enviarform(pagina,busqueda){
	document.enviar.action=pagina;
	document.enviar.busqueda.value=busqueda;
	document.enviar.submit();
}
		
function votar(campo,id,valor,sx)
{
if (valor!='')
{
	
var url = 'votar.php?campo='+campo+'&valor='+valor+'&id=' + id  ;
//window.open (url);
document.getElementById(sx).style.display="none";
document.getElementById("ultranotas").style.display="block";
document.getElementById("ultranotas").innerHTML="GRACIAS POR VOTAR!! HEMOS TOMADO NOTA DE TU VOTACIÓN";
xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
data = xmlhttp.responseText;
//alert('Gracias por votar!!!\nHemos tomado nota.');

}
}
xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
xmlhttp.send(null);
return false;	
}
}
function setDirections(fromAddress, toAddress, locale) {
  gdir.load("from: " + fromAddress + " to: " + toAddress,
            { "locale": locale });
}
	function handleErrors(){
		   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
		   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);

		   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

		//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
		//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);

		   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
		     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

		   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

		   else alert("An unknown error occurred.");

		}
		function onGDirectionsLoad(){ 
		      // Use this function to access information about the latest load()
		      // results.

		      // e.g.
		      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
			  // and yada yada yada...
			}

						
						function puntuarmal(idmapa)
									{
										var url = 'puntuarmal.php?idmapa=' + idmapa  ;
										xmlhttp.open("GET",url,true);
									//	window.open (url)
										xmlhttp.onreadystatechange=function() {
										if (xmlhttp.readyState==4) {
											data = xmlhttp.responseText;
											alert('Gracias por  ayudarnos!!!\nHemos tomado nota.');

										}
										}
										xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
										xmlhttp.send(null);

										return false;	
									}
									var enviar ='no';
										function trim(stringToTrim) {
										return stringToTrim.replace(/^\s+|\s+$/g,"");
									}
									function ltrim(stringToTrim) {
										return stringToTrim.replace(/^\s+/,"");
									}
									function rtrim(stringToTrim) {
										return stringToTrim.replace(/\s+$/,"");
									}
										function IsNumeric(valor) 
											{ 
												var log=valor.length; var sw="S"; 
												for (x=0; x<log; x++) 
													{ v1=valor.substr(x,1); 
													v2 = parseInt(v1); 
													//Compruebo si es un valor numérico 
													if (isNaN(v2)) { sw= "N";} 
													} 
													if (sw=="S") {return true;} else {return false; } 
											} 
											function validarEmail(valor) {
												  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
												   return (true)
												  } else {
												      return (false);
												  }
												 }
												
												

function parseJson(doc) {
var jsonData = eval("(" + doc + ")");

	for (var i = 0; i < jsonData.markers.length; i++) {
			if (jsonData.markers[i].nombre!=''){
					var markermas = createMarker(jsonData.markers[i],i);
		map.addOverlay(markermas);}
	}

}

function createMarker(input,numero) {
var marker = new GMarker(input.point,iconm);
imagen="images/museum_icon.png";
GEvent.addListener(marker, "click", function() {
initialize(input.point.lat(),input.point.lng(),input.idwifi);
marker.openInfoWindowHtml('<div id="globo"><img src="'+imagen+'" style="margin-right:5px;float:left;width:30px"/><h3 style="padding:8px">'+input.nombre+'</h3><br />'+input.ciudad+'</strong><br /><a href="museo-'+input.enlace+'-ID'+input.idwifi+'.htm">Ver más detalles</a></div>');
});
return marker;
}
function recargar(){

	var url = 'recargar.php';
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		datos = xmlhttp.responseText;
		datos=datos.split("|");
		load2(datos[0],datos[1],datos[2],datos[3],datos[4],datos[5],datos[6]);
		return false;
		}
	}
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttp.send(null);
	return false;
	setTimeout("recargar()",5000);
}
function load2(lat,lng,nombre,tipo,lugar,enlace,idx) {
	if (play=="yes")
	{
  	map.clearOverlays(); 
	mostrarnegocios(idx);
    map.setCenter(new GLatLng(lat,lng), 16);
	pointx = new GLatLng(lat,lng);
	markerx  = new GMarker(pointx,iconw);
	map.addOverlay(markerx);
	markerx.openInfoWindowHtml('<img src="images/logo_wifi.png" style="margin-right:5px;float:left;width:30px"/><h3 style="padding:8px">Wifi '+nombre+'</h3><br />Tipo: '+tipo+'<br />Ubicada en: '+lugar+'<br /><a href="wifi-'+enlace+'.htm">Ver más detalles</a>');
//	clicked(map,pointx);
	}
}
function clicked(overlay, latlng) {
      if (latlng) {
        geocoder.getLocations(latlng, function(addresses) {
          if(addresses.Status.code != 200) {
            alert("No conocemos esta dirección, sin embargo puedes introducirla " + latlng.toUrlValue());
          }
          else {
            address = addresses.Placemark[0];
            var myHtml = address.address;
            document.getElementById('info').innerHTML=myHtml;
			return myHtml;
          }
        });
      }
    }

	function clicked2(overlay, latlng) {
	      if (latlng) {
	        geocoder.getLocations(latlng, function(addresses) {
	          if(addresses.Status.code != 200) {
	            alert("No conocemos esta dirección" + latlng.toUrlValue());
	          }
	          else {
	            address = addresses.Placemark[0];
	            var myHtml = address.address;
				direccionarray=myHtml.split(",");
				if (direccionarray.length==5)
				{
				document.f.calle.value=direccionarray[0];
				document.f.numero.value=direccionarray[1];
				document.f.cp.value=direccionarray[2];
				document.f.ciudad.value=direccionarray[3];
				document.f.pais.value=direccionarray[4];
				html='Calle: <strong>'+direccionarray[0]+'</strong><br />';
				html+='Nº: <strong>'+direccionarray[1]+'</strong><br />';
				html+='C.P.: <strong>'+direccionarray[2]+'</strong><br />';
				html+='Ciudad: <strong>'+direccionarray[3]+'</strong><br />';
				html+='País: <strong>'+direccionarray[4]+'</strong><br />';
				}
				if (direccionarray.length==4)
				{
				document.f.calle.value=direccionarray[0];
				document.f.numero.value='';
				document.f.cp.value=direccionarray[1];
				document.f.ciudad.value=direccionarray[2];
				document.f.pais.value=direccionarray[3];
				html='Calle: <strong>'+direccionarray[0]+'</strong><br />';
				html+='C.P.: <strong>'+direccionarray[1]+'</strong><br />';
				html+='Ciudad: <strong>'+direccionarray[2]+'</strong><br />';
				html+='País: <strong>'+direccionarray[3]+'</strong><br />';
				}
				if (direccionarray.length==3)
				{
					document.f.calle.value='';
					document.f.numero.value='';
					document.f.cp.value=direccionarray[0];
					document.f.ciudad.value=direccionarray[1];
					document.f.pais.value=direccionarray[2];
				html='C.P.: <strong>'+direccionarray[0]+'</strong><br />';
				html+='Ciudad: <strong>'+direccionarray[1]+'</strong><br />';
				html+='País: <strong>'+direccionarray[2]+'</strong><br />';
				}
	            marker.openInfoWindowHtml('<h2>Dirección encontrada</h2>'+html+'<br />');
				//<input type="button" value="Utilizar esta dirección" onclick="cabiardireccion(\''+myHtml+'\')"/>
	          }
	        });
	      }
	    }
		
		function cabiardireccion(dir)
		{
			document.f.direccion.value=dir;
		}
		function localizar2(direccion){
			showAddress2 (direccion);	
		}
		function showAddress2(address) {
		      if (geocoder) {
		        geocoder.getLatLng(
		          address,
		          function(point) {
		            if (!point) {
		              alert("Lo sentimos, pero no hemos encontrado esta dirección:\n"+address+".\nIntenta ser un poco más preciso. Gracias");
		            } else {
		              map.setCenter(point, 17);
		              marker.setLatLng(point);
						document.f.lat.value = marker.getPoint().lat();
						document.f.lng.value = marker.getPoint().lng();
					  clicked2(map, point)
		            }
		          }
		        );
		      }
		    }
		
		
				function votar2(tipo,id)
							{
								var url = 'votar2.php?tipo='+tipo+'&id=' + id  ;
								//window.open (url);
								xmlhttp.open("GET",url,true);
								xmlhttp.onreadystatechange=function() {
								if (xmlhttp.readyState==4) {
									data = xmlhttp.responseText;
									alert('Gracias por votar!!!\nHemos tomado nota.');

								}
								}
								xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
								xmlhttp.send(null);

								return false;	
							}		
							function enviarcomentario(){
							var msgerror='';

							if (document.forms['contacto'].nombre.value=='') 
								msgerror = '* Nombre o apodo\n';

							if (document.forms['contacto'].comentario.value=='') 
									msgerror += '* Tu comentario\n';

							if (document.forms['contacto'].email.value=='') 
								msgerror += '* Email\n';
							else
								if (validarEmail(document.forms['contacto'].email.value)==false)
									msgerror = msgerror +'* El Email parece incorrecto\n';


							 	if (msgerror!='')
								{
									alert('Los siguientes campos son obligatorios:\n\n'+msgerror);
									return false;
								}
								else
								{
									document.forms['contacto'].action='enviaropinion.php';
									return true;

									}

								}
								

								function localizarx(direccion){
									direccion=document.buscador.buscar.value;
									showAddressx (direccion);	
									return false;
								}
								function showAddressx(address) {
								      if (geocoder) {
								        geocoder.getLatLng(
								          address,
								          function(point) {
								            if (!point) {
								              alert("Lo sentimos, pero no hemos encontrado esta dirección:\n"+address+".\nIntenta ser un poco más preciso. Gracias");
											} else {
								            	map.setCenter(point, 13);
												mostrarnegocios(0);
											}
								          }
								        );
								      }
								    }
function buscarprovincia(destino){
	if (destino!='')
		location.href=destino;
}

function buscarcampos(){
	document.getElementById('resultadosxx').innerHTML='<center><h3>Buscando bodegas</h3><img src="./images/loading.gif"></center>';
	var texto =document.getElementById('buscar').value;
	if (texto.length>3)
	{
		var url = '/buscar.php?texto='+escape(texto);
		//window.open (url);
		xmlhttp.open("GET",url,true);
		xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			data = xmlhttp.responseText;
			document.getElementById('resultadosxx').innerHTML=data;
		}
		}
		xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
		xmlhttp.send(null);

		return false;
	}
	else{
		alert('Debe escribir al menos 4 letras en su búsqueda');
		return false;
	}
}


function comprobar(){
var msgerror='';
var telefono = trim(document.forms['contacto'].telefono.value);

if (document.forms['contacto'].nombre.value=='') 
	msgerror = '* Nombre completo\n';
	
	
if (document.forms['contacto'].telefono=='') 
	{
	msgerror += '* Teléfono\n';
	}
	
if (document.forms['contacto'].email.value=='') 
	msgerror += '* Email\n';
else
	{
	if (validarEmail(document.forms['contacto'].email.value)==false)
		msgerror += '* El Email parece incorrecto\n';
	}
	
if (document.forms['contacto'].mensaje.value=='') 
	msgerror += '* Debe escribir un mensaje\n';
	
if (msgerror==''){
 if ((document.forms['contacto'].telefono.length)<9)
 	msgerror += '* El teléfono ha de tener 9 cifras como mínimo\n';
	document.forms['contacto'].telefono.focus();
}
if (msgerror!=''){
	alert('Los siguientes campos son obligatorios:\n\n'+msgerror);
	return false;
	}
else{
	document.forms['contacto'].action='/envcont.php';
	document.forms['contacto'].submit();
	return false;
}
}


function comprobar2(){
var msgerror='';
var telefono = trim(document.forms['contacto'].telefono.value);

if (document.forms['contacto'].nombre.value=='') 
	msgerror = '* Nombre completo\n';
	
	
if (document.forms['contacto'].telefono=='') 
	{
	msgerror += '* Teléfono\n';
	}
	
if (document.forms['contacto'].email.value=='') 
	msgerror += '* Email\n';
else
	{
	if (validarEmail(document.forms['contacto'].email.value)==false)
		msgerror += '* El Email parece incorrecto\n';
	}
	
if (document.forms['contacto'].mensaje.value=='') 
	msgerror += '* Debe escribir un mensaje\n';
	
if (msgerror==''){
 if ((document.forms['contacto'].telefono.length)<9)
 	msgerror += '* El teléfono ha de tener 9 cifras como mínimo\n';
	document.forms['contacto'].telefono.focus();
}
if (msgerror!=''){
	alert('Los siguientes campos son obligatorios:\n\n'+msgerror);
	return false;
	}
else{
	document.forms['contacto'].action='envcont2.php';
	document.forms['contacto'].submit();
	return false;
}
}