//
//
// ***** Search function called by Scene 2 *****
//
//
var geocoder;
var code;
var search_marker = "";
function addressSearch(code) {
	// First try to find the coordinates with the standard Google geocoder
	// Create new geocoding object
    geocoder = new GClientGeocoder();
	// Retrieve location information
    geocoder.getLocations(code, flashGeocodeResponse);
}
function flashGeocodeResponse(response){
	// See if the address has been successfully geocoded
	if (response.Status.code == 200) {
		// Success
		// How many possible addresses were found?
		total_addresses = response.Placemark.length;
		if (total_addresses > 1) {
			alert("We found several possible addresses, so we've gone for the most likely one!\nTo get closer please try again with a more detailed address.");
		}
		place = response.Placemark[0];
		point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
		
		if (search_marker != "") {
			// Remove existing search marker
			global_map.removeOverlay(search_marker);
		}
		// Create a marker at new location
		icon = new GIcon(G_DEFAULT_ICON, "../images/global/mapping/blue-dot.png");
		search_marker = new GMarker(point, {icon:icon, title:"Your search location"});
		// Add the marker to map
		global_map.addOverlay(search_marker);
		
		// Zoom in to the new location
		global_map.setMapType(G_NORMAL_MAP); 
		global_map.setZoom(10);
		global_map.panTo(point);
	} else {
		// Failure
		alert("Sorry, we couldn't find your address...\nTry adding more details, like your city or country, or just scroll around the map with your mouse.");
	}
	// Stop memory leaks
	//GUnload();
}
function addressHelp() {
	alert("Addresses in the format:\n\nStreet Name, Town/City, Country\n\nshould give the best results!\n\nAdd your postcode to choose between areas with similar names.\n\nZoom the map out to see more outlets near you.");	
}