function showAddress(address) {
	geocoder.getLatLng (
	address,
	function(point) {
		if (!point) {
			if (address != '') {
				alert("Haulla " + address + " ei löytynyt kohdetta");
			} else {
				alert("Haulla ei löytynyt kohdetta");
			}
		} else {
			searchArrow=new GMarker(point, hotIcon, true);
			searchMarker=new GMarker(point, addIcon, true);
				
			map.addOverlay(searchArrow);
			map.addOverlay(searchMarker);
			
			map.setCenter(point, 14);
			cachePoint(point, address);
		}
	});
}

function cachePoint(point, address) {

	var options = {

		method : 'post',
		parameters : 'point='+point+'&address='+address,

		onSuccess: function(t) {}
	};
	
	new Ajax.Request('/kuvakartta/geocache_insert.php', options);
}

function checkCache(address) {

	var options = {

		method : 'post',
		parameters : 'name='+address,

		onSuccess: function(t) {
		
			var geocacheResponse = t.responseText;

			try {
				map.removeOverlay(searchMarker);
				map.removeOverlay(searchArrow);
			} catch (e) { };
			
			if (geocacheResponse != '') {
				var geocacheArray = geocacheResponse.split(":");
				
				var searchPoint = new GLatLng(geocacheArray[0],geocacheArray[1]);
				
				searchArrow=new GMarker(searchPoint, hotIcon, true);
				searchMarker=new GMarker(searchPoint, addIcon, true);
				
				map.addOverlay(searchArrow);
				map.addOverlay(searchMarker);
				
				map.setCenter(new GLatLng(geocacheArray[0], geocacheArray[1]), 14);
			} else {
				showAddress(address);
			}
		}
	};
	
	new Ajax.Request('/kuvakartta/geocache.php', options);
}
