//Global variables
//
// 		formSubmit = "TheNameOfThePageYouWantTheFormToSubmitTo.asp";
// 		formName = "TheNameOfTheFormYouAreUsing";
//	
// 		lat_field = "TheNameOfTheLatituteFieldInTheForm";
// 		lon_field = "TheNameOfTheLongitudeFieldInTheForm";
//	
// 		street_address_field = "StreetAddressFieldFromTheForm";
//		 city_field = "CityFieldFromTheForm";
//		 state_field = "StateFieldFromTheForm";
//		 zip_field = "ZipFieldFromTheForm";
//
//end global vars


//Example Form
/*

<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA" 
type="text/javascript"></script>

<script type="text/javascript" src="geocode.js"></script>
			
			
<form name="myForm" action="#" onSubmit="return geocode('processing.asp', 'producer_post', 'latitude', 'longitude', 'street', 'city', 'state', 'zip'))" method="post">

Your Address
<input name="street" /> 

City
<input name="city" /> 

State
<input name="state" /> 

Zip
<input name="zip" /> 

<input type="hidden" name="latitude" value="" />
<input type="hidden" name="longitude" value="" />

<input type="submit" value="Submit Form" />

</form>
*/



	
    var map;
    var geocoder;
	
	
    function initialize() {
      geocoder = new GClientGeocoder();
    }

	function geocode(formSubmit, formName, lat_field, lon_field, street_address_field, city_field, state_field, zip_field) {

	
						
				//var street = document.producer_post.contact_address.value;
				var street = eval("document." + formName + "." + street_address_field + ".value");
				var city = eval( "document." + formName + "." + city_field + ".value");
				var state = eval( "document." + formName + "." + state_field + ".value");
		 		var zip = eval( "document." + formName + "." + zip_field + ".value");

				//validate address info so js wont have an error
				if (street == "" || city == "" || state == "" || zip == "") {
					//set the action of the form
					eval( "document." + formName + ".action='" + formSubmit + "'");
		
					//submit the form
					eval( "document." + formName + ".submit()");
							
							return true;
				}
				else {
				
					var address = street + ", " + city + ", " + state + " " + zip;
					geocoder.getLocations(address, addAddressToMap);
					return false;
					
				}//end validation if statment
					  
				  
		
					function addAddressToMap(response) {        	
				
				
						place = response.Placemark[0];
						point = new GLatLng(place.Point.coordinates[1],
												place.Point.coordinates[0]);
							
							
							//get geocoded values					
							lat = place.Point.coordinates[1];
							lon = place.Point.coordinates[0];
		
							//put coorinates in form
							eval( "document." + formName + "." + lat_field + ".value = lat");
							eval( "document." + formName + "." + lon_field + ".value = lon");
												
							
							//set the action of the form
							eval( "document." + formName + ".action='" + formSubmit + "'");
		
							//submit the form
							eval( "document." + formName + ".submit()");
						
	
					}//addAddressToMap
				
				

	}//geocode


initialize();