function getClickAddress(overlay, latlng) {
  if (latlng != null) {
    address = latlng;
    geocoder.getLocations(latlng, showClickAddress);
    switchVisibility();
  }
}

function showClickAddress(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Status Code: " + response.Status.code + " I was unable to complete your map request at this time. The server may be busy, or you may have a slow connection. Please try again.");
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],
                        place.Point.coordinates[0]);
    marker = new GMarker(point, homePins);
    map.addOverlay(marker);
    map.setCenter(point);

		// Set values in the page form to match the map
    $("#address").val(place.address);
    $("#long").val(place.Point.coordinates[0]);
    $("#lat").val(place.Point.coordinates[1]);
    $("#address2").val(place.address);
    $("#long2").val(place.Point.coordinates[0]);
    $("#lat2").val(place.Point.coordinates[1]);
  }
}

function showAddress(address) {
	if(address != null) {
		geocoder.getLocations(address, showClickAddress);
	}
}