// global flag
var isIE = false;

// global request and XML document objects
var ajax_req;

// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url, StatusChangeProc) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) 
    {
        ajax_req = new XMLHttpRequest();
        ajax_req.onreadystatechange = StatusChangeProc;
        ajax_req.open("GET", url, true);
        ajax_req.send(null);
 // alert("Request verstuurd"+url+" " + StatusChangeProc);
    // branch for IE/Windows ActiveX version
    } 
    else if (window.ActiveXObject) 
    {
        isIE = true;
        ajax_req = new ActiveXObject("Microsoft.XMLHTTP");
        if (ajax_req) 
        {
            ajax_req.onreadystatechange = StatusChangeProc;
            ajax_req.open("GET", url, true);
            ajax_req.send();
        }
    }
}


// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        // the namespace versions of this method 
        // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
					if (result.childNodes.length==1) {
            return result.firstChild.nodeValue;    		
					} else {
						return "";
					}
        }
    } else {
        return "n/a";
    }
}
