
	function usePointFromPostcode(postcode, control) {

		localSearch.setSearchCompleteCallback(null, function() {
				
			if (localSearch.results[0]) {		
				
				var resultLat = localSearch.results[0].lat;
				var resultLng = localSearch.results[0].lng;
				var point = new GLatLng(resultLat,resultLng);
				var data = [];
										
				// Call an AJAX script to add the new coordinates to the database
				//new Ajax("/includes/ajax/update_coords.php?dealer_id=" + dealer_id + "&x=" + resultLng + "&y=" + resultLat, {
				//	method: 'get'
				//}).request();

				// If the mode is 0 then assume they are a user with a postcode
				if (!map_mode && postcode) {
					var ajax_return = ajax_query("update_coords.php", "postcode=" + postcode + "&y=" + resultLng + "&x=" + resultLat + "&code=" + ajax_request_code);
				} else if (map_mode && dealer_id) {
					var ajax_return = ajax_query("update_coords.php", "dealer_id=" + dealer_id + "&y=" + resultLng + "&x=" + resultLat + "&mode=1&code=" + ajax_request_code);
				} else {
				}
					
				map_x = resultLat;
				map_y = resultLng;
					
				if (map_mode) {
					dealers[0]['posn'][0] = map_x;
					dealers[0]['posn'][1] = map_y;
					load();
				} 
				
			} else {
				//alert("Postcode not found!");
			}
		});	
		
		localSearch.execute(postcode + ", UK");
		
	}

	//<![CDATA[

	function load(control) {

		if (control == "false") {
			control = false;
		}

		if (GBrowserIsCompatible()) {
	  		if (document.getElementById(map_id)) {
				
				var map = new GMap2(document.getElementById(map_id));
				
				if (map_x && map_y) {
					var posn = new GLatLng(map_x, map_y);
				} else {
					var posn = new GLatLng(54, 11);
				}
				
				map.setCenter(posn, 5);
				map.setMapType(G_NORMAL_MAP);
				map.setZoom(zoom);
				map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());

		
				var mgr = new MarkerManager(map);
				var markersLow = [];
				var markersMid = [];
				var markersMidhigh = [];
				var markersHigh = [];

				theIcon = new GIcon(G_DEFAULT_ICON);
				theIcon.image = "http://geocoder.ca/marker.png";
	
				// Set up our GMarkerOptions object
				if (control) {
					//alert("draggable");
					markerOptions = { icon:theIcon, draggable: true };
				} else {
					//alert("not draggable");
					markerOptions = { icon:theIcon };
				}
				for (var j=0; j<dealers.length; j++) {
					var this_dealer = dealers[j];
					//if (this_dealer) {

						var posn = new GLatLng(this_dealer["posn"][0], this_dealer["posn"][1]);
						newMarker[j] = new GMarker(posn, markerOptions);
						
						newMarker[j].dealer_id = this_dealer["id"];
		
						if (control) {
							
							GEvent.addListener(newMarker[j], "dragstart", function() {
								map.closeInfoWindow();
							});
							
							GEvent.addListener(newMarker[j], "dragend", function() {
								point = this.getPoint();
								updateCoordinates(point, this.dealer_id);
							});
							
							GEvent.addListener(newMarker[j], "drag", function() {
								//point = newMarker[j].getPoint();
								//updateCoordinates(point);
							});
		
						}
						
	
						//newMarker[j].bindInfoWindowTabsHtml('ID: ' + this_dealer["id"]);
						//markersLow.push(newMarker);
						mgr.addMarker(newMarker[j], 1);
						
					//}



				}
								
				mgr.refresh();
						
				GEvent.addListener(map, "click", function(overlay, point) {

					if (overlay && overlay.dealer_id) {
						
						var tabs = [];
								
						tabs.push(new GInfoWindowTab("General", overlay.dealer_id));
								
						overlay.openInfoWindowTabs(tabs);	
						
					}
				});
				
			}
			
		}
	
	}
	
	function displayProperty(overlay) {
				
		// Call an AJAX script to get the property information
	
	}
	
	// Update marker position
	function updateMarker(point) {
		map.setCenter(point, 12);
		marker.setPoint(point);
		marker.openInfoWindowHtml(markerText());
		updateCoordinates(point);
	}
	
	function updateCoordinates(point, dealer_id) {
		lat = point.lat().toFixed(6);
		lng = point.lng().toFixed(6);
		
		// Call an AJAX script to add the new coordinates to the database
		var ajax_return = ajax_query("update_coords.php", "dealer_id=" + dealer_id + "&mode=1&y=" + lng + "&x=" + lat + "&code=" + ajax_request_code);
					
		if (ajax_return) {
			alert("Thank you!\nThe new location has been saved successfully.");	
		}

	}
	
	function confirmCoords() {

		// Get the postcode
		var postcode = document.getElementById('dealer_company_postcode').value;
		control = false;

		usePointFromPostcode(postcode, control);

	}