// Handle Location Selection
var locationSelectionHandler = {

	// Initialise
	init: function(formName) {
	
		// Check
		if (!$(formName) || !$(formName+'_update')) return;
	
		// Hide button
		$(formName+'_update').hide();
		
		// Get location boxes
		var country = $$('.fieldname_location_country')[0];
		var region = $$('.fieldname_location_region')[0];
		var subregion = $$('.fieldname_location_subregion')[0];
		var location = $$('.fieldname_location_location')[0];
		
		// Get location text
		var locationTexts = Array();
		
		// Submit on change
		[country, region, subregion, location].each(function(i) {
			if (i) {
			
				// Add event handler
				i.observe('change', function() {
					$(formName+'_update_hidden').value = '1';
					$(formName).submit();
				});
				
				// Add to location string
				var temp = i.options[i.selectedIndex].text.strip();
				if (temp !== '') locationTexts[locationTexts.length] = temp;
				
			}
		});
		return;
		// Update image
		var image = $('location_map');
		if (image) {
		
			// Get geocode JSON
			var locationText = encodeURI(locationTexts.join(', ')); 
			var url = 'http://maps.google.com/maps/geo?q='+locationText+'&output=json&key=ABQIAAAAMhtMZ_2Y6J3uUF1dFodV3BTVUL78IJ6_FPd1BoN6sfjqao-cOxTvsxcF-HYWSZi4H1qnt-86QOr_Ig';
url = 'http://www.michaelwaterfall.com';
			// Request
			new Ajax.Request(url, {
				method: 'get',
				onSuccess: function(transport) {
					alert(transport.responseText);
				},
				onException: function(transport) {console.log(transport);
					alert(transport.statusCode);
				}
				
			});
			
			// Set image src
		
			// Show
			image.show();
		
		}
		
	}

}