<!--

// global flag
var isIE = false;

// global request and XML document objects
var 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) 
{
    if (window.XMLHttpRequest) 
    {
		// branch for native XMLHttpRequest object
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    } 
    else if (window.ActiveXObject) 
    {
		// branch for IE/Windows ActiveX version
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) 
        {
        	//alert(url);
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

// handle onreadystatechange event of req object
function processReqChange() 
{
    // only if req shows "loaded"
    if (req.readyState == 4) 
    {
        // only if "OK"
        if (req.status == 200) 
        {
            showRequestResultDetail();
         } 
         else 
         {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
         }
    }
}
 // 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 
        {
            return result.firstChild.nodeValue;    		
        }
    } 
    else 
    {
        return "";
    }
}

function getRS(rootnode, iCurRec, sFieldName){
	/*
	   Function allows you to read an XML structure like a 
	   ADO recordset.
	  
	   Variables:
	  				rootnode		:reference to root XML object
	  				iCurRec			:current child node record
	  				sFieldName	:field we are looking for in XML record
	   Assumptions:		Function assumes XML string will look like this:
	  		<tablename>
	  			<row>
	  				<field1>data1</field1>
	  				<field2>data2</field2>
	  			</row>
	  		</tablename>
	  				
	  	example:
	  		<tbl_Employee>
	  			<EmployeeRow>
	  				<FirstName>John</FirstName>
	  				<LastName>Doe</LastName>
	  			</EmployeeRow>
	  			<EmployeeRow>
	  				<FirstName>Jane</FirstName>
	  				<LastName>Doe</LastName>
	  			</EmployeeRow>
	  		</tbl_Employee>

		Naviating the tree:

		rootnode												Root node (tbl_Employee)
			.childNodes.item(iCurRec)			The nth level 2 node (EmployeeRow)
				.childNodes.item(iField)		The nth level 3 node (FirstName)
					.tagName									Name of the 3ed node (ie FirstName)
					.childNodes.length				Number of 3ed level child nodes.
																			(0 if no data 1 if has data)
					.childNodes.item(0).text	Value of 4th level node

	*/
	var iField;
	var sData;
	sData = "";
	for (iField = 0 ; iField < rootnode.childNodes.item(iCurRec).childNodes.length ; iField++){
		if (rootnode.childNodes.item(iCurRec).childNodes.item(iField).tagName  == sFieldName){
			if (rootnode.childNodes.item(iCurRec).childNodes.item(iField).childNodes.length > 0){
				sData = rootnode.childNodes.item(iCurRec).childNodes.item(iField).childNodes.item(0).text;
				}
			else {
				sData = "_";
				}
			}
		}
	if (sData == "#20") 
	{
		sData = "&nbsp;";
	}
	//sData = sData.replace("&", "&amp;") 
	//sData = sData.replace(">", "&gt;") 
	//sData = sData.replace("<", "&lt;") 
	//sData = sData.replace("\"", "&quot;") 
	return(sData);
}
	

//-->

