function XmlElement(node) {
	this.me = node;
	//this.IsMozilla = ((document.implementation != null) && (typeof document.implementation.createDocument == "function"));	
	this.IsMozilla = (typeof ActiveXObject != 'undefined');
	this.text = "";

	this.Init = function () {
		if (!this.IsMozilla) {
			if (this.me) {
				this.text = this.me.textContent;
			}
		}
		else {
			if (this.me) {
				this.text = this.me.text;
			}
		}
	}

	this.getAttribute = function (name) {
		if (!this.IsMozilla) {
			var s = this.me.attributes.getNamedItem(name);
			if (s) return s.textContent;
			else return "";
		}
		else {
			return this.me.getAttribute(name);
		}
	}

	this.Init();
}

function XmlIterator(nodes) {
	//this.IsMozilla = ((document.implementation != null) && (typeof document.implementation.createDocument == "function"));	
	this.IsMozilla = (typeof ActiveXObject != 'undefined');
	this.collection = nodes;
	this.iref = -1;
	this.Current = null;

	this.Next = function () {
		var elm;
		if (!this.IsMozilla) {
			var node = this.collection.iterateNext();
			if (node) elm = new XmlElement(node);
			else elm = null;
		}
		else {
			this.iref++;
			if (this.iref < this.collection.length) elm = new XmlElement(this.collection[this.iref]);
			else elm = null;
		}
		this.Current = elm;
		return elm;
	}
}

function XML() {
	this.parser = null;
	this.IsMozilla = false;
	this.root = null;

	this.selectSingleNode = function (expr) {
		if (this.IsMozilla) {
			var result = null;
				result = this.parser.evaluate(expr, this.parser, null, 9, null);

			this.root = null;
			return new XmlElement(result.singleNodeValue);
		}
		else {
			var e = this.parser.selectSingleNode(expr);
			return new XmlElement(e);
		}
	}

	this.selectNodes = function (expr) {
		if (this.IsMozilla) {
			this.root = new XmlIterator(this.parser.evaluate(expr, this.parser, null, 4, null));
			//alert(this.root);
			return this.root;
		}
		else {
			this.root = new XmlIterator(this.parser.selectNodes(expr));
			return this.root;
		}
	}

	this.LoadXML = function (s) {
		if (this.IsMozilla) {

				this.parser = this.parser.parseFromString(s, "text/xml");

		} else {
			this.parser.loadXML(s);
		}
	}

	this.Init = function () {

		if (typeof ActiveXObject != 'undefined') {
			this.parser = new ActiveXObject('MSXML2.DOMDocument.3.0');
			this.parser.setProperty('SelectionLanguage', 'XPath');
		} else {

				this.parser = new DOMParser();

			this.IsMozilla = true;
		}
		/*
		if ((document.implementation != null) && (typeof (document.implementation.createDocument) == "function")) {
		this.parser = new DOMParser();

		this.IsMozilla = true;
		}
		else {
		this.parser = new ActiveXObject('MSXML2.DOMDocument.3.0');
		this.parser.setProperty('SelectionLanguage', 'XPath');
		}*/
	}

	this.Init();

}
