// [SU] 24.04.2009
// event handler for search form submission (handles client-side geocoding of entered location)
function submitGeoSearch(event) {

	// get value of location field
	var locationValue  = $('location').get('value');
	
	// if user didn't enter any location simply submit the form
	if (locationValue.length == 0)
		return true;
		
	var form = this;
	
	// find out lat/lng pair of desired location
	var geocoder = new google.maps.ClientGeocoder();
	geocoder.getLatLng(
		locationValue,
    	function(point) {
      		if (point) {
      			// we found the point, so set the hidden fields for lat/lng
				$('latitude').set('value', point.lat());
				$('longitude').set('value', point.lng());
      		}
      		// submit the form
      		form.submit();
    	}
  	);
  	
  	// prevent the default submission of the form
	event.stop();
  	return false;
}

window.addEvent('domready', function(){
	var form = $('extended_search');
	if (form)
 		form.addEvent('submit', submitGeoSearch.bind(form));
});
