// InicializaciÃ›n de variables.
var map      = Array();
var geocoder = null;
 
function loadmapa( id ) {                                 // Abre LLAVE 1.
	if (GBrowserIsCompatible()) {						   // Abre LLAVE 2.
        map[id] = new GMap2(document.getElementById( id ));
		
        map[id].setCenter(new GLatLng(37.567236,-1.803499), 15);
		//map[id].setCenter(new GLatLng(17.502030, 78.382801), 12);
		//var ct = new GLatLng(37.4419, -122.1419);

        map[id].addControl(new GSmallMapControl());
	   	map[id].addControl(new GMapTypeControl());
		
        geocoder = new GClientGeocoder();
		
        //---------------------------------//
        //   MARCADOR AL HACER CLICK
		//---------------------------------//
		/*GEvent.addListener(map, "click",
		 function(marker, point) {
		 if (marker) {
		 null;
		 } else {
		 map.clearOverlays();
		 var marcador = new GMarker(point);
		 map.addOverlay(marcador);
		 //marcador.openInfoWindowHtml("<b><br>Coordenadas:<br></b>Latitud : "+point.y+"<br>Longitud : "+point.x+"<a href=http://www.mundivideo.com/fotos_pano.htm?lat="+point.y+"&lon="+point.x+"&mapa=3 TARGET=fijo><br><br>Fotografias</a>");
		 //marcador.openInfoWindowHtml("<b>Coordenadas:</b> "+point.y+","+point.x);
		 document.form_mapa.coordenadas.value = point.y+","+point.x;
		 }
		 }
		 );
		 */
        //---------------------------------//
        //   FIN MARCADOR AL HACER CLICK
		//---------------------------------//
		
	} // Cierra LLAVE 1.
}   // Cierra LLAVE 2.

//---------------------------------//
//           GEOCODER
//---------------------------------//

function showCoords(pLat, pLong, zoom, id, html)
{
	
	var Icon = new GIcon(G_DEFAULT_ICON);
	//Imagen del marker
	Icon.image = "http://guiajoy.planetajoy.com/pin.png";
	Icon.iconSize = new GSize(32, 32);
	Icon.shadowSize = new GSize(0, 0);
	markerOptions = { icon:Icon };
	
	
	
	point = new GLatLng(pLat, pLong, false);
	
	map[id].setCenter(point, zoom);
	var marker = new GMarker(point, markerOptions);
	map[id].addOverlay(marker);
	
	//document.form_mapa.coordenadas.value = point.y+","+point.x;
	 GEvent.addListener( marker, "click", function() {  openWindow(marker, html) } );  
}

function showAddress(address, zoom, id, html) 
{
	
	if (geocoder) 
	{
		
		var Icon = new GIcon(G_DEFAULT_ICON);
		//Imagen del marker
		Icon.image = "http://guiajoy.planetajoy.com/pin.png"
		Icon.iconSize = new GSize(32, 32);
		Icon.shadowSize = new GSize(0, 0);
		markerOptions = { icon:Icon };
		
		geocoder.getLatLng(address,
						   function(point) {
						   if (!point) {
						   //alert(address + " not found");
						   } else {
						   
						   map[id].setCenter(point, zoom);
						   marker = new GMarker(point, markerOptions);
						   map[id].addOverlay(marker);	
						   //---------------------------------//
						   //   MARCADOR AL HACER CLICK
						   //---------------------------------//
						   
						   GEvent.addListener( marker, "click", function() {  openWindow(marker, html) } );  
						   
							
						   
						 }
						   
					}
			);
	}
	
}


function openWindow( marker, html )
{
	//alert('click');
	 marker.openInfoWindowHtml(html);	
}


function btnBuscar()
{
	search = $("#s").val();
	// limpiamos texto buscado
	search = search.toLowerCase();
	search = search.replace("  "," ");
	search = search.replace("+","%2B");
	search = search.replace(" ","+");
	search = search.replace("%20","+");
	search = search.replace("/","+");
	search = search.replace(" ","+");
	search = search.replace("++","+");
	search = search.replace("'","");
	search = search.replace('"',"");
	
	explorer = "";
	
	
	if( search.length > 3 )
	{
		document.location.href= "/" + search ;
	}
	
	
}


