var map;
var geocoder;

window.onload = addCodeToFunction(window.onload,function() {
	if (GBrowserIsCompatible()) { 
		map = new GMap2(document.getElementById("map-checkloc"));
		map.setCenter(new GLatLng(34, 0), 1);
		geocoder = new GClientGeocoder();
	} else {
		alert("Sorry, your browser isn't compatible with Jaikuvision!")
	}
});
function addAddressToMap(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
	alert("Sorry, we were unable to find that address.");
  } else {
	place = response.Placemark[0];
	point = new GLatLng(place.Point.coordinates[1],
						place.Point.coordinates[0]);
	marker = new GMarker(point);
	map.addOverlay(marker);
	marker.openInfoWindowHtml(place.address + '<br>' +
	  '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode,{maxWidth:250});
  }
}

// showLocation() is called when you click on the Search button
// in the form.  It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
	var address = document.forms[0].location.value;
	new Ajax.Request('/backend/functions.php', 
		{method:'post',postBody:'function=checkloc&loc='+address, onSuccess : function(response) {
			eval(response.responseText);
		}}
	);
}

// findLocation() is used to enter the sample addresses into the form.
function findLocation(address) {
  document.forms[0].location.value = address;
  showLocation();
}