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