
/////////////////////////////////////////////
// e-mail-results.js
// Copyright 2006, 1995 Sustainable By Design
/////////////////////////////////////////////


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  LookupLatLong
	//
	/////////////////////////////////////////////////////////
	
		function LookupLatLong () {
		
			var zipCode = document.theForm.zipCode.value;

		// ---------------------------------------------
		// validate zip code
		// ---------------------------------------------
 
 			if (zipCode == '') {
 			
 				alert ("Please enter a USA ZIP Code and click 'lookup'");
 			}
 			
 			else if (! zipCode.match (/\d\d\d\d\d/)) {
 			
 				alert ("The ZIP Code must consist of five digits");
 			}
 			
		// ---------------------------------------------
		// send Ajax request
		// ---------------------------------------------

			else {
				
				var processingScript = "/php/zip_code_to_lat_long.php";
				
				var ajaxRequestString = processingScript + "?zipCode=" + zipCode;
	
				AJAX_Make_Request (ajaxRequestString);
			}
		}
		
		
	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Populate_Lat_Long
	//
	/////////////////////////////////////////////////////////
	
 		function Populate_Lat_Long (response) {
 		
 			var f = document.theForm;
 			
 			response = unescape (response);
 		
			if (response == 'noZipCode') {
				
				alert ("Please enter a ZIP Code before looking up latitude/longitude");
			}

			else if (response == 'notFound') {
				
				alert ("Sorry...that ZIP Code wasn't found...please click on 'other options' and use alternative lookup features");
			}

			else {

		// ---------------------------------------------
		// get values
		// ---------------------------------------------
 				
				var responseParts = response.split ('#');
				
				var city = responseParts[0];
				
				var latitude = responseParts[1];
				
				var longitude = responseParts[2];
				
				var timeZone = responseParts[3];

		// ---------------------------------------------
		// update latitude
		// ---------------------------------------------
 				
				f.inputLatitude.value = latitude;
					
				f.inputNorthSouth.selectedIndex = 0;
 				
		// ---------------------------------------------
		// update longitude
		// ---------------------------------------------
 				
				f.inputLongitude.value = longitude * -1;
					
				f.inputEastWest.selectedIndex = 1;

		// ---------------------------------------------
		// update time zone
		// ---------------------------------------------
  				
				f.inputTimeZone.value = timeZone;

		// ---------------------------------------------
		// feedback
		// ---------------------------------------------
 				
				alert ("The latitude, longitude, and time zone have been set to " + city);
			}
 		}
 		
 		
 		
		

 		
