﻿<!--

		var geocoder = null;
		var dir_index = 10; // 10 means out of range



		function initializeGeocoder() {
			if (GBrowserIsCompatible()) {
				geocoder = new GClientGeocoder();
			}
		} // EOF
	
	



		// geocodeDirectionsAddress() is called when you click on the Get
		// Directions button in a marker. It geocodes the address and submits
		// form to directions.php.
		function geocodeDirectionsAddress(index) {
			var form_label = 'getDirections'+String(index);
			var address = document.forms[form_label].startAddr.value; // Take the value
			dir_index = index; // For use later
			geocoder.getLocations(address, getAddrForDirections); // Send data to Google, process response
		} // EOF
	
	



		// geocodeAddress() is called when you click on the Search button
		// in the form. It geocodes the address and sets the lat/lon
		// hidden fields to pass on to process.php.
		function geocodeAddress() {
			var address = document.forms['addressSearch'].addressFld.value; // Take the value
			geocoder.getLocations(address, getLatLonForAddress); // Send data to Google, process response
		} // EOF
	
	



		// geocodeCity() is called when you click on the Search button
		// in the form. It geocodes the address and sets the lat/lon
		// hidden fields to pass on to process.php.
		function geocodeCity() {
			var city_state = document.forms['citySearch'].citySelect.value; // Take the value
			var city_state = city_state.replace("_",", ");
			geocoder.getLocations(city_state, getLatLonForCity); // Send data to Google, process response
		} // EOF






		// getLatLonForCity() is called when the geocoder returns an answer
		// after user tries to geocode an address for proximity searches
		function getLatLonForCity(response) {

			var userMsg = geocodeTest(response,3);
			if(userMsg) {
				alert(userMsg);
			} else {
				

				//  ******************************************
				//  ***** This is what we want to get to *****
				//  ******************************************


				var points = response.Placemark[0].Point.coordinates;
				var lat = points[1]; // Set latitude & longitude
				var lon = points[0];
				document.forms['citySearch'].lat.value = lat;
				document.forms['citySearch'].lon.value = lon;


				// Submit and continue
				document.forms['citySearch'].submit();


				//  ******************************************
				//  ******************************************
				//  ******************************************



			} // End if we could run this
		} // EOF
	






		// getAddrForDirections() is called when the geocoder returns an answer
		// after user tries to geocode an address for proximity searches
		function getAddrForDirections(response) {

			var userMsg = geocodeTest(response,6);
			if(userMsg) {
				alert(userMsg);
			} else {
				

				//  ******************************************
				//  ***** This is what we want to get to *****
				//  ******************************************


				var place = response.Placemark[0].AddressDetails;
				var accuracy = place.Accuracy;
				var country = place.Country.CountryNameCode;
				var points = response.Placemark[0].Point.coordinates;



				// Set scrubbed address
				var clean_address = response.Placemark[0].address;
				if(country == 'US') {
					clean_address = clean_address.replace(", USA", "");
				} else {
					clean_address = clean_address.replace(", Canada", "");
				}
				var form_label = 'getDirections'+String(dir_index);
				document.forms[form_label].startAddr.value = clean_address;



				// Submit and continue
				document.forms[form_label].submit();


				//  ******************************************
				//  ******************************************
				//  ******************************************



			} // End if we could run this
		} // EOF

	






		// getLatLonForAddress() is called when the geocoder returns an answer
		// after user tries to geocode an address for proximity searches
		function getLatLonForAddress(response) {

			var userMsg = geocodeTest(response,6);
			if(userMsg) {
				alert(userMsg);
			} else {
				

				//  ******************************************
				//  ***** This is what we want to get to *****
				//  ******************************************


				var place = response.Placemark[0].AddressDetails;
				var accuracy = place.Accuracy;
				var country = place.Country.CountryNameCode;
				var points = response.Placemark[0].Point.coordinates;


				// Set latitude & longitude
				var lat = points[1];
				var lon = points[0];
				document.forms['addressSearch'].lat.value = lat;
				document.forms['addressSearch'].lon.value = lon;



				// Set scrubbed address
				var clean_address = response.Placemark[0].address;
				if(country == 'US') {
					clean_address = clean_address.replace(", USA", "");
				} else {
					clean_address = clean_address.replace(", Canada", "");
				}
				document.forms['addressSearch'].addressFld.value = clean_address;



				// Submit and continue
				document.forms['addressSearch'].submit();


				//  ******************************************
				//  ******************************************
				//  ******************************************



			} // End if we could run this
		} // EOF






		// geocodeTest() is called by a few functions to see if
		// lat & lon accuracy meet a certain threshold
		function geocodeTest(response, accuracy_level) {

			var userMsg = "";

			if (!response || response.Status.code != 200) { // Error
				userMsg = "Sorry, we were unable to geocode that address.\n";
				userMsg += "Please try another address.";
		
			} else { // We got something
			

				var place = response.Placemark[0].AddressDetails;
				var accuracy = place.Accuracy;


				if(accuracy >= accuracy_level) { // 4 = town level accuracy, 6 = street level accuracy


					var country = place.Country.CountryNameCode;
					if((country != 'US') && (country != 'CA')) {
						userMsg = "Sorry, your starting point must be in the United\n";
						userMsg += "States or Canada.";
					} // End if we have the right country (US & Canada)



				} else { // Not accurate enough
					userMsg = "Sorry, we were unable to geocode that address\n";
					userMsg += "to a necessary level of accuracy. Please try\n";
					userMsg += "another address.";				
				} // End if accurate enough
			}// End if we had a 200 level response


			return userMsg;


		} // EOF


-->