var map;
function mapContent(url,type){
	loading();
	  if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	  }
	  if (x) {
		x.onreadystatechange = function() {
		  if (x.readyState == 4 && x.status == 200) {
			el = document.getElementById('p5-content');
			el.innerHTML = x.responseText;
			map = new google.maps.Map2(document.getElementById("map"));
			loading();
			mapIsLoaded(type);
		  }
		}
		x.open("GET", '/reserved/maps/'+url, true);
		x.send(null);
	  }	
}

function geocode(){
	map.addControl(new GLargeMapControl3D());
	map.addControl(new GMapTypeControl());
	map.enableScrollWheelZoom();
	GEvent.addDomListener(map, "click", getCoordinate);
}

function createMarker(point) {
  var marker = new GMarker(point);
  /*GEvent.addListener(marker, 'click', function() {
	marker.openInfoWindowHtml('ciao');
  });*/
  return marker;
}

function getCoordinate(overlay, point) {
	if (!overlay) {
		map.clearOverlays();
		var longitude = point.lng();
		var latitude =  point.lat();
		
		var point = new GLatLng(latitude,longitude);
		var marker = createMarker(point);
		map.addOverlay(marker);
		document.getElementById('MAP_LAT').value = latitude;
		document.getElementById('MAP_LNG').value = longitude;
	}
}
