	// Update the main map
	function ShowMap() {
		if ( sLayerName != "" || sFieldName != "" || sFieldValue != "" ) {
				
			// Find out the new Easting and Northing of the selected feature
			if ( FindCoordinatesFromLayerSearch() == true ) {
		
				// Peform Layer Search
				UpdateMapLayerSearch();
			
				// Update the Geoset
				UpdateOverviewMap();
			
				MapWidthTag.innerHTML = "<span>MapWidth: " + Zoom + " meters</span>";
				
			} else {
			
				// As there was a problem with the layer search, switch to normal search
				DefaultMap();
				
			}
			
		} else {
			// Load the default map as there is no layer search
			DefaultMap();
		}
	}
	
	// Default start map
	function DefaultMap() {
		// Update the Geoset
		UpdateOverviewMap();
		// Select the correct zoom level
		SelectZoomLevelIndicator();
		MapWidthTag.innerHTML = "<span>MapWidth: " + Zoom + " meters</span>";
		map.src = 'http://' + Domain + '/' + Virtual + '/' + 'getmapimage.asp?theme=LDFopenV&layername=' + sLayerName + '&FieldName=' + sFieldName + '&FieldValue=' + sFieldValue + '&Zoom=' + Zoom + '&ZoomToSearch=false&MapWidth=' + MapWidth + '&MapHeight=' + MapHeight + "&easting=" + Easting + "&northing=" + Northing + '&LabelText=380,628,Local Development Framework Maps&PointCoordinates=pixel&LabelStyle=s2';
		// beware, setting a label outside the lower bound generates a js error.
	}
	
	function FindCoordinatesFromLayerSearch() {
	
		var xmlDoc;
		var bReturn = false;
		
		if (document.implementation && document.implementation.createDocument) {
			xmlDoc = document.implementation.createDocument("", "", null);
		} else if (window.ActiveXObject) {
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		}
	
		var sURL = "http://" + Domain  + "/" + Virtual;
		sURL += "/dialogbox_MapInformation.asp?theme=" + theme + "&layername=" + sLayerName + "&fieldname=" + sFieldName + "&fieldvalue=" + sFieldValue + "&mapmode=GetBounds";

		xmlDoc.async = false; // Tell the Xml document to wait until the document has been complete read
		xmlDoc.load( sURL );

		rootNode = xmlDoc.documentElement;
		
		if ( rootNode.childNodes.length > 0 ) {
		
			if ( rootNode.nodeName.toLowerCase() != "planaccesserror" ) {
				
				if (BrowserName == "Netscape") {				
					Easting = parseInt(rootNode.childNodes.item(4).firstChild.nodeValue);
				} else {
					Easting = parseInt(rootNode.childNodes.item(4).text);
				}
				
				if (BrowserName == "Netscape") {
					Northing = parseInt(rootNode.childNodes.item(5).firstChild.nodeValue);
				} else {
					Northing = parseInt(rootNode.childNodes.item(5).text);
				}
				
				if (BrowserName == "Netscape") {
					Zoom = parseInt(rootNode.childNodes.item(6).firstChild.nodeValue);
				} else {
					Zoom = parseInt(rootNode.childNodes.item(6).text);
				}
				
				bReturn = true;
				
			}
			
		}
		
		xmlDoc = null;
		return bReturn;
	}
	
	function UpdateMapLayerSearch() {
		
		sURL = "http://" + Domain + "/" + Virtual + "/GetMapImage.asp?theme=" + theme;
		sURL += "&mapheight=" + MapHeight + "&mapwidth=" + MapWidth;
		sURL += "&layername=" + sLayerName + "&FieldName=" + sFieldName + "&fieldvalue=" + sFieldValue;
		
		// Fetch the new image
		map.src = sURL;
		
	}
	
	// Update the map with the new layer selection
	function UpdateMap() {

		var x = 0;
		var sURL = "";

		sURL = "http://" + Domain + "/" + Virtual + "/GetMapImage.asp?theme=" + theme;
		sURL += "&layers=" + ReturnVisibleLayers();

		// Add the hidden layercontrol layers to the GetMapImage call
		for ( x = 0; x < HiddenLayers.length; x++ ) {

			sURL += HiddenLayers[x] + ",";
		}
		sURL += "&mapheight=" + MapHeight + "&mapwidth=" + MapWidth + "&easting=" + Easting + "&northing=" + Northing + "&zoom=" + Zoom;
		sURL += "&maxzoomlevel=" + Zoom + "&MinZoomLevel=" + MinZoomLevel;
		sURL += "&LabelText=380,628,LDF Proposals Maps&PointCoordinates=pixel&LabelStyle=s2";
		
		if ( bMapPointer == true ) {
			sURL += "&arrowpointer=true";
			bMapPointer = false;
		}

		// Fetch the new image
		map.src = sURL;

		// Update the Geoset
		UpdateOverviewMap();

		MapWidthTag.innerHTML = "<span>MapWidth: " + Zoom + " meters</span>";

	}
	
	function UpdateOverviewMap() {

		var sOverURL = '';
		OverHeight = 240;
		OverWidth = 360;

		sOverURL = "http://" + Domain + "/" + Virtual + "/GetMapImage.asp?theme=" + OverviewMap + "&arrowpointer=true"
		sOverURL += "&mapheight=" + OverHeight + "&mapwidth=" + OverWidth + "&easting=" + Easting + "&northing=" + Northing + "&zoom=" + Zoom*10;
		sOverURL += "&maxzoomlevel=" + Zoom*2.5; 

		theMap.src = sOverURL;

	}
	
	function MoveMap( iEasting, iNorthing, iZoom ) {

		Easting = iEasting;
		Northing = iNorthing;
		Zoom = iZoom;

		// Select the correct zoom level
		SelectZoomLevelIndicator();

		UpdateMap();

	}
	
	/* Nav */
	
	function ZoomMapIn( mouseX, mouseY ) {
		
		// Calculate the bounds
		var mapX1 = Easting - ( Zoom / 2 )
		var mapX2 = Easting + ( Zoom / 2 )
		var mapY1 = Northing - Math.round(((Zoom / 2) * (MapHeight / MapWidth)));
		var mapY2 = Northing + Math.round(((Zoom / 2) * (MapHeight / MapWidth)));
		if ( parseInt(Zoom / 2) < MinZoomLevel ) {
			Zoom = MinZoomLevel;
		} else {
			Zoom = Zoom / 2;
		}
		
		Easting = Math.round((mouseX / MapWidth * (mapX2 - mapX1) + mapX1));
		Northing = Math.round(mapY2 - mouseY / MapHeight * (mapY2 - mapY1));
		
		// Select the correct zoom level
		SelectZoomLevelIndicator();
		
		UpdateMap();
	}
	
	function ZoomMapOut( mouseX, mouseY ) {
		
		// Calculate the bounds
		var mapX1 = Easting - ( Zoom / 2 )
		var mapX2 = Easting + ( Zoom / 2 )
		var mapY1 = Northing - Math.round(((Zoom / 2) * (MapHeight / MapWidth)));
		var mapY2 = Northing + Math.round(((Zoom / 2) * (MapHeight / MapWidth)));
		// Only zoom out if under the max zoom level
		if ( (Zoom * 2) < MaxZoomLevel ) {
			Zoom = Zoom * 2;
		}
			
		Easting = Math.round((mouseX / MapWidth * (mapX2 - mapX1) + mapX1));
		Northing = Math.round(mapY2 - mouseY / MapHeight * (mapY2 - mapY1));
		
		// Select the correct zoom level
		SelectZoomLevelIndicator();
		
		UpdateMap();
	}
	
	function PanCoordinates(x1, y1, x2, y2) {
		
		// Calculate the new bounds
		var mapX1 = Easting - ( Zoom / 2 )
		var mapX2 = Easting + ( Zoom / 2 )
		var mapY1 = Northing - Math.round(((Zoom / 2) * (MapHeight / MapWidth)));
		var mapY2 = Northing + Math.round(((Zoom / 2) * (MapHeight / MapWidth)));
		
		// Work out the new center X & Y
		var mapX = Math.round((x2 / MapWidth * (mapX2 - mapX1) + mapX1));
		var mapY = Math.round(mapY2 - y2 / MapHeight * (mapY2 - mapY1));
	
		var oldCentreX = (mapX2-mapX1)/2+mapX1
		var oldCentreY = (mapY1-mapY2)/2+mapY2
	
		// Calculate the new X and Y
		Easting = oldCentreX - mapX + mapX1
		Northing = oldCentreY - mapY + mapY2	
		
		UpdateMap();
	}
	
	// Calculations which move the map to the new position by generating the new BNG coordinates
	function PanMap( mouseX, mouseY ) {
		
		// Calculate the new bounds
		var mapX1 = Easting - ( Zoom / 2 )
		var mapX2 = Easting + ( Zoom / 2 )
		var mapY1 = Northing - Math.round(((Zoom / 2) * (MapHeight / MapWidth)));
		var mapY2 = Northing + Math.round(((Zoom / 2) * (MapHeight / MapWidth)));
			
		// Work out the new center X & Y
		Easting = Math.round((mouseX / MapWidth * (mapX2 - mapX1) + mapX1));
		Northing = Math.round(mapY2 - mouseY / MapHeight * (mapY2 - mapY1));
			
		UpdateMap();
	}
	
	// Pan Navigation
	function PanBut(sDirection) {

		var mouseX = 0;
		var mouseY = 0;

		switch (sDirection) {
			case 'NW':
				mouseX = Math.round(MapWidth / 4);
				mouseY = Math.round(MapHeight / 4);
				break;
			case 'NN':
				mouseX = Math.round(MapWidth / 2);
				mouseY = Math.round(MapHeight / 4);
				break;
			case 'NE':
				mouseX = Math.round(MapWidth / 4) * 3;
				mouseY = Math.round(MapHeight / 4);
				break;
			case 'WW':
				mouseX = Math.round(MapWidth / 4);
				mouseY = Math.round(MapHeight / 2);
				break;
			case 'EE':
				mouseX = Math.round(MapWidth / 4) * 3;
				mouseY = Math.round(MapHeight / 2);
				break;
			case 'SW':
				mouseX = Math.round(MapWidth / 4);
				mouseY = Math.round(MapHeight / 4) * 3;
				break;
			case 'SS':
				mouseX = Math.round(MapWidth / 2);
				mouseY = Math.round(MapHeight / 4) * 3;
				break;
			case 'SE':
				mouseX = Math.round(MapWidth / 4) * 3;
				mouseY = Math.round(MapHeight / 4) * 3;
				break;
			}

		PanMap(mouseX, mouseY);
	}
	
	function ZoomExtents() {

		Easting = dEastingExtents;
		Northing = dNorthingExtents;
		Zoom = dZoomExtents;
		MoveMap(Easting,Northing,Zoom);
		// SelectZoomLevelIndicator();
	}
	
	
