

    if (GBrowserIsCompatible()) {
      var side_bar_html = "";
      var gmarkers = [];
      var htmls = [];
      var i = 0;
      // arrays to hold variants of the info window html with get direction forms open
      var to_htmls = [];
      var from_htmls = [];
	}else{
		
		}


      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {
        var marker = new GMarker(point);

				html = html.replace(/Schuylkill Medical Center/i,'Schuylkill Medical Center<br />');
        // The info window version with the "to here" form open
        to_htmls[i] = html + '<br>Directions: <strong>To here</strong> - <a href="javascript:fromhere(' + i + ')"><strong>From here</strong></a>' +
           '<br><small style="color:#666;">Start address</small><form style="margin:0 0 5px 0; padding:0;" action="javascript:getDirections()">' +
           '<input type="text" size="20" maxlength="40" name="saddr" id="saddr" value="" />' +
           '<input value="Go" type="submit">' +
           '<input type="hidden" id="daddr" value="'+name+"@"+ point.lat() + ',' + point.lng() + 
           '"/></form>';
        // The info window version with the "to here" form open
        from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere(' + i + ')"><strong>To here</strong></a> - <strong>From here</strong>' +
           '<br><small style="color:#666;">End address</small><form style="margin:0 0 5px 0; padding:0;" action="javascript:getDirections()">' +
           '<input type="text" size="20" maxlength="40" name="daddr" id="daddr" value="" />' +
           '<input value="Go" type="submit">' +
           '<input type="hidden" id="saddr" value="'+name+"@"+ point.lat() + ',' + point.lng() +
           '"/></form>';
        // 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);
        });
        // save the info we need to use later for the side_bar
        gmarkers[i] = marker;
        htmls[i] = html;
        // add a line to the TownLinks html
				side_bar_html += '<li><a href="javascript:myclick(' + i + ')">' + name + '</a></li>';
        i++;
        return marker;
      }

      // ===== request the directions =====
      function getDirections() {
        var saddr = document.getElementById("saddr").value
        var daddr = document.getElementById("daddr").value
        gdir.load("from: "+saddr+" to: "+daddr);
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      }

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


var map;    
var gdir;

function load(lat,lng, name, address, type){
    if (GBrowserIsCompatible()) {
		var side_bar_html = "";
		var gmarkers = [];
		var htmls = [];
		var i = 0;
		// arrays to hold variants of the info window html with get direction forms open
		var to_htmls = [];
		var from_htmls = [];


		// create the map
		map = new GMap2(document.getElementById("gMap"));
		map.addControl(new GSmallMapControl());
//		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(lat,lng), 13);

		gdir=new GDirections(map, document.getElementById("directions"));
			// === create a GDirections Object ===

		// === Array for decoding the failure codes ===
		var reasons=[];
		reasons[G_GEO_SUCCESS]            = "Success";
		reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
		reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
		reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
		reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
		reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
		reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
		reasons[G_GEO_BAD_REQUEST]        = "A directions request could not be successfully parsed.";
		reasons[G_GEO_MISSING_QUERY]      = "No query was specified in the input.";
		reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";

		// === catch Directions errors ===
		GEvent.addListener(gdir, "error", function() {
		var code = gdir.getStatus().code;
		var reason="Code "+code;
		if (reasons[code]) {
			reason = reasons[code]
			} 

		alert("Failed to obtain directions, "+reason);
		});
		var point = new GLatLng(parseFloat(lat), parseFloat(lng));
		var html = name;
		var label = name;
		// create the marker
		var marker = createMarker(point,label,html);
		map.addOverlay(marker);		
		}
	}

// put the assembled side_bar_html contents into the side_bar div
//document.getElementById("TownLinks").innerHTML = side_bar_html;

// This Javascript is based on code provided by the
// Blackpool Community Church Javascript Team
// http://www.commchurch.freeserve.co.uk/   
// http://econym.googlepages.com/index.htm

  
