var xmlRequest;
var isIE;

function loadXMLDoc(url, processReqChange, asyncMode) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
		xmlRequest = new XMLHttpRequest();
		xmlRequest.onreadystatechange = processReqChange;
		xmlRequest.open("GET", url, asyncMode);
		xmlRequest.send(null);
    }
    // branch for IE/Windows ActiveX version
    else if (window.ActiveXObject) {
        isIE = true;
        xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlRequest) {
            xmlRequest.onreadystatechange = processReqChange;
            xmlRequest.open("GET", url, asyncMode);
            xmlRequest.send();
        }
    }
}

function getElementText(e, tag) {
    return e.getElementsByTagName(tag)[0].firstChild.data;
}

// retrieve text of an XML document element, including elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    
    // IE/Windows way of handling namespaces
    if (prefix && isIE)
        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 {
            return result.firstChild.nodeValue;
		}
    }
    else {
		return "n/a";
	}
}