
		$(function()
		{
			//branch finder callout 
			$('#branchFinderCallout').submit(function(event)
			{
				event.preventDefault();
				theForm = $('#branchFinderCallout').get(0);
				address = $('input[name=radius]',theForm).val(50);
				address = $('#ShopField',theForm).val() + ", UK";
				findBranch(theForm,address,false);
				return false;
			});

			//book a test 1
			$('#book1').submit(function(event)
			{
				event.preventDefault();
				theForm = $('#book1').get(0);
				address = $('input[name=postcode]',theForm).val() + ", UK";
				findBranch(theForm,address,false);
				return false;
			});


			$('#ShopField').focus(function(event)
			{
				if ($('#ShopField').val() == "Town or Postcode")
				{
					$('#ShopField').val("");
				}
			});

			$('#ShopField').blur(function(event)
			{
				if ($('#ShopField').val() == "")
				{
					$('#ShopField').val("Town or Postcode");
				}
			});


		});



		var branchGeocoder = new google.maps.Geocoder();


		function findBranch(theForm,address,haltOnNotFound)
		{
			//alert('Find ' + address);
			if (branchGeocoder)
			{
				branchGeocoder.geocode( { 'address': address}, function(results, status)
				{
					if (status == google.maps.GeocoderStatus.OK)
					{
						var latlng = results[0].geometry.location;
						theForm.latitude.value = latlng.lat();
						theForm.longtitude.value = latlng.lng();
						theForm.submit();
					}
					else
					{
						if(haltOnNotFound)
						{
							alert("Sorry! Your address was not found. Please try again.");
							return false;
						}
						else
						{
							theForm.submit();
							return false;
						}
					}
				});
			}
			return false;
	}

