﻿ if (GBrowserIsCompatible()) {

       // functions that open the directions forms
      function tohere(i) {
	      gmarkers[i].openInfoWindowHtml(to_htmls[i]);
	      document.getElementById('saddr').focus();
      }
      function fromhere(i) {
	      gmarkers[i].openInfoWindowHtml(from_htmls[i]);
	      document.getElementById('daddr').focus();
      }

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

      function myclick_supressOfficeLink(i) {
        gmarkers[i].openInfoWindowHtml(htmls_supressOfficeLink[i]);
      }      
      
      // this variable will collect the html which will eventually be placed in the sidebar
      var sidebar_html = "";
    
      // arrays to hold copies of the markers and html used by the sidebar
      // because the function closure trick doesnt work there
      var gmarkers = [];
      var htmls = [];
      var htmls_supressOfficeLink = [];
      var to_htmls = [];
      var from_htmls = [];
      var i=0;


	function strip_Office(str) {
	    // prevent 'Office Office' from appearing
	    return str.replace("Office", "");
	}

      // A function to create the marker and set up the event window
      function createMarker(point,name,html, link) {
        var marker = new GMarker(point);
	
	 // The info window version with the "to here" form open
	 
	 	 
        to_htmls[i] = html + '<br><div style=\'padding-bottom:0px;padding-top:12px;\'>Directions: <b>To here</b> - <a href="javascript:fromhere(' + i + ');">From here</a></div>' +
           '<br><div style=\'padding-top:0px;padding-bottom:5px;\'>Start address:</div><form action="http://maps.google.com/maps" method="get" target="_blank">' +
           '<input type="text" SIZE=40 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" id="daddr" name="daddr" value="'+ html +'"' + 
           '"/>';
        // The info window version with the "to here" form open
        from_htmls[i] = html + '<br><div style=\'padding-bottom:0px;padding-top:12px;\'>Directions: <a href="javascript:tohere(' + i + ');">To here</a> - <b>From here</b></div>' +
           '<br><div style=\'padding-top:0px;padding-bottom:5px;\'>End address:</div><form action="http://maps.google.com/maps" method="get"" target="_blank">' +
           '<input type="text" SIZE=40 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" id="saddr" name="saddr" value="'+ html +'"' +
           '"/>';
        // The inactive version of the direction info
        
                sidebar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
        html = '<a style=\'font-weight:bold;\' href="'+ link +'">' + strip_Office(name) + ' Office</a><br />' +
        '<a style=\'font-size:smaller; text-decoration:none;\' href="'+ link +'">[Click here for info]</a><br />' +
        '<br>Directions: <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a>';

	html_supressOfficeLink = '<strong>' + strip_Office(name) + ' Office</strong><br />' +
        '<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 sidebar
        gmarkers[i] = marker;
        htmls[i] = html;
	htmls_supressOfficeLink[i] = html_supressOfficeLink;
        // add a line to the sidebar html
        i++;
        return marker;
      }


    } else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
  }
