// JavaScript Document
//============================================================
//Google Map Code 

    function loadinitmap() {
      if (GBrowserIsCompatible()) {
		//Set Settings for Default Map
		var map = new GMap2(document.getElementById("map"));
		map.addControl (new GSmallMapControl ());
		map.addControl (new GMapTypeControl ());
		map.setCenter (new GLatLng(40.75658, -73.98618), 12);
		//Add Default Marker - Times Square, New York City
		var point = new GLatLng(40.75658, -73.98618);
		var marker = new GMarker(point, icon);
		map.setCenter(marker.getPoint(), 12);
		map.addOverlay(marker, icon);
		marker.openInfoWindowHtml("Times Square, NYC NY 10036");
		
		// Call the Event Listener function and wait for "click"
		map.addOverlay(createMarker1(point));

		function createMarker1(point) {
        var marker = new GMarker(point, icon);
		GEvent.addListener(marker, "click", function() {
    	map.setCenter(marker.getPoint(), 15);
		marker.openInfoWindowHtml("<strong>Times Square, New York City, NY 10036</strong><br><br><a href=http://maps.google.com/maps?f=d&hl=en&saddr=&daddr=Times+Square,+New+York+City,+NY&ie=UTF8&z=10&om=1&iwloc=A target=_blank> Directions</a>");
  		});
		return marker; }
		// Display Latitude and Longitude Settings
        var center = map.getCenter();
		document.getElementById("message").innerHTML = center.toString() + 
		"  - These are the latitude and longitude points for your address lookup.";		
      }
    }

// Fucntion to lookup address and display with a Directions link, if marker clicked
    function showAddress(address) {
		// Create text string for Direction lookup - no spacess allowed
		var addrlen = address.length;
		var address2 = address;
		for (i = 0; i < addrlen; i++) {
			address2 = address2.replace(" ", "+");
		}
		// Setup Map Defaults
		var map = new GMap2(document.getElementById("map"));
		map.addControl (new GSmallMapControl ());
//		map.addControl (new GMapTypeControl ());
		if (geocoder) {
        	geocoder.getLatLng(address, function(point) {
	            if (!point) {
    	        	alert(address + " not found");
					loadinitmap();
        	    } else {
					var marker = new GMarker(point, icon);
					map.setCenter(marker.getPoint(), 12);
					map.addOverlay(marker, icon);
					map.addOverlay(createMarker1(point));
					marker.openInfoWindowHtml(address);
					
					function createMarker1(point) {
			        	var marker = new GMarker(point, icon);
						GEvent.addListener(marker, "click", function() {
    					map.setCenter(marker.getPoint(), 15);
						marker.openInfoWindowHtml("<strong>" + address + "</strong><br><br><a href=http://maps.google.com/maps?f=d&hl=en&saddr=&daddr="  + address2 + "&ie=UTF8&z=10&om=1&iwloc=A target=_blank>Directions</a>");
  						}); //End of GEvent
						return marker; 
					} // End of createMarker1 function

	          		//Get and Display GPS - longitude and latitude values in Div
					var center = map.getCenter();
					document.getElementById("message").innerHTML = center.toString() + 
					"  - These are the latitude and longitude points for your address lookup.";
				} // End of IF
			} // End of function POINT
	        ); // End of GEOCODER
		} // End of IF
    } // End of ShowAddress function
    //]]>

//==================================================================
