var map; 
var localSearch = new GlocalSearch();
var curpoint;
var mapzoom = 3;
var longmess = '<div class="PlaceSnip">This is the Watford Town Hall, where the council ' +
'<br>and also houses The Colosseum (an events venue). ' +
'<br>The present building was opened in 1940. Above the doors to the Colosseum , ' +
'<br>there are three panels carved into the brickwork: </div>'
/*
'The left is an abacus, representing accountancy and official routine, ' +
'the centre is a set-square, trowel and compass representing planning and building, ' +
'and the right has some musical instruments, representing the social side of the building.' +
'</div>';
 */

var icon = new GIcon();
icon.image = "http://www.google.com/mapfiles/marker.png";
icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
icon.iconSize = new GSize(20, 34);
icon.shadowSize = new GSize(37, 34);
icon.iconAnchor = new GPoint(10, 34);

   function initialize(Option) { 
      if (GBrowserIsCompatible()) { 
        map = new GMap2(document.getElementById("map")); 
		if (Option == 1)
		   {mapzoom = 8;}
		else
		   {mapzoom = 6;}
		   
        curpoint = new GLatLng(51.658866,-0.372740);
		map.setCenter(curpoint, mapzoom); 
		placeMarkerAtPoint(curpoint,"Watford Band Hut, The Lincolnsfield Centre");
        map.setUIToDefault(); 
      } 
    } 

function usePointFromPostcode(postcode, callbackFunction,Message) {
	
	localSearch.setSearchCompleteCallback(null, 
		function() {
			
			if (localSearch.results[0])
			{		
				var resultLat = localSearch.results[0].lat;
				var resultLng = localSearch.results[0].lng;
				var point = new GLatLng(resultLat,resultLng);
				curpoint = point;
				callbackFunction(point,Message);
			}else{
				alert("Postcode not found!");
			}
		});	
		
	localSearch.execute(postcode + ", UK");
}

function setCenterToPoint(point,Message){
	map.setCenter(point, 14);
	placeMarkerAtPoint(point,Message);
}

function placeMarkerAtPoint(point,markmessage){
	var MarkOpts = {title: markmessage,clickable: true,icon: icon};
	var marker = new GMarker(point,MarkOpts);
	GEvent.addListener(marker, "click", function()
	  { var myHtml = "<b>" + markmessage + "</b><br/>" ;  
	  map.openInfoWindowHtml(point, myHtml);});
	map.addOverlay(marker);
}

function showPointLatLng(point){
	alert("Latitude: " + point.lat() + "\nLongitude: " + point.lng());
}
	
 function SetPostCodeMap(Cell) {
 var postcode = Cell.parentNode.childNodes[3].innerHTML; 
    
if (postcode.length > 6)
{
  var EventMessage = Cell.parentNode.childNodes[1].innerHTML; 
  document.getElementById('mapcaption').innerHTML = EventMessage ;
  usePointFromPostcode(postcode, setCenterToPoint,EventMessage);
  // placeMarkerAtPoint(curpoint,EventMessage); 
}  
}
 
