var geocoder;
var map;
var theaddress;
var address;
var title;
var viewAddress;


	function setAddress(theaddress, theTitle, theViewAddress){
		title = theTitle;
		viewAddress = theViewAddress;
		address = theaddress;
		load(address);
	};

   function load(address)
   {
	

      map = new GMap2(document.getElementById("map"));
	  map.addControl(new GLargeMapControl());
	 
      map.addControl(new GMenuMapTypeControl());
 
	  map.enableScrollWheelZoom();

      // Create new geocoding object
      geocoder = new GClientGeocoder();

      // Retrieve location information, pass it to addToMap()
      geocoder.getLocations(address, addToMap);
   }


   function addToMap(response)
   {

      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
                          place.Point.coordinates[0]);
		
      // Center the map on this point
      map.setCenter(point, 13);
		
      // Create a marker
      marker = new GMarker(point);
		
      // Add the marker to map
      map.addOverlay(marker);
	  
	  tohere = '<div class="get-directions">Start address:<form action="http://maps.google.com/maps" method="get">' +
           '<input type="text" size=40 maxlength=40 name="saddr" id="saddr" value="" /><br>' +
           '<input value="Get Directions" type="submit" id="google-get-directions" />' +
           '<input type="hidden" name="daddr" value="' + address + 
                 //"(" + name + ")" + 
           '"/></form></div>';
	  
      // Add address information to marker
	  myAddressSplit = viewAddress.split(",");
      marker.openInfoWindowHtml('<p style="margin:0;"><strong>' + title + '</strong><br />' + myAddressSplit[0] + '<br />' + myAddressSplit[1] + '</p>' + tohere);
   	  GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml('<p><strong>' + title + '</strong>' +  myAddressSplit[0] + '<br />' + myAddressSplit[1] + '</p>' + tohere);
	  });
   }



