var win = null;
function newWindow(mypage,myname,w,h,features) {
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}



var i=0;
function mostrar(markita){
//markita.openInfoWindow( document.createTextNode("Click sobre icono."));
if (markita.isHidden())
markita.show();
GEvent.trigger(markita, "click");
}

// Mostrar contenido de una capa sobre el mapa. Funci n obtenida de  GPS VISUALIZER (http://www.gpsvisualizer.com/)
function toggleGroup(type) {

      for (i=0;i<markerGroups[type].length; i++) {
        var marker = markerGroups[type][i];
        if (marker.isHidden()) {
	marker.show();
        } else {
          marker.hide();
        }
      } 
}
var contador=1;
function cambiaestado(){

     for (i=0; i<gmarkers2.length; i++) {
	var marker = gmarkers2[i];
	 if (contador%2==0) {      
	marker.show();}
	 else {
	marker.hide();
        }
    }
contador++;
}


function tecla() {
document.getElementById('ocultar').style.visibility = 'hidden';
document.getElementById('mostrar').style.visibility = 'visible';
 } 
function GV_Place_Control(map,control_id,anchor,x,y) {
	if (document.getElementById(control_id)) {
		document.getElementById(control_id).style.display = 'block';
		var gv_position = new GControlPosition(anchor, new GSize(x,y));
		gv_position.apply(document.getElementById(control_id));
		map.getContainer().appendChild(document.getElementById(control_id));
	}

}



//A&ntilde;adido para autogesti&oacute;n de iconos
function crearicono(cont) {

var iconotes= new GIcon();
var nombre='pin';
nombre+=cont+1+'.png';   // Juega con la resta para que coincidan la ruta y el icono. 
// Nota importante, deben aparecer en el xml los inicios de rutas lo primero y en el orden que
//las tengas puestas las rutas en la tabla.

iconotes.image="../../../images/iconosgoogle/"+nombre;
iconotes.shadow="../../../images/iconosgoogle/shadowminipin.png";
iconotes.iconSize = new GSize(15, 26);
iconotes.shadowSize = new GSize(29, 26);
iconotes.iconAnchor = new GPoint(7, 13);
iconotes.infoWindowAnchor = new GPoint(7, 13);
return iconotes;
}	
//Fin a&ntilde;adido

//<![CDATA[

var MyMap;

// Crea icono inicio
      var icon = new GIcon();
      icon.image = "../../../images/iconosgoogle/inicio.png";
      icon.shadow = "../../../images/iconosgoogle/shadowinicio.png";
      icon.iconSize = new GSize(32, 32);
      icon.shadowSize = new GSize(49, 32);
      icon.iconAnchor = new GPoint(16, 16);
      icon.infoWindowAnchor = new GPoint(16, 16);
      
// Crea icono camping
      var icon2 = new GIcon();
      icon2.image = "../../../images/iconosgoogle/camping.png";
      icon2.shadow = "../../../images/iconosgoogle/shadowcamping.png";
      icon2.iconSize = new GSize(28, 28);
      icon2.shadowSize = new GSize(43, 28);
      icon2.iconAnchor = new GPoint(14, 14);
      icon2.infoWindowAnchor = new GPoint(14, 14);      		

// Crea icono poblacion
      var icon3 = new GIcon();
      icon3.image = "../../../images/iconosgoogle/poblacion.png";
      icon3.shadow = "../../../images/iconosgoogle/shadowpoblacion.png";
      icon3.iconSize = new GSize(32, 32);
      icon3.shadowSize = new GSize(49, 32);
      icon3.iconAnchor = new GPoint(16, 16);
      icon3.infoWindowAnchor = new GPoint(16, 16);

// Crea icono area recreativa
      var icon4 = new GIcon();
      icon4.image = "../../../images/iconosgoogle/area.png";
      icon4.shadow = "../../../images/iconosgoogle/area.png";
      icon4.iconSize = new GSize(28, 28);
      icon4.shadowSize = new GSize(43, 28);
      icon4.iconAnchor = new GPoint(14, 14);
      icon4.infoWindowAnchor = new GPoint(14, 14);;

// Crea icono info
      var icon5 = new GIcon();
      icon5.image = "../../../images/iconosgoogle/info.png";
      icon5.shadow = "../../../images/iconosgoogle/shadowinfo.png";
      icon5.iconSize = new GSize(28, 28);
      icon5.shadowSize = new GSize(43, 28);
      icon5.iconAnchor = new GPoint(14, 14);
      icon5.infoWindowAnchor = new GPoint(14, 14);

// Crea icono otros
      var icon6 = new GIcon();
      icon6.image = "../../../images/iconosgoogle/home.png";
      icon6.shadow = "../../../images/iconosgoogle/shadowhome.png";
      icon6.iconSize = new GSize(32, 32);
      icon6.shadowSize = new GSize(49, 32);
      icon6.iconAnchor = new GPoint(16, 16);
      icon6.infoWindowAnchor = new GPoint(16, 16);
      
// Crea icono wpt
      var icon7 = new GIcon();
      icon7.image = "../../../images/iconosgoogle/wpt.png";
      icon7.shadow = "../../../images/iconosgoogle/shadowwpt.png";
      icon7.iconSize = new GSize(32, 32);         
      icon7.shadowSize = new GSize(49, 32);       
      icon7.iconAnchor = new GPoint(16, 16);      
      icon7.infoWindowAnchor = new GPoint(16, 16);      		

// Crea icono foto
      var icon8 = new GIcon();
      icon8.image = "../../../images/iconosgoogle/foto.png";
      icon8.shadow = "../../../images/iconosgoogle/shadowfoto.png";
      icon8.iconSize = new GSize(32, 32);         
      icon8.shadowSize = new GSize(49, 32);       
      icon8.iconAnchor = new GPoint(16, 16);      
      icon8.infoWindowAnchor = new GPoint(16, 16);

// Crea icono cruce
      var icon9 = new GIcon();
      icon9.image = "../../../images/iconosgoogle/cruce.png";
      icon9.shadow = "../../../images/iconosgoogle/shadowcruce.png";
      icon9.iconSize = new GSize(28, 28);
      icon9.shadowSize = new GSize(43, 28);
      icon9.iconAnchor = new GPoint(14, 14);
      icon9.infoWindowAnchor = new GPoint(14, 14);;

// Crea icono arbolito
      var icon10 = new GIcon();
      icon10.image = "../../../images/iconosgoogle/arbolito.png";
      icon10.shadow = "../../../images/iconosgoogle/shadowarbolito.png";
      icon10.iconSize = new GSize(32, 32);         
      icon10.shadowSize = new GSize(49, 32);       
      icon10.iconAnchor = new GPoint(16, 16);      
      icon10.infoWindowAnchor = new GPoint(16, 16);

var gmarkers= [];
      var htmls = [];
      var to_htmls = [];
 var from_htmls = [];
      var i=0;

function createMarker(point,name,html,bool) {
  var marker = new GMarker(point,icon);

 // The info window version with the "to here" form open
        to_htmls[i] =  '<br>Destino:<b> '+ name + '</b>' +
           '<br>Desde:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
           '<input type="text" SIZE=30 MAXLENGTH=30 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Ruta por carretera" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
                  // "(" + name + ")" + 
           '"/>';

// The inactive version of the direction info
       html = '<br>Direcciones: <a href="javascript:tohere('+i+')"><u>Llegar aqu&iacute;</u></a> ';
		  GEvent.addListener(marker, "click", function() {
	    marker.openInfoWindowHtml("Poblaci&oacute;n:<b> " + name + "</b>" + "<br>" + html);
		  });
   gmarkers[i] = marker;
        htmls[i] = html;
        i++;
  return marker;
}

function LoadGPXFileIntoGoogleMap(map, filename,color,grosor)
{
	// Remove any existing overlays from the map.
	//map.clearOverlays();

	var request = GXmlHttp.create();
	request.open("GET", filename, true);
	request.onreadystatechange = function()
	{
		if (request.readyState == 4)
		{
		parser = new GPXParser(request.responseXML, map);
		parser.SetTrackColour(color);				 // Set the track line colour
		parser.SetTrackWidth(grosor);				 // Set the track line width
		parser.SetMinTrackPointDelta(0.00001);			 // Set the minimum distance between track points
		parser.CenterAndZoom(request.responseXML, G_PHYSICAL_MAP); // Center and Zoom the map over all the points.
		parser.AddTrackpointsToMap();				 // Add the trackpoints
		parser.AddWaypointsToMap();				 // Add the waypoints
		}
	}
	request.send(null);
}

// functions that open the directions forms
function tohere(i) {
        gmarkers[i].openInfoWindowHtml(to_htmls[i]);
function fromhere(i) {
        gmarkers[i].openInfoWindowHtml(from_htmls[i]);
      }
}

function load() {
      if (GBrowserIsCompatible()) {
  	MyMap = new GMap2(document.getElementById("map"));
        MyMap.addControl(new GLargeMapControl());
        MyMap.addMapType(G_PHYSICAL_MAP);
        MyMap.addControl(new GMapTypeControl());
        MyMap.addControl(new GScaleControl());
	var center = new GLatLng(40.2814759, -5.3210992);
        MyMap.setCenter(center, 8);
        //MyMap.setMapType(G_PHYSICAL_MAP);
        //MyMap.setMapType(G_NORMAL_MAP);        
        //MyMap.setMapType(G_SATELLITE_MAP);
        //MyMap.setMapType(G_HYBRID_MAP);

//A adido para mostrar texto sobre mapa
GV_Place_Control(MyMap,"texto1-global",G_ANCHOR_BOTTOM_LEFT,170,4);
GV_Place_Control(MyMap,"nombre-parque",G_ANCHOR_TOP_LEFT,90,8); // Tantos como quieras
     }

}

//]]>
//var MyMap;
	
//function Oerr(){return true;}
//self.onerror=Oerr


