<!--
//==========================================================================================
// This function returns the value of an attribute of the "nth" child node of 'ParentNode'. 
// If that attribute or child node is absent or empty, it returns a user supplied default
// value (if "bRetFlag" is set). 
//==========================================================================================
function getAttribute(ParentNode, ChildNodeName, AttributeName, n, bRetFlag, DefRetVal) {
	var ChildNodeArray = "", ChildNode = "", AttributeVal = "";
	
	ChildNodeArray = ParentNode.getElementsByTagName(ChildNodeName); 
	if (ChildNodeArray.length > 0) 
	{// At least 1 child node is present
		if (ChildNodeArray.length >= n  &&  n > 0) 
		{
			AttributeVal = ChildNodeArray[n-1].getAttribute(AttributeName);
			if (AttributeVal == null) AttributeVal = "AttributeAbsent"; 
		}
		else AttributeVal = "OutOfRange"; 	
	}
	else AttributeVal = "ChildNodeAbsent"; 	

	//-------------------------------------------------------
	// Make sure Attribute does not contain only white space
	//-------------------------------------------------------
	if (FindFirstNonBlankChar(AttributeVal) == -1) AttributeVal = "Empty";  
	
	//--------------------------------------------------
	// If Attribute empty, return user supplied default
	//--------------------------------------------------
	if (bRetFlag)
	{// Don't do this unless user says so!
		if (AttributeVal == "AttributeAbsent"  ||  AttributeVal == "ChildNodeAbsent"  
		||  AttributeVal == "Empty"  ||  AttributeVal == "OutOfRange") 
		AttributeVal = DefRetVal; 
	}
	return AttributeVal;
} // End of function getAttribute(ParentNode, ChildNodeName, AttributeName, n, bRetFlag, DefRetVal)

//===========================================================================
// This function returns the value of the "nth" child node of 'ParentNode'. 
// If that child node is absent or empty, it returns a user supplied default
// value (if "bRetFlag" is set). 
//===========================================================================
function getChildNode(ParentNode, ChildNodeName, n, bRetFlag, DefRetVal) {
	var ChildNodeArray = "", ChildNode = "", ChildNodeVal = "";
	
	ChildNodeArray = ParentNode.getElementsByTagName(ChildNodeName); 
	if (ChildNodeArray.length > 0) 
	{// At least 1 child node is present
		if (ChildNodeArray.length >= n  &&  n > 0) 
		{
			ChildNode = ChildNodeArray[n-1].childNodes[0];
			if (!ChildNode) ChildNodeVal = "Empty";
			else ChildNodeVal = ChildNode.nodeValue;
		}
		else ChildNodeVal = "OutOfRange"; 	
	}
	else ChildNodeVal = "Absent"; 	
	
	//--------------------------------------------------------
	// Make sure child node does not contain only white space
	//--------------------------------------------------------
	if (FindFirstNonBlankChar(ChildNodeVal) == -1) ChildNodeVal = "Empty";  
	
	//---------------------------------------------------
	// If child node empty, return user supplied default
	//---------------------------------------------------
	if (bRetFlag)
	{// Don't do this unless user says so!
		if (ChildNodeVal == "OutOfRange"  ||  ChildNodeVal == "Absent"  
		||  ChildNodeVal == "Empty") ChildNodeVal = DefRetVal; 
	}
	return ChildNodeVal;
} // End of function getChildNode(ParentNode, ChildNodeName, n, bRetFlag, DefRetVal)

//===============================================
// Function to load XML file into the XML parser 
//===============================================
function XMLFileLoad(XMLFile, toScreen, toAlert) {
	var xmlDoc; 
	var Str = ""; 
	
	if (window.ActiveXObject)
	{// Code for IE
		try 
		{
			//-------------------------------------
			// Create an empty XML document object	
			//-------------------------------------
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		}
		catch (e)
		{
			if (toAlert)
			{
				Str = "Error creating XML DOM object\n";
				Str = Str + e.message; 
				alert(Str);
			}
			if (toScreen) 
			{
				Str = "Error creating XML DOM object<br/>";
				Str = Str + e.message; 
				document.write(Str); 
			}
			return null;
		}
		try 
		{
			//-----------------------------------------------------------------------
			// Turn off asynchronized loading, to make sure that the parser will not 
			// continue execution of the script before the document is fully loaded.  
			// Then load the XML document and check status.  
			//-----------------------------------------------------------------------
			xmlDoc.async = "false";
			xmlDoc.load(XMLFile);
		}
		catch (e)
		{
			if (toAlert)
			{
				Str = "Error loading XML document\n";
				Str = Str + e.message; 
				alert(Str);
			}
			if (toScreen) 
			{
				Str = "Error loading XML document<br/>";
				Str = Str + e.message; 
				document.write(Str); 
			}
			return null;
		}
		if (xmlDoc.parseError.errorCode != 0)
		{
			if (toAlert) 
			{
				Str = "Error loading XML document (see details below)\n";
				Str = Str + "Error in line: " + xmlDoc.parseError.line + "\n"; 
				Str = Str + "Position: " + xmlDoc.parseError.linePos + "\n";
				Str = Str + "Error Code: " + xmlDoc.parseError.errorCode + "\n";;
				Str = Str + "Error Reason: " + xmlDoc.parseError.reason + "\n";
				Str = Str + "Error Line: " + xmlDoc.parseError.srcText;
				alert(Str); 
			}
			if (toScreen)
			{
				Str = "Error loading XML document (see details below)<br/>";
				Str = Str + "Error in line: " + xmlDoc.parseError.line + "<br/>"; 
				Str = Str + "Position: " + xmlDoc.parseError.linePos + "<br/>"; 
				Str = Str + "Error Code: " + xmlDoc.parseError.errorCode + "<br/>"; 
				Str = Str + "Error Reason: " + xmlDoc.parseError.reason + "<br/>"; 
				Str = Str + "Error Line: " + xmlDoc.parseError.srcText;
				document.write(Str); 
			}
			return null;
		}
		else return xmlDoc; 
	}
	else if (document.implementation && document.implementation.createDocument)
	{// Code for Mozilla, Firefox, Opera, etc.
		try 
		{
			//-------------------------------------
			// Create an empty XML document object	
			//-------------------------------------
			xmlDoc = document.implementation.createDocument("","",null);
		}
		catch (e)
		{
			if (toAlert)
			{
				Str = "Error creating XML DOM object\n";
				Str = Str + e.message; 
				alert(Str);
			}
			if (toScreen) 
			{
				Str = "Error creating XML DOM object<br/>";
				Str = Str + e.message; 
				document.write(Str); 
			}
			return null;
		}
		try 
		{
			//-----------------------------------------------------------------------
			// Turn off asynchronized loading, to make sure that the parser will not 
			// continue execution of the script before the document is fully loaded.  
			// Then load the XML document and check status.  
			//-----------------------------------------------------------------------
			xmlDoc.async = false;
			var loaded = xmlDoc.load(XMLFile);
			if (loaded) return xmlDoc;
			else throw 1;
		}
		catch (e)
		{
			if (toAlert)
			{
				Str = "Error loading XML document\n";
				if (e.message != undefined) Str = Str + e.message;
				alert(Str);
			}
			if (toScreen) 
			{
				Str = "Error loading XML document<br/>";
				if (e.message != undefined) Str = Str + e.message;
				document.write(Str); 
			}
			return null;
		}
	}
	else 
	{// Exit if unable to create  XML document object
		Str = "Error - Your browser cannot handle this script";
		if (toAlert) alert(Str); 
		if (toScreen) document.write(Str+"<br/>"); 
		return null;
	}
}// End of function XMLFileLoad(XMLFile, toScreen, toAlert)
//-->
