/*
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
(function($){$.extend({xmlToJSON:function(h){try{if(!h){return null}var i={};i.typeOf="JSXBObject";var j=(h.nodeType==9)?h.documentElement:h;i.RootName=j.nodeName||"";if(h.nodeType==3||h.nodeType==4){return h.nodeValue}var k=function(s){var a="";if(s&&typeof s=="string"){a=s}var b=/^((-)?([0-9]*)((\.{0,1})([0-9]+))?$)/;return b.test(a)};function formatName(a){var b=/-/g;var c=String(a).replace(b,"_");return c}function setAttributes(b,c){if(c.attributes.length>0){var a=c.attributes.length-1;var d;b._attributes=[];do{d=String(formatName(c.attributes[a].name));b._attributes.push(d);b[d]=$.trim(c.attributes[a].value)}while(a--)}}function setHelpers(g){g.getNodeByAttribute=function(a,b){if(this.length>0){var c;var d=this.length-1;try{do{c=this[d];if(c[a]==b){return c}}while(d--)}catch(e){return false}return false}};g.contains=function(a,b){if(this.length>0){var c=this.length-1;try{do{if(this[c][a]==b){return true}}while(c--)}catch(e){return false}return false}};g.indexOf=function(a,b){var c=-1;if(this.length>0){var d=this.length-1;try{do{if(this[d][a]==b){c=d}}while(d--)}catch(e){return-1}return c}};g.SortByAttribute=function(e,f){if(this.length){function getValue(a,b){var c=a[b];c=(k(c))?parseFloat(c):c;return c}function sortFn(a,b){var c=0;var d,tB;d=getValue(a,e);tB=getValue(b,e);if(d<tB){c=-1}else if(tB<d){c=1}if(f){c=(f.toUpperCase()=="DESC")?(0-c):c}return c}this.sort(sortFn)}};g.SortByValue=function(e){if(this.length){function getValue(a){var b=a.Text;b=(k(b))?parseFloat(b):b;return b}function sortFn(a,b){var c=0;var d,tB;d=getValue(a);tB=getValue(b);if(d<tB){c=-1}else if(tB<d){c=1}if(e){c=(e.toUpperCase()=="DESC")?(0-c):c}return c}this.sort(sortFn)}};g.SortByNode=function(e,f){if(this.length){function getValue(a,b){var c=a[b][0].Text;c=(k(c))?parseFloat(c):c;return c}function sortFn(a,b){var c=0;var d,tB;d=getValue(a,e);tB=getValue(b,e);if(d<tB){c=-1}else if(tB<d){c=1}if(f){c=(f.toUpperCase()=="DESC")?(0-c):c}return c}this.sort(sortFn)}}}function setObjects(a,b){var c;var d;var e;var f="";if(!b){return null}if(b.attributes.length>0){setAttributes(a,b)}a.Text="";if(b.hasChildNodes()){var g=b.childNodes.length-1;var n=0;do{d=b.childNodes[n];switch(d.nodeType){case 1:a._children=[];c=(d.localName)?d.localName:d.baseName;c=formatName(c);if(f!=c){a._children.push(c)}if(!a[c]){a[c]=[]}e={};a[c].push(e);if(d.attributes.length>0){setAttributes(e,d)}if(!a[c].contains){setHelpers(a[c])}f=c;if(d.hasChildNodes()){setObjects(e,d)}break;case 3:a.Text+=$.trim(d.nodeValue);break;case 4:a.Text+=(d.text)?$.trim(d.text):$.trim(d.nodeValue);break}}while(n++<g)}}setObjects(i,j);h=null;j=null;return i}catch(e){return null}}});$.extend({textToXML:function(a){var b=null;try{b=($.browser.msie)?new ActiveXObject("Microsoft.XMLDOM"):new DOMParser();b.async=false}catch(e){throw new Error("XML Parser could not be instantiated");}var c;try{if($.browser.msie){c=(b.loadXML(a))?b:false}else{c=b.parseFromString(a,"text/xml")}}catch(e){throw new Error("Error parsing XML string");}return c}})})(jQuery);