
	function ClearAddressSearch() {

		ASName.value = "";
		ASNumber.value = "";
		ASRoad.value = "";
		ASPostcode.value = "";

	}

	function PerformAddressSearch() {

		document.body.style.cursor = 'wait';
		toolmode = 0;

		var xmlDoc;
		
		if (document.implementation && document.implementation.createDocument) {
			xmlDoc = document.implementation.createDocument("", "", null);
		} else if (window.ActiveXObject) {
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		}

		var sURL = "http://" + Domain  + "/" + Virtual + "/panel_AP_SearchView.asp?AddressMode=xml&pagelength=" + cAddressPageLength;

		if ( ASName.value != "" ) { sURL += "&name=" + ASName.value; }
		if ( ASNumber.value != "" ) { sURL += "&number=" + ASNumber.value; }
		if ( ASRoad.value != "" ) { sURL += "&road=" + ASRoad.value; }
		if ( ASPostcode.value != "" ) { sURL += "&postcode=" + ASPostcode.value; }

		xmlDoc.async = false; // Tell the Xml document to wait until the document has been complete read
		xmlDoc.load( sURL );
		
		ReadAddressData(xmlDoc);
		
		xmlDoc = null;
		
	}

	function ReadAddressData(xmlDoc) {

		var ASEasting = 0;
		var ASNorthing = 0;
		var sHTML = "";
		var sText = "";

		rootNode = xmlDoc.documentElement;

		if ( rootNode.childNodes.length > 0 ) {

			if ( rootNode.nodeName.toLowerCase() == "planaccesserror" ) {
				if (BrowserName == "Netscape") {
					sHTML = rootNode.childNodes.item(0).childNodes.item(1).firstChild.nodeValue;
				} else {
					sHTML = rootNode.childNodes.item(0).childNodes.item(1).text;
				}
			} else {

				sHTML = "<table border=\"1\" bordercolor=\"#ffffff\" style=\"border:1pt solid #9EBFE0;\">";

				for ( x = 1; x < rootNode.childNodes.length; x++ ) {

					sHTML += "<tr>";

					var AddressElement = rootNode.childNodes.item(x)

					// Find the Easting and Northing for the row
					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 );
					}

					sText = "";

					// Add the data from each element of the tree
					for ( i = 0; i < AddressElement.childNodes.length; i++ ) {

						var AddressLineElement = AddressElement.childNodes.item(i);

						if ( AddressLineElement.nodeName == "X" || AddressLineElement.nodeName.substring(0,7) == "Easting" || AddressLineElement.nodeName == "Y" || AddressLineElement.nodeName.substring(0,8) == "Northing" || AddressLineElement.nodeName.substring(0,8) == "URSN" || AddressLineElement.nodeName.substring(0,8) == "UPRN") {
							// Do Nothing as the nodeName is a Easting or Northing Field
							// UPRN also removed (AML 10.03.08)
						} else {

							// Capture the field info
							if (BrowserName == "Netscape") {

								if ( AddressLineElement.childNodes.length == 1 ) {
									sText += AddressLineElement.firstChild.nodeValue + ", ";
								}

							} else {
								// Only add element if there is data on the node
								if ( AddressLineElement.text.length > 0 ) {
									sText += AddressLineElement.text + ", ";
								}
							}

						}
					}

					// Remove the last ,
					sText = sText.substring(0, sText.length - 2);
					sHTML += "<td bgcolor=\"#9EBFE0\" class=\"QueryValueColumn\" onclick=\"MoveMap(" + ASEasting + "," + ASNorthing + "," + cAddressZoomLevel + ")\">" + sText + "</td>";

					sHTML += "</tr>";

				}

			}

			sHTML += "</table>";

			queryTag.innerHTML = sHTML;
		}

		document.body.style.cursor = 'default';
		QueryTitle.innerHTML = "<h3><font color=\"#336699\">Results of Address Search &#8211; Click Address to Locate on the Map</font></h3>";

	}
