var map;

function openMap()
{
	document.getElementById("map_container").style.display = "block";
	loadMap();
}

function loadMap() 
{
	if (GBrowserIsCompatible()) 
	{
   	map = new GMap2(document.getElementById("map"));
   	
   	var latitude = document.getElementById("addressLatitude").innerHTML;
   	if(latitude == "")
   	{
   		latitude = document.getElementById("addressLatitude").value;
   	}
   	var longitude = document.getElementById("addressLongitude").innerHTML;
   	if(longitude == "")
   	{
	   	longitude = document.getElementById("addressLongitude").value;
	   }
   	
   	if (latitude == "" || longitude == "")
   	{
   	 	latitude = 51.048948;
   		longitude = -114.070873;
   	}

      map.setCenter(new GLatLng(latitude, longitude ), 13);   	
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());   	
   }
}

function showLocationMarker() 
{
	var marker = new GMarker(map.getCenter());
	var message = document.getElementById("location_info_display").innerHTML;	

	GEvent.addListener(marker, "click", function() 
	{
		marker.openInfoWindowHtml(message);
   });

	
	map.addOverlay(marker);
	marker.openInfoWindowHtml(message);
}

function setLocationMarker() 
{
	var marker = new GMarker(map.getCenter(), {draggable: true});
			        
	GEvent.addListener(marker, "dragend", function() 
	{
		map.panTo(marker.getLatLng());
		document.getElementById("addressLatitude").value = marker.getLatLng().lat();
		document.getElementById("addressLongitude").value = marker.getLatLng().lng();
	});
	
	map.addOverlay(marker);
}

function closeMap()
{
	var element = document.getElementById("map_container");
	GUnload();
	element.style.display = "none";		
}
  

