	var map;
	var geocoder;
	var websiteURL = "http://cake.strobe.net.nz/flexibin";

    function initialize()
		{
		map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(-42, 176), 4);
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GLargeMapControl());
		geocoder = new GClientGeocoder();
		}
	
	function initialize_nomap()
		{
		geocoder = new GClientGeocoder();
		}

    // this function actually shows the location on the map.
    function addAddressToMap(response)
		{
		place = response.Placemark[0];
		map.clearOverlays();
		point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
		marker = new GMarker(point);
		map.addOverlay(marker);

		map.setCenter(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]), 15);
		document.location_form.address.value=place.address;
		marker.openInfoWindowHtml(place.address+"<br /><br /><a href='#' class='order_button' onClick='document.location_form.submit();'>Confirm This Address >></a>");
		}
	
	// this function passes the selected location to the map
	function selectLocation(address)
		{
		//document.getElementById("results").innerHTML="";
		geocoder.getLocations(address, addAddressToMap);
		}
	
	// this function lists out the possible results for the user to choose from.
	function listResults(response)
		{
		var results = "Please click your address below:<br />";
		
		if (!response || response.Status.code != 200)
			{
        	results = results + "Sorry, we could not find that address.";
      		}
		else
			{
			for (a=0;a<response.Placemark.length;a++)
				{
				results = results + "<span class='resultlink' class='order_button' onClick='document.address.full_address.value=\"" + response.Placemark[a].address + "\"; document.address.submit();'>" + response.Placemark[a].address + "</span><br />";
				}
			}

		document.getElementById("results").innerHTML=results;
		}

	// this function lists out the possible results for the user to choose from.
	function listResultsFull(response)
		{
		var results = "Please click your address below:<br />";
		
		if (!response || response.Status.code != 200)
			{
        	results = results + "Sorry, we could not find that address.";
      		}
		else
			{
			for (a=0;a<response.Placemark.length;a++)
				{
				results = results + "<span class='resultlink' onClick='document.location_form.address.value=\"" + response.Placemark[a].address + "\"; selectLocation(\""+response.Placemark[a].address+"\");'>" + response.Placemark[a].address + "</span><br />";
				}
			}

		document.getElementById("results").innerHTML=results;
		}
		
    // this function will retreive the results and pass them to the listResults() function
    function showLocation()
		{
		var firstChar = document.forms[0].q.value.charAt(0);
		
		if (isNaN(firstChar))
			{
			var address = "1 "+document.forms[0].q.value+", New Zealand";
			}
		else
			{
			var address = document.forms[0].q.value+", New Zealand";
			}
			
		geocoder.getLocations(address, listResults);
		}

    function showLocationFull()
		{
		var firstChar = document.forms[0].q.value.charAt(0);
		
		if (isNaN(firstChar))
			{
			var address = "1 "+document.forms[0].q.value+", New Zealand";
			}
		else
			{
			var address = document.forms[0].q.value+", New Zealand";
			}
		
		geocoder.getLocations(address, listResultsFull);
		}

   // this function passes the form data to google maps.
    function findLocation(address)
		{
		document.forms[0].q.value = address;
		showLocation();
		}

    function confirm_address(address)
		{
		map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(-42, 176), 4);
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addControl(new GLargeMapControl());
		geocoder = new GClientGeocoder();
		geocoder.getLocations(address, addAddressToMap);
		}
