var mostrarayuda="no";
var markers = [];
var map=null;
var gdir;
var Gicon;
var geocoder = null;
var addressMarker;
var icon_peq = new GIcon();
icon_peq.image = "http://www.campings.net/camping.gif";
icon_peq.iconSize = new GSize(15, 15);
icon_peq.iconAnchor = new GPoint(15, 15);
icon_peq.infoWindowAnchor = new GPoint(15, 15);    
icon_peq.infoShadowAnchor = new GPoint(15, 15);

function cargarmapa(lat,lng) {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(lat,lng), 14,G_HYBRID_MAP);
	map.addControl(new GOverviewMapControl());
	point = new GLatLng(lat,lng);
	markers[0]  = new GMarker(point,icon_peq);
	map.addOverlay(markers[0] );
	gdir = new GDirections(map, document.getElementById("directions"));
    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", handleErrors);
	initialize2(lat,lng);
  }
}
function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	      alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");

	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	       alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");

	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	      alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	      alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");

	   else   alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");

	}

	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 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 validarEmail(valor) {
		  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		   return (true)
		  } else {
		      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 mostrarfotos(mostrarencapa){
			mapa = map;
			bounds = mapa.getBounds();
			var miny = bounds.getSouthWest().lat();
			var minx = bounds.getSouthWest().lng();
			var maxy = bounds.getNorthEast().lat();
			var maxx = bounds.getNorthEast().lng();
			var url = 'panoramio.php?minx=' + minx + "&miny=" + miny +'&maxx=' + maxx + "&maxy=" + maxy ;
			//window.open (url)
			GDownloadUrl(url, function(data, responseCode) {
				var panoramio = eval("(" + data + ")");
				if (mostrarencapa=='yes'){
					var divpanoramio = document.getElementById('galeria2');
					divpanoramio.innerHTML='<table><tr>';
				}
				var entra = 'no';
				for (var i = 0; i < panoramio.photos.length; i++) {
					var entra = 'yes';
					//createMarkerfoto(panoramio.photos[i]);

					if (mostrarencapa=='yes')
		divpanoramio.innerHTML="<a id='photo_infowin' target='_blank' href='http://www.panoramio.com/photo/" +panoramio.photos[i].photo_id + "'>" +"<img alt='Imagen de Panoramio llamada "+panoramio.photos[i].photo_title+"' width='270'  src='http://www.panoramio.com/photos/small/" + panoramio.photos[i].photo_id + ".jpg'/><\/a>" + divpanoramio.innerHTML;
				}
				if (mostrarencapa=='yes'){
				if (entra=='no')
				divpanoramio.innerHTML=divpanoramio.innerHTML + '<strong>No hemos encontrado imagenes cercanas.</strong><br />';
				else
				divpanoramio.innerHTML=divpanoramio.innerHTML + '<br /><a class="atencionpanoramio" href="http://www.panoramio.com">Las imagenes de Panoramio estan bajo el Copyright de sus autores</a>';
				}
				});
		}
			function votar(tipo,id)
						{
							var url = 'votar.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 ventana(URL,Nombre,opciones) {
						  window.open(URL,Nombre,opciones);
						}	




function verayuda(){
	if (mostrarayuda=="no")
	{
		document.getElementById('ayudamapa').style.visibility="visible";
		document.getElementById('ayuda2').style.visibility="visible";
		mostrarayuda="yes";
	}
	else
	{
		document.getElementById('ayudamapa').style.visibility="hidden";
		document.getElementById('ayuda2').style.visibility="hidden";
		mostrarayuda="no";
	}
}
function mostrartelefono(idcamping){
	var url = 'vertelefono.php?idcamping='+ idcamping  ;
	//window.open (url);
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		data = xmlhttp.responseText;
		document.getElementById('vertelefono').style.position="absolute";
		document.getElementById('vertelefono').style.visibility="hidden";
		document.getElementById('mostrartelefono').style.display="block";
		

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

	return false;
}
function mostrarcomentarios(){
		document.getElementById('occcomentarios').style.display="block";
		document.getElementById('occcomentarios').style.position="relative";
		document.getElementById('occcomentariospre').style.display="none";
		document.getElementById('occcomentariospre').style.position="absolute";
}
function mostrarcapa(capa){
		document.getElementById(capa).style.display="block";
		document.getElementById(capa).style.position="relative";

}
function ocultarcapa(capa){
		document.getElementById(capa).style.display="none";
		document.getElementById(capa).style.position="absolute";

}
function comprobarprovinciaycomunidad(){
	var aviso="";
	if (document.formulario.nom.value!="")
		return true
	if (document.formulario.loc.value!="")
		return true
	if (document.formulario.prov.value=="")
		aviso="Debe introducir al menos la provincia.";
	else
		return true
		
	if (document.formulario.zona.value=="")
		aviso+="\nDebe introducir al menos la región.";
	else
		return true
	

	if (aviso!='')
		{alert(aviso);
		return false;
		}
}	