
//----------------------------------------------------------------------------------------------------
// SHOW LANDSCAPE ASSESSMENT LEGENDS
// Called from find_category.jsp
function getLegend(layerRef,returnPage)
{



	if (returnPage == "myLayers")
	{
		parent.MapFrame.theReturnPage = "myLayers"
		
	}
	else
	{
		parent.MapFrame.theReturnPage = "catLayers"
	}



	if (layerRef == "LE018")
	{
    var theURL = webServerName + "/website/intermap/parking_bay.htm"
	}

	else if (layerRef == "CY026")
	{
	var theURL = webServerName + "/website/intermap/sunday_bus_services.htm"
	}
	else if (layerRef == "CY027")
	{
	var theURL = webServerName + "/website/intermap/weekday_bus_services.htm"
	}
	else
	{
	//alert("Sorry there is no legend available for this layer")
	//var theURL = webServerName + "/website/intermap/layers.htm"
	return;
	}


parent.LeftFrame.location=theURL;
}

function zoomToAddress(xIn,yIn)
{
	//HIGHLIGHT SELECTION
	parent.MapFrame.xPointHighlight = xIn;
	parent.MapFrame.yPointHighlight = yIn;
	parent.MapFrame.showHighlighted = true;
	

	var theZoomScale = addressPointZoomScale

	var mWMargin = 0;
	var mHMargin = 0;
	mWMargin = Math.abs(limitRight-limitLeft) * (selectPointMargin /4);
	mHMargin = Math.abs(limitTop-limitBottom) * (selectPointMargin /4);
	var xNum = parseFloat(xIn);
	var yNum = parseFloat(yIn);
	saveLastExtent();
	eLeft = xNum - mWMargin;
	eRight = xNum + mWMargin;
	eTop = yNum + mHMargin;
	eBottom = yNum - mHMargin;
	
	if (parent.ToolFrame.document.forms[0])
	{
		if (parent.ToolFrame.document.forms[0].txtScale)
		{
			parent.ToolFrame.document.forms[0].txtScale.value = parseInt(theZoomScale);
			parent.MapFrame.RecalculateExtent(); 
		}
	}
	else
	{
		
		var factorOldToNew = parseInt(theZoomScale) /  GetMapScale();
	
		var oldWidth = eRight - eLeft;
		var oldHeight = eTop - eBottom;
		var newWidth = oldWidth * factorOldToNew;
		var newHeight = oldHeight * factorOldToNew;
	
		var horIncrement = 0.5 * (newWidth - oldWidth);
		var verIncrement = 0.5 * (newHeight - oldHeight);

		eLeft -= horIncrement;
		eRight += horIncrement;
		eBottom -= verIncrement;
		eTop += verIncrement;	
		
	}

	//Set the age of map
	if (parent.MapFrame.chosenMapAge != "")
	{
		parent.MapFrame.changeMapping(chosenMapAge,false)
	}

	//Refresh the map
	sendMapXML();
}



//-----------------------------------------------------------------------------------------------------------------

// ADDRESSPOINT STUFF
//----------------------------------------------------------------------------------------------------

function showAddresspointSearch()
{
	//Show the search form and draw address points
	parent.MapFrame.doIdentifyAddressPoint = true;
	LayerVisible[getLayerIndexPosn("Addresspoint")]=1;

	parent.LeftFrame.location= webServerName + "/website/intermap/addresspoint.htm";

	sendMapXML()
}

//---------------------------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------------------------


function searchAddressPoint()
{
	var buildNo = parent.LeftFrame.document.addresspoint.buildingNo.value
	var streetName = parent.LeftFrame.document.addresspoint.streetName.value
	var postalTown = parent.LeftFrame.document.addresspoint.postalTown.value
	var postcode = parent.LeftFrame.document.addresspoint.postcode.value
	var organisation = parent.LeftFrame.document.addresspoint.organisation.value
	var buildingName = parent.LeftFrame.document.addresspoint.buildingName.value

	//Check user entered something
	if ((buildNo=="") && (streetName=="") && (postalTown=="") && (postcode=="") && (organisation=="") && (buildingName==""))
	{
		alert("Please enter search criteria")
		return
	}
	else
	{	

		var postcodeLen = postcode.length
		
		//Just postcode
		if ((buildNo=="") && (streetName=="") && (postalTown=="") && (organisation=="") && (buildingName==""))
		{
			if ((postcodeLen > 0) && (postcodeLen <=5))
			{
				alert("Please enter more of the postcode that you would like to find")
				return
			}
		}
		else
		{
			if ((postcodeLen > 0) && (postcodeLen <=2))
			{
				alert("Please enter more of the postcode that you would like to find")
				return
			}
		}

		//If we have a building number, then we will not do a like search on the building no.
		if (buildNo !="")
		{
			//Build the where clause containing building number equals 
			var theWhereClause = 'FEAT.GISDBA.ADDRESSPOINT.BUILDING_NUMBER = \'' + buildNo + '\' AND FEAT.GISDBA.ADDRESSPOINT.STREET_NAME LIKE \'%' + streetName + '%\' AND FEAT.GISDBA.ADDRESSPOINT.POSTAL_TOWN LIKE \'%' + postalTown + '%\' AND FEAT.GISDBA.ADDRESSPOINT.POSTCODE LIKE \'' + postcode + '%\' AND FEAT.GISDBA.ADDRESSPOINT.ORGANISATION LIKE \'%' + organisation + '%\' AND FEAT.GISDBA.ADDRESSPOINT.BUILDING_NAME LIKE \'%' + buildingName + '%\''

		}
		else
		{
			//Build the where clause containing building number like ...
			var theWhereClause = 'FEAT.GISDBA.ADDRESSPOINT.BUILDING_NUMBER LIKE \'%' + buildNo + '%\' AND FEAT.GISDBA.ADDRESSPOINT.STREET_NAME LIKE \'%' + streetName + '%\' AND FEAT.GISDBA.ADDRESSPOINT.POSTAL_TOWN LIKE \'%' + postalTown + '%\' AND FEAT.GISDBA.ADDRESSPOINT.POSTCODE LIKE \'' + postcode + '%\' AND FEAT.GISDBA.ADDRESSPOINT.ORGANISATION LIKE \'%' + organisation + '%\' AND FEAT.GISDBA.ADDRESSPOINT.BUILDING_NAME LIKE \'%' + buildingName + '%\''
		}
		
		parent.MapFrame.showRetrieveData()
		//Pass this where clause to a find function
		parent.LeftFrame.location= webServerName + "/website/intermap/JSP/findAddress.jsp?WHERE=" + escape(theWhereClause) + "&LAYER=" + escape(parent.MapFrame.navigationLayerList[addressArrayRowPos][navigationLayerNamePos]) + "&LAYERALIAS=" + escape("Addresspoints")
	}
}

//---------------------------------------------------------------------------------------------------

// ADDRESSPOINT SEARCH - Called from findAddress.jsp
function zoomToAddressPointCoords(xIn,yIn,OSAPR)
{

	//HIGHLIGHT SELECTION
	parent.MapFrame.xPointHighlight = xIn;
	parent.MapFrame.yPointHighlight = yIn;
	parent.MapFrame.showHighlighted = true;
	
	parent.MapFrame.theOSAPR = OSAPR
	var theZoomScale = queryZoomScale

		

	if (parent.MapFrame.activeLayerName==parent.MapFrame.navigationLayerList[addressArrayRowPos][navigationLayerNamePos])
	{

	
	theZoomScale = addressPointZoomScale

	var theNewQueryString = "";
	var theTempString = "";
	


	//fieldListString = "#ID# #SHAPE# FEAT.GISDBA.ADDRESSPOINT";	
	theNewQueryString = "OSAPR='" + parent.MapFrame.OSAPRString + "'"
	
	
	theNewQueryString=makeXMLsafe(theNewQueryString);
	setQueryString = theNewQueryString;
	
	parent.MapFrame.OSAPRQuery = setQueryString

	
		
		//parent.MapFrame.OSAPRQuery = "OSAPR='" + parent.MapFrame.OSAPRString + "'" 
		//parent.MapFrame.OSAPRQuery=makeXMLsafe(parent.MapFrame.OSAPRQuery);
		parent.MapFrame.findAddressPoint(parent.MapFrame.OSAPRString)
	}
	
	var mWMargin = 0;
	var mHMargin = 0;
	mWMargin = Math.abs(limitRight-limitLeft) * (selectPointMargin /4);
	mHMargin = Math.abs(limitTop-limitBottom) * (selectPointMargin /4);
	var xNum = parseFloat(xIn);
	var yNum = parseFloat(yIn);
	saveLastExtent();
	eLeft = xNum - mWMargin;
	eRight = xNum + mWMargin;
	eTop = yNum + mHMargin;
	eBottom = yNum - mHMargin;
	
	if (parent.ToolFrame.document.forms[0])
	{
		if (parent.ToolFrame.document.forms[0].txtScale)
		{
			parent.ToolFrame.document.forms[0].txtScale.value = parseInt(theZoomScale);
			parent.MapFrame.RecalculateExtent(); 
		}
	}
	else
	{
		var factorOldToNew = parseInt(theZoomScale) /  GetMapScale();
		var oldWidth = eRight - eLeft;
		var oldHeight = eTop - eBottom;
		var newWidth = oldWidth * factorOldToNew;
		var newHeight = oldHeight * factorOldToNew;

		var horIncrement = 0.5 * (newWidth - oldWidth);
		var verIncrement = 0.5 * (newHeight - oldHeight);

		eLeft -= horIncrement;
		eRight += horIncrement;
		eBottom -= verIncrement;
		eTop += verIncrement;		
	}

	//Set the age of map
	if (parent.MapFrame.chosenMapAge != "")
	{
		parent.MapFrame.changeMapping(chosenMapAge,false)
	}

	
	//Refresh the map
	sendMapXML();
}

//-------------------------------------------------------------------------------------------------
function doIdentify()
{
	// Clear Addresspoints
	parent.MapFrame.doIdentifyAddressPoint = false;
	parent.MapFrame.showHighlighted = false;
	
	parent.MapFrame.clickFunction('identify');
}
//----------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------

// ADDRESSPOINT SEARCH
function findAddressPoint(theValue)
{

	
	var theNewQueryString = "";
	var theTempString = "";
		
	theNewQueryString = "OSAPR='" + theValue + "'"
	
	
	theNewQueryString=makeXMLsafe(theNewQueryString);
	setQueryString = theNewQueryString;

	

	parent.MapFrame.OSAPRQuery = setQueryString
	return;


}


//---------------------------------------------------------------------------------------------------





//----------------------------------------------------------------------------------------------------
function unselectTools()
{
	//Set active tool
	parent.ToolFrame.document["zoomin"].src='images/GIS_zoomin_UP.gif'
	parent.ToolFrame.document["zoomout"].src='images/GIS_zoomout_UP.gif'
	parent.ToolFrame.document["pan"].src='images/GIS_drag_UP.gif'
	parent.ToolFrame.document["identify"].src='images/GIS_info_UP.gif'
}

//-------------------------------------------------------------------------------------------------------

function showXY()
{
	unselectTools()

	if (hasLayer("measureBox"))
		hideLayer("measureBox");
	toolMode=-1
	//Show the search form.
	parent.LeftFrame.location= webServerName + "/website/intermap/XY.htm";
}

//----------------------------------------------------------------------------------------------------

function showAdvanced()
{
	var noLayers = 0;
	noLayers = noOfDBLayersOnMap();
	var layerCount=0;

	if (noLayers > 0)
	{
		//Loop through all layers that have been added
		for (i=0; i < noLayers; i++ )
		{
			//If there are layers that are visbile
			if (dataBrowserLayerList[i][dbLayerVisibilityPos]==1)
			{
				//Increment the layer count
				layerCount ++;
			}
		}
	}

	//Show the search form.
	if ((noOfDBLayersOnMap()!=0) && (layerCount !=0))
	{
		parent.LeftFrame.location= webServerName + "/website/intermap/findNearest.htm";
	}
	else
	{
		parent.LeftFrame.location= webServerName + "/website/intermap/addMapsForfindNearest.htm";
	}
}

//----------------------------------------------------------------------------------------------------

function showMyLayers()
{
	var noLayers = 0;
	noLayers = noOfDBLayersOnMap();
	var layerCount=0;

	if (noLayers > 0)
	{
		//Loop through all layers that have been added
		for (i=0; i < noLayers; i++ )
		{
			//If there are layers that are visbile
			if (dataBrowserLayerList[i][dbLayerVisibilityPos]==1)
			{
				//Increment the layer count
				layerCount ++;
			}
		}
	}

	//Show the map layers that the user has loaded
	if ((noOfDBLayersOnMap()!=0) && (layerCount !=0))
	{
		parent.LeftFrame.location= webServerName + "/website/intermap/myLayers.htm";
	}
	else
	{
		parent.LeftFrame.location= webServerName + "/website/intermap/addMapsForMyLayers.htm";
	}
}

//----------------------------------------------------------------------------------------------------

function showSearch()
{
	//Show the search form.
	parent.LeftFrame.location= webServerName + "/website/intermap/search.htm";
}

//----------------------------------------------------------------------------------------------------

function tooManyLayers(obj)
{
	obj.checked = false;
	alert("Only five map layers can be drawn at one time.\n\nTo add this map layer to the map, you must first remove one of the other map layers.")
}

//----------------------------------------------------------------------------------------------------

function showMaps()
{
	//If the user has already added map layers to the map, show them wha they have added, with a link to add more
	//Otherwise, just show them the list of all map layers
	
	//User has added maps from data browser
	if (noOfDBLayersOnMap()!=0)
	{
		parent.LeftFrame.location=webServerName + "/website/intermap/layers.htm";
	}
	else
	{	
		parent.LeftFrame.location=webServerName + "/website/intermap/layers.htm";
	}
}

//----------------------------------------------------------------------------------------------------
function aboutGIS()
{
	parent.LeftFrame.location=webServerName + "/website/intermap/welcome.htm";
}
//----------------------------------------------------------------------------------------------------

function showGISHelp()
{
	//var helpURL="http://www.durham.gov.uk/durhamcc/usp.nsf/pws/Main+-+Help+-+GIS" //'http://www.durham.gov.uk/durhamcc/usp.nsf/pws/GIS+-+Help'

	//var helpURL="http://notesi01/durhamcc/usp.nsf/pws/Main+-+Help+-+GIS" 
        //var helpURL="http://www.durham.gov.uk/durhamcc/usp.nsf/pws/Main+-+Help+-+GIS"
        var helpURL="http://www.durham.gov.uk/Pages/Service.aspx?ServiceId=7070"

	if (parent.opener && !parent.opener.closed)
	{
		parent.opener.location=helpURL;
		parent.opener.focus();
	}
	else
	{
		//var myWin = window.open("http://www.durham.gov.uk/durhamcc/usp.nsf/pws/Main+-+Help+-+GIS")
                var myWin = window.open("http://www.durham.gov.uk/Pages/Service.aspx?ServiceId=7070")
		parent.opener = myWin
	}
}

//----------------------------------------------------------------------------------------------------

function showContactUs()
{
	var contactUsURL='http://www.durham.gov.uk/feedback.nsf/feedback?OpenForm&subject=GIS+Team&forward=ZMAIL_GIS&'
	if (parent.opener && !parent.opener.closed)
	{
		parent.opener.location=contactUsURL;
		parent.opener.focus();
	}
	else
	{
		var myWin = window.open("http://www.durham.gov.uk/feedback.nsf/feedback?OpenForm&subject=GIS+Team&forward=ZMAIL_GIS&")
		parent.opener = myWin
	}
}

//----------------------------------------------------------------------------------------------------

function showContactHAUC()
{
	var contactUsURL='http://www.durham.gov.uk/hauc'
	if (parent.opener)
	{
		parent.opener.location=contactUsURL;
		parent.opener.focus();
	}
	else
	{
		//alert("Sorry, unable to show this page.");
		parent.location="http://www.durham.gov.uk/feedback.nsf/feedback?OpenForm&subject=GIS+Team&forward=ZMAIL_GIS&"
	}
}

//----------------------------------------------------------------------------------------------

function showContactHAL()
{
	var contactUsURL='http://www.durham.gov.uk/hal'
	if (parent.opener)
	{
		parent.opener.location=contactUsURL;
		parent.opener.focus();
	}
	else
	{
		//alert("Sorry, unable to show this page.");
		parent.location="http://www.durham.gov.uk/feedback.nsf/feedback?OpenForm&subject=GIS+Team&forward=ZMAIL_GIS&"
	}
}
//----------------------------------------------------------------------------------------------

function showContactRoadWorks()
{
	var contactUsURL='http://www.durham.gov.uk/durhamcc/usp.nsf/pws/Transport+and+Streets+-+Road+Works+and+Improvements'
	if (parent.opener)
	{
		parent.opener.location=contactUsURL;
		parent.opener.focus();
	}
	else
	{
		//alert("Sorry, unable to show this page.");
		parent.location="http://www.durham.gov.uk/feedback.nsf/feedback?OpenForm&subject=GIS+Team&forward=ZMAIL_GIS&"
	}
}


//----------------------------------------------------------------------------------------------

function getLayersInCategory(theCategory, theAlias)
{
	//Set the active category
	parent.MapFrame.activeCategory = theCategory
	parent.MapFrame.activeCategoryAlias = theAlias

	//Set the URL
	var theURL = webServerName + "/website/intermap/JSP/find_category.jsp?CATEGORY=" + parent.MapFrame.activeCategory + "&ALIAS=" + escape(theAlias)
	
	//Now, get a list of layers that the user has already drawn, and pass these to the jsp page, so that
	//the page can show these as already drawn.
	var noLayers = noOfDBLayersOnMap();

	//If layers have been drawn
	var theLayerList = "LAYERS=";

	//Flag - no visible layers to draw.
	var visibleLayersToDraw=false;

	//A count of the number of layers
	var layerCount=0;
	
	//If layers have been added
	if (noLayers > 0)
	{
		//Loop through all layers that have been added
		for (i=0; i < noLayers; i++ )
		{
			//If there are layers that are visbile
			if (dataBrowserLayerList[i][dbLayerVisibilityPos]==1)
			{
				//Set flag to say that visible layers have been found.
				visibleLayersToDraw = true;

				//Increment the layer count
				layerCount ++;

				//If this is the last layer in the list, don't add a comma to the end
				if (i == (noLayers-1))
				{
					//If the layer is visible
					theLayerList +=dataBrowserLayerList[i][dbLayerSDENamePos]
				}
				else //Not the last in the list, so add a comma to the end
				{
					theLayerList +=dataBrowserLayerList[i][dbLayerSDENamePos] + ","
				}
			}
		}
		
		//Append to list if there are visible layers to draw
		if (visibleLayersToDraw==true)
		{
			//layerCount="" + layerCount + "";
			theURL +="&" + theLayerList;
		}
	}

	theURL += "&LAYERCOUNT=" + layerCount

	//alert(theURL)
	parent.LeftFrame.location=theURL;
}

//----------------------------------------------------------------------------------------------------

function noOfDBLayersOnMap()
{
	//Work out the number of databrowser layers on the map
	for (i=0; i<parent.MapFrame.dataBrowserLayerList.length ; i++)
	{
		//If this entry in the array is blank, then this is the number of layers added
		if (dataBrowserLayerList[i][0] == "")
		{
			return i;
		}
	}
	return 0;
}

//----------------------------------------------------------------------------------------------------

function changeLayerVisibility(theRef, theAlias, theSDEName, theRender, theDescription, theType, theSearchField, showMoreInfo, legendImage, showDisclaimer)
{
	//alert(theRef + "\n" + theAlias + "\n" + theSDEName + "\n" + theRender + "\n" + theDescription + "\n" + theType + "\n" + theSearchField)

	//Get a count of the number of map layers that have been drawn - those in the databrowser array ...
	var numOfLayers = noOfDBLayersOnMap()

	//Loop through all layers
	for (i=0; i< numOfLayers; i++ )
	{	
		//If we find the layer we want.
		//alert(dataBrowserLayerList[i][dbLayerSDENamePos])
		if (dataBrowserLayerList[i][dbLayerSDENamePos] == theSDEName)
		{
			//If it is not visible, make it visible and vice versa
			if ((dataBrowserLayerList[i][dbLayerVisibilityPos]=="") || (dataBrowserLayerList[i][dbLayerVisibilityPos]==0))
			{
				dataBrowserLayerList[i][dbLayerVisibilityPos]=1;
			}
			else
			{
				dataBrowserLayerList[i][dbLayerVisibilityPos]=0;
			}
			
			//Refresh the Map
			if ((parent.MapFrame.startX !="") && (parent.MapFrame.startY !=""))
			{
				parent.MapFrame.zoomToCoords(parent.MapFrame.startX,parent.MapFrame.startY)
			}
			else
			{
				sendMapXML()
			}
			return
		}
	}

	//If we get to here, then the layer was not found on the map, so we must add it.
	addSDELayer(theRef, theAlias, theSDEName, theRender, theDescription, theType, theSearchField, showMoreInfo, legendImage)
	
	
	
		//Show Streetworks Disclaimer (Utility works only)
	if ((theRef == 'TS007') && (showDisclaimer == 'Y'))
		{
		parent.LeftFrame.location = webServerName + "/website/intermap/hauc_disclaimer.htm";
		}
	
}

//----------------------------------------------------------------------------------------------------

function addSDELayer(theRef, theAlias, theSDEName, theRender, theDescription, theType, theSearchField, showMoreInfo, legendImage)
{
	//alert(theRef + "\n" + theAlias + "\n" + theSDEName + "\n" + theRender + "\n" + theDescription + "\n" + theType + "\n" + theSearchField)

	//Get a count of the number of map layers that have been drawn
	var numOfLayers = noOfDBLayersOnMap()

	//Check that the layer has not already been added and is currently visible. If it has already been added and is currently invisible,
	//make it visible, otherwise inform user that it is already displayed, and exit.
	for (i=0; i< numOfLayers; i++ )
	{
		//If we already have this layer in the array (use SDE name to test)
		if (dataBrowserLayerList[i][dbLayerSDENamePos] == theSDEName)
		{
			//If the layer is currently invisible
			if (dataBrowserLayerList[i][dbLayerVisibilityPos]==0)
			{
				//Make it visible
				dataBrowserLayerList[i][dbLayerVisibilityPos]==1;
				
				//Refresh map
				sendMapXML();
				return;
			}
			else //Layer is already added and is curently visible.
			{
				alert(theAlias + " is already visible on the map")
				return;
			}
			
			//Layer is already added, so bail
			return;
		}
	}	

	//Replace with " - prevents HTML errors
	var tempRender = ""
	tempRender = theRender
	tempRender = "" + tempRender + ""; 
	
	//Replace with quotes.
	var pos = tempRender.indexOf("&apos;")
	
	//This fails in NETSCAPE
	while (pos !=-1)
	{
		tempRender = tempRender.replace('&apos;', '"')
		pos = tempRender.indexOf("&apos;")
	}
	//alert("Renderer: " + tempRender)
	
	//Set it back ..
	theRender = tempRender;

	//Add the entries to the array.
	dataBrowserLayerList[numOfLayers][dbLayerRefPos]=theRef;
	dataBrowserLayerList[numOfLayers][dbLayerAliasPos]=theAlias;
	dataBrowserLayerList[numOfLayers][dbLayerSDENamePos]=theSDEName;
	dataBrowserLayerList[numOfLayers][dbLayerSDERenderPos]=theRender;
	dataBrowserLayerList[numOfLayers][dbLayerDescriptionPos]=theDescription;
	dataBrowserLayerList[numOfLayers][dbLayerTypePos]=theType;
	dataBrowserLayerList[numOfLayers][dbLayerSearchFieldPos]=theSearchField
	dataBrowserLayerList[numOfLayers][dbLayerShowMoreInfoPos]=showMoreInfo
	dataBrowserLayerList[numOfLayers][dbLayerImagePos]=legendImage

	//Make layer visible
	dataBrowserLayerList[numOfLayers][dbLayerVisibilityPos]=1;

	//Set flag to show layers have been added
	dbLayerAdded=true;

	//Refresh Map
	if (parent.MapFrame.activeCategory !="")
	{
		//getLayersInCategory(parent.MapFrame.activeCategory,parent.MapFrame.activeCategoryAlias);
		sendMapXML();
	}




}

//----------------------------------------------------------------------------------------------------

function addAllLayers()
{

}

//----------------------------------------------------------------------------------------------------

function drawDynamicLayersOnMap()
{
	//Get a count of the number of map layers that have been drawn
	var numOfLayers = noOfDBLayersOnMap()
	
	//The XML String to return
	var customString = "";

	//If the user has added layers to the map
	if (numOfLayers > 0)
	{
		//For every layer the user has added ..
		for (i=0; i< numOfLayers; i++ )
		{
			//If it's visibility is set to visible, write out XML to draw it
			if (parent.MapFrame.dataBrowserLayerList[i][dbLayerVisibilityPos]==1)
			{
				customString += '<LAYER type="featureclass" name="' + dataBrowserLayerList[i][dbLayerAliasPos]  + '" visible="true" id="' + eval(parent.MapFrame.dynamicLayerIDStartPosition + i) + '">\n';	
			}
			else
			{
				customString += '<LAYER type="featureclass" name="' + dataBrowserLayerList[i][dbLayerAliasPos]  + '" visible="false" id="' + eval(parent.MapFrame.dynamicLayerIDStartPosition + i) + '">\n';
			}
			
			//Set the dataset
			customString += '<DATASET name="' + dataBrowserLayerList[i][dbLayerSDENamePos] + '" type="' + dataBrowserLayerList[i][dbLayerTypePos] + '" workspace="' + parent.MapFrame.dynamicSDEWorkSpace + '" />\n';
			
			//XML to render the layer - take from database if it was there ...
			if (dataBrowserLayerList[i][dbLayerSDERenderPos] != "")
			{
				customString += dataBrowserLayerList[i][dbLayerSDERenderPos]
			}
			else //Not defined in database, so use some default values.
			{
				//Default values for POINTS
				if (dataBrowserLayerList[i][dbLayerTypePos]=="point")
				{
					customString += '<SIMPLERENDERER>\n<SIMPLEMARKERSYMBOL color="255,0,0" width="15">\n</SIMPLEMARKERSYMBOL>\n</SIMPLERENDERER>\n';
				}
				//LINES
				else if (dataBrowserLayerList[i][dbLayerTypePos]=="line")
				{
					customString += '<SIMPLERENDERER>\n<SIMPLELINESYMBOL color="255,0,0" width="3">\n</SIMPLELINESYMBOL>\n</SIMPLERENDERER>\n';
				}
				//POLYGON
				else if (dataBrowserLayerList[i][dbLayerTypePos]=="polygon")
				{
					customString += '<SIMPLERENDERER>\n<SIMPLEPOLYGONSYMBOL color="255,0,0">\n</SIMPLEPOLYGONSYMBOL>\n</SIMPLERENDERER>\n';
				}
				//OTHERS??
				else// not known, use polygon
				{
					customString += '<SIMPLERENDERER>\n<SIMPLEPOLYGONSYMBOL color="255,0,0">\n</SIMPLEPOLYGONSYMBOL>\n</SIMPLERENDERER>\n';
				}
			}
				
			//FInish off the layer
			customString += '</LAYER>\n\n';

			//Show user the renderer XML
			//alert(customString)
		}
	}
	else
	{
		customString = ""
	}

	return customString;
}

//----------------------------------------------------------------------------------------------------

function layerIsDrawn(layerName)
{
	//Get number of maps added
	var numOfLayers = parent.MapFrame.noOfDBLayersOnMap()

	//Loop through them all, writing out their details
	for (i=0; i< numOfLayers; i++ )
	{
		if (dataBrowserLayerList[i][dbLayerSDENamePos]==layerName)
		{
			return true;
		}
	}
	return false;
}

//----------------------------------------------------------------------------------------------------

function jspIdentify(e)
{
	showRetrieveData();

	var theXCoord=0;
	var theYCoord=0;	
	
	//Convert to map coords
	getMapXY(mouseX, mouseY);
	theXCoord = mapX;
	theYCoord = mapY;

	pixelTolerance = 8;
	searchTolerance = (xDistance/iWidth) * pixelTolerance
	
	var tempWest = theXCoord - searchTolerance; //minx
	var tempNorth = theYCoord + searchTolerance; //maxy
	var tempEast = theXCoord + searchTolerance; //maxx
	var tempSouth = theYCoord - searchTolerance; //miny

	// Identify AddressPoint
	if (parent.MapFrame.doIdentifyAddressPoint == true)
	{
	theQueryLayers = "FEAT.GISDBA.ADDRESSPOINT-Addresspoint";
	theQueryLayers = "&LAYERS=" + escape(theQueryLayers);
	var theURL = webServerName + "/website/intermap/jsp/jspAddressPointIdentify.jsp?MINX=" + tempWest + "&MAXY=" + tempNorth + "&MAXX=" + tempEast + "&MINY=" + tempSouth + theQueryLayers;
	parent.LeftFrame.location= theURL;
	hideRetrieveData();
	return
	}
	//-----------------------------------



	//What layers are we going to query.
	var theQueryLayers = ""

	//Get number of maps added
	var numOfLayers = parent.MapFrame.noOfDBLayersOnMap()
	
	//For each dynamic layer added, add this to the string.
	if (numOfLayers !=0)
	{
		for (i=0; i< numOfLayers ; i++ )
		{
			if (parent.MapFrame.dataBrowserLayerList[i][dbLayerVisibilityPos] == 1)
			{
				theQueryLayers = theQueryLayers + parent.MapFrame.dataBrowserLayerList[i][dbLayerSDENamePos] + "-" + parent.MapFrame.dataBrowserLayerList[i][dbLayerAliasPos] + "_" + parent.MapFrame.dataBrowserLayerList[i][dbLayerShowMoreInfoPos] + ",";
			}
		}
	}

	//If we have some layers to query
	if (theQueryLayers != "")
	{
		theQueryLayers = "&LAYERS=" + escape(theQueryLayers);
		
		var theURL = webServerName + "/website/intermap/jsp/jspIdentify.jsp?MINX=" + tempWest + "&MAXY=" + tempNorth + "&MAXX=" + tempEast + "&MINY=" + tempSouth + theQueryLayers;
		parent.LeftFrame.location= theURL;
	}
	else
	{
		hideRetrieveData();
		alert("No map layers have been added to the map, or no map layers are currently visible.\n\nPlease ensure that the map layer you want to query is currently visible.")
	}

	hideRetrieveData();
}

//----------------------------------------------------------------------------------------------------

function getHistoric()
{
	var theURL="";

	var scale = parent.MapFrame.GetMapScale();	
	if (scale > 10000) //Not allowed
	{
		theURL = "../intermap/no_historic.htm";
		parent.LeftFrame.location= theURL;
	}
	else
	{
		theURL = "../intermap/historicMapLayers.htm";
		parent.LeftFrame.location= theURL;
	}	
}

//----------------------------------------------------------------------------------------------------

function showHistoricLayers()
{
	var theURL="";
	theURL = "../intermap/historicMapLayers.htm";
	parent.LeftFrame.location= theURL;
}

//----------------------------------------------------------------------------------------------------

function zoomToHistoric()
{
		//Make all other layers invisible except histocial 1st edition.
		LayerVisible[getLayerIndexPosn("10,000")]=0;
		LayerVisible[getLayerIndexPosn("OS Vector (Master Map)")]=0;
		LayerVisible[getLayerIndexPosn("OS Text")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1980-1994")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1970-1979")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1960-1969")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1951-1959")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1938-1950")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1919-1926")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1894-1899")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1856-1865")]=1;
		LayerVisible[getLayerIndexPosn("Photos")]=0;
	
	parent.ToolFrame.document.forms[0].txtScale.value = parseInt("10000");
	parent.MapFrame.RecalculateExtent()
	parent.MapFrame.sendMapXML();
	//getHistoric()
}

//----------------------------------------------------------------------------------------------------

function resetPreviousSearches()
{
	//Reset any previous searches - sets variables to ""
	parent.MapFrame.OSCARQuery = ""; //Remove any roads that have been added top to the top of the map

	//Remove any map layers that have been added to the map
	parent.MapFrame.dynamicLayerIDStartPosition=1000;

	//Has a layer been added yet?
	parent.MapFrame.dbLayerAdded=false;

	//Initialise the multidimensional array for data browser - populated by database query.
	parent.MapFrame.dataBrowserLayerList = new Array(parent.MapFrame.maxNoOfDataBrowserLayersAllowed); 
	for (i=0; i<parent.MapFrame.dataBrowserLayerList.length ; i++)
	{
		parent.MapFrame.dataBrowserLayerList[i] = new Array("","","","","","","","","");
	}

	parent.MapFrame.activeLayerIsDynamic=false;
	
	//What is the active layer
	parent.MapFrame.activeLayerName="";

	//If the user has just added/removed a layer, we need to show this.
	var url = parent.LeftFrame.location
	url = "" + url
	var thePos = url.indexOf("/findNearest.htm")
	if (thePos !=-1)
	{
		parent.LeftFrame.location="../intermap/addMapsForFindNearest.htm";
	}

	var thePos = url.indexOf("/search.htm")
	if (thePos !=-1)
	{
		parent.LeftFrame.location="../intermap/search.htm";
	}

	var thePos = url.indexOf("/myLayers.htm")
	if (thePos !=-1)
	{
		parent.LeftFrame.location="../intermap/addMapsForMyLayers.htm";
	}
}

//----------------------------------------------------------------------------------------------------

function searchActiveLayer(theFindString)
{	
	//Validate user query.
	var pos = theFindString.indexOf("'")
	if (pos !=-1)
	{
		alert("The keyword contains a restricted character.")
		return
	}

	//Validate user query.
	var pos = theFindString.indexOf("\"")
	if (pos !=-1)
	{
		alert("The keyword contains a restricted character.")
		return
	}

	//Validate user query.
	var pos = theFindString.indexOf("%")
	if (pos !=-1)
	{
		alert("The keyword contains a restricted character.")
		return
	}
	
	//Validate user query.
	if ((theFindString.length < 1) || (theFindString == "") || (theFindString == " "))
	{
		alert("Please provide more information")
		return
	}

	//Postcode search.
	if ((theFindString.length <=4) && (parent.MapFrame.activeLayerName == navigationLayerList[postcodeArrayRowPos][navigationLayerNamePos]))
	{
		alert("Please provide at least five characters for the postcode search")
		return
	}

	//Postcode search.
	if (parent.MapFrame.activeLayerName == navigationLayerList[postcodeArrayRowPos][navigationLayerNamePos])
	{
		//Format string for the postcode search.
		var theLen = theFindString.length;
		var fourthChar = "";
		
		//Six figure postcode - must contain a space for the fourth character.
		if (theLen == 6)
		{
			//Get the fourthChar
			fourthChar = theFindString.substring(3,4);

			//If the fourthChar is not a " ", insert one at this position.
			if (fourthChar != " ")
			{
				var left=theFindString.substring(0,3);
				var right = theFindString.substring(4,theFindString.length);
				theFindString = left + " " + fourthChar + right
				//alert(left)
				//alert(right)
			}
		}
		else if (theLen > 7) //Seven figure postcode - must not contain a space for the fourth character.
		{
			theFindString = theFindString.replace(" ","");
		}
	}

	//Try and write a cookie, saves the last thing the user searched for
	//parent.MapFrame.saveCookie("LASTSEARCHTEXT",theFindString).

	
	//If the user wants to do a road search, we must do it a different way. We select a distinct road name, then
	//use the QueryServer to zoom to the extent of all of the roads.
	if (parent.MapFrame.activeLayerName == navigationLayerList[OSCARArrayRowPos][navigationLayerNamePos])
	{
		var theURL = "../intermap/JSP/findUniqueOSCAR.jsp?OSCAR_NUM=" + theFindString;

		//If searching the roads layer and the user has chosen an historic layer, we must tell user that the
		//historic layer may not be visible?
		var isHistoric=-1;
		isHistoric = parent.MapFrame.chosenMapAge.indexOf("Historic")
		if (isHistoric !=-1)
		{
			theURL +="&HISTORIC=YES";
		}
		
		parent.MapFrame.showRetrieveData();
		parent.LeftFrame.location = theURL;
		return
	}


	//If we are searching a navigational layer
	if (activeLayerIsDynamic==false)
	{
		//We are about to query a navigational layer ...
		if (parent.MapFrame.activeLayerName !="")
		{			
			//Get indexPosn of this layer
			var i = null;
			for (i=0; i < navigationLayerList.length-1; i++)
			{
				//Check the names
				if (navigationLayerList[i][navigationLayerNamePos]==activeLayerName)
				{
					break;
				}
			}
			
			//Generate a URL to send to JSP/Servlet
			var theURL = webServerName + "/website/intermap/JSP/findfeatures.jsp?LAYER=" + activeLayerName + "&SEARCHSTRING=" + escape(theFindString) ;
			
			//Add alias, if we have one ..
			if ((navigationLayerList[i][navigationLayerAliasPos]) && (navigationLayerList[i][navigationLayerAliasPos] != ""))
			{
				theURL +="&LAYERALIAS=" + escape(navigationLayerList[i][navigationLayerAliasPos])
			}

			//Add Search field, if we have one - we should have ..
			if (navigationLayerList[i][navigationLayerSearchFieldPos] != "")
			{
				theURL +="&SEARCHCOLUMN=" + escape(navigationLayerList[i][navigationLayerSearchFieldPos])
			}

			//Go to the JSP/Servlet
			//alert(theURL)
			parent.MapFrame.showRetrieveData();
			parent.LeftFrame.location = theURL;
		}
		else
		{
			alert("Sorry, an error has occured and the system is unable to query this particular navigational map layer")
		}
	}
	else //we are searching a dynamic layer
	{
		//We are about to query a dynamic layer, so, check that the dynamic layer is "active" 
		if (parent.MapFrame.activeLayerName !="")
		{
			//alert("Call JSP Find on layer: " + parent.MapFrame.activeDynamicLayerName + " using " + theFindString)
			
			//Get indexPosn of this dynamic layer
			var i = null;
			for (i=0; i<dataBrowserLayerList.length-1; i++)
			{
				//Check the names
				if (dataBrowserLayerList[i][dbLayerSDENamePos]==activeLayerName)
				{
					break;
				}
			}
			
			//Generate a URL to send to JSP/Servlet
			var theURL = webServerName + "/website/intermap/JSP/findFeatures.jsp?LAYER=" + activeLayerName + "&SEARCHSTRING=" + escape(theFindString) ;
			
			//Add alias, if we have one ..
			if ((dataBrowserLayerList[i][dbLayerAliasPos]) && (dataBrowserLayerList[i][dbLayerAliasPos] != ""))
			{
				theURL +="&LAYERALIAS=" + escape(dataBrowserLayerList[i][dbLayerAliasPos])
			}

			//Add Search field, if we have one - we should have ..
			if (dataBrowserLayerList[i][dbLayerSearchFieldPos] != "")
			{
				theURL +="&SEARCHCOLUMN=" + escape(dataBrowserLayerList[i][dbLayerSearchFieldPos])
			}
	
			//Go to the JSP/Servlet
			parent.MapFrame.showRetrieveData();
			parent.LeftFrame.location = theURL;
		}
		else
		{
			alert("Sorry, an error has occured and the system is unable to query this particular map layer")
		}
	}
}

//----------------------------------------------------------------------------------------------------

function setLayer(theLayer)
{
	//alert(theLayer)

	//If the layer is from the mapservice, we can easily query it (unless its the roads). If it is a dynamic layer, we must do it
	//another way - check to see which it is by its name.

	/*toolMode=9;
	panning=false;
	zooming=false;
	selectBox=false;
	shapeSelectBuffer = false;
	queryStartRecord=1;
	
	LayerFields.length=1;
	LayerFieldType.length=1;
	LayerFieldCount=0;
	
	fieldIndex=0;
	setQueryString="";
	hideLayer("measureBox");
	modeBlurb = modeList[17];

	//Change the active tool to a search.
	showGeocode=false;
	showBuffer=false;

	//Change cursor
	if (isIE)
	{
		document.all.theTop.style.cursor = "default";
		theCursor = document.all.theTop.style.cursor;
	}

	//Refresh tool bar
	parent.ToolFrame.location = webServerName + "/website/intermap/toolbar.htm";
	*/
	//Decide if we are quering a dynamic layer, or navigational layer
	for (var i=0; i < navigationLayerList.length; i++ )
	{
		//alert("Comparing " + navigationLayerList[i][navigationLayerNamePos] + " with " + theLayer)
		if (navigationLayerList[i][navigationLayerNamePos] == theLayer)
		{
			//If we find the layer in the array of navigational layers, then it is not dynamic, so set flag 
			activeLayerIsDynamic = false;
			//alert("Match")
			break;
		}
		else
		{
			//alert("No match")
			activeLayerIsDynamic = true;
		}
	}
	
	//Set the layer to be active
	setActiveLayerName(theLayer)

	//alert("Active layer name: " + activeLayerName + " Dynamic layer: " + activeLayerIsDynamic)
}

//----------------------------------------------------------------------------------------------------

function getLayerIndexPosn(layerName)
{	
	var t = parent.MapFrame;
		
	//loop through all layers in the mapservice.
	var theCount = t.layerCount;
	for (var i=0;i<theCount;i++) 
		{
			//check to see if the layer in the loop is the layer we want the index position of.
			if (parent.MapFrame.LayerName[i] == layerName) 
			{
				return i
				break
			}
		}
		//if the map layer was not found.
		//alert("The map layer:" + layerName + ", was not found by the JavaScript function ''getLayerIndexPosn'' in ''aimsDCCgeneric.js''. Please ensure that this layer exists within the mapService.")
}

//----------------------------------------------------------------------------------------------------

function addWaterMarkToMap()
{
	//If we want to add a water mark to the map
	if (drawWaterMark==true)
	{
		//Watermark 1
		var waterMarkString = "";
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords1 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 2
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords2 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 3
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords3 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 4
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords4 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 5
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords5 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 6
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords6 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 7
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords7 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 8
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords8 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 9
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords9 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 10
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords10 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 11
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords11 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 12
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords12 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 13
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords13 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 14
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords14 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 15
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords15 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		//Watermark 16
		waterMarkString += '<LAYER type="ACETATE" name="theWatermark">\n';		
		waterMarkString += '<OBJECT units="PIXEL">\n<TEXT coords="' + waterMarkCoords16 + '" label="' + waterMarkText + '">\n';
		waterMarkString += '<TEXTMARKERSYMBOL fontstyle="' + waterMarkStyle + '" fontsize="' + waterMarkSize + '" ';
		waterMarkString += 'font="' + waterMarkFont + '" fontcolor="' + waterMarkColor + '" antialiasing="false" ';
		waterMarkString += '/>\n</TEXT>\n</OBJECT>\n';
		waterMarkString += '</LAYER>\n';

		return waterMarkString;
	}
}

//----------------------------------------------------------------------------------------------------

function RecalculateExtent()
{	
	var oldScale = GetMapScale();
	var newScale = parseInt(parent.ToolFrame.document.forms[0].txtScale.value);

	if((oldScale == 0) || (isNaN(oldScale) || isNaN(newScale)))
	{
		alert("This is not a valid scale.\nPlease try again.");
		return;
	}

	var factorOldToNew = newScale / oldScale;

	var oldWidth = eRight - eLeft;
	var oldHeight = eTop - eBottom;
	var newWidth = oldWidth * factorOldToNew;
	var newHeight = oldHeight * factorOldToNew;

	var horIncrement = 0.5 * (newWidth - oldWidth);
	var verIncrement = 0.5 * (newHeight - oldHeight);

	eLeft -= horIncrement;
	eRight += horIncrement;
	eBottom -= verIncrement;
	eTop += verIncrement;		

}

//-----------------------------------------------------------------------------------------------------------------

function GetMapScale()
{
	/*
		specific function comments :-

	*/

	var tempScale = (eRight - eLeft) / iWidth;

	var tempFactor = 96;
	var inchPerMeter = 39.4;
	return parseInt((tempScale * tempFactor * inchPerMeter) + 0.5);
}

//-----------------------------------------------------------------------------------------------------------------

function setActiveLayerName(theLayerName)
{
	//Set the name of the active layer - will be "" if the active layer is not dynamic
	activeLayerName = theLayerName;
}

//-----------------------------------------------------------------------------------------------------------------

//Last updated for DPA - TK 14/7
function zoomToCoords(xIn,yIn)
{
//alert(xIn + " " + yIn)
	parent.MapFrame.xPointHighlight = xIn;
	parent.MapFrame.yPointHighlight = yIn;
	parent.MapFrame.showHighlighted = true;
	

	var theZoomScale = queryZoomScale

	var mWMargin = 0;
	var mHMargin = 0;
	mWMargin = Math.abs(limitRight-limitLeft) * (selectPointMargin /4);
	mHMargin = Math.abs(limitTop-limitBottom) * (selectPointMargin /4);
	var xNum = parseFloat(xIn);
	var yNum = parseFloat(yIn);
	saveLastExtent();
	eLeft = xNum - mWMargin;
	eRight = xNum + mWMargin;
	eTop = yNum + mHMargin;
	eBottom = yNum - mHMargin;
	
	if (parent.ToolFrame.document.forms[0])
	{
		if (parent.ToolFrame.document.forms[0].txtScale)
		{
			parent.ToolFrame.document.forms[0].txtScale.value = parseInt(theZoomScale);
			parent.MapFrame.RecalculateExtent(); 
		}
	}
	else
	{
		
		var factorOldToNew = parseInt(theZoomScale) /  GetMapScale();
	
		var oldWidth = eRight - eLeft;
		var oldHeight = eTop - eBottom;
		var newWidth = oldWidth * factorOldToNew;
		var newHeight = oldHeight * factorOldToNew;
	
		var horIncrement = 0.5 * (newWidth - oldWidth);
		var verIncrement = 0.5 * (newHeight - oldHeight);

		eLeft -= horIncrement;
		eRight += horIncrement;
		eBottom -= verIncrement;
		eTop += verIncrement;	
		
	}

	//Set the age of map
	if (parent.MapFrame.chosenMapAge != "")
	{
		parent.MapFrame.changeMapping(chosenMapAge,false)
	}

	//Refresh the map
	sendMapXML();
}

//-----------------------------------------------------------------------------------------------------------------

function zoomToCoordEnvelope(maxX,minX,maxY,minY)
{
	saveLastExtent();
	
	eLeft=minX;
	eBottom=minY;
	eRight=maxX;
	eTop=maxY;
	
	checkFullExtent();

	//parent.ToolFrame.document.forms[0].txtScale.value = parseInt(queryZoomScale);
	//parent.MapFrame.RecalculateExtent();
	
	sendMapXML()
}

//-----------------------------------------------------------------------------------------------------------------

function findOSCARByWord(theValue) 
{
	/*
		specific function comments :-
		
		finds a feature in the active layer using a keyword
	*/

	//selectPointMargin = 20/1000

	showRetrieveData();
	
	var backmaxFeaturesReturned = maxFeaturesReturned
	maxFeaturesReturned = 5000
	
	var theNewQueryString = "";
	var theTempString = "";
	var fieldListString = LayerIDField[ActiveLayerIndex] + " " + LayerShapeField[ActiveLayerIndex];

	fieldListString = "#ID# #SHAPE# FEAT.GISDBA.OSCAR.ROAD_NUM";	
	theNewQueryString = "ROAD_NUM='" + theValue + "'"
				
	theNewQueryString=makeXMLsafe(theNewQueryString);
	setQueryString = theNewQueryString;
	
	var theString = writeOSCARFindRequest(theNewQueryString,fieldListString);
	sendToServer(imsQueryURL,theString,1001);

	parent.MapFrame.OSCARQuery = setQueryString

	maxFeaturesReturned = backmaxFeaturesReturned
}
//-----------------------------------------------------------------------------------------------------------------

function writeOSCARFindRequest(findQuery,fieldList)
{
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" geometry="false" envelope="true"';
	theString += ' featurelimit="' + maxFeaturesReturned + '" beginrecord="' + queryStartRecord + '">\n';
	theString += '<LAYER id="' + ActiveLayer + '" />\n';
	if (useLimitExtent) {
		// keep this within the limitExtent
		theString += '<SPATIALQUERY subfields="' + fieldList + '" where="' + findQuery + '" />';
		theString += '<SPATIALFILTER relation="area_intersection">\n';
		theString += '<ENVELOPE maxx="' + forceComma(limitRight) + '" maxy="' + forceComma(limitTop) + '" minx="' + forceComma(limitLeft) + '" miny="' + forceComma(limitBottom) + '" />\n';
		theString += '</SPATIALFILTER>\n';
		theString += '</SPATIALQUERY>\n';
	} else {
	theString += '<QUERY subfields="' + fieldList + '" where="' + findQuery + '" />';
	}
	theString += '</GET_FEATURES>\n';
	theString += '</REQUEST>\n';
	theString += '</ARCXML>';
	selectLayer=ActiveLayer;
	selectType=ActiveLayerType;
	selectCount=0;
	hightlightedOne="";
	selectPoints.length=1;
	selectLeft.length=1;
	selectRight.length=1;
	selectTop.length=1;
	selectBottom.length=1;
	return theString;
}

//-----------------------------------------------------------------------------------------------------------------

function parseOSCARQuery(theReply) 
{
	//If nothing was found
	var featureCount = justGetFeatureCount(theReply);
	if (featureCount == 0)
	{
		alert("Sorry, nothing found")
		return;
	}	
	self.focus()

	var endpos = 1;

	selectPoints.length=0;
	selectLeft.length=0;
	selectRight.length=0;
	selectTop.length=0;
	selectBottom.length=0;
	selectCount = 0

	showRetrieveMap()

	for (var i=0;i<featureCount;i++)
	{			
		//alert("passing start positon " + endpos)
		var theXYs = getEnvelopeXYs(theReply, endpos)
		selectLeft[selectCount] = theXYs[0];
		selectBottom[selectCount] = theXYs[1];
		selectRight[selectCount] = theXYs[2];
		selectTop[selectCount] = theXYs[3];
		endpos = xmlEndPos;

		selectCount ++;
	}

	selectCount = featureCount

	//Set the age of map
	if (parent.MapFrame.chosenMapAge != "")
	{
		parent.MapFrame.changeMapping(chosenMapAge,false)
	}

	zoomToReturnedRecords();
}

//-----------------------------------------------------------------------------------------------------------------

function checkHistoricIsAvailable(theYear, refresh, obj)
{
	var scale = parent.MapFrame.GetMapScale()
	if (scale > 10000)
	{
		obj.checked = false
		parent.MapFrame.showHistoricLayers()
		alert("Historical maps are only available for selection when the map scale is 1:10,000 or below.\n\nPlease zoom to 1:10,000 or below and try again.")
		return
	}
	else
	{
		parent.MapFrame.changeMapping(theYear, refresh)
		parent.MapFrame.showHistoricLayers()
	}
}

//-----------------------------------------------------------------------------------------------------------------

function changeMapping(type,refresh)
{
	if ((type=="") || (type==null))
	{
		alert("Please choose a map date")
		return
	}
	else
	{
		//Which layer are we going to display
		var theLayerToDisplay = 0
		theLayerToDisplay = getLayerIndexPosn(type);
		
		//Make all other layers invisible
		LayerVisible[getLayerIndexPosn("10,000")]=0;
		LayerVisible[getLayerIndexPosn("OS Vector (Master Map)")]=0;
		LayerVisible[getLayerIndexPosn("OS Text")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1980-1994")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1970-1979")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1960-1969")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1951-1959")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1938-1950")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1919-1926")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1894-1899")]=0;
		LayerVisible[getLayerIndexPosn("Historic 1856-1865")]=0;
		LayerVisible[getLayerIndexPosn("Photos")]=0;
		//Make layer visible
		LayerVisible[theLayerToDisplay]=1;

		parent.MapFrame.chosenMapAge = type

		//If user wants to make 10k visible, make the MM visible
		if (type == "10,000")
		{
			LayerVisible[getLayerIndexPosn("OS Vector (Master Map)")]=1;
			LayerVisible[getLayerIndexPosn("OS Text")]=1;
		}

		if (type == "Historic")
		{
		parent.MapFrame.zoomToHistoric()
		return;
		}

		//Scale
		if (parent.ToolFrame.document.forms[0].txtScale)
		{
			parent.ToolFrame.document.forms[0].txtScale.value = GetMapScale();
			var CurrentScale = parseInt(parent.ToolFrame.document.forms[0].txtScale.value);
		}
		
	
		//Refresh the map
		if (refresh)
		{
			sendMapXML();
		}
	}
}

//-----------------------------------------------------------------------------------------------------------------
function openSite(theLink)
{

theLink = "http://" + theLink
parent.opener.location=theLink
parent.opener.focus();
return;

}
//----------------------------------------------------------------------------------------

function openLink(theLink, theLayer)
{

	
	//alert(theLink + " " + theLayer)
	if (parent.opener)
	{
		//Loop through the layers that we have added
		for (i=0; i<parent.MapFrame.dataBrowserLayerList.length ; i++)
		{
			if (parent.MapFrame.dataBrowserLayerList[i][parent.MapFrame.dbLayerSDENamePos] == theLayer)
			{
				var theLayerCode = parent.MapFrame.dataBrowserLayerList[i][parent.MapFrame.dbLayerRefPos];
				var theURL="";


		
				//LINK TO ETECH NOTES DATABASE FOR DCC COUNCILLOR INFORMATION
				

				if (theLayerCode == parent.MapFrame.councillorsLayerCode)
				{
				

					theURL= parent.MapFrame.councillorsURL + theLayerCode + theLink;
			
				}


				//Is this the Durham Record layer - if so, we must use a different URL
				else if (theLayerCode == parent.MapFrame.durhamRecordLayerCode)
				{
					theURL= durhamRecordReturnURL1 + theLink + durhamRecordReturnURL2;
				}
				//Is this the Private Day Care Nurseries layer - if so, we must use a different URL
				else if (theLayerCode == parent.MapFrame.privateDayCareNurseriesLayerCode)
				{
					theURL= privateDayCareNurseriesURL1 + theLink + privateDayCareNurseriesURL2;
				}
				//Is this the Child Minders layer - if so, we must use a different URL
				else if (theLayerCode == parent.MapFrame.childMindersLayerCode)
				{
					theURL= childMindersURL1 + theLink + childMindersURL2;
				}
				//Is this the Nursing Homes Layers - if so, we must use different URL
				else if (theLayerCode == parent.MapFrame.nursingHomesLayerCode)
				{
					theURL = CommInfoDataURL1 + theLink + CommInfoDataURL2;
				}
				//Is this the Residential Care Homes Layers - if so, we must use different URL
				else if (theLayerCode == parent.MapFrame.residentialCareHomesLayerCode)
				{
					theURL = CommInfoDataURL1 + theLink + CommInfoDataURL2;
				}
				//Is this the Local History Societies Layers - if so, we must use different URL
				else if (theLayerCode == parent.MapFrame.localHistoryLayerCode)
				{
					theURL = CommInfoDataURL1 + theLink + CommInfoDataURL2;
				}
				//Is this is a schools layer - if so, we need to use Comm Database URL
				//else if ((theLayerCode == parent.MapFrame.secSchoolsLayerCode) || (theLayerCode == parent.MapFrame.primSchoolsLayerCode) || (theLayerCode == parent.MapFrame.specSchoolsLayerCode) || (theLayerCode == parent.MapFrame.nursSchoolsLayerCode) || (theLayerCode == parent.MapFrame.sixthSchoolsLayerCode))
				else if (theLayerCode == parent.MapFrame.sixthSchoolsLayerCode)
				{
					
					theURL = CommInfoDataURL1 + theLink + CommInfoDataURL2;
				}
				else if ((theLayerCode == parent.MapFrame.secSchoolsLayerCode) || (theLayerCode == parent.MapFrame.primSchoolsLayerCode) || (theLayerCode == parent.MapFrame.specSchoolsLayerCode) || (theLayerCode == parent.MapFrame.nursSchoolsLayerCode))
				{

					theURL = schoolsURL + theLink;
				}
				//Derwentside Planning
				else if (theLayerCode == parent.MapFrame.derwentsidePlanLayerCode)
				{
					theURL = derwentsidePlanURL + theLink;
				}
				else
				{
					theURL="http://www.durham.gov.uk/durhamcc/usp.nsf/vwebgis/" + theLayerCode + theLink;
					//theURL="http://notesi01/durhamcc/usp.nsf/vwebgis/" + theLayerCode + theLink;
				}
				//alert(theURL)
				parent.opener.location=theURL;
				parent.opener.focus();
				break;
			}
		}
	}
	else
	{
		alert("Sorry, unable to link to this feature.");
	}
}

//-----------------------------------------------------------------------------------------------------------------

function getSearchColumn(theLayer)
{
	for (i=0; i<parent.MapFrame.dataBrowserLayerList.length ; i++)
	{
		if (parent.MapFrame.dataBrowserLayerList[i][parent.MapFrame.dbLayerSDENamePos] == theLayer)
		{
			var theSeachColumn = parent.MapFrame.dataBrowserLayerList[i][parent.MapFrame.dbLayerSearchFieldPos]
			return theSeachColumn
			break;
		}
	}
	return "";
}

//-----------------------------------------------------------------------------------------------------------------

function getAlias(theLayer)
{
	for (i=0; i<parent.MapFrame.dataBrowserLayerList.length ; i++)
	{
		if (parent.MapFrame.dataBrowserLayerList[i][parent.MapFrame.dbLayerSDENamePos] == theLayer)
		{
			var theAlias = parent.MapFrame.dataBrowserLayerList[i][parent.MapFrame.dbLayerAliasPos]
			return theAlias
			break;
		}
	}
	return "";
}

//-----------------------------------------------------------------------------------------------------------------

function setJSPStartQuery()
{
	//Check that something was passed over
	if ((imsQueryLayer !="") && (imsStartQuery != ""))
	{
		//POSTCODES:
		if (imsQueryLayer=="POSTCODE")
		{
			//Do the query
			var theURL = webServerName + "/website/intermap/JSP/findFeatures.jsp?LAYER=" + navigationLayerList[postcodeArrayRowPos][navigationLayerNamePos] + "&SEARCHSTRING=" + escape(imsStartQuery) + "&LAYERALIAS=" + navigationLayerList[postcodeArrayRowPos][navigationLayerAliasPos] + "&SEARCHCOLUMN=" + navigationLayerList[postcodeArrayRowPos][navigationLayerSearchFieldPos];
			parent.LeftFrame.location=theURL;
			imsQueryLayer="";
			imsStartQuery="";
			return;
		}
		//STREETS:
		else if (imsQueryLayer=="STREET")
		{
			var theURL = webServerName + "/website/intermap/JSP/findFeatures.jsp?LAYER=" + navigationLayerList[streetArrayRowPos][navigationLayerNamePos] + "&SEARCHSTRING=" + escape(imsStartQuery) + "&LAYERALIAS=" + navigationLayerList[streetArrayRowPos][navigationLayerAliasPos] + "&SEARCHCOLUMN=" + navigationLayerList[streetArrayRowPos][navigationLayerSearchFieldPos];
			parent.LeftFrame.location=theURL;
			imsQueryLayer="";
			imsStartQuery="";
			return;
		}
		//TOWN:
		else if (imsQueryLayer=="TOWN")
		{
			var theURL = webServerName + "/website/intermap/JSP/findFeatures.jsp?LAYER=" + navigationLayerList[settlementArrayRowPos][navigationLayerNamePos] + "&SEARCHSTRING=" + escape(imsStartQuery) + "&LAYERALIAS=" + navigationLayerList[settlementArrayRowPos][navigationLayerAliasPos] + "&SEARCHCOLUMN=" + navigationLayerList[settlementArrayRowPos][navigationLayerSearchFieldPos];
			parent.LeftFrame.location=theURL;
			imsQueryLayer="";
			imsStartQuery="";
			return;
		}
		//ROAD:
		else if (imsQueryLayer=="ROAD")
		{
			var theURL = webServerName + "/website/intermap/JSP/findUniqueOSCAR.jsp?OSCAR_NUM=" + escape(imsStartQuery) ;
			parent.LeftFrame.location=theURL;
			imsQueryLayer="";
			imsStartQuery="";
			return;
		}
		//DYNAMIC LAYER:
		//We have got to take alternative action here, as the map layer does not already exist within the application.
		//We need to get the reference number passed over (imsStartQuery), go to the database for this reference number,
		//Select all of the details for this layer (SDE layer name, select column etc), load in the layer, do the query and
		//zoom to the results.
		else
		{
			//alert("Get database details for layer: " + imsQueryLayer + " and query it with: " + imsStartQuery)
			
			//Extract the first 2 characters of the reference number (imsQueryLayer) - this gives us the database table
			//that we must query to get the information we need to add the layer dynamically.
			var layerName = imsQueryLayer;
			var layerQuery = imsStartQuery;
			var theCategory="";

			//Check length of layer reference that was passed over.
			if (layerName.length <= 2)
			{
				//Refresh the map.
				sendMapXML();
				imsQueryLayer="";
				imsStartQuery="";
				alert("Invalid layer reference passed over. Layer is: " + layerName + " Unable to load layer")
			}
			else
			{
				//Extract the table name - first 2 characters ..
				theCategory = layerName.substring(0,2);
				
				//Pass the entire reference number to a JSP, which extracts the relevant information from the database table.
				var theURL = webServerName + "/website/intermap/JSP/getLayerDetails.jsp?CATEGORY=" + escape(theCategory) + "&LAYERREF=" + escape(layerName) + "&LAYERQUERY=" + escape(layerQuery);
				//alert(theURL)
				parent.LeftFrame.location = theURL;
				imsQueryLayer="";
				imsStartQuery="";
			}
		}
	}
	else
	{
		alert("Information not passed to GIS. Unable to continue.")
		imsQueryLayer="";
		imsStartQuery="";
	}
}

//-----------------------------------------------------------------------------------------------------------------

function findFeaturesFromLoad(theSDEName, theLayerQuery, theAlias, strSearchCol, legendImage, showMoreInfo)
{
	//If we are linking to this on start up, from NOTES, we must use the NOTES Search field - the unique reference field.

	if (theLayerQuery=="NULL")
	{
			if ((parent.MapFrame.startX !="") && (parent.MapFrame.startY !=""))
			{
				parent.MapFrame.zoomToCoords(parent.MapFrame.startX,parent.MapFrame.startY)
			}
			else
			{
				sendMapXML()
			}
		return;
	}

	var theQueryURL=webServerName + "/website/intermap/JSP/findStartFeatures.jsp?LAYER=" + escape(theSDEName) + "&SEARCHSTRING=" + theLayerQuery + "&LAYERALIAS=" + escape(theAlias) + "&DISPLAYCOLUMN=" + escape(strSearchCol) + "&SEARCHCOLUMN=" + escape(parent.MapFrame.notesSearchColumn);
	//alert(theQueryURL)

	//Call a function to do the query on the map layer
	parent.LeftFrame.location = theQueryURL
}

//-----------------------------------------------------------------------------------------------------------------

function findNearestCoords(xIn,yIn,theLayer)
{
	//Extract the search column, given the layer
	var theSearchColumn= getSearchColumn(theLayer);
	var theAlias = getAlias(theLayer);

	if (theSearchColumn != "")
	{
		var theURL= webServerName + "/website/intermap/jsp/jspfindnearest.jsp?X=" + escape(xIn) + "&Y=" + escape(yIn) +  "&SEARCHCOLUMN=" + escape(theSearchColumn) + "&LAYERS=" + escape(theLayer) + escape("-" + theAlias + ",") 
		//alert(theURL)
		parent.LeftFrame.location=theURL
	}
	else
	{
		alert("Error - unable to get the search column for layer: " + theLayer)
	}
}

//-----------------------------------------------------------------------------------------------------------------

function findNearestCoordEnvelope(maxX,minX,maxY,minY,theLayer)
{
	//Extract the search column, given the layer
	var theSearchColumn= getSearchColumn(theLayer);
	var theAlias = getAlias(theLayer);

	if (theSearchColumn != "")
	{
		var theURL= webServerName + "/website/intermap/jsp/jspfindnearest.jsp?X=" + escape(xIn) + "&Y=" + escape(yIn) +  "&SEARCHCOLUMN=" + escape(theSearchColumn) + "&LAYERS=" + escape(theLayer) + escape("-" + theAlias + ",") 
		//alert(theURL)
		parent.LeftFrame.location=theURL
	}
	else
	{
		alert("Error - unable to get the search column for layer: " + theLayer)
	}
}

//-----------------------------------------------------------------------------------------------------------------

function searchForNearest(theFindString,theLayer)
{	
	//alert(theLayer + "\n\n" + theFindString )
	//Validate user query.
	var pos = theFindString.indexOf("'")
	if (pos !=-1)
	{
		alert("The keyword contains a restricted character.")
		return
	}

	//Validate user query.
	var pos = theFindString.indexOf("\"")
	if (pos !=-1)
	{
		alert("The keyword contains a restricted character.")
		return
	}

	//Validate user query.
	var pos = theFindString.indexOf("%")
	if (pos !=-1)
	{
		alert("The keyword contains a restricted character.")
		return
	}
	
	//Validate user query.
	if ((theFindString.length < 1) || (theFindString == "") || (theFindString == " "))
	{
		alert("Please provide more information")
		return
	}

	//Postcode search.
	if ((theFindString.length <=4) && (parent.MapFrame.activeLayerName == navigationLayerList[postcodeArrayRowPos][navigationLayerNamePos]))
	{
		alert("Please provide at least five characters for the postcode search")
		return
	}

	//Postcode search.
	if (parent.MapFrame.activeLayerName == navigationLayerList[postcodeArrayRowPos][navigationLayerNamePos])
	{
		//Format string for the postcode search.
		var theLen = theFindString.length;
		var fourthChar = "";
		
		//Six figure postcode - must contain a space for the fourth character.
		if (theLen == 6)
		{
			//Get the fourthChar
			fourthChar = theFindString.substring(3,4);

			//If the fourthChar is not a " ", insert one at this position.
			if (fourthChar != " ")
			{
				var left=theFindString.substring(0,3);
				var right = theFindString.substring(4,theFindString.length);
				theFindString = left + " " + fourthChar + right
			}
		}
		else if (theLen > 7) //Seven figure postcode - must not contain a space for the fourth character.
		{
			theFindString = theFindString.replace(" ","");
		}
	}

	//We are about to query a navigational layer ...
	if (parent.MapFrame.activeLayerName !="")
	{			
		//Get indexPosn of this layer
		var i = null;
		for (i=0; i < navigationLayerList.length-1; i++)
		{
			//Check the names
			if (navigationLayerList[i][navigationLayerNamePos]==activeLayerName)
			{
				break;
			}
		}
		
		//Generate a URL to send to JSP/Servlet
		var theURL = webServerName + "/website/intermap/JSP/findNearestSetup.jsp?LAYER=" + activeLayerName + "&SEARCHSTRING=" + escape(theFindString) ;
		
		//Add alias, if we have one ..
		if ((navigationLayerList[i][navigationLayerAliasPos]) && (navigationLayerList[i][navigationLayerAliasPos] != ""))
		{
			theURL +="&LAYERALIAS=" + escape(navigationLayerList[i][navigationLayerAliasPos])
		}

		//Add Search field, if we have one - we should have ..
		if (navigationLayerList[i][navigationLayerSearchFieldPos] != "")
		{
			theURL +="&SEARCHCOLUMN=" + escape(navigationLayerList[i][navigationLayerSearchFieldPos])
		}

		theURL += "&NEARESTLAYER=" + escape(theLayer);

		//Go to the JSP/Servlet
		//alert(theURL)
		parent.MapFrame.showRetrieveData();
		parent.LeftFrame.location = theURL;
	}
	else
	{
		alert("Sorry, an error has occured and the system is unable to query this particular navigational map layer")
	}
}

//-----------------------------------------------------------------------------------------------------------------

function getCopyrightText()
{
	//Get the scale.
	var theScale = GetMapScale()

	//Set the copyright.
	var theCopyText= parent.MapFrame.CopyrightText;

	//Decide what copyright text to display...
	if (theScale <= 50050)
	{
		theCopyText = CopyrightTextOS;
	}
	else if ((theScale > 50050) && (theScale <=100050))
	{
		theCopyText = CopyrightTextPhil;
	}
	else if ((theScale > 100050) && (theScale <=250250))
	{
		theCopyText = CopyrightTextOS;
	}
	else if ((theScale > 250250) && (theScale <=450000))
	{
		theCopyText = CopyrightTextPhil;
	}
	else if ((theScale > 450000) && (theScale <=750000))
	{
		theCopyText = CopyrightTextBarth;
	}
	else
	{
		theCopyText = CopyrightTextOS;
	}



	return theCopyText;
}

//-----------------------------------------------------------------------------------------------------------------

