
//<![DATA[
    if (GBrowserIsCompatible()) {
    // this variable will collect the html which will eventually be placed in the side_bar
	  var side_bar_html = "";
	// arrays to hold copies of the markers and html used by the side_bar
      // because the function closure trick doesnt work there  
      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 = [];
	 

	// A function to create the marker and set up the event window
      function createMarker(point,name,sidebarlink,location,comma,html,address,phone) {
        // use a custom icon with letter A - Z
        var letter = String.fromCharCode("A".charCodeAt(0) + i);
        var myIcon = new GIcon(G_DEFAULT_ICON, "http://www.google.com/mapfiles/marker" + letter + ".png");
        myIcon.printImage = "http://maps.google.com/mapfiles/marker"+letter+"ie.gif"
        myIcon.mozPrintImage = "http://maps.google.com/mapfiles/marker"+letter+"ff.gif"
        var marker = new GMarker(point, {icon:myIcon});
		
		// The info window version with the "to here" form open
        to_htmls[i] ='' + name + '<br> ' +location  +'<br>Directions: <b>To here</b> - <a href="javascript:fromhere(' + i + ')">From here</a>' +
           '<br>Enter Start address:<form action="javascript:getDirections()">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
		   
           '<input type="hidden" id="daddr" value=" ' + name  + comma  + address  +"@"+ point.lat() + ',' + point.lng() + 
           '"/>';
		   
        // The info window version with the "to here" form open
        from_htmls[i] ='' + name + '<br> ' +location  +'<br>Directions: <a href="javascript:tohere(' + i + ')">To here</a> - <b>From here</b>' +
           '<br>Enter End address:<form action="javascript:getDirections()">' +
           '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr" id="daddr" value="" /><br>' +
           '<INPUT value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" id="saddr" value=" ' + name  + comma  + address  +"@"+ point.lat() + ',' + point.lng() +
           '"/>';
		   
        // The inactive version of the direction info
        html =  ''+ name  + '<br> ' +location   + '<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 side_bar html
        side_bar_html += '<a href="javascript:myclick(' + i + ')">'+letter +'&nbsp;&nbsp;&nbsp;' + sidebarlink  + '</a><br>'+address+'<br>'+ phone +'<br><br>';
		 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);
		
		// Closes side_bar and opens directions	
		var side_bar = document.getElementById("side_bar");
 	  	side_bar.style.display="none";
		var directions = document.getElementById("directions");
  	  	directions.style.display="block";
		var directions_inst = document.getElementById("directions_inst");
  	  	directions_inst.style.display="block";
      }
      
	  
	  // 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]);
      }
	  

		// create the map
      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(34.221703,-118.532825), 9);

		// Van Nuys    
      var point = new GLatLng(34.194050,-118.465575);
      var marker = createMarker(point,"Cardiovascular Consultants","Van Nuys","Van Nuys",", ","","15243 Vanowen Street, Suite 301, Van Nuys, CA 91405","Telephone: 818-782-5041 &bull; Fax: 818-782-4864")
      map.addOverlay(marker);
	  
	   // Mission Hills    
      var point = new GLatLng(34.279985,-118.45768);
      var marker = createMarker(point,"Cardiovascular Consultants","Mission Hills","Mission Hills",", ","","14901 Rinaldi Street, Suite 110, Mission Hills, CA 91345","Telephone: 818-365-1339 &bull; Fax: 818-898-4301")
      map.addOverlay(marker);
	  
	  // Northridge   
      var point = new GLatLng(34.221703,-118.532825);
      var marker = createMarker(point,"Cardiovascular Consultants","Northridge","Northridge",", ","","18350 Roscoe Boulevard, Suite 603, Northridge, CA 91325","Telephone: 818-993-8283 &bull; Fax: 818-993-4919")
      map.addOverlay(marker);
	  
	  // Valencia   
      var point = new GLatLng(34.396322,-118.554883);
      var marker = createMarker(point,"Cardiovascular Consultants","Valencia","Valencia",", ","","23929 McBean Parkway, Suite 216, Valencia, CA 91355","Telephone: 661-259-1534 &bull; Fax: 661-284-3670")
      map.addOverlay(marker);

      // Westwood    
      var point = new GLatLng(34.065459,-118.445706);
      var marker = createMarker(point,"Cardiovascular Consultants","Westwood","Westwood",", ","","100 UCLA Medical Plaza, Suite 770, Los Angeles, CA 90024","(west side of Westwood Plaza, north of LeConte, on the UCLA campus)<br>Telephone: 310-824-3378 &bull; Fax: 310-208-2870<br>")
      map.addOverlay(marker);

		// === create a GDirections Object ===
      var gdir=new GDirections(map, document.getElementById("directions"));
     
	  // === 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);
      });
	  
	  	
          // put the assembled side_bar_html contents into the side_bar div
	
		document.getElementById("side_bar").innerHTML = side_bar_html;
      request.send(null);
    }

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


    // 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

    //]]>
