	<!--
	
	//
	//	pinpoint.js
	//
	//	This is the main javascript file for PinPoint LITE
	//	
	//	Modification history
	//	===============================================================================
	//	Ref		Date		By		Description
	//	===============================================================================
	//
	//			22-01-05	DJEM	Stripped out all redundant code not used in LITE, sadly
	//								including LKL's line code. This was to help in the move 
	//								cross-browser capability. Specifically:
	//
	//									W3C events:		pass in 'event' with onClick, etc	
	//
	//	===============================================================================
	
	// TD 001 12-Oct-2006
	//		Allow a click to be notified to the parent window, if a click-handler is defined.
	// TD 002 14-Feb-2007
	//		Permit display of CC Boundaries
	
	loaded = false;
	ilibWasOn = false;		//	DJEM 06-02-04
	newFrameObj = null;
	gSiteActiveDiv = null;
	startupTimer = null;

	//	cctv stuff
	//	NB: 'cctvTimeoutSecs' is written to DOM by display.php::displayInitializeJavascript() using
	//	value 'ppl_cctv_timeout_secs' in ppl_default.conf
	cctvCurrSite = null;
	cctvTimer = null;
	cctvCountdownElem = null;
	cctvSecsRemaining = 0;
	cctvCycle = 0;
	
	ptr = 0;
	count = 0;
	offsetX = -1;
	offsetY = -1;
	originEast = easting - (arrowX * metresPerPixel);
	originNorth = (arrowY * metresPerPixel) + northing;

	altPressed = false;
	
	currEasting = 0;	//	DJEM 26-02-04
	currNorthing = 0;	//	DJEM 26-02-04

	ltisCycle = 0;
	vcsaCycle = 0;
	ltisOptions = "";
	
	document.onkeypress = keyhandler;

	//	New bit for dragging infolib div (07-03-05)...
	//	-----------------------------------------------
	var ie=document.all
	// var ie7 = (ie && window.XMLHttpRequest)
	var ns6=document.getElementById&&!document.all

	var dragapproved=false
	var z,x,y

	function move(e){
		if (dragapproved){

			// HW: Javascript now needs to be XHTML compliant! Added px.
			z.style.left=( ns6? temp1+e.clientX-x: temp1+event.clientX-x ) + "px"
			z.style.top=( ns6? temp2+e.clientY-y : temp2+event.clientY-y ) + "px"
			
			// Change by NCG 10/07/06
			// Prevent the box being dragged outside the bounds of the 
			// parent container
			// ------------------------------------------
			var maxleft = parseInt( (ns6? z.parentNode.offsetWidth : z.parentElement.offsetWidth), 10) - parseInt( (ns6? z.offsetWidth : z.offsetWidth), 10)
			var curleft = parseInt(z.style.left, 10)
			
			if ( curleft > maxleft ) {
				z.style.left = maxleft+"px"
			}
			
			if ( curleft < 0 ) {
				z.style.left = "0px"
			}


			var maxtop = parseInt( (ns6? z.parentNode.offsetHeight : z.parentElement.offsetHeight), 10 ) - parseInt( (ns6? z.offsetHeight : z.offsetHeight), 10 )
			var curtop = parseInt( z.style.top, 10 )
			
			if ( curtop > maxtop ) {
				z.style.top = maxtop + "px"
			}
			
			if ( curtop < 0 ) {
				z.style.top = "0px"
			}
			// ------------------------------------------
			// End change by NCG 10/07/06
			
			return false
			}
		}

/*
			// HW DEBUG code
			var debugDiv = document.getElementById ( 'debugDiv' )
			if (debugDiv) {
				// debugDiv.innerHTML = "z.height=" + z.height + " z.width=" + z.width;
				debugDiv.innerHTML = "maxleft=" + maxleft + " curleft=" + curleft + " curtop=" + curtop + " z.parentNode.offsetHeight=" + parseInt( z.parentNode.offsetHeight, 10 ) + " z.offsetHeight=" + parseInt( z.offsetHeight, 10 )+ " z.parentNode.offsetWidth=" + z.parentNode.offsetWidth + " z.offsetWidth=" + z.offsetWidth + " z.parentNode.style.height=" + z.parentNode.style.height
			}
*/


	function drags(e){
		if (!ie&&!ns6)
			return;

		var firedobj=ns6? e.target : event.srcElement ;
		var topelement=ns6? "HTML" : "BODY" ;
		
		if (firedobj == null)
			return;	// null event

		while (firedobj != null && firedobj.tagName!=topelement&&firedobj.className!="drag"){
			firedobj=ns6? firedobj.parentNode : firedobj.parentElement
			}

		if (firedobj != null && firedobj.className=="drag"){
			dragapproved=true
			z=firedobj
			temp1=parseInt(z.style.left+0)
			temp2=parseInt(z.style.top+0)
			x=ns6? e.clientX: event.clientX
			y=ns6? e.clientY: event.clientY
			document.onmousemove=move
			return false
			}
		}

	document.onmousedown=drags
	document.onmouseup=new Function("dragapproved=false")
	// HW: Tried to fix continual drag while mouse button is down,
	// but this made it lose drag to often, appears to fire
	// even when mouse stays within CCTV image.
	// document.onmouseout=new Function("dragapproved=false")

	//	End new bit for infolib dragging
	//	-----------------------------------------------


	//	loadPage
	//	This is called when the page has completely finished loading. Put any javascript 
	//	processing here...
	function loadPageComplete () {
	
		/*
		if ( parent.window.isOn )	// see if function exists
			if ( parent.isOn ( 'LCON' ) == true )	//	call it
				setTimeout("PerformScootLinks('con')",500);
		*/
		
		loaded = true;

		if ( parent.setMinimap )
			parent.setMinimap(easting,northing);

		if ( parent.setExtents )
			parent.setExtents(minx,maxx,miny,maxy);

		if ( parent.isOn ) {

			if ( parent.isOn ( 'LTIS' ) ) {
				ltisOptions = parent.getLTISOptions();
				startupTimer = setTimeout ( 'startupFunc()', 500 );
				//ltisLoad(ltisOptions,minx,maxx,miny,maxy,metresPerPixel,ltisCycle);
				}

			
			var lconDiv = document.getElementById ( 'lconDiv' );
			if (lconDiv)
				if ( parent.isOn ( 'LCON' ) ) {
					scootLoad(minx,maxx,miny,maxy,metresPerPixel);
					lconDiv.style.visibility = 'visible';
					}
				else
					lconDiv.style.visibility = 'hidden';

			var cboundsDiv = document.getElementById ('ccDiv') ;
			if (cboundsDiv) {
				//if ( parent.isOn ( 'CC' )) {
					// LKL Apr 2007 - always show the zone DS request
					var mapType = 'colour';
					mapType = parent.getMapType();
					
					ccLoad(minx,maxx,miny,maxy,metresPerPixel,parent.getTNSCCZLEZ(), mapType) ;
					
					cboundsDiv.style.visibility = 'visible' ;
/*
				} else {
					cboundsDiv.style.visibility = 'hidden' ;
				}
*/
			}

/* HW: Removed TLRN, Freight, VCSA and Tour De France

			var tlrnDiv = document.getElementById ( 'tlrnDiv' );
			if ( tlrnDiv ) {
				if ( parent.isOn ( 'TLRN' ) ) {
					tlrnLoad(minx,maxx,miny,maxy,metresPerPixel);
					tlrnDiv.style.visibility = 'visible';
					}
					else
					tlrnDiv.style.visibility = 'hidden';
				}
			

			var freightDiv = document.getElementById ( 'freightDiv' );
			if ( freightDiv ) {
				var frt_ldg = 0;
				var frt_wtg = 0;
				var frt_wid = 0;
				var frt_hgt = 0;
				var frt_wgt = 0;
				if ( parent.isOn ( 'Loading' ) ) frt_ldg = 1;
				if ( parent.isOn ( 'Waiting' ) ) frt_wtg = 1;
				if ( parent.isOn ( 'Width' ) ) frt_wid = 1;
				if ( parent.isOn ( 'Height' ) ) frt_hgt = 1;
				if ( parent.isOn ( 'Weight' ) ) frt_wgt = 1;
				if ( frt_ldg == 1 || frt_wtg == 1 || frt_wid == 1 || frt_hgt == 1 || frt_wgt == 1 ) { 
					freightLoad(minx,maxx,miny,maxy,metresPerPixel,frt_ldg,frt_wtg,frt_wid,frt_hgt,frt_wgt);
					freightDiv.style.visibility = 'visible';
					}
				}

			var vcsaDiv = document.getElementById ( 'vcsaDiv' );
			if ( vcsaDiv ) {
				vcsaLoad(minx,maxx,miny,maxy,metresPerPixel);
				vcsaDiv.style.visibility = 'visible';
				}

			// Tour de France 
			var tourdefranceDiv = document.getElementById ('tdfDiv') ;
			tdfLoad(minx,maxx,miny,maxy,metresPerPixel) ;
			tourdefranceDiv.style.visibility = 'visible' ;
*/

			//	Legend
			if ( parent.isOn ( 'LGND' ) )
				legend('visible');


			}


		if ( parent.childLoaded )
			parent.childLoaded();

		if ( noparent == true )
			ltisvmsLoad(ltis_options,minx,maxx,miny,maxy,metresPerPixel,ltisCycle);  // NCG 11-07-06
			//ltisLoad(ltis_options,minx,maxx,miny,maxy,metresPerPixel,ltisCycle);
		
		return;
			
		}


	//	vcsaLoad
	//	Loads VCS access data	
	function vcsaLoad ( minx, maxx, miny, maxy, mpp ) {

		var elem = document.getElementById ( "vcsaDiv" );
		if ( !elem ) return;
	
		imgid = "vcsaImage_" + vcsaCycle;
		vcsaCycle++;

		// 	NB: The 'cyc=no' parameter is ESSENTIAL - the image will not update without a unique
		//	URL, and this dummy parameter is how this has been implemented. This is a problem with
		//	all browsers, even with special header/cache instructions.
	 
		var url = "vcsa.php?";
		url += "minx=" + minx + "&maxx=" + maxx + "&miny=" + miny + "&maxy=" + maxy;
		url += "&mpp=" + metresPerPixel + "&cyc=" + vcsaCycle;

		elem.innerHTML = "";
		elem.innerHTML = "<img id=" + imgid + "border=0px width=600px height=400px src=" + url + " />";

		}


	function startupFunc () {

		ltisvmsLoad(ltisOptions,minx,maxx,miny,maxy,metresPerPixel,ltisCycle); // NCG 11-07-06
		//ltisLoad(ltisOptions,minx,maxx,miny,maxy,metresPerPixel,ltisCycle);
		//vmsLoad(minx,maxx,miny,maxy,metresPerPixel,ltisCycle);
		
		clearTimeout ( startupTimer );
		startupTimer = null;

		}
		
		
	function ChangeCursor ( csr ) {
	
		//	NB: 'hand' will not work in browsers other than IE
			
		if ( ChangeCursor.arguments.length > 1 ) {
			var divid = ChangeCursor.arguments[1];
			var elem = document.getElementById(divid).style;
			elem.cursor = csr;
			return;
			}
			
		document.body.style.cursor = csr;
				
		}
		
	//	keyhandler
	//	Used for checking for carriage return, which is used to submit the page
	//	after a search string is entered...
	function keyhandler(e) {
	
		//alert ( "key handler: " + window.event.keyCode );
		
    	if (document.layers)
        	key = e.which;
    	else
			if (window.event)
	        	key = window.event.keyCode;
			else
				key = 0;
			
		switch(key) {    	
			case 13:	LoadPage(currEasting,currNorthing,-1);		break;
			case 27:	popdownInfolib ();
						if ( ilibWasOn == true )	//	DJEM 06-02-04
							infolibOn();	//LKL 23-01-04 switch the hovertext back on again
						break;
			case 68:
			case 100:	popupDetails ();
						break;
			default:	return;
			}		
		}
		


	function LoadPage (e,n,z) {
	
		var url = "index.php?discard_pointer=1&retain_session&easting="+e+"&northing="+n;
		//alert ( "z=" + z + ", min=" + minZoom + ", max=" + maxZoom );
		if ( z != -1 ) {
			if ( z == "in" ) {
				if ( zoom-1 >= minZoom )
					zoom--;
				else
					return;
				}
			else if ( z == "out" ) {
				if ( zoom+1 <= maxZoom )
					zoom++;
				else
					return;
				}
			else {
				tmpZoom = zoom;
				zoom = z;
				}
			}
				
		url = url + "&zoom=" + zoom;
		if ( parent.setZoom )
			parent.setZoom(zoom);

		//	Get various settings for which we do not use session variables...
		// HW: Removed VCS
		/*
		if ( parent.isOn ) {
			var vcs = false;
			if ( parent.isOn ( 'TLRN' ) )	{ url = url + "&tlrn"; }
			if ( parent.isOn ( 'THTR' ) ) { url = url + "&thtr"; }
			if ( parent.isOn ( 'CoachParks' ) ) url = url + "&vcs";
			
			}
		*/

		//alert(url);
		window.location = url;
		
		}
		
	function Loading ( on ) {
		var divid;
		if (( divid = document.getElementById("loadingDiv")) == null )
			return;
		if ( on == false )
			divid.style.visibility = "hidden";
		else
			divid.style.visibility = "visible";
		}
		
	//	DJEM	30-01-04
	function PerformSearch ( url ) {
		if ((iframeElem=document.getElementById("searchResultsDiv"))==null)
			return;
		
		Loading(true);
			
		newFrameObj = new Object();
		newFrameObj.document = new Object();
		newFrameObj.document.location = new Object();
		newFrameObj.document.location.iframe = document.getElementById("srFrame");
		//	URL of iframe. We must tell the source url where the user temp directory is
		//	as this is where old search results are written to for later retrieval...		
		var newloc = "searchresults.php?userdir=" + userdir + "&url=" + url;
		newFrameObj.document.location.replace = function(location) { this.iframe.src = location; }
		newFrameObj.document.location.replace(newloc);
		//iframeElem.document.URL = "searchresults.php";
		//iframeElem.style.visibility = "visible";
		ChangeCursor ( 'wait' );
		
		//	Remove old string from search field...
		var streetElem = document.getElementById ( "streetSearchTextField" );
		if ( !streetElem ) return null;
		streetElem.value = "";		

		}
		
	function CloseSearchResults () {
		if ((iframeElem=document.getElementById("searchResultsDiv"))==null)
			return;
		iframeElem.style.visibility = "hidden";
		}

	function ShowSearchResults () {
		if ((iframeElem=document.getElementById("searchResultsDiv"))==null)
			return;		
		iframeElem.style.visibility = "visible";
		}

	
		
	//	DJEM	19-01-04
	function PositionSearch () {
		//	Get easting & northing from text fields...
		var eTF = document.getElementById("eastingSearchTF");
		var nTF = document.getElementById("northingSearchTF");
		if ( !eTF || !nTF ) return;
		
		var e = eTF.value;
		var n = nTF.value;
		
		if ( e.length != 6 || n.length != 6 ) {
			alert ( "Invalid easting or northing: 6-digit values required" );
			eTF.value = easting;
			nTF.value = northing;
			return;
			}
			
		if ( e < 500000 || e > 570000 ) {
			alert ( "Easting out of range: specify a value between 500000 and 570000" );
			eTF.value = easting;
			return;
			}

		if ( n < 150000 || n > 210000 ) {
			alert ( "Northing out of range: specify a value between 150000 and 210000" );
			nTF.value = northing;
			return;
			}

		//	OK, so call LoadPage()...
		LoadPage ( e, n, -1, 1 );
		
		}
		
		
	function is_on ( toggName ) {
		// arrrgh!
		}
				
	function openWin(URL) {
		this.aWindow=window.open(URL,"duncsWin",
		"scrollbars=yes,status=yes,menubar=no");
		}
		
	function openWin2(URL) {
		this.aWindow=window.open(URL,"duncsWin",
		"scrollbars=yes,status=yes,menubar=no,resizable");
		}

	//	DJEM	07-01-04
	//	Modded function as part of replacement of overlib with infolib...
	function popupDetails () {
		//	Return if not a streetworks site...
		//	See if infoLib is up...if not, then return...
		var idiv = document.getElementById ( "infoDiv" ).style;
		if ( idiv.visibility == "hidden" )
			return;
		//	Check the caption (our test for a streetworks site). 'o3_cap' is the overLib
		//	variable containing the caption...
		if ( idiv_cap != swCaption )
			return;
		}
		
		
	//	DJEM 07-01-04
	//	Modded function to use new infoDiv
	function popdownInfolib () {
		var idiv = document.getElementById ( "infoDiv" ).style;
		if ( idiv.visibility == "hidden" )
			return;
		idiv.visibility = "hidden";
		return;
	}
		
/* HW: This second version simply checks if x and y are outside the allowable
   rectangle */
	function checkMapExtents2 (x, y) {

		// HW DEBUG 
		// alert ( "x= " + x + " y= " + y + " zoom=" + zoom + " mineast=" + mineast + " maxeast=" + maxeast + " minnorth=" + minnorth + " maxnorth=" + maxnorth + "\nmineasting=" + mineasting + " maxeasting=" + maxeasting + " minnorthing=" + minnorthing + " maxnorthing=" + maxnorthing );
		
		if ( x < mineasting ) return false;
		if ( x > maxeasting ) return false;
		if ( y < minnorthing ) return false;
		if ( y > maxnorthing ) return false;

		return true;

	}

	//	New mouseClick event to handle cross-browser zooming.

	function mouseClick(evt) {
		
		evt = (evt) ? evt : ((window.event) ? window.event : "");
		if ( evt.button != 0 && evt.button != 1 ) return false;

		var x = originEast + (evt.clientX*metresPerPixel);
		var y = originNorth - (evt.clientY*metresPerPixel);

		if ( checkMapExtents2 (x,y) == false ) {
			//  If at edge, set updateArrow=false.
			//  Do not update E,N, or arrow E,N, or drawArrow.
				alert ( "Edge of map has been reached!\nYou may need to zoom in,\nand move or search the map again." );
				return false;
		}

		if ( disable_onclick == true ) {
			if (parent.childClickNotification)
				parent.childClickNotification(x,y);
				
			return;
		}


		var shiftPressed = evt.shiftKey;
		if ( shiftPressed == true ) {
			if ( zoom < 6 )
				LoadPage ( x, y, 'out', 1 );
		} else {
			if ( zoom > 1 )
				LoadPage ( x, y, 'in', 1 );
		}
	}


		
	function fMouseMove(evt) {
	
		if ( loaded == false ) return;

		evt = (evt) ? evt : ((window.event) ? window.event : "");
    	if (!evt) return;
		
		//	Display cursor position in metres east and north...
		if ( offsetX == -1 ) {
			offsetX = DL_GetElementLeft(document.getElementById("tiletable"));
			offsetY = DL_GetElementTop(document.getElementById("tiletable"));
			}
		currEasting = originEast + ((evt.clientX-offsetX)*metresPerPixel);
		currNorthing = originNorth - ((evt.clientY-offsetY)*metresPerPixel);
		currEasting = Math.floor(currEasting);
		currNorthing = Math.floor(currNorthing);

			
		}// fMouseMove


	//---------------------------------------------
	// LKL Changes
	// Added for the Line
	//---------------------------------------------

	
	function fMouseDown(evt) {

		fMouseMove(evt);
	
		if ( currEasting == 0 || currNorthing == 0 )
			return;
					
		var altPressed = false;
		
		evt = (evt) ? evt : ((window.event) ? window.event : "");
    	if (evt) {
			altPressed = evt.altKey;
			var shiftPressed = evt.shiftKey;
			}
		
		if ( altPressed == false ) {
			if ( fMouseDown.arguments.length == 6 ) {
				if ( fMouseDown.arguments[1] == 'drilldown' ) {
					if ( window.event.button == 2 ) {
						infolibContextMenu();
						return false;
						}				
					var arg1 = fMouseDown.arguments[2];
					var arg2 = fMouseDown.arguments[3];
					var arg3 = fMouseDown.arguments[4];
					var arg4 = fMouseDown.arguments[5];
					LoadPage ( arg1, arg2, arg3 );
					return;
					}
				return;
				}
			}
						
		if ( altPressed == true ) {
		
			//Starting line draw
			ChangeCursor('crosshair');
				
			//	Disable hovertext
			//	DJEM 06-02-04 
			if (( ilibWasOn = infolibIsOn()) == true )
				infolibOff ();

			} //alt key pressed
		//	DJEM 26-02-04
		else {
			if ( shiftPressed == true )	
				LoadPage ( currEasting, currNorthing, 'out', 1 );
			else {
				//alert ( "e=" + currEasting + ", n=" + currNorthing );
				LoadPage ( currEasting, currNorthing, 'in', 1 );
				}
			}

		}		
		
	//	DL funcs to get positions of elements (eg, for use by menu images)
	function DL_GetElementLeft(eElement) {
    	var nLeftPos = eElement.offsetLeft;
    	var eParElement = eElement.offsetParent;
    	while (eParElement != null) {
        	nLeftPos += eParElement.offsetLeft;
        	eParElement = eParElement.offsetParent;
    		}
    	return nLeftPos;
		}

	function DL_GetElementTop(eElement)
		{
    	var nTopPos = eElement.offsetTop;
    	var eParElement = eElement.offsetParent;
    	while (eParElement != null) {
        	nTopPos += eParElement.offsetTop;
        	eParElement = eParElement.offsetParent;
    		}
    	return nTopPos;
		}

		
	function stopEverything () {
		document.execCommand('Stop');
		}
		
		
	function layerPopup ( id, what ) {
		ltDiv = document.getElementById ("ltisMenuDiv").style;
		swDiv = document.getElementById ("streetworksMenuDiv").style;
		var x = 130;
		var y = 30;
		if ( id == "LT" ) {
			if ( ltDiv.visibility == "visible" ) {
				ltDiv.visibility = "hidden";
				return;
				}
			if ( what == "visible" ) {
				if ( swDiv.visibility == "visible" ) {
					y += 290;
					}
				}	
			ltDiv.pixelTop = y;
			ltDiv.pixelLeft = x;		
			ltDiv.visibility = what;
			return;
			}
			
		if ( id == "SW" ) {
			if ( what == "visible" ) {
				if ( swDiv.visibility == "visible" ) {
					swDiv.visibility = "hidden";
					return;
					}
				if ( ltDiv.visibility == "visible" ) {
					y += 290;
					}
				}	
			swDiv.pixelTop = y;
			swDiv.pixelLeft = x;		
			swDiv.visibility = what;
			return;
			}
		}
		
	//	DJEM 08-06-04
	function popupSiteTypeDiv ( divid, what, id ) {
		
		var div = document.getElementById(divid);
		if ( !div ) return;
		
		if ( what == "hidden" ) {
			if ( gSiteActiveDiv != null )
				return;
			div.style.visibility = what;
			gSiteActiveDiv = null;
			return;
			}
			
		if ( what == "click" ) {
			if ( gSiteActiveDiv != null ) {
				if ( gSiteActiveDiv.style.visibility == "hidden" ) 
					gSiteActiveDiv.style.visibility = "visible";
				else {
					gSiteActiveDiv.style.visibility = "hidden";
					//gSiteActiveDiv = null;
					}
				}
			return;
			}
			
		if ( gSiteActiveDiv != null ) {
			gSiteActiveDiv.style.visibility = "hidden";
			gSiteActiveDiv = null;
			}
			
		x = DL_GetElementLeft(document.getElementById(id)) + 50;
		y = DL_GetElementTop(document.getElementById(id)) - 15;
		
		div.style.top = y;
		div.style.left = x;
		
		div.style.visibility = what;
		gSiteActiveDiv = div;
		
		}
		
	function popupSiteDivHandler ( id, what ) {
	
		if ( what == "out" ) {
			//gSiteActiveDiv = null;
			return;
			}
		
		gSiteActiveDiv = document.getElementById(id);
			
		}
		
	function popupSiteDivClose () {
		//alert ( "popupSiteDivClose() " + gSiteActiveDiv );
		if ( gSiteActiveDiv != null ) {
			gSiteActiveDiv.style.visibility = "hidden";
			gSiteActiveDiv = null;
			return true;
			}
		return false;
		}


	function legend(what) {

		var elem = document.getElementById('legendDiv');
		if ( !elem ) return;

		elem.style.visibility = what;

		}

	
	//	DJEM 08-06-04
	//-->
	

