var nropredio=7;
var nromarker=0;
// HASTA AQUI LAS FUNCIONES AJAX 


      var side_bar_html1 = "";
      var gmarkers = [];
	  
      var baseIcon = new GIcon();
	      baseIcon.iconSize=new GSize(32,32);
          baseIcon.shadowSize=new GSize(32,32);
          baseIcon.iconAnchor=new GPoint(16,32);
          baseIcon.infoWindowAnchor=new GPoint(32,0);
 
      var baseIcon2 = new GIcon();
	      baseIcon2.iconSize=new GSize(24,24);
          baseIcon2.shadowSize=new GSize(24,24);
          baseIcon2.iconAnchor=new GPoint(12,24);
          baseIcon2.infoWindowAnchor=new GPoint(24,0);
		            
      var iconoestacion = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal4/icon30.png", null, "http://maps.google.com/mapfiles/kml/pal4/icon30.png");
      var iconopredio   = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon10.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon10.png");
      var iconoensayo   = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon12.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon12.png");	  


      function createMarker(point,name,urlcontenido,tipoicono) {
        var marker;
	         if (tipoicono=="estacion")  marker = new GMarker(point,iconoestacion);
	    else if (tipoicono=="ensayo")  marker = new GMarker(point,iconoensayo);				
	    else if (tipoicono=="predio")
		{
		 nropredio++;
		 marker = new GMarker(point,new GIcon(baseIcon2, "http://maps.google.com/mapfiles/kml/pal3/icon"+nropredio+".png", null, "http://maps.google.com/mapfiles/kml/pal3/icon"+nropredio+".png"));
		} // marker = new GMarker(point,iconopredio);
		else marker = new GMarker(point);
		nromarker++;				
        GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml("<div id='infotab"+name+"'><table width='350px' height='180px'><tr><td>&nbsp;</td></tr></table></div>");
        pedirAJAX('infotab'+name,urlcontenido);
//		 setTimeout("pedirAJAX('infotab',"+urlcontenido+")",250);
		 
        });
        // save the info we need to use later for the side_bar
        gmarkers.push(marker);
        // add a line to the side_bar html
        side_bar_html1 += '<li><a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '</a></li>';
         return marker;
      }
	function AgregarGrupoMenu(label,linklabel)
	{

	 side_bar_html1+='<a class="menuitem submenuheader" href="'+linklabel+'" >'+label+'</a>   <div class="submenu"><ul>';
	}
	function TerminarGrupoMenu()
	{

	  side_bar_html1+='</ul></div>';
	}
      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        GEvent.trigger(gmarkers[i], "click");
        //map.panTo(gmarkers[i].getLatLng());
      }
	  function ubicaren(lat,lon,zoom)
	  {
	//  GEvent.trigger(gmarkers[0], "click");
//       map.panTo(new GLatLng(lat,lon));
       map.setCenter(new GLatLng(lat,lon),zoom);
	  }

// ----------------------- DESDE AQUI LAS FUNCIONES AJAX ----------------
function getHTTPObject()
{ var xmlHttp;
  try{xmlHttp=new XMLHttpRequest(); }//firefox
  catch (e)
  {
   try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }//explorer
   catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  }
 return xmlHttp;
}//fin function getHTTPObject()
//LAS DOS FUNCIONES A CONTINUACION SON PARA USAR AJAX EN FORMA GENERICA
//SE LLAMA EL PEDIR CON EL ID DEL DIV Y LA URL QUE VA A MANDAR EL CODIGO HTML
//PARA RELLENARLO
function cambiardivAJAX()
 {
   if (http.readyState==1) {
     //document.getElementById(div_id).innerHTML = "<p>Cargando...</p>";;
         }
  else if (http.readyState == 4) 
  {
    var results = http.responseText;
    document.getElementById(div_id).innerHTML = results;
  } //fin  if (http.readyState == 4)
  else document.getElementById(div_id).innerHTML="Estado="+http.readyState;
 }//fin function handleHttpResponse()
function pedirAJAX(div_idf,urlf)
{
// ocultar('fadeimg')
 //este aleatorio en la URL impide que el explorer no muestre el archivo en cache
 //el escapre hace un parseo de los caracteres especiales al formato url
// http=getHTTPObject();
 var aleatorio=Math.random();
 div_id=div_idf; 
 //http.open("GET", urlf+"&nocache="+aleatorio, true);
 http.open("GET", urlf+"&nocache="+aleatorio, false);//no se usa el cambiar divajax, 
 http.send(null);//cierra la conexion
 var results = http.responseText;
 document.getElementById(div_id).innerHTML = results;//comentar esta y descomentar la siguiente
// http.onreadystatechange = cambiardivAJAX; //para cambiar a modo a asincrono
}
var div_id="";
var http = getHTTPObject(); // We create the HTTP Object
