window.addEvent('domready', function() {
	var geocoder, location;

	geocoder = new GClientGeocoder();
	
	geocoder.setBaseCountryCode('uk')

	function showLocation(postcode) {
		geocoder.getLocations(postcode, function (response) {
			if (!response || response.Status.code != 200)
			{
				alert("Sorry, we were unable to find your postcode. Please ensure you have entered a vaild UK poscode");
			}
			else
			{
				var lat = response.Placemark[0].Point.coordinates[1];
				var lon = response.Placemark[0].Point.coordinates[0];
				
				window.location = "/index2.asp?sessionx=IaqiNwB6IHqlNwEmNwB6IA&lat="+lat+"&lon="+lon;
			}
		});
	}
	
	
	
	function start_search() {
		if ($("search_postcode").value !== 'Enter Postcode' && $("search_postcode").value !== '') {
			showLocation($("search_postcode").value);
		} else {
			alert('Please enter a valid UK postcode');
		};
	}
	
	var keyStrokeEvent = function(event){
	    if (event.key == "enter") { 
			start_search()
			event.preventDefault();
	    };
	}
	
	$("do_search").addEvent('click', function(){
		start_search()
	});
	
	$("search_postcode").addEvent('keydown', keyStrokeEvent);
	
	
})