

var map = null;
var geocoder = null;

function initialize() {
  if (GBrowserIsCompatible()) {
	
	map = new GMap2(document.getElementById("map_canvas"));        	
	geocoder = new GClientGeocoder();
	map.addControl(new GSmallMapControl());	
	map.addControl(new GMapTypeControl());

	if(cordinate!="") showAddressByCord(cordinate);
	else showAddress(address);
  }
}


function showAddress(address) {
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (!point) {
		  alert(address + " not found");
		} else {
		  map.setCenter(point, 16);
		  var marker = new GMarker(point);
		  map.addOverlay(marker);
		}
	  }
	);
  }
}

function showAddressByCord(cordinate) {
   
  if (GBrowserIsCompatible()) {
	  
	tmp=cordinate.split(',');  
	var pos = new GLatLng(tmp[0],tmp[1]);
	// Aggiunge dei controlli per lo zoom e lo spostamento 
	map.addControl(new GSmallMapControl());	
	map.setCenter(pos, 16);
	
	function createMarker(point, description) {
		  var marker = new GMarker(point);
		  /*GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(description);
		  });*/
		  return marker;
	}
					
	map.addOverlay(createMarker(pos, "")); 
	   
  }
}

window.onload=initialize;
window.onunload=GUnload;

