/*
var markers = [];
var direccionarray = [];
var gdir;
var map = null;
var geocoder = null;
var addressMarker;
var play="yes";
var direccion="";
var mostrarfoneras="yes";
var mostrarwifis="yes";
var iconp = new GIcon();
iconp.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
iconp.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
iconp.iconSize = new GSize(12, 20);
iconp.shadowSize = new GSize(22, 20);
iconp.iconAnchor = new GPoint(6, 20);
iconp.infoWindowAnchor = new GPoint(5, 1);
var iconm = new GIcon();
   iconm.image = "images/museum_icon.png";
   iconm.shadow = "images/shadow-museum_icon.png";
   iconm.iconSize = new GSize(21.0, 28.0);
   iconm.shadowSize = new GSize(36.0, 28.0);
   iconm.iconAnchor = new GPoint(10.0, 14.0);
   iconm.infoWindowAnchor = new GPoint(10.0, 14.0);

var iconw = new GIcon();
   iconw.image = "images/logo_wifi.png";
   iconw.shadow = "images/shadow-logo_wifi.png";
   iconw.iconSize = new GSize(57.0, 45.0);
   iconw.shadowSize = new GSize(80.0, 45.0);
   iconw.iconAnchor = new GPoint(28.0, 22.0);
   iconw.infoWindowAnchor = new GPoint(28.0, 10.0);

var iconw2 = new GIcon();
   iconw2.image = "images/logo_wifi.png";
   iconw2.shadow = "images/shadow-logo_wifi.png";
   iconw2.iconSize = new GSize(26, 22.0);
   iconw2.shadowSize = new GSize(40.0, 26.0);
   iconw2.iconAnchor = new GPoint(14.0, 11.0);
   iconw2.infoWindowAnchor = new GPoint(14.0, 5.0);

var haypano="no";

var iconf = new GIcon();
    iconf.image = "images/r14.png";
    iconf.shadow = "images/shadow-r14.png";
    iconf.iconSize = new GSize(22.0, 22.0);
    iconf.shadowSize = new GSize(34.0, 22.0);
    iconf.iconAnchor = new GPoint(11.0, 11.0);
    iconf.infoWindowAnchor = new GPoint(11.0, 11.0);

	var myPano;



	    function initialize(lat,lng,id) {
			panoClient = new GStreetviewClient();  
	      var fenwayPark = new GLatLng(lat,lng);
	      panoramaOptions = { latlng:fenwayPark };
	      myPano = new GStreetviewPanorama(document.getElementById("pano"), panoramaOptions);
		  
	      GEvent.addListener(myPano, "error", handleNoFlash);
     	panoClient.getNearestPanorama(fenwayPark, showPanoData);
	
		
		}
		function showPanoData(panoData) {
		      if (panoData.code != 200) {
		        document.getElementById("pano").style.position='absolute';
				document.getElementById("pano").style.borderBottom = "none";
				if (document.getElementById("mapa"))
				document.getElementById("mapa").style.height = "400px";
				return;
		      }
		      else
				{
					document.getElementById("pano").style.position='relative';
					document.getElementById("pano").style.height = "200px";
					document.getElementById("pano").style.width = "100%";
					document.getElementById("pano").style.borderBottom = "5px solid #EDF4F7";
					if (document.getElementById("mapa"))
					document.getElementById("mapa").style.height = "250px";
					return;
				}
		    }
		

	    function handleNoFlash(errorCode) {
		
		
		
	      if (errorCode == FLASH_UNAVAILABLE) {
	        alert("Error: Flash doesn't appear to be supported by your browser");
	        return;
	      
	    }
*/
function enviarform(pagina,busqueda){
	document.enviar.action=pagina;
	document.enviar.busqueda.value=busqueda;
	document.enviar.submit();
}
function wifis()
{
	if (document.getElementById('wifis').checked)
		mostrarwifis="yes";
	else
		mostrarwifis="no";
				
		mostrarnegocios(0)
}
function foneras()
{
	if (document.getElementById('foneras').checked)
		mostrarfoneras="yes";
	else
		mostrarfoneras="no";
				
		mostrarnegocios(0)
}
	function comprobar(){
	var msgerror='';
	
	if (document.f.nombre.value=='') 
		msgerror = '* Nombre de la red\n';

	if (document.f.direccion.value=='') 
			msgerror += '* Dirección\n';

	if (document.f.email.value=='') 
		msgerror += '* Email\n';
	else
		if (validarEmail(document.f.email.value)==false)
			msgerror = msgerror +'* El Email parece incorrecto\n';
	
	if (document.f.calle.value=='') 
		msgerror += '* Calle incorrecta (debes corregir la dirección)\n';
	
	if (document.f.cp.value=='') 
		msgerror += '* C.P. incorrecta (debes corregir la dirección)\n';
	
	if (document.f.ciudad.value=='') 
		msgerror += '* Ciudad incorrecta (debes corregir la dirección)\n';
	
	if (document.f.pais.value=='') 
		msgerror += '* País incorrecto (debes corregir la dirección)\n';
	
	if (document.f.usuario.value=='') 
		msgerror += '* El usuario está vacío.\n';
	
		if (document.f.lat.value=='') 
			msgerror += '* Latitud incorrecta.\n';
			if (document.f.lng.value=='') 
				msgerror += '* Longitud incorrecta.\n';
	
	 	if (msgerror!='')
		{
			alert('Los siguientes campos son obligatorios:\n\n'+msgerror);
			return false;
		}
		else
		{
			document.f.action='guardar_wifis.php';
			document.f.submit();
			return true;
		
			}
	
		}
		
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 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 comprobarsitionuevo(){
var msgerror='';
if (document.f.lugar.value=='') 
msgerror = '* Lugar\n';

if (document.f.latitud.value=='') 
msgerror += '* Seleccione un lugar del mapa\n';


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

function mostrarnegocios(idwif)
{
	map.clearOverlays(); 
		if (map.getZoom()>=12)
		{
	var mapa = map;
	var bounds = mapa.getBounds();
	var miny = bounds.getSouthWest().lat();
	var minx = bounds.getSouthWest().lng();
	var maxy = bounds.getNorthEast().lat();
	var maxx = bounds.getNorthEast().lng();
	var centro = map.getCenter(); 
	var centrolat=(centro.lat());
	var centrolon=(centro.lng());
	var zoom = map.getZoom();
	var url = 'json.php?mostrarwifis='+mostrarwifis+'&mostrarfoneras='+mostrarfoneras+'&id='+idwif+'&zoom='+zoom+'&minx=' + minx + "&miny=" + miny +'&maxx=' + maxx + "&maxy=" + maxy +"&centro=" + centrolat +',' + centrolon;
	//window.open (url);

	GDownloadUrl(url, function(data, responseCode) {
	parseJson(data);
	});
	document.getElementById('info').innerHTML='<strong>Nota:</strong> Puedes hacer clic en los iconos <img src="images/museum_icon.png" width="15" /> para ver el lugar que representan. También puedes desplazar el mapa e irán apareciendo más iconos.';
}
else
	document.getElementById('info').innerHTML='<strong style="color:red">Nota:</strong> Con este nivel de zoom no se muestran lugares ya que son demasiados y saturarían el mapa. Aumente el zoom y aparecerán los lugares con este icono: <img src="images/museum_icon.png" width="15" />'

}
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 campos</h3><img src="./images/loading.gif"></center>';
	var texto =document.getElementById('buscar').value;
	if (texto.length>3)
	{
		var url = '/buscar.php?texto='+escape(texto);
		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;
	}
}
