  var geocoder;
  
  
  function place(latitude, longitude, formatted_address)
  {
  	//Relocate the map to this place
  	point = new google.maps.LatLng(latitude, longitude);
  	map.setCenter(point);
  	

	document.getElementById("lat").value = latitude;
	document.getElementById("lon").value = longitude;
	


	document.getElementById("did-you-mean").innerHTML = "";  
  	  	
  	$("#geocode").hide();
  	

  	
  }
  
  //See: http://blog.mapmyglobe.com/2007/08/29/gmaps-geocoder-accuracy-and-zoom-level/
  var tabAccuracy = new Array(2,4,6,10,12,13,16,16,17);

  
  
  function geocodeAddress() {
    atl_submit_on_success=false; 
    no_location();	    		//Start the map
    
    var address = document.getElementById("newaddress").value;
    
    //Register the address on byke
    $.get('/click_register.php?type=enter-address&address=' + address,
						function(response)
						{

						}
					);
    
    
    if (geocoder) {
      geocoder.geocode( { 'address': address }, function(results, status) {   //'address': address, 'region': 'GB' 
	
	if (status == google.maps.GeocoderStatus.OK) {
	
	  sw_1 = results[0].geometry.viewport.getSouthWest();	//map.panToBounds(results[0].geometry.viewport); would be the answer if we were all in ver 3 of the api.
	  ne_1 = results[0].geometry.viewport.getNorthEast();
	  sw = new GLatLng(sw_1.lat(), sw_1.lng() , true);
	  ne = new GLatLng(ne_1.lat(), ne_1.lng() , true);
	  bounds = new GLatLngBounds(sw, ne);  
	  zoomlevel = map.getBoundsZoomLevel(bounds);
	 
	  
	  
	  map.setCenter(new GLatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()), zoomlevel);
	  
	  document.getElementById("lat").value = results[0].geometry.location.lat();
	  document.getElementById("lon").value = results[0].geometry.location.lng();
	
	  

	
	
	  if(results.length > 1) { 
		document.getElementById("did-you-mean").innerHTML = "Did you mean:";
		// Loop through the results
		for (var i=0; i<results.length; i++) {
		  var p = results[i].geometry.location;
		  thisFormattedAddress = results[i].formatted_address;
		  //alert(thisFormattedAddress);
		  //thisFormattedAddress = thisFormattedAddress.split("'").join("\'");		//Get rid of apostrophes
		  thisFormattedAddress = thisFormattedAddress.replace(/'/g, "&apos"); 
		  //alert(thisFormattedAddress);
		  newHTML = "<br><a href='javascript:place(" +p.lat()+","+p.lng()+",\""+ thisFormattedAddress + "\")'>"+ results[i].formatted_address+"<\/a>";
		  //alert(newHTML);
		  document.getElementById("did-you-mean").innerHTML += newHTML;
		}
	  } else {
		formattedAddress = results[0].formatted_address;
	  	
		
	  }

	  
	 
	
	} else {
	  alert("Geocode was not successful for the following reason: " + status);
	}
      });
    }
  }
  

