<!--
	function XML() {} // Cross-browser compliant XML functions
	
	function XMLElement()
	{
		// private
		this._value = 'not assigned yet';
		this._attributes = [];
		
		// public
		this.getValue = function()
		{
			return this._value;
		}
		
		this.getAttribute = function(attribute)
		{
			return this._attributes[attribute];
		}
	}
	
	XML.parseAsArray = function(xmlDoc)
	{
		return XML.xml2array(xmlDoc.documentElement);
	}
	
	XML.parse = function(xmlDoc)
	{
		return XML.xml2obj(xmlDoc.documentElement);
	}
	
	XML.xml2obj = function(node)
	{
		if ( node.nodeType != 1 )
			return;
		
		//alert('Processing: ' + node.tagName + "\nType: " + node.nodeType + "\nValue: " + node.firstChild.nodeValue + "\nChildren: " + XML.getChildren(node).length);
		var xmlElement = new XMLElement();
		for ( var j = 0; j < node.attributes.length; j++ )
			xmlElement._attributes[node.attributes[j].name] = node.attributes[j].value.trim();
		if ( XML.getChildren(node).length == 0 )
		{
			//alert("Setting value of " + node.tagName + " to: " + node.firstChild.nodeValue.trim());
			xmlElement._value = node.firstChild ? node.firstChild.nodeValue : node.nodeValue;
			return xmlElement;
		}
		
		var nodeChildren = XML.getChildren(node);
		for ( var i = 0; i < nodeChildren.length; i++ )
		{
			//alert('Processing: ' + nodeChildren[i].tagName + "\nType: " + nodeChildren[i].nodeType + "\nValue: " + nodeChildren[i].nodeValue + "\nChildren: " + XML.getChildren(nodeChildren[i]).length);
			var isArray = false;
			for ( var j = 0; j < nodeChildren.length; j++ )
			{
				if ( (i != j) && (nodeChildren[i].tagName == nodeChildren[j].tagName) )
					isArray = true;
			}
			
			if ( isArray )
			{
				if ( !xmlElement[nodeChildren[i].tagName] )
				{
					//alert("Creating an array for: " + nodeChildren[i].tagName);
					xmlElement[nodeChildren[i].tagName] = new Array();
				}
				
				//alert("Pushing a value for: " + nodeChildren[i].tagName);
				xmlElement[nodeChildren[i].tagName].push(XML.xml2obj(nodeChildren[i]));
			} else {
					//alert("Adding a child object for: " + nodeChildren[i].tagName);
					xmlElement[nodeChildren[i].tagName] = XML.xml2obj(nodeChildren[i]);
			}
		}
		
		return xmlElement;
	}
	
	XML.xml2array = function(node)
	{
		if ( node.nodeType != 1 )
			return;
		
		//alert('Processing: ' + node.tagName + "\nType: " + node.nodeType + "\nValue: " + node.nodeValue + "\nChildren: " + XML.getChildren(node).length);
		var xmlElement = new XMLElement();
		for ( var j = 0; j < node.attributes.length; j++ )
			xmlElement._attributes[node.attributes[j].name] = node.attributes[j].value.trim();
		if ( XML.getChildren(node).length == 0 )
		{
			xmlElement._value = node.firstChild ? node.firstChild.nodeValue : node.nodeValue;
			return xmlElement;
		}
		
		var nodeChildren = XML.getChildren(node);
		for ( var i = 0; i < nodeChildren.length; i++ )
		{			
			if ( !xmlElement[nodeChildren[i].tagName] )
				xmlElement[nodeChildren[i].tagName] = new Array();

			xmlElement[nodeChildren[i].tagName].push(XML.xml2array(nodeChildren[i]));
		}
		
		return xmlElement;
	}
	
	// XML cross-browser parsing functions
	XML.getChildren = function(node)
	{
		var childNodes = new Array();
		for ( var i = 0; i < node.childNodes.length; i++ )
		{
			if ( node.childNodes[i].nodeType != 1 )
				continue;
		
			childNodes.push(node.childNodes[i]);
		}
	
		return childNodes;
	}
	
	XML.serializeToString = function(node)
	{
		if ( typeof(XMLSerializer) != "undefined" )
		{
			var xml = new XMLSerializer().serializeToString(node.firstChild);
			return XML.loadXML(xml);
		} else {
			return XML.loadXML(node.firstChild.xml);
		}
	}
	
	XML.parseElementAsArray = function(node)
	{
		if ( node.nodeType == 3 && node.nodeValue.trim() == '' )
			return;
		
		var xmlElement = new XMLElement();
		for ( var j = 0; j < node.attributes.length; j++ )
			xmlElement._attributes[node.attributes[j].name] = node.attributes[j].value.trim();
		
		// Children: 1 => End node, store value and return
		if ( node.childNodes.length == 1 )
		{
			xmlElement._value = node.firstChild.nodeValue.trim();
			return xmlElement;
		}
		
		for ( var i = 0; i < node.childNodes.length; i++ )
		{
			if ( node.childNodes[i].nodeType == 3 && node.childNodes[i].nodeValue.trim() == '' )
				continue;
			
			if ( !xmlElement[node.childNodes[i].tagName] )
				xmlElement[node.childNodes[i].tagName] = new Array();
			
			xmlElement[node.childNodes[i].tagName].push(XML.parseElementAsArray(node.childNodes[i]));
		}
		
		return xmlElement;
	}
	
	XML.parseElement = function(node)
	{
		if ( node.nodeType == 3 && node.nodeValue.trim() == '' )
			return;
		
		alert('Processing: ' + node.tagName + "\nType: " + node.nodeType + "\nValue: " + node.nodeValue + "\nChildren: " + node.childNodes.length);
		var xmlElement = new XMLElement();
		for ( var j = 0; j < node.attributes.length; j++ )
		{
			//alert(node.attributes[j].name + '::' + node.attributes[j].value.trim());
			xmlElement._attributes[node.attributes[j].name] = node.attributes[j].value.trim();
			//alert(xmlElement._attributes[node.attributes[j].name]);
		}
		
		// Children: 1 => End node, store value and return
		if ( node.childNodes.length == 1 )
		{
		
			alert("Setting value of " + node.tagName + ": " + node.firstChild.nodeValue);
			xmlElement._value = node.firstChild.nodeValue.trim();
			return xmlElement;
		}
		
		for ( var i = 0; i < node.childNodes.length; i++ )
		{
			if ( node.childNodes[i].nodeType == 3 && node.childNodes[i].nodeValue.trim() == '' )
				continue;
			
			var isArray = false;
			for ( var j = 0; j < node.childNodes.length; j++ )
			{
				if ( (i != j) && (node.childNodes[i].tagName == node.childNodes[j].tagName) )
					isArray = true;
			}
			
			if ( isArray )
			{
				if ( !xmlElement[node.childNodes[i].tagName] )
				{
					//alert("Creating an array for: " + node.childNodes[i].tagName);
					xmlElement[node.childNodes[i].tagName] = new Array();
				}
				
				//alert("Pushing a value for" + node.childNodes[i].tagName);
				xmlElement[node.childNodes[i].tagName].push(XML.parseElement(node.childNodes[i]));
			} else {
				//alert("Adding a child object for: " + node.childNodes[i].tagName);
				xmlElement[node.childNodes[i].tagName] = XML.parseElement(node.childNodes[i]);
			}
		}
		
		return xmlElement;
	}
	
	// Old functions for SOAP
	XML.getElementsByTagName = function(parentElem, tag)
	{
		return (window.ActiveXObject ? parentElem.getElementsByTagName(tag) : parentElem.getElementsByTagName(tag.split(':')[1] + '' == 'undefined' ? tag.split(':')[0] : tag.split(':')[1]));
	}
	
	String.prototype.stripNamespace = function()
	{
		return (this.split(':')[1] + '' == 'undefined' ? this.split(':')[0] : this.split(':')[1]);
	}
	
	// Need to enhance to allow parameter key/value pairs and all WSDL types
	XML.serialize = function(parameters)
	{
		var xml = '';
		for ( var i = 0; i < parameters.length; i++ )
		{
			xml += '<' + 'param' + i + '>';
			
			switch ( typeof(parameters[i]) )
			{
				case 'string':
					xml += parameters[i].replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
					break;
				case 'number': case 'boolean':
					xml += parameters[i].toString();
					break;
				case 'object':
					for (var j in parameters[i])
						xml += "<" + j + ">" + parameters[i][j] + "</" + j + ">";
					break;
			}
			
			xml += '</' + 'param' + i + '>';
		}

		return xml;
	}
	
	XML.getAttribute = function(xmlElem, attribute)
	{
		return xmlElem.attributes.getNamedItem(attribute).nodeValue;
	}

	// Old functions for loading XML documents
	XML.HttpRequest = function()
	{
		try {
			return new XMLHttpRequest(); // Firefox, Safari, IE7
		} catch(e) {
			try {
				return new ActiveXObject('MSXML2.XMLHTTP'); // IE6
			} catch(e) {
				try {
					return new ActiveXObject('Microsoft.XMLHTTP'); // IE5.5
				} catch(e) {
					try {
						return new ActiveXObject('Msxml2.XMLHTTP.5.0'); // IE5
					} catch(e) {
						try {
							return new ActiveXObject('Msxml2.XMLHTTP.4.0'); // IE4
						} catch(e) {
							try {
								return new ActiveXObject('MSXML2.XMLHTTP.3.0'); // IE3
							} catch(e) {
								alert("No XMLHttpRequest functionality enabled in web browser.");
							}
						}
					}
				}
			}
		}
	}
	
	XML.load = function(url)
	{
		//alert('url: ' + url);
		var xmlRequest = XML.HttpRequest();
		
		xmlRequest.open("GET", url, false); // Synchronous
		if ( window.ActiveXObject ) // IE/Windows ActiveX version
			xmlRequest.send();
		else if ( XMLHttpRequest ) // Native XMLHttpRequest object
		{
			if ( xmlRequest.overrideMimeType )
				xmlRequest.overrideMimeType('text/xml');
			xmlRequest.send(null);
		}
		
		if ( xmlRequest.status != 200 )
			return null;
		
		//alert('response: ' + xmlRequest.responseXML);
		return xmlRequest.responseXML;
	}
	
	XML.loadXML = function(xmlText)
	{
		var obj = null;
		
		if ( (document.implementation != null) && (typeof document.implementation.createDocument == "function") )
		{
			// Gecko / Mozilla / Firefox
			var parser = new DOMParser();
			obj = parser.parseFromString(xmlText, "text/xml");
		} else {    
			// IE
			try {
				obj = new ActiveXObject("MSXML2.DOMDocument");
			} catch (e) { }

			if ( obj == null )
			{
				try {
					obj = new ActiveXObject("Microsoft.XMLDOM");
				} catch (e) { }
			}
  
			if ( obj != null )
			{
				obj.async = false;
				obj.validateOnParse = false;
			}

			obj.loadXML(xmlText);
		}

		return(obj);
	}
	
	
	function getDomAdapter()
{
	var adapter = '';
	if ('undefined' != typeof ActiveXObject) {
		adapter = 'MS';
	} else if ('undefined' != typeof document
		&& document.implementation
		&& document.implementation.createDocument
		&& 'undefined' != typeof DOMParser)
	{
		adapter = 'default';
	}
	switch (adapter) {
		case 'MS':
			return new (function () {
				this.createDocument = function () {
					var names = ["Msxml2.DOMDocument.6.0",
						"Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument",
						"MSXML.DOMDocument", "Microsoft.XMLDOM"];
					for (var key in names) {
						try {
							return new ActiveXObject(names[key]);
						} catch (e) {}
					}
					throw new Error('Unable to create DOMDocument');
				};
				this.serialize = function (doc) {
					return doc.xml;
				};
				this.parseXml = function (xml) {
					var doc = this.createDocument();
					if (!doc.loadXML(xml)) {
						throw new Error('Parse error');
					}
					return doc;
				};
			})();
		case 'default':
			return new (function () {
				this.createDocument = function () {
					return document.implementation.createDocument("", "", null);
				};
				this.serialize = function (doc) {
					return new XMLSerializer().serializeToString(doc);
				};
				this.parseXml = function (xml) {
					var doc = new DOMParser().parseFromString(xml, "text/xml");
					if ("parsererror" == doc.documentElement.nodeName) {
						throw new Error('Parse error');
					}
					return doc;
				};
			})();
		default:
			throw new Error('Unable to select the DOM adapter');
	}
};
//-->