<!-- //

// define factory
function _XMLFT() {}

var _XmlFactory = _XMLFT;
var XmlFactory = _XMLFT;

// define createXmlHttpRequest method
_XMLFT.createXmlHttpRequest = function() {
	try {
		if(window.XMLHttpRequest) {
			var _req = new XMLHttpRequest();
			
			// some versions of Moz do not support the readyState property
			// and the onreadystate event so we patch it!
			if(_req.readyState==null) {
				_req.readyState = 1;
				_req.addEventListener("load", function() {
					_req.readyState = 4;
					if(typeof(_req.onreadystatechange)=="function") _req.onreadystatechange();
				}, false);
			}

			return _req;
		} else if(window.ActiveXObject) {
			var ARR_XMLHTTP = ["MSXML4.XmlHttp", "MSXML3.XmlHttp", "MSXML2.XmlHttp", "MSXML.XmlHttp", "Microsoft.XmlHttp"];
			for(var i=0; i<ARR_XMLHTTP.length; i++) {
				try {
					var _xh = new ActiveXObject(ARR_XMLHTTP[i]);
					return _xh;
				} catch(_ex) {}
			}
		}
	} catch(_ex) {}
	// fell through
	throw new Error("Your browser does not support XmlHttp objects");
}

// define method
_XMLFT.createXmlDomDocument = function(_ns, _rn) { // _ns : Namespace URI, _rn = Root tag name

	//determine if this is a standards-compliant browser like Mozilla
	if(document.implementation&&document.implementation.createDocument) {

		//create the DOM Document the standards way
		var _doc = document.implementation.createDocument(_ns, _rn, null);

		_doc.addEventListener("load", _Document_OnLoad, false);
		return _doc;

	} else if(is_ie4up) {

		//create the DOM Document the IE way
		var ARR_XMLDOM = ["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom"];
	//	var STR_XMLDOM = "";
		for(var i=0; i<ARR_XMLDOM.length; i++) {
			try {
				var _doc = new ActiveXObject(ARR_XMLDOM[i]);

				//if there is a root tag name, we need to preload the DOM
				if (_rn) {
					//If there is both a namespace and root tag name, then
					//create an artifical namespace reference and load the XML.
					if (_ns) 	_doc.loadXML("<a0:"+_rn+" xmlns:a0=\""+_ns+"\"/>");
					else _doc.loadXML("<"+_rn+"/>");
				}

				return _doc;
			} catch(_ex) {}
		}

		throw new Error("Could not find an installed XML parser");

		//create the DOM Document the IE way
		//_doc = new ActiveXObject(STR_XMLDOM);
	}

	//return the object
	//return _doc;
}

// Mozilla Options..
if(document.implementation&&document.implementation.createDocument) {

	//add the loadXML() method to the Document class
	Document.prototype.loadXML = _Document_LoadXML;

	//add the xml property to the Node class
	Node.prototype.__defineGetter__("xml", _Node_GetXML);

	Node.prototype.__defineGetter__("text", _Node_GetText);

	Node.prototype.selectSingleNode = _Node_SelectSingleNode;

	//add the readyState attribute to the Document class and initialize it to 0:
	Document.prototype.readyState = "0";

	Document.prototype.__load__ = Document.prototype.load;
	Document.prototype.load = _Document_Load;

	Document.prototype.onreadystatechange = null;

	Document.prototype.parseError = 0;
}

// Document.prototype.loadXML = _Document_LoadXML;
function _Document_LoadXML(_sx) { // _sx : strXML

	//change the readystate
	_ChangeReadyState(this, 1);

	try {
		//create a DOMParser
		var _parser = new DOMParser();

		//create new document from string
		var _doc2 = _parser.parseFromString(_sx, "text/xml");
		//var _doc2 = _parser.parseFromStream(_sx, "euc-kr", _sx.length, "text/xml");

		//make sure to remove all nodes from the document
		while(this.hasChildNodes()) this.removeChild(this.lastChild);

		//add the nodes from the new document
		for(var i=0; i<_doc2.childNodes.length; i++) {

			//append the child to the current document
			this.appendChild(this.importNode(_doc2.childNodes[i], true));

		} //End: for
	} catch(_ex) {}

	_HandleOnLoad(this);

	return true;

} //End: function

// Node.prototype.__defineGetter__("xml", _Node_GetXML);
function _Node_GetXML() {
	//create a new XMLSerializer
	var _XMLSerializer = new XMLSerializer;

	//get the XML string
	return _XMLSerializer.serializeToString(this);
}

function _Node_GetText() {
	return this.childNodes[0].nodeValue;
}

function _Node_SelectSingleNode(_t) { // _t : tagName
	return this.getElementsByTagName(_t)[0];
}

function _Document_Load(_su) { // _su : strURL
	//set the parseError to 0
 //   this.parseError = 0;

	//change the readyState
	_ChangeReadyState(this, 1);

	//watch for errors
//	try {
		//call the original load method
		this.__load__(su);

//	} catch(_ex) {
		//set the parseError attribute
//		this.parseError = -9999999;

		//set readyState to 4, we are done loading
		_ChangeReadyState(this, 4);
//	} // End: try..catch
}

function _Document_OnLoad() {
	//handle the onload event
    _HandleOnLoad(this);
}

function _ChangeReadyState(_d, _s) { // _d : DomDocument, _s : iReadyState
	//change the readyState
	_d.readyState = _s;

	//if there is an onreadystatechange event handler, run it
    if(_d.onreadystatechange!=null&&typeof(_d.onreadystatechange)=="function") _d.onreadystatechange();
}

function _HandleOnLoad(_d) { // _d : DomDocument
	//check for a parsing error
	if (!_d.documentElement||_d.documentElement.tagName=="parsererror") _d.parseError = -9999999;

	//change the readyState
	_ChangeReadyState(_d, 4);
}

/* -- ΕΧ½ΊΖ® --
var _xmldom = _XMLFT.createDomDocument();
alert(_xmldom);
_xmldom.async = true;
_xmldom.onreadystatechange = function() { alert(_xmldom.parseError+", "+_xmldom.readyState); }
alert(_xmldom.loadXML("<root><elm>aaa</xxelm></root>"));
alert(_xmldom.xml);
*/

// -->