// JavaScript Document

	//<![CDATA[

		var geocoder = new GClientGeocoder();	// geocoder class 
		var map = null;				// map

		var gMarkers = [];			// this is a list of all the markers that are placed by the db on the map
		var gMarkersPlaces = [];	// the names of the places that the markers are placed at (desc)
		var meMarker;				// the 'memarker' - where you are getting distances or directions to
		var meAddress;				// the address that someone has entered
		var counter = 0;			// counter variable

		var usedirectionsPanel = true;
		var directionsPanelId = "directions";// directions panel - want to give text based routes?

		var directions;

		function initialisethemap(){

			if (GBrowserIsCompatible()) {

				map = new GMap2(document.getElementById("map"));

	      	}
		}
    //]]>

// ================================================================================================
$(document).ready(function() {
  // setup the override for postcode section
  $('#postcode_search').submit(function() {

    // check for a missing postcode
    if (!$('#search_postcode').attr('value'))
    {
      alert('Please enter your Postcode');
      return false;
    }
    
    // check for a valid post
    if ($('#lat_long').attr('value'))
    {
      return true;
    }
    
    // check for a uk country code
    var postcode = $('#search_postcode').attr('value');
    if ($('#country_id').attr('value') == '2')
    {
			postcode = postcode.replace(/\s/g, '') + ', UK';
    }
    
    // get the lat/long
		geocoder.getLatLng(postcode, function(point) {
      // check for a valid point
      if (point) {
        // store the point
        $('#lat_long').attr('value', point);
        
        // submit the form
        $('#postcode_search').submit();
      }
    });
    
    // set up a standard fail
		setTimeout(function() {
      if (!$('#lat_long').attr('value')) {
        alert('Sorry, but your postcode - ' + postcode + ' was not found');
      }
    }, 5000);
    
    // stop the form submitting until we have the geocode
    return false;
  });
});