var mapUpdater = {
	
	/*
	refreshMap: function(){
		if($('#tourAddress').val() == '') {
			
			// don't call zip ajax script unless country is U.S.
			if($('#tourCountryId').val() != '1' || $('#tourZip').val() == '') {
				
				function centerMap(response) {
					if(typeof response.Placemark == 'undefined')
						return false;
					// Retrieve the object
					place = response.Placemark[0];
					
					// Retrieve the latitude and longitude
					point = new GLatLng(place.Point.coordinates[1],
										place.Point.coordinates[0]);
					
					//update form values
					$('#tourLatitude').val(place.Point.coordinates[1]);
					$('#tourLongitude').val(place.Point.coordinates[0]);
										
					// Center the map on this point
					map.setCenter(point, 3);
					
					//remove the old marker
					if(typeof marker != "undefined")
						map.removeOverlay(marker);
				}
				country = $('#tourCountryId :selected').text();
				// Retrieve location information, pass it to addToMap()
  				geocoder.getLocations(country, centerMap);
				
			} else {
				zipCode = $('#tourZip').val();
				// US zip lookup only
				if ($('#tourCountryId').val() == '1') {
					$.post('/accounts/scripts/zip.php', {'zipCode': zipCode}, function(o){
						if(o == "false")
							return false;
						
						zip = eval(o);
						zip = zip[0];
						point = new GLatLng(zip.zipLat, zip.zipLon);
						
						//update form values
						$('#tourLatitude').val(zip.zipLat);
						$('#tourLongitude').val(zip.zipLon);
						
						// Center the map on this point
						map.setCenter(point, 11);
						
						//remove the old marker
						if(typeof marker != "undefined")
							map.removeOverlay(marker);

						// Create a marker
						marker = new GMarker(point,tvIcon);
						
						// Add the marker to map
						map.addOverlay(marker);

					});
				}
				else {

					function centerMap(response) {
						if(typeof response.Placemark == 'undefined')
							return false;
						// Retrieve the object
						place = response.Placemark[0];
						
						// Retrieve the latitude and longitude
						point = new GLatLng(place.Point.coordinates[1],
											place.Point.coordinates[0]);
						
						//update form values
						$('#tourLatitude').val(place.Point.coordinates[1]);
						$('#tourLongitude').val(place.Point.coordinates[0]);
							
						// Center the map on this point
						map.setCenter(point, 14);
						
						//remove the old marker
						if(typeof marker != "undefined")
							map.removeOverlay(marker);

						//remove the old marker
						if(typeof marker != "undefined")
							map.removeOverlay(marker);

						// Create a marker
						marker = new GMarker(point,tvIcon);
						
						// Add the marker to map
						map.addOverlay(marker);
						
					}
		
					/*
					address = $('#tourAddress').val().replace(/\n/, '');
					address += ", "+$('#tourCity').val();
					address += ", "+$('#tourState').val();
					address += ", "+$('#tourZip').val();
					
					// Retrieve location information, pass it to addToMap()
					geocoder.getLocations(address, centerMap);
					*/
					/*
				}
			}
			
		} else {
			function centerMap(response) {
				if(typeof response.Placemark == 'undefined')
					return false;
				// Retrieve the object
				place = response.Placemark[0];
				
				// Retrieve the latitude and longitude
				point = new GLatLng(place.Point.coordinates[1],
									place.Point.coordinates[0]);
				
				//update form values
				$('#tourLatitude').val(place.Point.coordinates[1]);
				$('#tourLongitude').val(place.Point.coordinates[0]);
					
				// Center the map on this point
				map.setCenter(point, 14);
				
				//remove the old marker
				if(typeof marker != "undefined")
					map.removeOverlay(marker);
				
				// Create a marker
				marker = new GMarker(point,tvIcon);
				
				// Add the marker to map
				map.addOverlay(marker);
				
			}
			address = $('#tourAddress').val().replace(/\n/, '');
			address += ", "+$('#tourCity').val();
			address += ", "+$('#tourState').val();
			address += ", "+$('#tourZip').val();
			
			// Retrieve location information, pass it to addToMap()
  			geocoder.getLocations(address, centerMap);
		}
	}



	*/
	refreshMap: function() {

		function centerMap (response) {
			if(typeof response.Placemark == 'undefined')
				return false;
			// Retrieve the object
			place = response.Placemark[0];
			
			// Retrieve the latitude and longitude
			point = new GLatLng(place.Point.coordinates[1],
								place.Point.coordinates[0]);
			
			//update form values
			$('#tourLatitude').val(place.Point.coordinates[1]);
			$('#tourLongitude').val(place.Point.coordinates[0]);
								
			// determine the zoom level by how much address info we have
			zoom = 3;
			if ($('#tourAddress').val() != '')
				zoom = 14;
			else if ($('#tourCity').val() != '')
				zoom = 11;
			else if ($('#tourState').val() != '' || $('#tourZip').val() != '')
				zoom = 9;
			else if ($('#tourCountryId').val() != '')
				zoom = 3;
			
			// Center the map on this point
			map.setCenter(point, zoom);
			
			//remove the old marker
			if(typeof marker != "undefined")
				map.removeOverlay(marker);

			// Create a marker
			//marker = new GMarker(point,tvIcon);
			marker = new GMarker(point, {icon:tvIcon, draggable:true});
			
			// Add the marker to map
			map.addOverlay(marker);

			// update lat/lon after dragging done (10/16/11)
			GEvent.addListener(marker, "dragend", function() {
				var coords = marker.getLatLng();
				$("#tourLatitude").val(coords.lat());
				$("#tourLongitude").val(coords.lng());
			});
			
		}
		
		address = $('#tourAddress').val().replace(/\n/, '');
		address += ", "+$('#tourCity').val();
		address += ", "+$('#tourState').val();
		address += ", "+$('#tourZip').val();
		address += $('#tourCountryId :selected').text();
		
		// Retrieve location information, pass it to addToMap()
		geocoder.getLocations(address, centerMap);
		
	},

	refreshMapCountry: function() {

		function centerMapOnCountry (response) {
			if(typeof response.Placemark == 'undefined')
				return false;
			// Retrieve the object
			place = response.Placemark[0];
			
			// Retrieve the latitude and longitude
			point = new GLatLng(place.Point.coordinates[1],
								place.Point.coordinates[0]);
			
			//update form values
			$('#tourLatitude').val(place.Point.coordinates[1]);
			$('#tourLongitude').val(place.Point.coordinates[0]);
								
			// Center the map on this point
			map.setCenter(point, 3);
			
			//remove the old marker
			if(typeof marker != "undefined")
				map.removeOverlay(marker);

			// Create a marker
			marker = new GMarker(point,tvIcon);
			
			// Add the marker to map
			map.addOverlay(marker);
		}
		
		address = $('#tourCountryId :selected').text();
		
		// Retrieve location information, pass it to addToMap()
		geocoder.getLocations(address, centerMapOnCountry);
		
	},

	refreshMapZip: function() {

		function centerMapOnZip (response) {
			if(typeof response.Placemark == 'undefined')
				return false;
			// Retrieve the object
			place = response.Placemark[0];
			
			// Retrieve the latitude and longitude
			point = new GLatLng(place.Point.coordinates[1],
								place.Point.coordinates[0]);
			
			//update form values
			$('#tourLatitude').val(place.Point.coordinates[1]);
			$('#tourLongitude').val(place.Point.coordinates[0]);
								
			// Center the map on this point
			map.setCenter(point, 11);
			
			//remove the old marker
			if(typeof marker != "undefined")
				map.removeOverlay(marker);
				
			// Create a marker
			marker = new GMarker(point,tvIcon);
			
			// Add the marker to map
			map.addOverlay(marker);
		}
		
//		address = $('#tourZip').val();

		address = ", "+$('#tourZip').val();
		address += $('#tourCountryId :selected').text();

		// Retrieve location information, pass it to addToMap()
		geocoder.getLocations(address, centerMapOnZip);
		
	},

	refreshMapAddress: function() {

		function centerMapOnAddress (response) {
			if(typeof response.Placemark == 'undefined')
				return false;
			// Retrieve the object
			place = response.Placemark[0];
			
			// Retrieve the latitude and longitude
			point = new GLatLng(place.Point.coordinates[1],
								place.Point.coordinates[0]);
			
			//update form values
			$('#tourLatitude').val(place.Point.coordinates[1]);
			$('#tourLongitude').val(place.Point.coordinates[0]);
								
			zoom = 11;
			if ($('#tourAddress').val() != '')
				zoom = 14;
			
			// Center the map on this point
			map.setCenter(point, zoom);
			
			//remove the old marker
			if(typeof marker != "undefined")
				map.removeOverlay(marker);
				
			// Create a marker
			marker = new GMarker(point,tvIcon);
			
			// Add the marker to map
			map.addOverlay(marker);
		}
		
		address = $('#tourAddress').val().replace(/\n/, '');
		address += ", "+$('#tourCity').val();
		address += ", "+$('#tourState').val();
		address += ", "+$('#tourZip').val();
		address += $('#tourCountryId :selected').text();

		// Retrieve location information, pass it to addToMap()
		geocoder.getLocations(address, centerMapOnAddress);
		
	}

}
