var whitespace="\n\r\t ",quotes="\"'";function convertEscapes(a){var e;var d;var b;for(b=-1;-1<a.indexOf("&lt;",b+1);){b=a.indexOf("&lt;",b+1);var c=a.substr(0,b),c=c+"<",a=c+=a.substr(b+4,a.length)}for(b=-1;-1<a.indexOf("&gt;",b+1);)b=a.indexOf("&gt;",b+1),c=a.substr(0,b),c+=">",d=c+=a.substr(b+4,a.length),a=d;for(b=-1;-1<a.indexOf("&amp;",b+1);)b=a.indexOf("&amp;",b+1),c=a.substr(0,b),c+="&",e=c+=a.substr(b+5,a.length),a=e;return a}
function convertToEscapes(a){var e;var d;for(var b=-1;-1<a.indexOf("&",b+1);)var b=a.indexOf("&",b+1),c=a.substr(0,b),c=c+"&amp;",a=c+=a.substr(b+1,a.length);for(b=-1;-1<a.indexOf("<",b+1);)b=a.indexOf("<",b+1),c=a.substr(0,b),c+="&lt;",d=c+=a.substr(b+1,a.length),a=d;for(b=-1;-1<a.indexOf(">",b+1);)b=a.indexOf(">",b+1),c=a.substr(0,b),c+="&gt;",e=c+=a.substr(b+1,a.length),a=e;return a}
function _displayElement(a,b){if(!(null==a||"ELEMENT"!=a.nodeType)){for(var c=a.tagName,d="",d="<"+c,e=a.getAttributeNames(),f=0;f<e.length;f++)var g=e[f],d=d+" "+g+"=",d=d+'"'+a.getAttribute(g)+'"';b+=d+">";if(null!=a.children){d=a.children;for(f=0;f<d.length;f++)e=d[f],"COMMENT"==e.nodeType?b=b+"<\!--"+e.content+"--\>":"TEXT"==e.nodeType?(g=trim(e.content,!0,!0),b+=e.content):"CDATA"==e.nodeType?(g=trim(e.content,!0,!0),b=b+"<![CDATA["+g+"]]\>"):b=_displayElement(e,b)}return b+"</"+c+">"}}
function firstWhiteChar(a,b){if(isEmpty(a))return-1;for(;b<a.length;){if(-1!=whitespace.indexOf(a.charAt(b)))return b;b++}return a.length}function isEmpty(a){return null==a||0==a.length}function trim(a,b,c){if(isEmpty(a))return"";null==b&&(b=!0);null==c&&(c=!0);var d=0,e=0,f=0,g=0;if(!0==b)for(;f<a.length&&-1!=whitespace.indexOf(a.charAt(f++));)d++;if(!0==c)for(g=a.length-1;g>=d&&-1!=whitespace.indexOf(a.charAt(g--));)e++;return a.substring(d,a.length-e)}
function XMLDoc(a,b){this.topNode=null;this.errFn=b;this.createXMLNode=_XMLDoc_createXMLNode;this.error=_XMLDoc_error;this.getUnderlyingXMLText=_XMLDoc_getUnderlyingXMLText;this.handleNode=_XMLDoc_handleNode;this.hasErrors=!1;this.insertNodeAfter=_XMLDoc_insertNodeAfter;this.insertNodeInto=_XMLDoc_insertNodeInto;this.loadXML=_XMLDoc_loadXML;this.parse=_XMLDoc_parse;this.parseAttribute=_XMLDoc_parseAttribute;this.parseDTD=_XMLDoc_parseDTD;this.parsePI=_XMLDoc_parsePI;this.parseTag=_XMLDoc_parseTag;
this.removeNodeFromTree=_XMLDoc_removeNodeFromTree;this.replaceNodeContents=_XMLDoc_replaceNodeContents;this.selectNode=_XMLDoc_selectNode;this.selectNodeText=_XMLDoc_selectNodeText;this.source=a;if(this.parse())return null!=this.topNode?this.error("expected close "+this.topNode.tagName):!0}function _XMLDoc_createXMLNode(a){return(new XMLDoc(a,this.errFn)).docNode}
function _XMLDoc_error(a){this.hasErrors=!0;if(this.errFn)this.errFn("ERROR: "+a);else if(this.onerror)this.onerror("ERROR: "+a);return 0}
function _XMLDoc_getTagNameParams(a,b){var c=-1,d,e=a.indexOf("["),f=[];0<=e&&(d=a.indexOf("]"),0<=d?c=a.substr(e+1,d-e-1):b.error("expected ] near "+a),a=a.substr(0,e),isNaN(c)&&"*"!=c?(f=c.substr(1,c.length-1),f=f.split("="),f[1]&&(e=f[1].indexOf('"'),f[1]=f[1].substr(e+1,f[1].length-1),d=f[1].indexOf('"'),0<=d?f[1]=f[1].substr(0,d):b.error('expected " near '+a)),c=-1):"*"==c&&(c=-1));return[a,c,f[0],f[1]]}
function _XMLDoc_getUnderlyingXMLText(){var a;if(null!=this.docNode)return a=_displayElement(this.docNode,'<?xml version="1.0"?>')}
function _XMLDoc_handleNode(a){if("COMMENT"==a.nodeType&&null!=this.topNode)return this.topNode.addElement(a);if("TEXT"==a.nodeType||"CDATA"==a.nodeType)if(null==this.topNode){if(""!=trim(a.content,!0,!1))return this.error("expected document node, found: "+a)}else return this.topNode.addElement(a);else{if("OPEN"==a.nodeType||"SINGLE"==a.nodeType){var b=!1;null==this.topNode?(this.docNode=a,a.parent=null,b=!0):b=this.topNode.addElement(a);if(b&&"SINGLE"!=a.nodeType)this.topNode=a;a.nodeType="ELEMENT";
return b}if("CLOSE"==a.nodeType){if(null==this.topNode)return this.error("close tag without open: "+a.toString());if(a.tagName!=this.topNode.tagName)return this.error("expected closing "+this.topNode.tagName+", found closing "+a.tagName);this.topNode=this.topNode.getParent()}}return!0}
function _XMLDoc_insertNodeAfter(a,b){var c=this.getUnderlyingXMLText(),d=a.getUnderlyingXMLText(),d=c.indexOf(d)+d.length,e=c.substr(0,d),e=e+b.getUnderlyingXMLText(),e=e+c.substr(d);return new XMLDoc(e,this.errFn)}function _XMLDoc_insertNodeInto(a,b){var c=this.getUnderlyingXMLText(),d=a.getUnderlyingXMLText(),e=d.indexOf(">")+1,d=c.indexOf(d)+e,e=c.substr(0,d),e=e+b.getUnderlyingXMLText(),e=e+c.substr(d);return new XMLDoc(e,this.errFn)}
function _XMLDoc_loadXML(a){this.topNode=null;this.hasErrors=!1;this.source=a;return this.parse()}
function _XMLDoc_parse(){var a=0;for(err=!1;!err;){var b="",c=this.source.indexOf("<",a),d;if(-1==c)break;d=c;var e=this.source.substring(a,d);0!=e.length&&(err=!this.handleNode(new XMLNode("TEXT",this,e)));if(c==this.source.indexOf("<?",a))a=this.parsePI(this.source,a+2),0==a&&(err=!0);else if(c==this.source.indexOf("<!DOCTYPE",a))a=this.parseDTD(this.source,c+9),0==a&&(err=!0);else{c==this.source.indexOf("<\!--",a)&&(b="--");c==this.source.indexOf("<![CDATA[",a)&&(b="]]");c=this.source.indexOf(b+
">",c);if(-1==c)return this.error("expected closing tag sequence: "+b+">");a=c+b.length;e=this.source.substring(d+1,a);(d=this.parseTag(e))&&(err=!this.handleNode(d));a+=1}}return!err}
function _XMLDoc_parseAttribute(a,b,c){for(;b<a.length&&-1!=whitespace.indexOf(a.charAt(b));)b++;if(b>=a.length)return b;for(var d=b;b<a.length&&"="!=a.charAt(b);)b++;var e="attributes must have values";if(b>=a.length)return this.error(e);for(var f=trim(a.substring(d,b++),!1,!0);b<a.length&&-1!=whitespace.indexOf(a.charAt(b));)b++;if(b>=a.length)return this.error(e);var e="attribute values must be in quotes",g=a.charAt(b++);if(-1==quotes.indexOf(g))return this.error(e);for(d=b;b<a.length&&a.charAt(b)!=
g;)b++;return b>=a.length?this.error(e):!c.addAttribute(f,trim(a.substring(d,b++),!1,!0))?0:b}function _XMLDoc_parseDTD(a,b){var c=a.indexOf(">",b);if(-1==c)return this.error("error in DTD: expected '>'");var d="",e=a.indexOf("[",b);for(-1!=e&&e<c&&(d="]");;){c=a.indexOf(d+">",b);if(-1==c)return this.error("expected closing tag sequence: "+d+">");b=c+d.length+1;if("]]\>"!=a.substring(c-1,c+2))break}return b}function _XMLDoc_parsePI(a,b){return a.indexOf("?>",b)+2}
function _XMLDoc_parseTag(a){if(0==a.indexOf("!--"))return new XMLNode("COMMENT",this,a.substring(3,a.length-2));if(0==a.indexOf("![CDATA["))return new XMLNode("CDATA",this,a.substring(8,a.length-2));var b=new XMLNode;b.doc=this;"/"==a.charAt(0)?(b.nodeType="CLOSE",a=a.substring(1)):b.nodeType="OPEN";if("/"==a.charAt(a.length-1)){if("CLOSE"==b.nodeType)return this.error("singleton close tag");b.nodeType="SINGLE";a=a.substring(0,a.length-1)}if("CLOSE"!=b.nodeType)b.attributes=[];if("OPEN"==b.nodeType)b.children=
[];a=trim(a,!0,!0);if(0==a.length)return this.error("empty tag");var c=firstWhiteChar(a,0);if(-1==c)return b.tagName=a,b;for(b.tagName=a.substring(0,c);c<a.length;)if(c=this.parseAttribute(a,c,b),0==this.pos)return null;return b}function _XMLDoc_removeNodeFromTree(a){var b=this.getUnderlyingXMLText(),a=a.getUnderlyingXMLText(),c=b.indexOf(a),d=b.substr(0,c),d=d+b.substr(c+a.length);return new XMLDoc(d,this.errFn)}
function _XMLDoc_replaceNodeContents(a,b){var c=this.createXMLNode("<X>"+b+"</X>");a.children=c.children;return this}
function _XMLDoc_selectNode(a){var a=trim(a,!0,!0),b,c,d,e,f;c=this.source?this.docNode:this;if(!a)return c;0==a.indexOf("/")&&(a=a.substr(1));a=a.replace(b,"");if(b=a.split("/")[0])if(0==a.indexOf("/")&&(a=a.substr(1)),a=a.replace(b,""),d=_XMLDoc_getTagNameParams(b,this),b=d[0],e=d[1],f=d[2],d=d[3],c="*"==b?c.getElements():c.getElements(b),c.length)if(0>e){b=c;for(e=0;e<b.length;){if(c=f?b[e].getAttribute(f)!=d?!1:!0:!0)if(c=b[e].selectNode(a))return c;e++}}else if(e<c.length&&(c=c[e].selectNode(a)))return c}
function _XMLDoc_selectNodeText(a){a=this.selectNode(a);return null!=a?a.getText():null}
function XMLNode(a,b,c){this.content="TEXT"==a||"CDATA"==a||"COMMENT"==a?c:null;this.children=this.attributes=null;this.doc=b;this.nodeType=a;this.tagName=this.parent="";this.addAttribute=_XMLNode_addAttribute;this.addElement=_XMLNode_addElement;this.getAttribute=_XMLNode_getAttribute;this.getAttributeNames=_XMLNode_getAttributeNames;this.getElementById=_XMLNode_getElementById;this.getElements=_XMLNode_getElements;this.getText=_XMLNode_getText;this.getParent=_XMLNode_getParent;this.getUnderlyingXMLText=
_XMLNode_getUnderlyingXMLText;this.removeAttribute=_XMLNode_removeAttribute;this.selectNode=_XMLDoc_selectNode;this.selectNodeText=_XMLDoc_selectNodeText;this.toString=_XMLNode_toString}function _XMLNode_addAttribute(a,b){this.attributes["_"+a]=b;return!0}function _XMLNode_addElement(a){a.parent=this;this.children[this.children.length]=a;return!0}function _XMLNode_getAttribute(a){return null==this.attributes?null:this.attributes["_"+a]}
function _XMLNode_getAttributeNames(){if(null==this.attributes)return[];var a=[],b;for(b in this.attributes)a[a.length]=b.substring(1);return a}function _XMLNode_getElementById(a){var b;if(this.getAttribute("id")==a)return this;for(var c=this.getElements(),d=0;d<c.length;){b=c[d].getElementById(a);if(null!=b)break;d++}return b}
function _XMLNode_getElements(a){if(null==this.children)return[];for(var b=[],c=0;c<this.children.length;c++)if("ELEMENT"==this.children[c].nodeType&&(null==a||this.children[c].tagName==a))b[b.length]=this.children[c];return b}function _XMLNode_getText(){if("ELEMENT"==this.nodeType){if(null==this.children)return null;for(var a="",b=0;b<this.children.length;b++)var c=this.children[b].getText(),a=a+(null==c?"":c);return a}return"TEXT"==this.nodeType?convertEscapes(this.content):this.content}
function _XMLNode_getParent(){return this.parent}function _XMLNode_getUnderlyingXMLText(){var a;return a=_displayElement(this,"")}
function _XMLNode_removeAttribute(a){if(null==a)return this.doc.error("You must pass an attribute name into the removeAttribute function");var b=this.getAttributeNames(),c=b.length,d=[];for(intLoop=0;intLoop<c;intLoop++)d[intLoop]=this.getAttribute(b[intLoop]);this.attributes=[];for(intLoop=0;intLoop<c;intLoop++)b[intLoop]!=a&&this.addAttribute(b[intLoop],d[intLoop]);return!0}
function _XMLNode_toString(){return""+this.nodeType+":"+("TEXT"==this.nodeType||"CDATA"==this.nodeType||"COMMENT"==this.nodeType?this.content:this.tagName)};

