//<![CDATA[

function load() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(41.879513, -87.663479), 14);

    // Creates a marker for each location
	function createMarker(mPoint, html) {
	  var marker = new GMarker(mPoint);
	  map.addOverlay(marker);
      GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
      });
	marker.openInfoWindowHtml(html);
      return marker;
    }

    // Load location data xml file and generate info window html
	var request = GXmlHttp.create();
	request.open("GET", "/gmap/locations.xml", true);
	request.onreadystatechange = function() {
	  if (request.readyState == 4) {
	    	var xmlDoc = request.responseXML;
			var xLocations = xmlDoc.documentElement.getElementsByTagName("Location");
			for (var i = 0; i < xLocations.length; i++) {
            var point = new GPoint(parseFloat(xLocations[i].getAttribute("Longitude")),
                                   parseFloat(xLocations[i].getAttribute("Latitude")));

            var mName = xLocations[i].getAttribute("Name");
            var mAddress = xLocations[i].getAttribute("Address");
            var mCity = xLocations[i].getAttribute("City");
            var mState = xLocations[i].getAttribute("State");
            var mZip = xLocations[i].getAttribute("Zip");
            var mPhone = xLocations[i].getAttribute("Phone");

            var fullAddress = mAddress + ", " + mCity + ", " + mState + "  " + mZip;

            var html = '<div id="map-box">';
            html += '<form action="http://maps.google.com/maps" method="get">';
            html += '<label>Enter Starting Address for Driving Directions:</label><br><input type="text" name="saddr" value="" style="width: 255px" size="30"/>';
            html += '<input type="hidden" name="daddr" value="' + fullAddress + '"/>';
            html += '<br /><span style="font-size: 0.85em; color: #615B45;">(Example: 1668 W. Ogden Ave., Chicago, IL 60612)</span><br /><input type="submit" class="submit" value="Get Directions"/></form>';
            html += '</div>';

            createMarker(point, html);
          }


	  }
	}
	request.send(null);


  }
}

//]]>