// JavaScript Document
// Code to calc geo code from address

// Globals defined in html doc
// var map, geocoder, geoPoint

function geocode(form)		{
	
	var addr;
	var xx;
	var err = 0;
	if (form.address.value == "") err = 1;
	if (form.city.value == "") err = 1;
	if (form.state.value == "") err = 1;
	if (form.zip.value == "") err = 1;
	
	if (err == 0) 	{
		globalForm = form;
		addr = form.address.value + "," + form.city.value  + "," + form.state.value + "," + form.zip.value;
		
		xx = geoAddress( addr );				
	}
}
		
	
function initialize() {	
      if (GBrowserIsCompatible()) {
        geocoder = new GClientGeocoder();
      }
    }


function geoAddress(address) {
	var yy;
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
             	yy = clearLatLng( point );
            } else {				
			 	yy = setLatLng( point );
              
            }
          }
        );
      }
}
	

function setLatLng( pt )	{
	globalForm.addressLat.value = pt.y;
	globalForm.addressLng.value = pt.x;
}


function clearLatLng( pt )	{
	alert("The address can't be found.  Please check your entries for address, city, state, & zip");
	globalForm.addressLat.value = "";
	globalForm.addressLng.value = "";
	
}