// cp522-mapa_administradores.js - Copyright (c) 2006 by Juan Rodríguez & Begues Internet, s.l.

function Resize() {window.location.reload()}
window.onresize=Resize;

function positionOverview(x,y) {
var overview = document.getElementById("map_overview"); 
document.getElementById("map").appendChild(overview);
overview.firstChild.firstChild.style.left="4px";
overview.firstChild.firstChild.style.top="4px";
overview.firstChild.firstChild.style.width="150px";
overview.firstChild.firstChild.style.height="150px"}

function Pagina(pag) { 
if (self.innerHeight) {ancho= self.innerWidth; alto= self.innerHeight}
else if (document.documentElement && document.documentElement.clientHeight) {ancho= document.documentElement.clientWidth; alto= document.documentElement.clientHeight}
else if (document.body) {ancho=document.body.clientWidth; alto=document.body.clientHeight}
ancho=parseInt(ancho);
alto=parseInt(alto);
document.getElementById("map").style.height=alto -120 +"px";
if (navigator.appName == "Microsoft Internet Explorer") {document.getElementById("DivDerecha").style.left=ancho -230 +"px"} else {document.getElementById("DivDerecha").style.left=ancho -245 +"px"};
// document.getElementById("DivDerecha").style.left=ancho -240 +"px"; 
document.getElementById("BandaPie").style.top=alto -110 +"px";
document.getElementById("BandaPie").style.visibility="visible" }

function goMenuLateral(pag) {
opc=document.getElementById("MenuLateral")[document.getElementById("MenuLateral").selectedIndex].text;
url = document.getElementById("MenuLateral").value;
document.getElementById("ampliar512").innerHTML=opc;
document.getElementById("sidebar").focus(); readMap(url); 
document.getElementById("TxtFlotante").style.visibility="visible" }

function readMap(url) {
var request = GXmlHttp.create();
request.open("GET", url, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = GXml.parse(request.responseText);
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
map.getInfoWindow().hide();
for (i=0; i<resenas.length; i++) {map.removeOverlay(resenas[i]) }

resenas=[];
res_lis="";
          
for (var i = 0; i < markers.length; i++) {
 var lat = parseFloat(markers[i].getAttribute("lat"));
 var lng = parseFloat(markers[i].getAttribute("lng"));
 var point = new GLatLng(lat,lng);
 var texto = markers[i].getAttribute("texto");
 var label = markers[i].getAttribute("label");
 var ba = "no";
 var ov = markers[i].getAttribute("letra"); 
 var localidad = markers[i].getAttribute("localidad");
 var marker = createMarker(point,label,texto,ba,ov,localidad);
 var zoom = parseFloat(markers[i].getAttribute("zoom"));
map.addOverlay(marker) }

if (zoom==6) {map.setZoom(zoom); map.panTo(new GLatLng(40.97989807, -3.28466797)) };
if (zoom !==6) {map.setZoom(zoom); window.setTimeout(function() {map.panTo(new GLatLng(markers[0].getAttribute("lat"),markers[0].getAttribute("lng") ));}, 100); }

document.getElementById("sidebar").innerHTML = res_lis }
}
request.send(null);
}

var background = [];
background["no"]  ="../rc/cv970-00.png";
var overlay = [];
overlay["a"] ="../rc/cv970-01-a.png";
overlay["b"] ="../rc/cv970-02-b.png";
overlay["c"] ="../rc/cv970-03-c.png";
overlay["d"] ="../rc/cv970-04-d.png";
overlay["e"] ="../rc/cv970-05-e.png";
overlay["f"] ="../rc/cv970-06-f.png";
overlay["g"] ="../rc/cv970-07-g.png";
overlay["h"] ="../rc/cv970-08-h.png";
overlay["i"] ="../rc/cv970-09-i.png";
overlay["j"] ="../rc/cv970-10-j.png";
overlay["l"] ="../rc/cv970-12-l.png";
overlay["m"] ="../rc/cv970-13-m.png";
overlay["n"] ="../rc/cv970-14-n.png";
overlay["p"] ="../rc/cv970-17-p.png";
overlay["r"] ="../rc/cv970-19-r.png";
overlay["s"] ="../rc/cv970-20-s.png";
overlay["t"] ="../rc/cv970-21-t.png";
overlay["u"] ="../rc/cv970-22-u.png";
overlay["v"] ="../rc/cv970-23-v.png";
overlay["w"] ="../rc/cv970-24-w.png";
overlay["+"] ="../rc/cv970-99-mas_info.png";

function createMarker(point,label,texto,ba,ov,localidad) {
var mylabel = {"url":overlay[ov], "anchor":new GLatLng(1,1), "size":new GSize(19,34)};
var Icon = new GIcon(G_DEFAULT_ICON, background[ba], mylabel)
var marker = new GMarker(point,Icon);
marker.tooltip = '<div class="tooltip">'+label+'</div>';
var html = "<div id='resena'>"+texto+"</div><div id='res-opc'><a href='javascript:MapaGeneral()' >Mapa General</a><a href='javascript:Acercar("+i+")' >Acercar</a><a href='javascript:Alejar("+i+")' >Alejar</a></div>";
var html_ac= "<div id='resena'>"+texto+"</div><div id='res-opc'><a href='javascript:MapaGeneral()' >Mapa General</a><a href='javascript:Acercar("+i+")' >Acercar</a></div>";
var html_al= "<div id='resena'>"+texto+"</div><div id='res-opc'><a href='javascript:MapaGeneral()' >Mapa General</a><a href='javascript:Alejar("+i+")' >Alejar</a></div>";

resenas[i]=marker;
res_txt[i]=html;
res_txt_ac[i]=html_ac;
res_txt_al[i]=html_al;
res_txt_ac_al[i]=html;
res_pos[i]=point;
var label="("+ov+") "+label;
res_lis += '<a href="javascript:myclick('+i+')">' + label + '</a><br>';
i++;
GEvent.addListener(marker, "click", function() {map.setZoom(15); map.setCenter(point); marker.openInfoWindowHtml(html)} );

GEvent.addListener(marker, "infowindowclose", function() {document.getElementById("TxtFlotante").style.visibility="visible" });
GEvent.addListener(marker, "infowindowopen", function() {document.getElementById("ampliar512").innerHTML=localidad; document.getElementById("TxtFlotante").style.visibility="hidden" } );   
GEvent.addListener(marker,"mouseover", function() {document.getElementById("map_overview").style.visibility="hidden"; marker.openInfoWindowHtml(html) });        
GEvent.addListener(marker,"mouseout", function() {document.getElementById("map_overview").style.visibility="visible" });
return marker }

function Acercar(i){
map.setZoom(17);
// map.zoomIn(); 
map.setCenter(res_pos[i]); 
map.setMapType(G_NORMAL_MAP); 
if (map.getZoom() >=17) {res_txt[i]= res_txt_al[i]};
resenas[i].openInfoWindowHtml(res_txt[i]); }

function Alejar(i){
map.zoomOut(); 
map.setCenter(res_pos[i]); 
map.setMapType(G_NORMAL_MAP); 
if (17 > map.getZoom()) {res_txt[i]= res_txt_ac_al[i]};
if (10 > map.getZoom()) {res_txt[i]= res_txt_ac[i]};
resenas[i].openInfoWindowHtml(res_txt[i]); }

function myclick(i) {map.setZoom(15); map.setCenter(res_pos[i]); resenas[i].openInfoWindowHtml(res_txt[i])}

function OtrasPaginas() {
window.location.href=(document.getElementById("OtrasPaginas").OpcOP.options[document.getElementById("OtrasPaginas").OpcOP.selectedIndex].value);
document.getElementById("OtrasPaginas").OpcOP.selectedIndex="1"}

function MapaGeneral(){
document.getElementById("MenuLateral").selectedIndex=0;
url="cp523-mapa_general.xml"; 
document.getElementById("ampliar512").innerHTML="España";
document.getElementById("TxtFlotante").style.visibility="visible";
document.getElementById("ampliar510").focus(); readMap(url) }

