var map;
var geoCoder;

function findLivePageHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	}
	if (document.body.clientHeight) {
		return document.body.clientHeight;
	}
	return (null);
}

function pageDim() {
	livePageHeight=findLivePageHeight();
	alert(livePageHeight);
}

function init() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));
		map.setUIToDefault();
		geocoder = new GClientGeocoder();
		var center= new GLatLng(38.62429950581108, -90.18564176280051); // Gateway Arch
		map.setCenter(center, 9);	
		GEvent.addListener(map, "click", getAddress);
  		geocoder = new GClientGeocoder();
	}
}

function getAddress(overlay, latlng) {
  if (latlng != null) {
    address = latlng;
	document.getElementById("txtLatLong").value = latlng;
		point = latlng; //new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
	marker = new GMarker(point, {draggable:true,clickable:false});	
	GEvent.addListener(marker, "dragend", function() {
			document.getElementById("txtLatLong").value = marker.getLatLng();
			geocoder.getLocations(marker.getLatLng(), showAddress);
		}); 
    geocoder.getLocations(latlng, showAddress);		
  }
}

function showAddress(response) {
	map.clearOverlays();
	if (!response || response.Status.code != 200) {
		alert("Status Code:" + response.Status.code);
	} else {
		place = response.Placemark[0];		
		document.getElementById("JobAddress").value = place.address;
//		document.getElementById("txtLatLong").value = "(" + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + ")"
//			

		map.addOverlay(marker);

	}
}