/*
   ixmlcompat.js  cross browser XMLDocument for IE6+ and Gecko

   @author Doi Daishin(dd@denpan.org)
*/
function XMLCompat(){}
if ('undefined' != typeof document.getElementsByTagName) {
  XMLCompat.prototype.getElementsByTagName = function(tagName) { return document.getElementsByTagName(tagName); }
} else if ('undefined' != typeof document.all.tags) {
  XMLCompat.prototype.getElementsByTagName = function(tagName) { return document.all.tags(tagName); }
}
if ('undefined' != typeof document.implementation.createDocument) {
  XMLCompat.prototype.createXMLDocument = function() {
    var doc = document.implementation.createDocument("", "", null);
    doc.addEventListener("load", doc.onload, false);
    return doc;
  }
  XMLCompat.prototype.createXMLHttpRequest = function() {
    return new XMLHttpRequest;
  }
} else if ('undefined' != typeof ActiveXObject) {
  XMLCompat.prototype.createXMLDocument = function() {
    return new ActiveXObject("Microsoft.XMLDOM");
  }
  XMLCompat.prototype.createXMLHttpRequest = function() {
    return new ActiveXObject("MSXML2.XMLHTTP.3.0");
  }
}
XMLCompat = new XMLCompat;

if ('undefined' != typeof XMLDocument && 'undefined' == typeof XMLDocument.prototype.loadXML) {
  XMLDocument.prototype.loadXML = function(str)
  {
    this.readyState = 1;
    this.parseError = {
      errorCode : 0,
      url : this.url,
      reason : "",
      line : 0,
      linepos : 0
    };
    var newDoc = (new DOMParser()).parseFromString(str, "text/xml");

    while (this.hasChildNodes())
      this.removeChild(this.lastChild);

    for (var i = 0; i < newDoc.childNodes.length; ++i) {
      var importedNode = this.importNode(newDoc.childNodes[i], true);
      this.appendChild(importedNode);
    }
    this.onload();
  }
}
if ('undefined' != typeof XMLDocument && 'undefined' != typeof XMLDocument.prototype.__defineGetter__) {
  XMLDocument.prototype.__defineGetter__("xml",
    function()
    {
      try {
        return (new XMLSerializer()).serializeToString(this)
          .replace(/^<transformiix:result.*?>|<\/tansformiix:result>$/, '')
          .replace(/&lt;/g, '<')
          .replace(/&gt;/g, '>');
      } catch (e) {};
    }
  );
}
if ('undefined' != typeof XMLDocument && 'undefined' != typeof XMLDocument.prototype.__defineSetter__) {
  XMLDocument.prototype.__defineSetter__("xml",
    function()
    {
      throw('xml is read-only');
      return;
    }
  );
}
if ('undefined' != typeof XMLDocument && 'undefined' == typeof XMLDocument.prototype.readyState) {
  XMLDocument.prototype.readyState = 0;
  XMLDocument.prototype.onreadystatechange = null;
  XMLDocument.prototype.__load__ = XMLDocument.prototype.load;
  XMLDocument.prototype.load = function(url) {
    this.readyState = 1;
    this.parseError = {
      errorCode : 0,
      url : this.url,
      reason : "",
      line : 0,
      linepos : 0
    };
    try {
            if (url.match(/^https?:\/\//)) { // Remote XML Fetch
                var __this__ = this;
                var s = new SOAPCall;
                s.transportURI = url;
                s.encode(0, null, url, 0, null, 1, [(new SOAPParameter('dummy', 'dummy'))]);
                s.asyncInvoke(function(responce)
                {
                    var newDoc = responce.message;

                    while (__this__.hasChildNodes())
                        __this__.removeChild(__this__.lastChild);

                    for (var i = 0; i < newDoc.childNodes.length; ++i) {
                      var importedNode = __this__.importNode(newDoc.childNodes[i], true);
                      __this__.appendChild(importedNode);
                    }
                    __this__.onload();
                });
            } else { // Local XML Fetch
                this.__load__(url);
            }
    } catch (e) {
            dump(e.toString());
            this.readyState = 4;
    }
  }
  XMLDocument.prototype.onload = function() {
    this.readyState = 4;
    if (!this.documentElement || 'parseerror' == this.documentElement.tagName) {
      this.parseError = {
        errorCode : -9999999,
        url : this.url,
        reason : "",
        line : 0,
        linepos : 0
      };
    }
    if ('function' == typeof this.onreadystatechange) {
      this.onreadystatechange();
    }
  }
}
if ('undefined' != typeof XMLDocument && 'undefined' != typeof XSLTProcessor && 'undefined' == typeof XMLDocument.prototype.transformNode) {
  XMLDocument.prototype.transformNode = function(xsl)
  {
    var xslProcessor = new XSLTProcessor();
    xslProcessor.importStylesheet(xsl);

    var str = (new XMLSerializer()).serializeToString(xslProcessor.transformToDocument(this));
    return str.replace(/^<transformiix:result.*?>|<\/tansformiix:result>$/, '')
      .replace(/&lt;/g, '<')
      .replace(/&gt;/g, '>');
  }
}
if ('undefined' != typeof XMLDocument && 'undefined' != typeof XSLTProcessor && 'undefined' == typeof XMLDocument.prototype.transformNodeToObject) {
  XMLDocument.prototype.transformNodeToObject = function(xsl)
  {
    var xslProcessor = new XSLTProcessor();
    xslProcessor.importStylesheet(xsl);

    return xslProcessor.transformToDocument(this);
  }
}
