
var callback; 
var req;

function getNearest(postcode, callbackfunc)
{
	callback = callbackfunc; 
	loadXMLDoc("/interface/getNearest.php?Postcode="+postcode+"&exactonly=1");
}

function processResponse()
{
		var fids = new Array(); 
		var reqxml = req.responseXML; 
		var matches = reqxml.getElementsByTagName("Match"); 
		//alert(fids[0]);
		callback(matches[0]); 
}


function loadXMLDoc(url ) 
{

    // branch for native XMLHttpRequest object
	//alert("going for it"); 
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange; 
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange; 
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange() 
{
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
			//alert("processing "+req.responseText);
			processResponse(); 
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}
