	
	var sName = "";
	var iNumber = 0;
	var sRoad = "";
	var sPostcode = "";
	var sTown = "";

	var iPages = 0;
	var iRecordTotal = 0;
	var iPage = 0;

	function blur() {
		document.getElementById("wait").style.display = "none";
	}

	function PageLoaded() {
		//document.getElementById("wait").style.visibility = "hidden";
		document.getElementById("wait").style.display = "none";
		
		// Get the easting, northing, zoom, title and description from the GET URL String
		var ParameterString = location.search.substring(1);
		
		var asName = getParm( ParameterString, 'Name');
		var asNumber = getParm( ParameterString, 'Number');
		var asRoad = getParm( ParameterString, 'Road');
		var asPostcode = getParm( ParameterString, 'Postcode');
		var asTown = getParm( ParameterString, 'Town');

		//remove whitespace
		asName = stripWhiteSpace(asName);
		asNumber = stripWhiteSpace(asNumber);
		asRoad = stripWhiteSpace(asRoad);
		asPostcode = stripWhiteSpace(asPostcode);
		asTown = stripWhiteSpace(asTown);

		//remove plus ( + ) signs generated by http address string
		document.refineSearch.Name.value = stripPlus(asName);
		document.refineSearch.Number.value = stripPlus(asNumber);
		document.refineSearch.Road.value =  stripPlus(asRoad);
		document.refineSearch.Postcode.value = stripPlus(asPostcode);
		document.refineSearch.Town.value = stripPlus(asTown);

		if ( asName != "" ) {
			sName = asName;
		}
		
		if ( asNumber != "" ) {
			iNumber = asNumber;
		}
		
		if ( asRoad != "" ) {
			sRoad = asRoad;
		}
		
		if ( asPostcode != "" ) {
			sPostcode = asPostcode;
		}
		
		if ( asTown != "" ) {
			sTown = asTown;
		}

		
		PerformAddressSearch();
		
	}
	
	function getParm(string,parm) {
	    var startPos = string.indexOf(parm + "=");
	    if (startPos > -1) {
	        startPos = startPos + parm.length + 1;
	        var endPos = string.indexOf("&",startPos);
	        if (endPos == -1)
	            endPos = string.length;
	        return unescape(string.substring(startPos,endPos));
	    }
	    return '';
	}
	
	// Fetch the Address Search Summary
	function PerformAddressSearch() {
		
		var sql = "";
		var error = "";
		var bQuery = false;
		
		
		sql = "http://" + Domain + "/" + Virtual + "/panel_AP_SearchView.asp?";
		
		if ( sName != "" ) {
			sql += "name=" + sName + "&";
			bQuery = true;
		}
		
		if ( iNumber != "" ) {
			if ( isNaN(iNumber) == false ) {
				sql += "number=" + iNumber + "&";
				bQuery = true;
			} else {
			//Altered code - allows non numeric values to be entered, but strips them into a number - TP 29/06/10			
			var numb = iNumber.match(/\d/g);
				numb = numb.join("")
				iNumber= numb
				sql += "number=" + iNumber + "&";
				bQuery = true;				
				//alert( "You need to enter a numeric value" );
			}
		}
		
		if ( sRoad != "" ) {
			sql += "road=" + sRoad + "&";
			bQuery = true;
		}
		
		if ( sPostcode != "" ) {
			sql += "postcode=" + sPostcode + "&";
			bQuery = true;
		}
		
		if ( sTown != "" ) {
			sql += "town=" + sTown + "&";
			bQuery = true;
		}

		if ( bQuery == true ) {		
			sql += "addressmode=xml&SummaryPage=false&pagelength=" + iPageLength + "&pagecurrent=" + iCurrentPage;			
			
			// Altered code - added test to catch Webkit's handling of CreateDocument function. It creates a Document rather than an XMLDocument and the .load() function is not supported for non xml docs - TP 29/06/2010
			try  //Firefox
			{
				xmlDoc = document.implementation.createDocument("", "", null);
				xmlDoc.load( sql );
				xmlDoc.onload = ParseSummary;
			
			} 
			catch(e)
			{
				try //Internet Explorer
			  	{
					xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.load( sql );
					xmlDoc.onreadystatechange = function () {if (xmlDoc.readyState == 4) ParseSummary()};
			  	}
			  	catch(e)
			  	{
			    		try //Webkit (Chrome, Safari, etc)
			    		{
						var xmlhttp = new window.XMLHttpRequest();
						xmlhttp.open("GET",sql,false);
						xmlhttp.onreadystatechange = function () {if (xmlhttp.readyState == 4) {
						xmlDoc = xmlhttp.responseXML
						ParseSummary()}}
						xmlhttp.send(null)
					} 
			    		catch(e)
		            		{
		              			error=e.message;
					}
				}
			}

		}
	}
	
	// Add the carto legend to the screen
	function ParseSummary() {
		
		var sHTML = "";
		var ASEasting = 0;
		var ASNorthing = 0;
		var firstEasting = 0;
		var firstNorthing = 0;
		
		rootNode = xmlDoc.documentElement;
			
		if ( rootNode.childNodes.length > 0 ) {
			
			var summary = rootNode.childNodes.item(0); 
			
			if (BrowserName == "Netscape") {
				iRecordTotal =  summary.childNodes.item(0).firstChild.nodeValue;
				iPages = parseInt(summary.childNodes.item(1).firstChild.nodeValue);
				iPage =  summary.childNodes.item(2).firstChild.nodeValue;
			} else {
				iRecordTotal =  summary.childNodes.item(0).text;
				iPages = parseInt(summary.childNodes.item(1).text);
				iPage =  summary.childNodes.item(2).text;
			}
			
			// ***************************************************************************************
			// Read Address Data
			// ***************************************************************************************
		if (iRecordTotal < 250){

			if ( rootNode.childNodes.length > 1 ) {
			  if (iPages > 1) {
				//ALTERED CODE. removed table and replaced with div and span
				sHTML += "<div class = 'pad2'>";
				sHTML += "<span class='navbutton'  width=30>";
				sHTML += "<img border=0 class='addressnavbutton' alt='First Page' title='First Page' src='images/double_page_back.gif' onclick='doubleBack()'></span>";
				sHTML += "<span class='navbutton' width=30>";
				sHTML += "<img border=0 class='addressnavbutton' alt='Previous' title='Previous' src='images/page_back.gif' onclick='goBack()'></span>";
				sHTML += "<span class='navbutton'  width=30>";
				sHTML += "&nbsp;";
	
				for (i=1; i <= iPages; i++) {
					if (i == iCurrentPage) {
						sHTML += "<span class='largetext' >" + i + "</span> ";
					} else {
					sHTML += "<span  class='link largetext' onclick='customPage("+ i +")'>" + i + "</span> ";
					}
				}
				sHTML += "&nbsp;";
		
				sHTML += "<img border=0 class='addressnavbutton' alt='Next' title='Next' src='images/page_forward.gif' onclick='goForward()'></span>";
				sHTML += "<span class='navbutton' width=30>";
				sHTML += "<img border=0 class='addressnavbutton' alt='Last Page' title='Last Page' src='images/double_page_forward.gif' onclick='doubleForward()'></span>";
				sHTML += "</div>";
			 }

				sHTML += "<div class='datacontent colour1' >"; //ALTERED CODE.
				sHTML += "<div class='dataheading colour2'>Properties Found</div>"; //ALTERED CODE.
				
				for ( x = 1; x < rootNode.childNodes.length; x++ ) {
				
					var AddressElement = rootNode.childNodes.item(x)

					
					// Find the Easting and Northing for the row *******IS THIS ROUTINE NEEDED? I THINK REDUNDANT********
					for ( i = 0; i < AddressElement.childNodes.length; i++ ) {
					
						var AddressLineElement = AddressElement.childNodes.item(i);
						
						if ( AddressLineElement.nodeName == "X" || AddressLineElement.nodeName.substring(0,7) == "Easting" ) {
							
							if (BrowserName == "Netscape") {
								ASEasting = AddressLineElement.firstChild.nodeValue;
							} else {
								ASEasting = AddressLineElement.text;
							}
							
						} else if ( AddressLineElement.nodeName == "Y" || AddressLineElement.nodeName.substring(0,8) == "Northing" ) {
							
							if (BrowserName == "Netscape") {
								ASNorthing = AddressLineElement.firstChild.nodeValue;
							} else {
								ASNorthing = AddressLineElement.text;
							}
						}
								
					}
					
					if ( ASEasting.toString().length == 7 ) {
						ASEasting = parseInt( ASEasting /= 10 );
					}
				
					if ( ASNorthing.toString().length == 7 ) {
						ASNorthing = parseInt( ASNorthing /= 10 );
					}
					
					// Store the first coordinates
					if ( x == 1 ) {
						firstEasting = ASEasting;
						firstNorthing = ASNorthing;
					}
					
					sHTML += "<div style='cursor: pointer' onclick='SelectAddress(" + x + ")'>";  //ALTERED CODE.*****change here to give row of selected record
																		//This was changed to allow a function to be changed below
					// Add the data from each element of the tree
						var AddressLineElement = AddressElement.childNodes.item(12);
						
						if (BrowserName == "Netscape") {
												
							if ( AddressLineElement.childNodes.length == 1 ) {
								sHTML += "<p class='clsValue colour3'>" + AddressLineElement.firstChild.nodeValue + "</p>";
							} else {
								sHTML += "<p class='clsValue colour3'>&nbsp;</p>"
							}
							
						} else {
							sHTML += "<p class=\"clsValue colour3\">" + AddressLineElement.text + "</p>";
						} 
					
					sHTML += "</div>";
					
				}
				
				sHTML += "</div>"; //ALTERED CODE.
			} else {
				sHTML = "<div class='datacontent colour1' >"; //ALTERED CODE. Output for a failed search.
				sHTML += "<div class='dataheading colour2'>No Properties Found</div>";
				sHTML += "<div class='pad'>Query produced no results</div>";
			}
		} else {
			sHTML = "<div class='datacontent colour1' >"; //ALTERED CODE. Output for an over-large search result.
			sHTML += "<div class='dataheading colour2'>Properties Found</div>";
			sHTML += "<div class='pad'>Query produced over 250 results, please refine your search. Try entering a complete postcode or full street name and house number.</div>";
		}
			document.getElementById("QueryResults").innerHTML = sHTML;
		}
		
		//xmlDoc = null;
		// Scroll window down to show results.
		window.scrollTo(0, 350);  
	}
	
	function SelectAddress(rowNumber) {
		
		var sName = "";
		var sNumber = "";
		var sRoad = "";
		var sPostcode = "";
		var sLocality = "";
		var sTown = "";
		var sUPRN = "";
		var sEasting = "";
		var sNorthing = "";
		var sFullAddress = "";
		rootNode = xmlDoc.documentElement;
		var newAddressElement = rootNode.childNodes.item(rowNumber);

		//document.getElementById("wait").style.visibility = "visible";
		document.getElementById("wait").style.display = "inline";
		
		if (BrowserName == "Netscape" ) {
		
			//ALTERED CODE. new code to get data from XML instead of table for firefox/netscape (non-IE) browsers
			
			if ( rootNode.childNodes[rowNumber].childNodes[2].childNodes.length == 1 ) {
					sName = rootNode.childNodes[rowNumber].childNodes[2].firstChild.nodeValue;
			} else {
					sName = "";
			}
			
			if ( rootNode.childNodes[rowNumber].childNodes[3].childNodes.length == 1 ) {
					sNumber = rootNode.childNodes[rowNumber].childNodes[3].firstChild.nodeValue;
			} else {
					sNumber = "";
			}
			sUPRN = newAddressElement.childNodes[4].firstChild.nodeValue;

			if ( rootNode.childNodes[rowNumber].childNodes[5].childNodes.length == 1 ) {
					sRoad = rootNode.childNodes[rowNumber].childNodes[5].firstChild.nodeValue;
			} else {
					sRoad = "";
			}
			if ( rootNode.childNodes[rowNumber].childNodes[6].childNodes.length == 1 ) {
					sLocality = rootNode.childNodes[rowNumber].childNodes[6].firstChild.nodeValue;
			} else {
					sLocality = "";
			}

			if ( rootNode.childNodes[rowNumber].childNodes[7].childNodes.length == 1 ) {
					sTown = rootNode.childNodes[rowNumber].childNodes[7].firstChild.nodeValue;
			} else {
					sTown = "";
			}

			if ( rootNode.childNodes[rowNumber].childNodes[9].childNodes.length == 1 ) {
					sPostcode = rootNode.childNodes[rowNumber].childNodes[9].firstChild.nodeValue;
			} else {
					sPostcode = "";
			}

			sEasting = newAddressElement.childNodes[10].firstChild.nodeValue;
			sNorthing = newAddressElement.childNodes[11].firstChild.nodeValue;

			sFullAddress = newAddressElement.childNodes.item(12).firstChild.nodeValue; //ALTERED CODE.
			
		} else {

			//ALTERED CODE. new code to get data from XML instead of table for IE browsers.
										
			sName = newAddressElement.childNodes(2).text + "";
			sNumber = newAddressElement.childNodes(3).text + "";
			sUPRN = newAddressElement.childNodes(4).text + "";
			sRoad = newAddressElement.childNodes(5).text + "";
			sLocality = newAddressElement.childNodes(6).text + "";
			sTown = newAddressElement.childNodes(7).text + "";
			sPostcode = newAddressElement.childNodes(9).text + "";
			sEasting = newAddressElement.childNodes(10).text + "";
			sNorthing = newAddressElement.childNodes(11).text + "";
			sFullAddress = newAddressElement.childNodes(12).text + ""; //ALTERED CODE.

		}
		 
		// Add the JavaScript vars to the HTML Form hidden parameters
		document.AddressSearch.adNumber.value = sNumber;
		document.AddressSearch.adName.value = sName;
		document.AddressSearch.adUPRN.value = sUPRN;
		document.AddressSearch.adRoad.value = sRoad;
		document.AddressSearch.adLocality.value = sLocality;
		document.AddressSearch.adTown.value = sTown;
		document.AddressSearch.adPostcode.value = sPostcode;
		document.AddressSearch.Easting.value = sEasting;
		document.AddressSearch.Northing.value = sNorthing;
		document.AddressSearch.FullAddress.value = sFullAddress; //ALTERED CODE.
		document.AddressSearch.submit();
		
	}
	
	// ********************************************************************************************************
	// ** Naviagtion
	// ********************************************************************************************************
	
	function goForward() {
		
		if ( parseInt(iCurrentPage) < parseInt(iPages) ) {
			
			var iPageNumber = parseInt(iCurrentPage);
			
			iPageNumber++;
			iCurrentPage= iPageNumber;
			PerformAddressSearch()
		
		}	
	}
	
	function goBack() {
		
		if ( parseInt(iCurrentPage) > 1 ) {
			
			var iPageNumber = parseInt(iCurrentPage);
			
			iPageNumber--;
			iCurrentPage = iPageNumber;
			PerformAddressSearch();
		
		}	
	}
	
	function doubleBack() {
		iPageNumber = 1;
		iCurrentPage = iPageNumber;
		PerformAddressSearch();
	}
	
	function doubleForward() {
		iCurrentPage = iPages
		PerformAddressSearch();
	}
	
	function customPage(pageNumber) {

		if (pageNumber > 0 ) {
			
			if ( pageNumber <= parseInt(iPages) ) {
					
					iCurrentPage = pageNumber;
					PerformAddressSearch();
				
			} 		
						
		}
	}
	



