
	function ClearAddressSearch() {

		document.getElementById("ASName").value = "";
		document.getElementById("ASNumber").value = "";
		document.getElementById("ASRoad").value = "";
		document.getElementById("ASPostcode").value = "";

	}

	function PerformAddressSearch() {

		document.body.style.cursor = 'wait';
		toolmode = 0;

		var xmlDoc;
		
		var sURL = "http://" + Domain  + "/" + Virtual + "/panel_AP_SearchView.asp?AddressMode=xml&pagelength=" + cAddressPageLength;

		if ( document.getElementById("ASName").value != "" ) { sURL += "&name=" + document.getElementById("ASName").value; }
		if ( document.getElementById("ASNumber").value != "" ) { sURL += "&number=" + document.getElementById("ASNumber").value; }
		if ( document.getElementById("ASRoad").value != "" ) { sURL += "&road=" + document.getElementById("ASRoad").value; }
		if ( document.getElementById("ASPostcode").value != "" ) { sURL += "&postcode=" + document.getElementById("ASPostcode").value; }
				
		xmlDoc = createDomObject(sURL);		
		if ( xmlDoc == null ) { return; }
		
		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) == "UPRN" ) {
							// Do Nothing as the nodeName is a Easting or Northing Field
						} 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>";

			document.getElementById("queryTag").innerHTML = sHTML;
		}

		document.body.style.cursor = 'default';
		document.getElementById("QueryTitle").innerHTML = "<h3><font color=\"#336699\">Results of Address Search &#8211; Click Address to Locate on the Map</font></h3>";

	}
