// JavaScript Document
/*     GOOGLE MAP     */

function googlekey(keyabajo,kayarriba,domabajo,domarriba){
	var documento = self.location.href.match( /\/([^/]+)$/ )[1];
	if (document.location.href == 'http://servidor.'+ domabajo +'/'+ documento)
	{
		document.write("<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key="+ keyabajo +"' type='text/javascript'></script>");
	}
	else
	{
		if (document.location.href == 'http://'+ domarriba +'/'+ documento);
		{
			document.write("<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key="+ kayarriba +"' type='text/javascript'></script>");
		}
	}
}

/*     GOOGLE MAP     */

function limpiar(idcapa){
	capalimpiar = document.getElementById(idcapa);
	capalimpiar.innerHTML="";
	var capa_imprimir = document.getElementById("capa_imprimir_mapa");
	capa_imprimir.style.display="none";
}

function mostrar_mapa(){
	var capa_imprimir = document.getElementById("capa_imprimir_mapa");
	capa_imprimir.style.display="";
}

function imprimir(que) {
	var ventana = window.open("", "", "");
	var contenido = "<html><body onload='window.print();window.close();'>" + document.getElementById(que).innerHTML + "</body></html>";
	ventana.document.open();
	ventana.document.write(contenido);
	ventana.document.close();
}	

var map;
function onLoad(long,lat,nombre) {
	if (GBrowserIsCompatible()){
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(long,lat), 17);
		map.setUIToDefault();
		
		var icon = new GIcon();
		icon.image = "../imagenes/mapas/logo_mapa_farmacia.png";
		icon.iconSize = new GSize(32, 32);
		icon.iconAnchor = new GPoint(32, 32);
		icon.infoWindowAnchor = new GPoint(32, 32);
		
		function createMarker(point,html,icono) {
			html = "<div style=' text-align:left;' >" + html + "<\/div>";
			var marker = new GMarker(point,icono);
		
			GEvent.addListener(marker, "click", function() {
				if (map.getZoom()<17){
				map.setCenter(point, 17);
				}
			});
		
			GEvent.addListener(marker, "mouseover", function() {
				marker.openInfoWindow(html);
			});
		
			GEvent.addListener(marker, "dblclick", function() {
				if (map.getZoom()<17){
					map.setCenter(point, 17);
				}
			});

		return marker;
		}
		
		var punto = new GLatLng(long,lat);
		var marca = createMarker(punto,nombre,icon);
		map.addOverlay(marca);
	}
}

