//<![CDATA[
    if (GBrowserIsCompatible()) {

      var gmarkers = [];
      var htmls = [];
      var to_htmls = [];
      var from_htmls = [];
      var i=0;
	  var polys = []; //poly
      var labels = []; //poly

      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {
        var marker = new GMarker(point);

        // The info window version with the "to here" form open
        to_htmls[i] = html + '<br>Directions: <b>To here</b> - <a href="javascript:fromhere(' + i + 
			')">From here</a>' +
			'<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
			'<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
			'<INPUT value="Get Directions" TYPE="SUBMIT">' +
			'<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
            '"/>';
			
        // The info window version with the "to here" form open
        from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere(' + i + 
			')">To here</a> - <b>From here</b>' +
			'<br>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
			'<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
			'<INPUT value="Get Directions" TYPE="SUBMIT">' +
			'<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
            '"/>';
        
		// The inactive version of the direction info
        html = html + '<br>Directions: <a href="javascript:tohere('+i+
			')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a>';

        GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);});
        gmarkers[i] = marker;
        htmls[i] = html;
        i++;
        return marker;
      }

      // functions that open the directions forms
      function tohere(i) {
        gmarkers[i].openInfoWindowHtml(to_htmls[i]);
      }
      function fromhere(i) {
        gmarkers[i].openInfoWindowHtml(from_htmls[i]);
      }

      // Display the map, with some controls and set the initial location 
      var map = new GMap2(document.getElementById("map"));

      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(43.4279,-80.43165), 14);
    
      var point = new GLatLng(43.4279,-80.43165);
	  var windowtitle = 'Used Car Depot';
	  var windowtext = '<span class="maintext04b"><b>Used Car Depot</b><br>3015 King St East<br>Kitchener, ON  N2A 1B1<br><b>Sales:</b> 519.748.5552<br><b>Service:</b> 519.748.9815<br/>Email:<a href="mailto:%73%61%6c%65%73%40%75%73%65%64%63%61%72%64%65%70%6f%74%2e%63%61">&#115;&#97;&#108;&#101;&#115;&#64;&#117;&#115;&#101;&#100;&#99;&#97;&#114;&#100;&#101;&#112;&#111;&#116;&#46;&#99;&#97;</a>';
	  
      var directionsbasic = '<br>Directions: <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a></span>';
	  var marker = createMarker(point, windowtitle, windowtext)
      map.addOverlay(marker);
      marker.openInfoWindowHtml(windowtext + directionsbasic)

//poly started
	  var request = GXmlHttp.create();
      request.open("GET", "polyshapelocations.xml", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = GXml.parse(request.responseText);
          // ========= Now process the polylines ===========
          //var locations = xmlDoc.documentElement.getElementsByTagName("location");
		  var locations = xmlDoc.getElementsByTagName("location");

          // read each line
          for (var a = 0; a < locations.length; a++) {
            // get any location attributes
            var label  = locations[a].getAttribute("name");
            var colour = locations[a].getAttribute("colour");
            // read each point on that line
            var points = locations[a].getElementsByTagName("point");
            var pts = [];
            var bound = new GLatLngBounds()
            for (var i = 0; i < points.length; i++) {
               pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")),
                                   parseFloat(points[i].getAttribute("lng")));
               bound.extend(pts[i]);
            }
            var poly = new GPolygon(pts,"#FFFFFF",1,1,colour,0.5,{clickable:false});
            polys.push(poly);
            labels.push(label);
            map.addOverlay(poly);
            poly.Bound = bound;
          }
        }
      }
      request.send(null); //poly ended
}
    
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
    //]]>
