(function(m){function r(a){this.parent=a||null}function i(a){this.nodeName=a||"";this.ns=""}function k(){var a=null,b=null,e=null;switch(arguments.length){case 1:b=arguments[0];break;case 2:a=arguments[0];b=arguments[1];break;case 3:a=arguments[0];b=arguments[1];e=arguments[2];break;default:b="noname"}i.apply(this,[b]);r.apply(this,[a]);this.Text=e||""}function p(){var a=[];m.extend(a,s);return a}var n=Object.prototype.toString,f={isIE:function(){return+"\u0000"===0},isStr:function(a){return n.call(a)===
"[object String]"},isFn:function(a){return n.call(a)==="[object Function]"},isDef:function(a){return typeof a!=="undefined"},isArr:function(a){return n.call(a)==="[object Array]"},isNum:function(a){var b=false;if(f.isStr(a))b=/^((-)?([0-9]*)((\.{0,1})([0-9]+))?$)/.test(a);return b},isXNode:function(a){return typeof a==="object"&&this.isDef(a.nodeName)},isNodeSet:function(a){return f.isArr(a)},trim:function(a){var b=a;if(this.isStr(a))b=a.replace(/^\s\s*/,"").replace(/\s\s*$/,"");return b},formatName:function(a){return this.trim(String(a))}},
l={newDocument:function(a,b){a||(a="");b||(b="");if(document.implementation&&document.implementation.createDocument)return document.implementation.createDocument(b,a,null);else{var e=new ActiveXObject("MSXML2.DOMDocument");if(a){var d="",c=a,g=a.indexOf(":");if(g!==-1){d=a.substring(0,g);c=a.substring(g+1)}if(b)d||(d="a0");else d="";e.loadXML("<"+(d?d+":":"")+c+(b?" xmlns:"+d+'="'+b+'"':"")+"/>")}return e}},objToNode:function(a,b){var e,d,c;if(f.isDef(a)&&f.isDef(b))for(e in b)if(b.hasOwnProperty&&
b.hasOwnProperty(e)){d=b[e];if(e.indexOf("@")!==-1)a.setAttribute(e.replace("@",""),d);else if(e==="$comments"){if(d.length){c=0;var g=d.length-1,h;do{h=d[c];a.appendChild(this.createComment(h))}while(c++<g)}}else if(f.isNodeSet(d)){g=0;h=d.length-1;var j;do{j=d[g];c=j.ns?f.isDef(this.createElementNS)?a.appendChild(this.createElementNS(j.ns,e)):a.appendChild(this.createNode(1,e,j.ns)):a.appendChild(this.createElement(e));if(j.Text)c.appendChild(f.isDef(j.hasCDATA)?this.createCDATASection(j.Text):
this.createTextNode(j.Text));l.objToNode.call(this,c,j)}while(g++<h)}}}},s={getNodesByAttribute:function(a,b){var e=[],d=this.length,c,g;if(d&&f.isStr(a)&&f.isDef(b))for(;d--;){c=this[d];g=c[a];f.isDef(g)&&g===b&&e.unshift(c)}return!e.length?NULL:e},getNodesByValue:function(a){var b=[],e=this.length,d;if(e&&f.isDef(a))for(;e--;){d=this[e];d.Text===a&&b.unshift(d)}return!b.length?NULL:b},contains:function(a,b){var e=FALSE,d=this.length,c;if(d&&f.isStr(a)&&f.isDef(b))for(;d--;){c=this[d];c=c[a];if(f.isDef(c)&&
c===b){e=TRUE;break}}return e},indexOf:function(){var a=-1,b,e,d=this.length,c;if(d)switch(arguments.length){case 1:for(e=arguments[0];d--;){c=this[d];c=c.val();if(f.isDef(c)&&c===e){a=d;break}}break;case 2:b=arguments[0];for(e=arguments[1];d--;){c=this[d];c=c[b];if(f.isDef(c)&&c===e){a=d;break}}}return a},sortByAttribute:function(a,b){this.length&&f.isStr(a)&&this.sort(function(e,d){var c=e.attr(a),g=d.attr(a);c=f.isNum(c)?parseFloat(c):c;g=f.isNum(g)?parseFloat(g):g;c=c<g?-1:g<c?1:0;return c=f.isDef(b)&&
b.toLowerCase()==="desc"?0-c:c})},sortByValue:function(a){this.length&&this.sort(function(b,e){var d=b.Text,c=e.Text;d=f.isNum(d)?parseFloat(d):d;c=f.isNum(c)?parseFloat(c):c;d=d<c?-1:c<d?1:0;return d=f.isDef(a)&&a.toLowerCase()==="desc"?0-d:d})},sortByChildNode:function(a,b){this.length&&f.isStr(a)&&this.sort(function(e,d){var c=e[a],g=d[a];c=f.isDef(c)&&c.length?c[0].Text:NULL;g=f.isDef(g)&&g.length?g[0].Text:NULL;c=f.isNum(c)?parseFloat(c):c;g=f.isNum(g)?parseFloat(g):g;c=c<g?-1:g<c?1:0;return c=
f.isDef(b)&&b.toLowerCase()==="desc"?0-c:c})},first:function(){var a=NULL;if(this.length)a=this[0];return a},last:function(){var a=NULL;if(this.length)a=this[this.length-1];return a}},o=function(){var a={makeNodeSet:function(){return p()},makeNode:function(b,e){var d=e.localName||e.baseName;d=f.trim(d);d=new k(b,d);d.ns=e.prefix||"";this.setAttributes(d,e);return d},setAttributes:function(b,e){if(f.isDef(e)&&e.attributes.length){var d=e.attributes.length-1,c=null;do{c="@"+e.attributes[d].name;b.attr(c,
e.attributes[d].value)}while(d--)}},run:function(b,e){var d,c;if(f.isDef(b)&&f.isDef(e))if(e.hasChildNodes()){var g=e.childNodes.length-1,h=0;do{d=e.childNodes[h];switch(d.nodeType){case 1:c=a.makeNode(b,d);if(f.isFn(this.decorator))if(this.decorator.call(c)===false)continue;if(c){b.appendChild(c);d.hasChildNodes()&&a.run.apply(this,[c,d])}break;case 3:if(b.Text)b.Text+=f.trim(d.nodeValue);else b.val(f.trim(d.nodeValue));break;case 4:b.hasCDATA=true;b.val(f.isDef(d.text)?f.trim(d.text):f.trim(d.nodeValue));
break;case 8:if(!f.isDef(this.noComments)||!this.noComments){if(!f.isDef(b.$comments))b.$comments=[];b.$comments.push(f.trim(d.nodeValue))}}}while(h++<g)}},init:function(b,e){e=e||{noComments:true};b=f.isStr(b)?this.textToXML(b):f.isXNode(b)?b:null;if(!b)return null;var d=b.nodeType===9?b.documentElement:b.nodeType===11?b.firstChild:b,c=new i(d.nodeName);f.isFn(e.decorator)&&e.decorator.call(c);if(b.nodeType===3||b.nodeType===4)return b.nodeValue;this.run.apply(e,[c,d]);this.setAttributes(c,d);return c},
textToXML:function(b){var e=null;try{e=f.isIE()?new ActiveXObject("MSXML2.DOMDocument"):new DOMParser;e.async=false}catch(d){throw Error("XML Parser could not be instantiated");}var c=null,g=true;if(f.isIE())c=(g=e.loadXML(b))?e:false;else{c=e.parseFromString(b,"text/xml");g=c.documentElement.tagName!=="parsererror"}if(!g)throw Error("Error parsing XML string");return c}};return a}();i.prototype={typeOf:"xmlObjectifier",attr:function(){var a,b,e;if(arguments.length)switch(arguments.length){case 1:b=
f.trim(arguments[0]);e=this["@"+b]||this[b];if(f.isDef(e)&&!f.isArr(e))a=e;break;case 2:b=f.trim(arguments[0]);e=arguments[1];if(f.isStr(b)){this[/^@/.test(b)?b:"@"+b]=e;a=this}}return a},find:function(a){var b=null,e,d;if(f.isStr(a)){var c,g=/\[(\d+|@\w+(=\w+)?)\]/,h=/^@\w+/;if(a.match(h)){d=a.match(h)[0];return this.attr(d)}a=a.match(/(?=\.)?([A-Za-z\-]+(\[(\d+|@\w+(=\w+)?)\])?)/g);if(a.length){b=0;h=a.length-1;do{e=a[b];d=e.match(/[A-Za-z\-]+/)[0];c=c?(f.isArr(c)?c[0]:c)[d]:this[d];if(!c)break;
if((e=!!e.match(g)&&e.match(g)[0].replace("[","").replace("]",""))&&e.length)if(e.indexOf("=")!==-1){e=e.split("=");d=f.trim(e[0]);e=f.trim(e[1]);if(d.indexOf("@")!==-1){d=d;c=c.getNodesByAttribute(d,e)}else if(d=f.trim(c[d]))c=d.getNodesByValue(e)}else if(f.isNum(e))c=c[~~+e]}while(b++<h);b=c}}return b},addComment:function(a){if(f.isStr(a)){if(!f.isDef(this.$comments))this.$comments=[];this.$comments.push(a)}return this},val:function(a){var b=this;if(f.isDef(a))this.Text=a;else b=this.Text;return b},
toXML:function(){var a=l.newDocument(this.nodeName,this.ns);l.objToNode.call(a,a.documentElement,this);return a},toString:function(){var a=this.toXML(),b="";if(f.isDef(a.xml))b=a.xml;else if(f.isDef(l))b=(new window.XMLSerializer).serializeToString(a);return b},appendChild:function(a){if(f.isDef(a)&&a instanceof k){a.parent=this;f.isDef(this[a.nodeName])||(this[a.nodeName]=o.makeNodeSet());this[a.nodeName].push(a)}}};k.prototype={attr:i.prototype.attr,val:i.prototype.val,find:i.prototype.find,addComment:i.prototype.addComment,
appendChild:i.prototype.appendChild};var q={xmlToJSON:function(a,b){return o.init(a,b)},textToXML:o.textToXML,xmlObjectifier:{RootClass:i,NodeClass:k,NodeSetClass:p}};if(f.isDef(m))m.extend(q);else window.XMLObjectifier=q})(typeof jQuery!=="undefined"&&jQuery||undefined);
