var i = 0;       
var gmarkers = [];
var htmls = [];
function makeMap(){
        if (GBrowserIsCompatible()) {// resize the map
            var m = document.getElementById("map");
            m.style.height = "500px";
            m.style.width = "350px";
            
      
       // A function to create the marker and set up the event window
    function createMarker(point,html,name) {
       var html='<div style="width:80px; height:110px;white-space:nowrap;">'+html + '</b>' +
           '<div style="font-family:arial; font-size: 11px; font-weight: bold;">Start address:</div><form action="http://maps.google.com/maps" method="get" target="_blank">' +
           '<input type="text" SIZE=28 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
           '"/>'
   
         var marker = new GMarker(point);
          marker.html = html;
          GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(marker.html);
        });
        
        
        gmarkers.push(marker);
        return marker;
      }
    // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      }  
        
      // create the map
      var map = new GMap2(m);
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
     
 // ==== It is necessary to make a setCenter call of some description before adding markers ====
      // ==== At this point we dont know the real values ====
      map.setCenter(new GLatLng(0,0),0);
// ===== Start with an empty GLatLngBounds object =====     
      var bounds = new GLatLngBounds();
      // Read the data from letter.xml
       var request = GXmlHttp.create();
       request.open("GET", "9036.xml", true);
       request.onreadystatechange = function() {
         if (request.readyState == 4) {
            var xmlDoc = request.responseXML;
              var markers = xmlDoc.documentElement.getElementsByTagName("marker");
          
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
         
           for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);;
            var html = markers[i].getAttribute("html");
            var icon = markers[i].getAttribute("icon");
            // create the marker
            var marker = createMarker(point,html,icon);
            
            bounds.extend(point);
            map.addOverlay(marker);
         
          } 
         
          // ===== determine the zoom level from the bounds =====
          map.setZoom(map.getBoundsZoomLevel(bounds));
          // ===== determine the centre from the bounds ======
          var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
          var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
          map.setCenter(new GLatLng(clat,clng));
        
        }
      }
       request.send(null);
    } 
  
      else {
        alert("Sorry, the Google Maps API is not compatible with this browser");
    }
}