// declare global variables and objects



// overlay array, this is used to hold the objects that are created while populating the map

// and used to then remove these from the map on view change

var OverlayCollection = new Array();

var RequiredServices = new Array(9);



// global object / variable references used throughout the code

var map, dOverlay, xmlHttp;

var bSouth, bWest, bNorth, bEast, bBounds;

var TruckPin, WalesPin, ScotPin;

var gdir, geocoder, addressMarker;



// status indicator to prevent double handling of a map pan event

var PanHandled = 0;



// container objects added to the map for display of information

var tooltip = document.createElement("div");

var ctrl_Help = document.createElement("div");

var ctrl_Key = document.createElement("div");

var ctrl_Welcome = document.createElement("div");

var ctrl_Search = document.createElement("div");

var scr_Help = document.createElement("div");

var info_Tab = document.createElement("div");



// region map points

var regions = new Array();

regions["north"] = new Array (55.0346198766454725, -2.10089111328125, 8);

regions["centralnorth"] = new Array (53.66843214835869, -1.04296875, 8);

regions["westmidlands"] = new Array (52.634292, -1.690711, 8);

regions["eastmidlands"] = new Array (52.634292, 0.690711, 8);

regions["southeast"] = new Array (50.97140012475756, -0.23895263671875, 8);

regions["south"]= new Array (50.97140012475756, -1.23895263671875, 8);

regions["southwest"] = new Array (50.67140012475756, -3.23895263671875, 8);

//pShowInfoWindow(inPoint, Title, Description, Address, Country, Image, UniqueTag, ID)



var lastPoint;

var lastTitle;

var lastDescription;

var lastAddress;

var lastCountry;

var lastImage;

var lastUniqueTag;

var lastID;




var hdnSrc;



//##################################################################//

// ************************* Start of Load() function (creates map object, and sets up controls, 					 //

// ************************* This also calls various other setup functions to create all the global objects//

// ************************* We use within the map																																				//

//##################################################################//
function GetDetails() {
	hdnSrc = document.getElementById("hdnSrc");
	var src = "";
	if( hdnSrc != null ) {
		hdnSrc.value = "lat="+map.getCenter().lat()+"&lon="+map.getCenter().lng()+"&zoom="+map.getZoom();
		src = hdnSrc.value;
	}
	return src;
}

function DisplayGetMap(btn) {
	
	var src = GetDetails();
	
	//nie dziala w IE - sprawdzic
	
	var parentWin = parent.window;
	btn.style.display = "none";
	parentWin.document.getElementById("ExploriadaFrame").height = "560";
	var div = document.getElementById("GrabMapDiv1");
	if( div ) {
	    div.style.display = "block";
	    var textarea = document.getElementById("GrabMap1");
	    RefreshCode(textarea);
	}
}

function RefreshCode(textarea) {
	var src = GetDetails();
	    if( src != "" && textarea != undefined ) {
	//alert( textarea.innerHTML );
		textarea.innerHTML = "&lt;iframe id=\"ExploriadaFrame\" src=\"http://www.exploriada.com/gemap.php?"+src+"&opt="+getParameter("opt")+"\" width=\"680\" height=\"484\" frameborder=\"no\"&gt;&lt;/iframe&gt;";
	    }
	textarea.select();
}

function none() {}
    

function load() {



// initialise google maps

	if (GBrowserIsCompatible()) {

		try {
	
	//alert(window.location.search.substring(1));

			//var mapElement = document.getElementById("map");
			
			//alert(document.implementation);

			if(document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#SVG","1.1")) { 

				_mSvgEnabled = true;

				_mSvgForced = true;

			}



			// Capture map container object and set it to be a GMap2 object (this initialises and loads google maps)

			map = new GMap2(document.getElementById("map"));	



			// Add the controls and set up the map

			map.enableScrollWheelZoom();

			map.enableContinuousZoom();

			map.addControl(new GScaleControl()); // displays the map scale

			map.addControl(new GLargeMapControl()); // a large pan/zoom control used on Google Maps. Appears in the top left corner of the map by default.





			// call our pin object creation function, this creates our global pin objects

			Create_Pins();

			// call the function to setup our custom control and tab overlays

			Create_ContainerObjects();

			// add in event listeners to reload the pins when the map view changes

			GEvent.addListener(map, "dragend", function() {handlePan(); }); //pShowInfoWindow(inPoint, Title, Description, Address, Country, Image, UniqueTag, ID)

			GEvent.addListener(map, "zoomend", function() {if(lastPoint != null){map.setCenter(lastPoint);pShowInfoWindow(lastPoint, lastTitle, lastDescription, lastAddress, lastCountry, lastImage, lastUniqueTag, lastID);}else{handlePan();}});

			// add in more event handlers to hide custom tabs on map move

			GEvent.addListener(map, "zoom", function() {if(lastPoint != null){map.setCenter(lastPoint);pShowInfoWindow(lastPoint, lastTitle, lastDescription, lastAddress, lastCountry, lastImage, lastUniqueTag, lastID);}else{handlePan();}});

			GEvent.addListener(map, "movestart", function() {info_Tab.style.visibility='hidden';});

			GEvent.addListener(map, "moveend", function() {if (info_Tab.style.visibility=='hidden'){lastPoint = null} });

			GEvent.addListener(map, "dragstart", function() {info_Tab.style.visibility='hidden';});

			GEvent.addListener(map, "dblclick", function() {info_Tab.style.visibility='hidden';});

			GEvent.addListener(map, "mousewheel", 
			    function() {
				info_Tab.style.visibility='hidden';
			    }
			);



			//var region = getParameter("area");
			var areaLat = getParameter("lat");
			var areaLon = getParameter("lon");
			var areaZoom = getParameter("zoom");
	
			//alert("areaLat: "+areaLat+"\nareaLon: "+areaLon+"\nareaZoom: "+areaZoom);

			if (areaLat == 'null' || areaLon == 'null' || areaZoom == 'null' || areaLat == '' || areaLon == '' || areaZoom == ''){

				map.setCenter(new GLatLng(32.96187505907603,-2.1533203125), 2);

			} else {

				//ZoomToRegion(region);
				ZoomToPoint( new Array( new Point(areaLat,areaLon) ), areaZoom );

			}

			

			// save the default load state into the cookies and googles own view save
			map.savePosition();
			setCookie("gmap_viewsave_CentreLat",map.getCenter().lat(),1);
			setCookie("gmap_viewsave_CentreLng",map.getCenter().lng(),1);
			setCookie("gmap_viewsave_ZoomLvl",map.getZoom(),1);

			// create our postcode search object
			//localSearch = new GlocalSearch();
			//localSearch.setAddressLookupMode( GlocalSearch.ADDRESS_LOOKUP_ENABLED );

			// fire the handlePan function to setup default points, this may have already happened, but we are better re-firing the event at this point
			//Show_Search();

		} catch( e ) {

			//alert("An error was caught: " + e );
			alert("The map may not render properly.\nPlease use one of the recommended browsers:\n\nFirefox (version 2 or higher)\nInternet Explorer (version 7 or higher)\nGoogle Chrome\nOpera (version 9 or higher)");

		}

	}

}



function Create_Pins(){
	// create pin objects
	TruckPin = new GIcon();
	TruckPin.image = "/imgs/exploriada-icon.png";
	TruckPin.iconSize = new GSize(34, 34);
	TruckPin.iconAnchor = new GPoint(17, 32);
	TruckPin.infoWindowAnchor = new GPoint(17, 32);
}



function Create_ContainerObjects() {

	// setup and add tooltop container
	tooltip.setAttribute("id","div_marker_tooltip");
	tooltip.style.border="1px #555555 solid";
	tooltip.style.backgroundColor="#ffffff";
	tooltip.style.fontWeight="bold";
	tooltip.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	tooltip.style.fontSize="9px";
	tooltip.style.opacity="0.7";
	tooltip.style.filter="alpha(opacity=70)";
	tooltip.style.padding="2px 1ex";
	tooltip.style.whiteSpace="nowrap";
	tooltip.style.margin="0";
	tooltip.style.zIndex=5;
	tooltip.style.visibility="hidden";
	document.getElementById("map").appendChild(tooltip);

	// key sidebar button
	/*ctrl_Key.innerHTML = "<div onclick=\"Show_Key();\" style='text-align:center;border-style: solid; border-color: white rgb(176, 176, 176) rgb(176, 176, 176) white; border-width: 1px; font-size: 12px;'>Services</div>";
	ctrl_Key.style.border="1px #000000 solid";
	ctrl_Key.style.backgroundColor="#ffffff";
	ctrl_Key.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	ctrl_Key.style.fontSize="9px";
	ctrl_Key.style.textalign="center";
	ctrl_Key.style.cursor="pointer";
	ctrl_Key.style.whiteSpace="nowrap";
	ctrl_Key.style.margin="0";
	ctrl_Key.style.padding="0";
	ctrl_Key.style.width="63px";
	ctrl_Key.style.zIndex=5;
	document.getElementById("map").appendChild(ctrl_Key);
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(67,24));
	pos.apply(ctrl_Key);

	// Search sidebar button
	ctrl_Search.innerHTML = "<div onclick=\"Show_Search();\" style='text-align:center;border-style: solid; border-color: white rgb(176, 176, 176) rgb(176, 176, 176) white; border-width: 1px; font-size: 12px;'>Search</div>";
	ctrl_Search.style.border="1px #000000 solid";
	ctrl_Search.style.backgroundColor="#ffffff";
	ctrl_Search.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	ctrl_Search.style.fontSize="9px";
	ctrl_Search.style.textalign="center";
	ctrl_Search.style.cursor="pointer";
	ctrl_Search.style.whiteSpace="nowrap";
	ctrl_Search.style.margin="0";
	ctrl_Search.style.padding="0";
	ctrl_Search.style.width="63px";
	ctrl_Search.style.zIndex=5;
	document.getElementById("map").appendChild(ctrl_Search);
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(131,24)); 
	pos.apply(ctrl_Search);	*/

	// create the helpscreen container
	scr_Help.innerHTML = "";
	scr_Help.style.height = "365px";
	scr_Help.style.width = "196px";
	scr_Help.style.border = "1px solid #5489BF";
	scr_Help.style.zIndex=5;
	scr_Help.style.backgroundColor="#E1EFFA";
	scr_Help.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	scr_Help.style.fontsize="10px";
	scr_Help.style.opacity="0.90";
	scr_Help.style.filter="alpha(opacity=90)";
	scr_Help.style.overflow="hidden";
	scr_Help.style.visibility="hidden";
	document.getElementById("map").appendChild(scr_Help);
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(47,50)); 
	pos.apply(scr_Help);

	// custom info tabs container
	info_Tab.innerHTML = "";
	info_Tab.style.visibility = "hidden";
	info_Tab.style.zIndex=5;
	info_Tab.style.width = "249px";
	info_Tab.style.opacity="0.90";
	scr_Help.style.fontFamily="Verdana, Arial, Helvetica, sans-serif";
	scr_Help.style.opacity="0.90";
	info_Tab.style.filter="alpha(opacity=90)";
	info_Tab.style.visibility = "hidden";
	document.getElementById("map").appendChild(info_Tab);

}



//#######################################################################################
// zoom handler - This function fires every time the map pan or zoom change events fire, 
// it clears overlays and re-loads the relevant overlays dependant map variables
//#######################################################################################

function handlePan() {

    info_Tab.style.visibility='hidden';

    if (PanHandled!=1) {
	PanHandled = 1;
	try {

		// check the tickbox for complete display, this needs to pass its status to the cComplete
		if(document.getElementById("dComplete")) {
			document.getElementById("cComplete").checked = document.getElementById("dComplete").checked;
		}
		if(document.getElementById("dCurrent")) {
			document.getElementById("cCurrent").checked = document.getElementById("dCurrent").checked;
		}
		if(document.getElementById("dPlanned")) {
			document.getElementById("cPlanned").checked = document.getElementById("dPlanned").checked;
		}		

		// check if we have a info window open, if we do we cant clear overlays
		//if (map.getInfoWindow().isHidden()) {	RemoveOverlays();	}	

		// check the window is inside the limits for this map (whole world), this map is limited to a minimum zoom level of 2
		// and the boundries of the map are below
		// South < -86 		// West < -180		// North > 86		// East > 180
		bBounds = map.getBounds();
		bSouth = bBounds.getSouthWest().lat();					bWest = bBounds.getSouthWest().lng();
		bNorth = bBounds.getNorthEast().lat();					bEast = bBounds.getNorthEast().lng();
		
		if ((bSouth <= -86) || (bWest <= -180) || (bNorth >= 86) || (bEast >= 180) ) 

		{ // if we are looking at zoom level 6, then we reset default viewstate, otherwise we re-load the saved position

			if(map.getZoom() == 6) {
				map.setCenter(new GLatLng(32.96187505907603,-2.1533203125), 2);
				// reset the viewstate memory to hold the default view
				map.savePosition();
				// set cookies to save viewstate of the map, these cookies should expire after 24 hours
				setCookie("gmap_viewsave_CentreLat",map.getCenter().lat(),1);
				setCookie("gmap_viewsave_CentreLng",map.getCenter().lng(),1);
				setCookie("gmap_viewsave_ZoomLvl",map.getZoom(),1);}
			else {	map.returnToSavedPosition();}
		} // outside limits, load last good viewstate

		else {
			map.savePosition(); 
			// set cookies to save viewstate of the map, these cookies should expire after 24 hours
			setCookie("gmap_viewsave_CentreLat",map.getCenter().lat(),1);
			setCookie("gmap_viewsave_CentreLng",map.getCenter().lng(),1);
			setCookie("gmap_viewsave_ZoomLvl",map.getZoom(),1);
		} // current viewstate is valid, save it


		RemoveOverlays();
		GetPointsXML(bBounds, map.getZoom());
		DisplayOverlays();


		PanHandled = 0;

	} catch( e ) {

		alert("An error was caught: " + e );
		PanHandled = 0;

	}

    }

}

// ************************* End of handlePan() function *************************************** //





//#######################################################################################
// info project marker function - creates the pointer on the map and attatches the info window function to it
//#######################################################################################

function CreateProjectMarker( inPoint, Title, Description, Address, Country, Image, UniqueTag, ID ) {

	// Render the pointers (and add in the associated info window function calls)
	var tmpLineCol
	var pntObj = new GMarker(inPoint, TruckPin);
	AddNewOverlay(pntObj);	

	// add the click listener to the point to call the infowindow function 
	GEvent.addListener(pntObj, "click", function() { pShowInfoWindow(inPoint, Title, Description, Address, Country, Image, UniqueTag, ID);})

	// mouseover tooltips
	pntObj.tooltip = "<div class='tooltip'>"+ Title +"</div>";
	GEvent.addListener(pntObj,"mouseover", function() {showTooltip(pntObj);});
	GEvent.addListener(pntObj,"mouseout", function() {tooltip.style.visibility="hidden";	});

}



// Create marker for printable page

function CreateMiniProjectMarker(inPoint) {
	var pntObj = new GMarker(inPoint, TruckPin);
	AddNewOverlay(pntObj);
}



//#######################################################################################

// create and send an AJAX request for point data relevant to the current map

//#######################################################################################

/*function GetPointsXML(winBounds, zoomlvl) {

// create the XMLhttp object	

	xmlHttp = GetXmlHttpObject();

	// check our XMLhttp object was created

	if (xmlHttp==null) {	alert ("Browser does not support HTTP Request (Dynamic point loading)");	return;	}

	

	// actually make the request

	var url = "/GetPointsxml.asp?n=" + winBounds.getNorthEast().lat() +"&e=" + winBounds.getNorthEast().lng();

	url = url +"&s="+ winBounds.getSouthWest().lat() +"&w="+ winBounds.getSouthWest().lng() + "&zoom=" + zoomlvl;
	
	// check for debug items on screen, if so, fill them out!! 

	if (document.getElementById("tNorth")) {

		document.getElementById("tNorth").value = winBounds.getNorthEast().lat();

		document.getElementById("tEast").value = winBounds.getNorthEast().lng();

		document.getElementById("tSouth").value = winBounds.getSouthWest().lat();

		document.getElementById("tWest").value = winBounds.getSouthWest().lng();

		document.getElementById("tZoom").value = zoomlvl;

		document.getElementById("tCentre").value = map.getCenter().lat() + "," + map.getCenter().lng();

		document.getElementById("tUrl").value = url;

	}

	xmlHttp.onreadystatechange=fnSearchSKUCallback;	// set the callback function (the function called when the status changes, ie the page loads)

	xmlHttp.open("GET",url,true);		

	xmlHttp.send(null);

}*/

//#######################################################################################

// create and send an AJAX request for point data relevant to the current map

//#######################################################################################

function GetPointsXML(winBounds, zoomlvl) {

	// create the XMLhttp object
	xmlHttp = GetXmlHttpObject();

	// check our XMLhttp object was created
	if (xmlHttp==null) {	alert ("Browser does not support HTTP Request (Dynamic point loading)");	return;	}	

	var areaOpt = getParameter("opt");
	var url = "/xml_places.php?d=places&n=" + winBounds.getNorthEast().lat() +"&e=" + winBounds.getNorthEast().lng();
	url = url +"&s="+ winBounds.getSouthWest().lat() +"&w="+ winBounds.getSouthWest().lng() + "&zoom=" + zoomlvl;
	if( areaOpt != null ) url += "&opt=" + areaOpt;
	//alert(url);
	
	// check for debug items on screen, if so, fill them out!!

	if (document.getElementById("tNorth")) {
		document.getElementById("tNorth").value = winBounds.getNorthEast().lat();
		document.getElementById("tEast").value = winBounds.getNorthEast().lng();
		document.getElementById("tSouth").value = winBounds.getSouthWest().lat();
		document.getElementById("tWest").value = winBounds.getSouthWest().lng();
		document.getElementById("tZoom").value = zoomlvl;
		document.getElementById("tCentre").value = map.getCenter().lat() + "," + map.getCenter().lng();
		document.getElementById("tUrl").value = url;
	}

	xmlHttp.onreadystatechange=fnSearchSKUCallback;	// set the callback function (the function called when the status changes, ie the page loads)
	xmlHttp.open("GET",url,true);		
	xmlHttp.send(null);

}

//#######################################################################################

// XMLhttp callback function - This function fires when the 

//#######################################################################################

function fnSearchSKUCallback() { // XMLhttp callback function
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		ProcessXML(xmlHttp.responseText);
	}
} 

	

//#######################################################################################
// create the XMLhttp object 
//#######################################################################################
function GetXmlHttpObject(handler) { 

	var objXMLHttp = null;
	if (window.XMLHttpRequest) { objXMLHttp = new XMLHttpRequest();	} // firefox & Mozilla based browsers
	else if (window.ActiveXObject) {	objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");	} // Internet Explorer based browsers
	return objXMLHttp;

}

//#######################################################################################

// Process XML that was returned by the XMLhttp request. (identify projects, points, and poly lines, as well as overlays

// This creates an XMLdom object and uses the XMLdom to parse the XML returned 

//#######################################################################################

function ProcessXML(ResponseText) {

	var cntTruckStop, cntItems, cntSubItems, cntServices ;

	// 4 counter variables, one for the master projects loop, 

	// one for Items (Points, Polylines, overlays

	// one for subItems - Polyline points

	// one for required services

	var arrItems, arrSubItems;

	// create level arrays - one for items, one for subitems 

	ResponseText = ResponseText.toString(); // lets make sure that the response is in a string format 

	

	// load the XML string returned into the XML parser

	if (window.ActiveXObject)	{	var XMLdoc=new ActiveXObject("Microsoft.XMLDOM");XMLdoc.async="false";	XMLdoc.loadXML(ResponseText);	} // IE XMLdom 

	else { var parser=new DOMParser(); var XMLdoc=parser.parseFromString(ResponseText,"text/xml"); 	} // FF & Mozilla XMLdom

	// grab the document element of the DOM

	XMLdoc=XMLdoc.documentElement;

	// ok, so now we need to start breaking the returned XML down for processing

	if (XMLdoc != undefined){

		// create a TruckStops array from the XML document

		var docTruckStops = XMLdoc.getElementsByTagName("Place");

		// @@@@@@

		// Main Loop start - for each TruckStop returned by the XML

		// @@@@@@ 

			for (cntTruckStop=0;cntTruckStop<docTruckStops.length;cntTruckStop++) // for each TruckStop found!! 

			{	// ok, so this point we are looking at a particular TruckStop		

				var docTruckStop = docTruckStops[cntTruckStop]; // just to neaten the code a little

					var arrItems = docTruckStop.getElementsByTagName("Point"); // grab the points associated with this truck stop

					// Loop through the points and render them as needed

					for (cntItems=0;cntItems<arrItems.length;cntItems++) // for each point in the project

						{

							var displayStop = true;
							
							if( cntServices != undefined ) {

							    for (cntService=0;cntService<9;cntService++){

								if (docTruckStop.getElementsByTagName("Facilities").item(0).childNodes[cntService].childNodes[0].nodeValue == "No" && RequiredServices[cntService]) {

									displayStop = false;

								}

							    }
							
							}

							if (displayStop){

								CreateProjectMarker(

									new GLatLng( parseFloat(arrItems[cntItems].getAttribute('lat')),

									parseFloat(arrItems[cntItems].getAttribute('lon'))), // inPoint

									docTruckStop.getElementsByTagName("Title")[0].childNodes[0].nodeValue, // Title

									docTruckStop.getElementsByTagName("Description")[0].childNodes[0].nodeValue + "," + // Description - place desc

									docTruckStop.getElementsByTagName("Title")[0].childNodes[0].nodeValue + "," + // Description - place title

									docTruckStop.getAttribute('uniquetag'), // Description - place url

									docTruckStop.getElementsByTagName("Address")[0].childNodes[0].nodeValue, // Address - Country

									docTruckStop.getElementsByTagName("Country")[0].childNodes[0].nodeValue, // Address - Country								

									docTruckStop.getElementsByTagName("Image")[0].attributes[0].nodeValue + "," + // Image - thumb url

									docTruckStop.getElementsByTagName("Image")[0].attributes[1].nodeValue + "," + // Image - img ext

									docTruckStop.getElementsByTagName("Image")[0].attributes[2].nodeValue + "," + // Image - img uid

									docTruckStop.getElementsByTagName("Title")[0].childNodes[0].nodeValue + "," + // Image - place title

									docTruckStop.getAttribute('uniquetag'), // Image - place url

									docTruckStop.getAttribute('uniquetag'), // Place url

									docTruckStop.getAttribute('id') // Place id

								);

							}

						} //CreateProjectMarker( inPoint, Title, Description, Address, Country, Image, UniqueTag, ID )

				}

			DisplayOverlays();

		}

}

	

	

//#######################################################################################

// Postcode Search handler function

//#######################################################################################

function doPostCodeSearch() {

	if (document.getElementById("srcSearch").value.replace(/^\s+|\s+$/g, '') != "") { // we have a search query

		usePointFromPostcode(document.getElementById("srcSearch").value.replace(/^\s+|\s+$/g, '') , ZoomToPoint);

	}



	return false;

}



//#######################################################################################

// Google AJAX Search API - takes an address, calculates name, lat and lng, returns results in array

// filter matches outside the screen, then zoom screen to position.. 

// there are filters to ensure results are uk based only.... 

//#######################################################################################

function usePointFromPostcode(postcode, callbackFunction) {

	// Set up the callback function that will be executed once the GLocalSearch object finishes

	localSearch.setSearchCompleteCallback( null, function() {

		// Remove anything with lat/longs that are not in the UK

		// (mostly bad results will be in San Francisco - the default centre for the

		// GLocalSearch object)

		for( i = 0; i < localSearch.results.length; i++ ) {

			

			if( localSearch.results[i].lat > 55.838 || localSearch.results[i].lat < 49.923 ||

				localSearch.results[i].lng > 1.845 || localSearch.results[i].lng < -5.77 ) {

				

				// Remove an object from the array, and decrement the counter by one.

				// It will be re-incremented by the for loop, and the element in the same position

				// will be tested again. Otherwise we would jump over the element

				localSearch.results.splice( i, 1 );

				i--;

			}

		}

		

		// If there is at least one result remaining, then we will invoke the callback function,

		// passing it the array of results. Otherwise we just display an error.

		if ( localSearch.results[0] ) {

			callbackFunction(localSearch.results, 11);

		} else {

			alert("Your search for '" + postcode + "' returned no results");

		}

	});

	

	// Invoke the search and wait for it to pass the result to our callback function

	localSearch.execute(postcode + ", UK");

	return false;

}





//#######################################################################################

// Zoom to road function - this takes a passed in comma separated value, parses it and zooms the map to the ralevant area

// format for CSV data passing into the function is latitude, longitude, zoom level

//#######################################################################################

function ZoomToRoad( CSVdata ) {

	try {

		lastPoint = null;

		if (CSVdata!="") { // we have something passed, should be CSV data, otherwise we have an error

			var inPoint = new GLatLng(parseFloat(CSVdata.split(",")[0]),parseFloat(CSVdata.split(",")[1]));

			map.setCenter( inPoint , parseInt(CSVdata.split(",")[2]));

			handlePan();

		}

	} catch( e ) {

		alert("An error was caught: " + e );

	}

}

function Point( lat, lng ) {
        this.lat = lat;
        this.lng = lng;
    }



function ZoomToPoint( inObject, inZoom) {

	lastPoint = null;

	var resultLat = inObject[0].lat;

	var resultLng = inObject[0].lng;
	
	//		alert("areaLat: "+resultLat+"\nareaLon: "+resultLng+"\nareaZoom: "+inZoom);
			
	map.setCenter( new GLatLng(resultLat, resultLng) , parseInt(inZoom));

//	var inPoint = new GLatLng(parseFloat(resultLat),parseFloat(resultLng));	

//	map.setZoom( parseInt(inZoom) );

//	map.panTo( inPoint );

//	handlePan();

	//var zoom = map.getZoom();
	//alert(map.getZoom());
	//var hdnZoom = document.getElementById("hdnZoom");

	return false;

}



function ZoomToRegion(region){

	lastPoint = null;
	
//	regions["westmidlands"] = new Array (52.634292, -1.690711, 8);
	
	//alert( region + ": " + regions[region][0] + " " + regions[region][1] + "\nzoom: " +regions[region][2])

//	map.setCenter( new GLatLng(regions[region][0], regions[region][1]) , regions[region][2]);

//	map.savePosition();

//	setCookie("gmap_viewsave_CentreLat",map.getCenter().lat(),1);

//	setCookie("gmap_viewsave_CentreLng",map.getCenter().lng(),1);

//	setCookie("gmap_viewsave_ZoomLvl",map.getZoom(),1);	

	return false;

}



//#######################################################################################

// pLinkWindow is used to show the balloon for scotland / wales pins

//#######################################################################################

function pLinkInfoWindow(inPoint,strTitle, htmlLink) {

	pntHTML = "<h3 style='padding:0px; margin: 3px;'>" + strTitle + "</h3>" + htmlLink;

	var tempDiv;		tempDiv = document.createElement("div");		tempDiv.className = "bubble";	tempDiv.style.width ="150px";	tempDiv.innerHTML = pntHTML;		

	infoTab = map.openInfoWindowHtml(inPoint, pntHTML );

}



// *********************************************************************************************************

//#######################################################################################

// This section is used to create the content for some of the custom overlays

//#######################################################################################

// *********************************************************************************************************





//#######################################################################################

// info window function, this creates the HTML for the custom tabs (the info when you click on a point)

//#######################################################################################

function pShowInfoWindow(inPoint, Title, Description, Address, Country, Image, UniqueTag, id) {



	// this will eventually be passed from the DB, but not yet

	ProjDescription = "";	

	if (map.getZoom > 6)

	{

		map.setZoom(6);

	}

	// first we need to create the HTML string for the custom tabs

	var pntHTML = "";

	pntHTML += "<div style=\"border:1px solid #5489BF;width:192px;font-family:arial;\">";

	pntHTML += "<div style=\"padding:5px 10px 5px 10px;margin:0px;background-color:#C3DFF5;border-bottom:1px solid #5489BF;color:#004D9A;font-size:11px;font-weight:bold;\">";

	pntHTML += "<img onclick=\"info_Tab.style.visibility='hidden'\" src=\"/imgs/helpclose.gif\" style=\"float:right;cursor:pointer;margin-top:-1px;margin-right:-6px;\" width=\"13px\" height=\"13px\"/>";

	pntHTML += Title;

	pntHTML += "</div>";

	pntHTML += "<div style=\"height:20px;padding:0px;margin:0px;background-color:#E1EFFA;color:#004D9A; font-weight:bold;font-size:12px;border-bottom:1px solid #5489BF;\">";

	pntHTML += "<div style=\"height:20px;margin:0px;padding:0px;width:58px;float:left;border-right:1px solid #5489BF;text-align: center;\" id=\"custom_tab_hours\" onclick=\"Do_Tab_desc('" + Description + "');\"><div style=\"padding:3px 0px\">About</div></div>";

	pntHTML += "<div style=\"height:20px;margin:0px;padding:0px;width:70px;float:left;border-right:1px solid #5489BF;text-align: center;\" id=\"custom_tab_service\" onclick=\"Do_Tab_photo('" + Image + "');\"><div style=\"padding:3px 0px\">Photo</div></div>";

	pntHTML += "<div style=\"height:20px;margin:0px;padding:0px;width:62px;float:left;text-align: center;\" id=\"custom_tab_address\" onclick=\"Do_Tab_address('" + Address + "','" + Country + "');\"><div style=\"padding:3px 0px\">Address</div></div>";

	//pntHTML += "<div style=\"height:30px;margin:0px;padding:0px;width:55px;float:left;text-align: center;\" id=\"custom_tab_print\" onclick=\"Do_Tab_print('" + id + "');\"><div style=\"padding:5px 0px\">Print</div></div>";

	pntHTML += "</div>";

	pntHTML += "<div style=\"height:100px; padding:8px 10px 0px 10px; margin:0px;background-color:#FFFFFF;\" id=\"custom_tab_content\">";

	pntHTML += "<!-- tab content goes here -->";

	pntHTML += "</div>";

	pntHTML += "</div>";

	// changed from PNG to GIF for IE6

	// pntHTML += "<div style=\"padding:0px; margin:0px;background-image:url('/images/tab_pointer.png');background-position:79px 0px ;background-repeat:no-repeat;height:49px;width:249px;\"></div>";

	pntHTML += "<div style=\"padding:0px; margin:0px;background-image:url('/images/tab_pointer.gif');background-position:73px -26px ;background-repeat:no-repeat;height:33px;width:249px;\"></div>";



	// now inject the code into our tab container div object

	info_Tab.innerHTML = pntHTML;



	// need to find the distance to the top of the map, and from the edge of the map... 

	// if its too close our custom tabs will pop ouside the map area

	// panBy(distance) is used to do the panning.... but

	// when we do the pan, we may have to re-grab our offsets as they could change 

	// our pop-up is pointing to a position that needs to be : 

	// now we also need to consider the controls.. these use up 40 pixels from the top



	var dNorth = 230; 

	var dSouth = 20; 

	var dWest = 330;

	var dEast = 175;



	// grab the window boundries, and the point co-ordinates in pixels

	var point1=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getNorthEast(),map.getZoom());

	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());

	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(inPoint,map.getZoom());



	// create an X and Y adjustment variable

	var adjustmentx = 0;

	var adjustmenty = 0;



	// test the point for proximity to the west, east and north boundries as defined by our boundry variables

	// where these are too close, calculate the offset required to move the tab and map by to fit inside our boundry

	if ((offset.x - point1.x) >= -dEast) {

		adjustmentx = - (dEast + (offset.x - point1.x));

	} // east



	if ((offset.x - point.x) <= dWest) {

		adjustmentx = dWest - (offset.x - point.x);

	} // west



	if ((offset.y-point1.y) <= dNorth) {

		adjustmenty = dNorth - (offset.y-point1.y);

	} // north



	if ((offset.y-point.y) >= -dSouth) {

		adjustmenty = - (dSouth + (offset.y - point.y));

	} // south



	if ((adjustmentx!=0) || (adjustmenty!=0)){ // check if we have an adjustment to make 

		//	we do so calculate the new anchor point from the offsets

		// create the tabs, then pan the window (and pins) to line up

		var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(((offset.x - point.x) - (80 - adjustmentx)),((point.y- offset.y) - adjustmenty))); 

		pos.apply(info_Tab);

		map.panBy(new GSize(adjustmentx, adjustmenty));

		info_Tab.style.visibility="visible";

	} else { // we dont have an adjustment, so we just create the tabs window

		var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - 80,- offset.y + point.y)); 

		pos.apply(info_Tab);

		info_Tab.style.visibility="visible";

	}

	

	lastPoint = inPoint;

	lastTitle = Title;

	lastDescription = Description;

	lastAddress = Address;

	lastImage = Image;

	UniqueTag = UniqueTag;

	lastID = id;

	
	Do_Tab_desc(Description);

}

//#######################################################################################

// info window helper functions, this creates the HTML for the tab content area (the info when you click on a tab on the custom tabs)

//#######################################################################################



function Do_Tab_photo(Image) {

	document.getElementById("custom_tab_service").style.backgroundColor="#9ABADA";

	document.getElementById("custom_tab_hours").style.backgroundColor="transparent";

	document.getElementById("custom_tab_address").style.backgroundColor="transparent";

	//document.getElementById("custom_tab_print").style.backgroundColor="transparent";



	document.getElementById("custom_tab_service").style.color="#FFFFFF";

	document.getElementById("custom_tab_hours").style.color="#004D9A";

	document.getElementById("custom_tab_address").style.color="#004D9A";

	//document.getElementById("custom_tab_print").style.color="#004D9A";



	document.getElementById("custom_tab_service").style.cursor="default";

	document.getElementById("custom_tab_hours").style.cursor="pointer";

	document.getElementById("custom_tab_address").style.cursor="pointer";

	//document.getElementById("custom_tab_print").style.cursor="pointer";



	var tmpHTML = "";

	var arrImage = Image.split(",");
	
	if( Image.split(",")[2].indexOf("noimage") > -1 ) { tmpHTML += '<a href="' + Image.split(",")[4] + '" title="' + Image.split(",")[3] + '" target="_parent">'; }
	tmpHTML += '<img height="80" width="80" src="/thumb/'+Image.split(",")[1]+'/' + Image.split(",")[2]+'/" alt="' + Image.split(",")[3] + '" title="' + Image.split(",")[3] + '" style="margin: 0px auto 3px auto;display:block;" border="0"/>';
	if( Image.split(",")[2].indexOf("noimage") > -1 ) { tmpHTML += '</a>'; }
	tmpHTML += '<a href="' + Image.split(",")[4] + '" title="All pictures of ' + Image.split(",")[3] + '" target="_parent" style="font-size:12px;display:block;text-align:center;color: #96201E;font-weight:bold;text-decoration: none;">All pictures &#187;</a>';
	
	document.getElementById("custom_tab_content").innerHTML = tmpHTML;

}



function Do_Tab_desc(Description) {

	document.getElementById("custom_tab_service").style.backgroundColor="transparent";

	document.getElementById("custom_tab_hours").style.backgroundColor="#9ABADA";

	document.getElementById("custom_tab_address").style.backgroundColor="transparent";



	document.getElementById("custom_tab_service").style.color="#004D9A";

	document.getElementById("custom_tab_hours").style.color="#FFFFFF";

	document.getElementById("custom_tab_address").style.color="#004D9A";



	document.getElementById("custom_tab_service").style.cursor="pointer";

	document.getElementById("custom_tab_hours").style.cursor="default";

	document.getElementById("custom_tab_address").style.cursor="pointer";



	var tmpHTML = "";

	tmpHTML += "<div style=\"padding:0px;margin-bottom:10px;color:#333333;font-size:12px;height:73px;overflow:hidden;\">";
	tmpHTML += Description.split(",")[0];
	tmpHTML += "</div>";

	tmpHTML += "<div style=\"padding:0px;margin:0px;color:#333333;font-size:12px;\">";
	tmpHTML += '<a href="' + Description.split(",")[2] + '" title="More about ' + Description.split(",")[1] + '" target="_parent" style="color: #96201E;font-weight:bold;text-decoration: none;">More &#187;</a>';

	tmpHTML += "</div>";

	document.getElementById("custom_tab_content").innerHTML = tmpHTML;

}



function Do_Tab_address(address, country) {	

	document.getElementById("custom_tab_service").style.backgroundColor="transparent";
	document.getElementById("custom_tab_hours").style.backgroundColor="transparent";
	document.getElementById("custom_tab_address").style.backgroundColor="#9ABADA";


	document.getElementById("custom_tab_service").style.color="#004D9A";
	document.getElementById("custom_tab_hours").style.color="#004D9A";
	document.getElementById("custom_tab_address").style.color="#FFFFFF";


	document.getElementById("custom_tab_service").style.cursor="pointer";
	document.getElementById("custom_tab_hours").style.cursor="pointer";
	document.getElementById("custom_tab_address").style.cursor="default";


	var tmpHTML = "";
	tmpHTML += "<div style=\"padding:0px;margin-bottom:10px;color:#333333;font-size:12px;\">";
	tmpHTML += address;
	tmpHTML += "</div>";
	tmpHTML += "<div style=\"padding:0px;margin:0px;color:#333333; font-weight:bold;font-size:12px;\">";
	tmpHTML += country;
	tmpHTML += "</div>";
	document.getElementById("custom_tab_content").innerHTML = tmpHTML;

}



function Do_Tab_print(id) {

	document.getElementById("custom_tab_service").style.backgroundColor="transparent";
	document.getElementById("custom_tab_hours").style.backgroundColor="transparent";
	document.getElementById("custom_tab_address").style.backgroundColor="transparent";


	document.getElementById("custom_tab_service").style.color="#004D9A";
	document.getElementById("custom_tab_hours").style.color="#004D9A";
	document.getElementById("custom_tab_address").style.color="#004D9A";


	document.getElementById("custom_tab_service").style.cursor="pointer";
	document.getElementById("custom_tab_hours").style.cursor="pointer";
	document.getElementById("custom_tab_address").style.cursor="pointer";


	var tmpHTML = "";
	tmpHTML += "<div style=\"padding:10px;margin:0px;color:#004D9A; font-weight:bold;font-size:12px;\">";
	var URL = "/printable.asp?stop=" + id
	tmpHTML += "<ul style=\"font-size:100%;\"><li><a href=\"javascript:showPrintable('" + URL + "')\">Print Truckstop</a></li>";
	tmpHTML += "<li><a target=\"blank\" href=\"/pdf.asp?stop=" + id + "\">Download PDF</a></li>";
	document.getElementById("custom_tab_content").innerHTML = tmpHTML;

}





//#######################################################################################

// more custom overlays =========================================================================

//#######################################################################################



function Show_Welcome() {

	// wecome screen, reset the view to default
	map.setCenter(new GLatLng(52.96187505907603,-2.1533203125), 6);

	// generate welcome message HTML
	var tmpHTML;
	tmpHTML = "<div style='width:180px;padding:18px 8px;margin:0px;background-color:#C3DFF5;border-bottom:1px solid #5489BF;color:#004D9A;font-size:12px;font-weight:bold;'>";
	tmpHTML += "<img onclick='scr_Help.style.visibility=\"hidden\";' src='/images/helpclose.gif' style='float:right;cursor:pointer;margin-top:-17px;margin-right:-6px;' width='13px' height='13px'/>Find Highways Agency Road Projects in your area</div>";
	tmpHTML += "<div style='padding:5px;background-color:#E1EFFA;color:#004D9A; font-weight:bold;font-size:12px;'>" ;
	tmpHTML += "<h3 style=margin:0px;padding:4px 5px;'>Using the map</h3><p style='font-family:verdana;margin:0px;padding:4px 5px;'>To use the map, use the controls to the left hand side, if you need further assistance, please click on the \"Help\" menu above.</p>";
	tmpHTML += "<p style=margin:0px;padding:4px 0px;'>In this section you can quickly find details of our road improvement projects and register for email alerts on information that's important to you.</p>";
	tmpHTML += "<p style=margin:0px;padding:4px 0px;'>Note that the Highways Agency only deal with main trunk roads and motorways in England, roads not covered include...............</p>";
	tmpHTML += "</div>";

	// push the HTML into the help screen div container	

	scr_Help.style.height = "auto";
	scr_Help.style.width = "196px";
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(47,50)); 

	pos.apply(scr_Help);

	scr_Help.innerHTML = tmpHTML;
	scr_Help.style.visibility = "hidden";

	// reset the viewstate memory to hold the default view
	map.savePosition(); 

	// set cookies to save viewstate of the map, these cookies should expire after 24 hours
	setCookie("gmap_viewsave_CentreLat",map.getCenter().lat(),1);
	setCookie("gmap_viewsave_CentreLng",map.getCenter().lng(),1);
	setCookie("gmap_viewsave_ZoomLvl",map.getZoom(),1);

}



function Show_Help() {

	// help button pop up information
	// plan will be to update this into a multi page help section, pointing out the map controls, and guiding the user as to how the map works
	// (panning, zooming, overlays, pins, popups, and other features)

	var tmpHTML;
	tmpHTML = "<div style='width:180px;padding:18px 8px;margin:0px;background-color:#C3DFF5;border-bottom:1px solid #5489BF;color:#004D9A;font-size:12px;font-weight:bold;'>";
	tmpHTML += "<img onclick='scr_Help.style.visibility=\"hidden\";' src='/images/helpclose.gif' style='float:right;cursor:pointer;margin-top:-17px;margin-right:-6px;' width='13px' height='13px'/>Road Projects Help Centre</div>";
	tmpHTML += "<div style='padding:5px;background-color:#E1EFFA;color:#004D9A; font-weight:bold;font-size:12px;'>" ;
	tmpHTML += "<p style=margin:0px;padding:4px 0px;'>Welcome to the Help Centre, this section will become a multi screen help section, guiding users on how the controls work, and how to find relevant information to them.</p>";
	tmpHTML += "<p style=margin:0px;padding:4px 0px;'>This can be as long or short as we feel is required for the end users.</p>";
	tmpHTML += "</div>";
	scr_Help.style.height = "auto";
	scr_Help.style.width = "196px";
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(47,50)); 
	pos.apply(scr_Help);
	scr_Help.innerHTML = tmpHTML;
	scr_Help.style.visibility = "hidden";

}



/*function Show_Key() {

	// key button pop up information
	var tmpHTML;
	tmpHTML = "<div style='width:180px;padding:18px 8px;margin:0px;background-color:#C3DFF5;border-bottom:1px solid #5489BF;color:#004D9A;font-size:12px;font-weight:bold;'>";
	tmpHTML += "<img onclick='scr_Help.style.visibility=\"hidden\";' src='/images/helpclose.gif' style='float:right;cursor:pointer;margin-top:-17px;margin-right:-6px;' width='13px' height='13px'/>Truck Stop Services</div>";
	tmpHTML += "<p style='margin:0px;padding:4px 5px;'>Select services to display on map. Select <a style='cursor: pointer' onclick=\"Show_Search();\">search</a> tab to find truckstops in required location </p>";
	tmpHTML += "<div style='padding:5px;background-color:#E1EFFA;color:#004D9A; font-weight:bold;font-size:12px;'>" ;
	tmpHTML += "<form name=\"svcForm\">";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[0]?" checked=\"checked\"":"") + "/> <img src='/images/icons/0_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"Advanced Booking\" alt=\"Advanced Booking\"/> Advanced Booking <br />";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[1]?" checked=\"checked\"":"") + "/> <img src='/images/icons/1_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"Shop\" alt=\"Shop\"/> Shop <br />";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[2]?" checked=\"checked\"":"") + "/> <img src='/images/icons/2_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"Cash Machine\" alt=\"Cash Machine\"/> Cash Machine <br />";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[3]?" checked=\"checked\"":"") + "/> <img src='/images/icons/3_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"Fuel\" alt=\"Fuel\"/> Fuel <br />";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[4]?" checked=\"checked\"":"") + "/> <img src='/images/icons/4_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"Lorry Wash\" alt=\"Lorry Wash\"/> Lorry Wash <br />";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[5]?" checked=\"checked\"":"") + "/> <img src='/images/icons/5_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"Accommodation\" alt=\"Accommodation\"/> Accommodation <br />";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[6]?" checked=\"checked\"":"") + "/> <img src='/images/icons/6_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"TV\" alt=\"TV\"/> TV <br />";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[7]?" checked=\"checked\"":"") + "/> <img src='/images/icons/7_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"CCTV\" alt=\"CCTV\"/> CCTV <br />";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[8]?" checked=\"checked\"":"") + "/> <img src='/images/icons/8_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"Security Fence\" alt=\"Security Fence\"/> Security Fence <br />";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[9]?" checked=\"checked\"":"") + "/> <img src='/images/icons/9_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"Toilets\" alt=\"Toilets\"/> Toilets <br />";
	tmpHTML += "<input type=\"checkbox\" id=\"service\"" + (RequiredServices[10]?" checked=\"checked\"":"") + "/> <img src='/images/icons/10_Yes.gif' width='24' height='24' style='vertical-align: middle;' title=\"Showers\" alt=\"Showers\"/> Showers <br /><br />";
	tmpHTML += "<input type=\"button\" name=\"srcSubmit\" value=\"GO\" style=\"width:180px;border: 1px solid #FFFFFF; color: #FFFFFF; background-color: #004F98;font-weight: bold; font-size: 100%; padding: 2px;\" onclick=\"return setRequiredServices();\" />";
	tmpHTML += "</form>";
	tmpHTML += "</div>"
	

	scr_Help.style.height = "auto";
	scr_Help.style.width = "196px";
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(47,50));
	pos.apply(scr_Help);
	scr_Help.innerHTML = tmpHTML;	

	// now to get the current values for the checkboxes : 
	if(document.getElementById("dComplete")) {
		document.getElementById("dComplete").checked = document.getElementById("cComplete").checked;
	}

	if(document.getElementById("dCurrent")) {
		document.getElementById("dCurrent").checked = document.getElementById("cCurrent").checked;
	}

	if(document.getElementById("dPlanned")) {
		document.getElementById("dPlanned").checked = document.getElementById("cPlanned").checked;
	}		

	scr_Help.style.visibility = "visible";

}*/





/*function Show_Search() {

	// search button pop up information
	var tmpHTML;
	tmpHTML = "<div style='width:180px;padding:18px 8px;margin:0px;background-color:#C3DFF5;border-bottom:1px solid #5489BF;color:#004D9A;font-size:12px;font-weight:bold;'>";
	tmpHTML += "<img onclick='scr_Help.style.visibility=\"hidden\";' src='/images/helpclose.gif' style='float:right;cursor:pointer;margin-top:-17px;margin-right:-6px;' width='13px' height='13px'/>Truck Stops Map Search</div>";
	tmpHTML += "<p style='margin:0px;padding:4px 5px;'>Search for location. Select <a style='cursor: pointer' onclick=\"Show_Key()\">Services</a> tab to show Truckstop services.</p>";
	tmpHTML += "<form action=\"/truckstops.asp\" name=\"srcForm\" method=\"post\" onsubmit=\"return doPostCodeSearch();\"><div style=\"padding:5px;\">";
	tmpHTML += "<label for=\"aRoad\" style=\"color:#194A73;float:left;font-weight:bold;font-size:12px;\">Jump to region</label> <br />";
	tmpHTML += "<select id=\"aRoad\" name=\"aRoad\" style=\"width:180px;border: 1px solid #6E95B2;color:#194A73;\" onchange=\"ZoomToRoad(this.value);document.getElementById('mRoad').value = ''\">";
	tmpHTML += "<option value=\"\"></option>";
	tmpHTML += "<option value=\"55.0346198766454725,-2.10089111328125,8\">North</option>";
	tmpHTML += "<option value=\"53.66843214835869,-1.04296875,8\">Central North</option>";
	tmpHTML += "<option value=\"52.634292,-1.690711,8\">West Midlands</option>";
	tmpHTML += "<option value=\"52.634292,0.690711,8\">East Midlands</option>";
	tmpHTML += "<option value=\"50.97140012475756,-1.23895263671875,8\">South</option>";
	tmpHTML += "<option value=\"50.67140012475756,-3.23895263671875,8\">South West</option>";
	tmpHTML += "<option value=\"50.97140012475756,-0.23895263671875,8\">South East</option>";	
	tmpHTML += "</select><br /><br />";
	tmpHTML += "<label for=\"mRoad\" style=\"color:#194A73;float:left;font-weight:bold;font-size:12px;\">Jump to Motorway</label>";
	tmpHTML += "<select id=\"mRoad\" name=\"mRoad\" style=\"width:180px;border: 1px solid #6E95B2;color:#194A73;\" onchange=\"ZoomToRoad(this.value);;document.getElementById('aRoad').value = ''\">";
	tmpHTML += "<option value=\"\"></option>";
	tmpHTML += "<option value=\"54.52108149544362,-1.57379150390625,9\">A1(M) north</option>";
	tmpHTML += "<option value=\"53.79091696637286,-1.34307861328125,9\">A1(M) midlands</option>";	
	tmpHTML += "<option value=\"51.879882095410224,-0.2032470703125,9\">A1(M) south</option>";

	tmpHTML += "<option value=\"53.491313790532956,-1.175537109375,9\">M1 north</option>";

	tmpHTML += "<option value=\"52.619725272670294,-1.20574951171875,9\">M1 midlands</option>";

	tmpHTML += "<option value=\"51.92055564515695,-0.4833984375,9\">M1 south</option>";

	tmpHTML += "<option value=\"51.3423,0.629038,11\">M2</option>";

	tmpHTML += "<option value=\"51.176,-1.06608,9\">M3</option>";

	tmpHTML += "<option value=\"51.5472,-2.45035,8\">M4</option>";

	tmpHTML += "<option value=\"51.6489,-2.57618,7\">M5</option>";

	tmpHTML += "<option value=\"54.4029457476126,-2.735595703125,8\">M6 north</option>";

	tmpHTML += "<option value=\"52.99164388840451,-2.1697998046875,8\">M6 south</option>";

	tmpHTML += "<option value=\"51.7391,-0.37551,11\">M10</option>";

	tmpHTML += "<option value=\"51.9802,0.121754,9\">M11</option>";

	tmpHTML += "<option value=\"53.5311,-1.08441,10\">M18</option>";

	tmpHTML += "<option value=\"51.2259,0.69231,10\">M20</option>";

	tmpHTML += "<option value=\"51.1634,-0.149387,11\">M23</option>";

	tmpHTML += "<option value=\"51.5065,-0.159284,9\">M25</option>";

	tmpHTML += "<option value=\"51.3017,0.307992,11\">M26</option>";

	tmpHTML += "<option value=\"50.9054,-1.32983,11\">M27</option>";

	tmpHTML += "<option value=\"51.4836,-2.55233,11\">M32</option>";

	tmpHTML += "<option value=\"51.867,-1.10364,9\">M40</option>";

	tmpHTML += "<option value=\"52.4261,-1.80711,9\">M42</option>";

	tmpHTML += "<option value=\"52.3331,-1.25801,11\">M45</option>";

	tmpHTML += "<option value=\"51.6045,-2.65481,11\">M48</option>";

	tmpHTML += "<option value=\"51.5254,-2.66796,11\">M49</option>";

	tmpHTML += "<option value=\"51.9839,-2.35373,11\">M50</option>";

	tmpHTML += "<option value=\"53.3185,-2.96592,10\">M53</option>";

	tmpHTML += "<option value=\"52.6644,-2.30836,11\">M54</option>";

	tmpHTML += "<option value=\"53.8023,-2.82831,11\">M55</option>";

	tmpHTML += "<option value=\"53.3436,-2.49103,10\">M56</option>";

	tmpHTML += "<option value=\"53.4475,-2.86377,11\">M57</option>";

	tmpHTML += "<option value=\"53.5315,-2.80735,11\">M58</option>";

	tmpHTML += "<option value=\"53.4753,-2.26707,10\">M60</option>";

	tmpHTML += "<option value=\"53.5971,-2.50952,10\">M61</option>";

	tmpHTML += "<option value=\"53.70646218454776,-1.20849609375,10\">M62 (east)</option>";

	tmpHTML += "<option value=\"53.5835379621847,-2.08740234375,9\">M62 (west)</option>";	

	tmpHTML += "<option value=\"53.7634,-2.41127,10\">M65</option>";

	tmpHTML += "<option value=\"53.5981,-2.27967,11\">M66</option>";

	tmpHTML += "<option value=\"53.4551,-2.09034,11\">M67</option>";

	tmpHTML += "<option value=\"52.5195,-1.34004,10\">M69</option>";

	tmpHTML += "<option value=\"55.8664,-4.0861,11\">M73</option>";

	tmpHTML += "<option value=\"55.5904,-3.82383,8\">M74</option>";

	tmpHTML += "<option value=\"55.7722,-4.35796,10\">M77</option>";

	tmpHTML += "<option value=\"55.9428,-4.07187,10\">M80</option>";

	tmpHTML += "<option value=\"56.2057,-3.41152,10\">M90</option>";

	tmpHTML += "<option value=\"53.5675,-0.69594,10\">M180</option>";

	tmpHTML += "<option value=\"53.7745,-1.55557,11\">M621</option>";

	tmpHTML += "<option value=\"56.0139,-3.88201,11\">M876</option>";

	tmpHTML += "</select><br /><br />";

	tmpHTML += "<label for=\"srcSearch\" style=\"color:#194A73;font-weight:bold;font-size:12px;\">Location Search</label>";

	tmpHTML += "<input type=\"text\" id=\"srcSearch\" name=\"srcSearch\" style=\"width:180px;border: 1px solid #6E95B2;color:#194A73;\" value=\"\"	/><br/><br/>";

	tmpHTML += "<input type=\"button\" name=\"srcSubmit\" value=\"GO\" style=\"width:180px;border: 1px solid #FFFFFF; color: #FFFFFF; background-color: #004F98;font-weight: bold; font-size: 80%; padding: 2px;\" onclick=\"return doPostCodeSearch();\" /><br /><br />";

	tmpHTML += "</div></form>";

	

	scr_Help.style.height = "auto";

	scr_Help.style.width = "196px";

	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(47,50)); 

	pos.apply(scr_Help);

	scr_Help.innerHTML = tmpHTML;

	scr_Help.style.visibility = "visible";

}*/



function showTooltip(marker) 

{ // tooltip function, this is a tooltip shown on mouseover of a pin

	tooltip.innerHTML = marker.tooltip;

	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());

	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());

	var anchor=marker.getIcon().iconAnchor;

	var width=marker.getIcon().iconSize.width;

	var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 

	pos.apply(tooltip);

	tooltip.style.visibility="visible";

}



function RemoveOverlays() {

	// we will loop through the Overlay collection array but for now we will use clearoverlays

	var mcount = OverlayCollection.length;

	for ( var i=0; i < mcount; i++) {

	map.removeOverlay(OverlayCollection[i]);

	}

	OverlayCollection.length = 0;

}



function AddNewOverlay(objOverlay) {

	OverlayCollection[OverlayCollection.length] =objOverlay;

}



function DisplayOverlays(){

	// alert("displayoverlays fires");

	// loop through the Overlay collection array and remove each overlay individually

	var mcount = OverlayCollection.length;

	for (var i=0; i < mcount; i++) {

		map.addOverlay(OverlayCollection[i]);

	}

}





// Cookie code - we are using this to save / recover the viewstate between sessions //



function setCookie(c_name,value,expiredays)

{

	var exdate=new Date();

	exdate.setDate(exdate.getDate()+expiredays);

	document.cookie=c_name+ "=" +escape(value)+	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

}



/*function getCookie(c_name)

{

	if (document.cookie.length>0)

	{

		c_start=document.cookie.indexOf(c_name + "=");

		if (c_start!=-1) { 

			c_start=c_start + c_name.length+1 ;

			c_end=document.cookie.indexOf(";",c_start);

			if (c_end==-1) c_end=document.cookie.length;

				return unescape(document.cookie.substring(c_start,c_end));

		} 

	}

	return "";

}*/



function getParameter (parameterName ) {

	var queryString = window.location.search.substring(1);

	parameterName = parameterName + "=";

	if ( queryString.length > 0 ) {

		var begin = queryString.indexOf ( parameterName );

		if ( begin != -1 ) {

			begin += parameterName.length;

			var end = queryString.indexOf ( "&" , begin );

			if ( end == -1 ) {

				end = queryString.length

			}

			return unescape ( queryString.substring ( begin, end ) );

		}

		return "null";

	}

}



/*function loadmini(lat, lng) {

// initialise google maps

	if (GBrowserIsCompatible()) {

		try {

			var mapElement = document.getElementById("map");

			if(document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#SVG","1.1")) {

				_mSvgEnabled = true;

				_mSvgForced = true;

			}

			// Capture map container object and set it to be a GMap2 object (this initialises and loads google maps)

			map = new GMap2(document.getElementById("map"));

			Create_Pins();

			// Add the controls and set up the map

			map.setCenter(new GLatLng(lat, lng), 10);

			// fire the handlePan function to setup default points, this may have already happened, but we are better re-firing the event at this point

			CreateMiniProjectMarker(new GLatLng(lat, lng));

			DisplayOverlays();

			setTimeout( showPrintMenu, 1000 )

		} catch( e ) {

			alert("An error was caught: " + e );

		}

	}

}*/



function showPrintable(URL) {

	if (screen.availwidth) {

		popupWidth = screen.availwidth * 0.75;

		popupHeight = screen.availheight * 0.75;

		popupLeft = (screen.availwidth - popupWidth) / 2;

		popupTop = (screen.availheight - popupHeight) / 2;

	} else {

		popupWidth = screen.width * 0.75;

		popupHeight = screen.height * 0.75;

		popupLeft = (screen.width - popupWidth) / 2;

		popupTop = (screen.height - popupHeight) / 2;

	}



	eval("page = window.open(URL, 'TruckStop', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + popupWidth + ",height=" + popupHeight + ",left = " + popupLeft + ",top = " + popupTop +"');");

}





function setRequiredServices(){

	for (cntRequired=0;cntRequired<9;cntRequired++){

		RequiredServices[cntRequired] = document.forms.svcForm.service[cntRequired].checked

	}

	handlePan();

}

