function htmlentities(a){var c=document.createElement("div");var b=document.createTextNode(a);c.appendChild(b);return c.innerHTML}var rpc={version:"0.8.0.2",requestCount:0};rpc.ServiceProxy=function(g,m){this.__serviceURL=g;this.__isCrossSite=false;var b=this.__serviceURL.match(/^(\w+:)\/\/([^\/]+?)(?::(\d+))?(?:$|\/)/);if(b){this.__isCrossSite=(location.protocol!=b[1]||document.domain!=b[2]||location.port!=(b[3]||""))}var k;this.__isAsynchronous=true;this.__isResponseSanitized=true;this.__authUsername=null;this.__authPassword=null;this.__callbackParamName="JSON-response-callback";this.__protocol="JSON-RPC";this.__dateEncoding="ISO8601";this.__decodeISO8601=true;if(m instanceof Object){if(m.asynchronous!==undefined){this.__isAsynchronous=!!m.asynchronous;if(!this.__isAsynchronous&&this.__isCrossSite){throw Error("It is not possible to establish a synchronous connection to a cross-site RPC service.")}}if(m.sanitize!=undefined){this.__isResponseSanitized=!!m.sanitize}if(m.user!=undefined){this.__authUsername=m.user}if(m.password!=undefined){this.__authPassword=m.password}if(m.callbackParamName!=undefined){this.__callbackParamName=m.callbackParamName}if(String(m.protocol).toUpperCase()=="XML-RPC"){this.__protocol="XML-RPC"}if(m.dateEncoding!=undefined){this.__dateEncoding=m.dateEncoding}if(m.decodeISO8601!=undefined){this.__decodeISO8601=!!m.decodeISO8601}k=m.methods}if(this.__isCrossSite){if(this.__isResponseSanitized){throw Error("You are attempting to access a service on another site, and the JSON data returned by cross-site requests cannot be sanitized. You must therefore explicitly set the 'sanitize' option to false (it is true by default) in order to proceed with making potentially insecure cross-site rpc calls.")}else{if(this.__protocol=="XML-RPC"){throw Error("Unable to use the XML-RPC protocol to access services on other domains.")}}}if(this.__isCrossSite&&!k){throw Error("You must manually supply the service's method names since auto-introspection is not permitted for cross-site services.")}if(k){this.__methodList=k}else{var c=this.__isAsynchronous;this.__isAsynchronous=false;this.__methodList=this.__callMethod("system.listMethods",[]);this.__isAsynchronous=c}this.__methodList.push("system.listMethods");this.__methodList.push("system.describe");for(var l,f=0;l=this.__methodList[f];f++){var h=this;var d=l.split(/\./);for(var e=0;e+1<d.length;e++){if(!h[d[e]]){h[d[e]]={}}h=h[d[e]]}var a=(function(i,j){var n={instance:i,methodName:j};return function(){if(n.instance.__isAsynchronous){if(arguments.length==1&&arguments[0] instanceof Object){n.instance.__callMethod(n.methodName,arguments[0].params,arguments[0].onSuccess,arguments[0].onException,arguments[0].onComplete)}else{n.instance.__callMethod(n.methodName,arguments[0],arguments[1],arguments[2],arguments[3])}return undefined}else{return n.instance.__callMethod(n.methodName,rpc.toArray(arguments))}}})(this,l);h[d[d.length-1]]=a}};rpc.setAsynchronous=function(b,a){if(!a&&b.__isCrossSite){throw Error("It is not possible to establish a synchronous connection to a cross-site RPC service.")}b.__isAsynchronous=!!a};rpc.ServiceProxy.prototype.__callMethod=function(j,r,p,o,k){rpc.requestCount++;if(this.__isAsynchronous){if(p&&typeof p!="function"){throw Error("The asynchronous onSuccess handler callback function you provided is invalid; the value you provided ("+p.toString()+') is of type "'+typeof(p)+'".')}if(o&&typeof o!="function"){throw Error("The asynchronous onException handler callback function you provided is invalid; the value you provided ("+o.toString()+') is of type "'+typeof(o)+'".')}if(k&&typeof k!="function"){throw Error("The asynchronous onComplete handler callback function you provided is invalid; the value you provided ("+k.toString()+') is of type "'+typeof(k)+'".')}}try{if(this.__isAsynchronous||this.__isCrossSite){rpc.pendingRequests[String(rpc.requestCount)]={onSuccess:p,onException:o,onComplete:k}}if(this.__isCrossSite){rpc.callbacks["r"+String(rpc.requestCount)]=(function(i,u){var t={instance:i,id:u};return function(v){if(v instanceof Object&&(v.result||v.error)){v.id=t.id;i.__doCallback(v)}else{i.__doCallback({id:t.id,result:v})}}})(this,rpc.requestCount);var s=document.createElement("script");s.setAttribute("type","text/javascript");var g=this.__serviceURL+"/"+j+"?"+this.__callbackParamName+"=rpc.callbacks.r"+(rpc.requestCount);if(r){g+="&"+rpc.toQueryString(r)}s.setAttribute("src",g);s.setAttribute("id","rpc"+rpc.requestCount);var e=document.getElementsByTagName("head")[0];rpc.pendingRequests[rpc.requestCount].scriptElement=s;e.appendChild(s);return undefined}else{if(r){if(!(r instanceof Object)||r instanceof Date){throw Error("When making asynchronous calls, the parameters for the method must be passed as an array (or a hash); the value you supplied ("+String(r)+') is of type "'+typeof(r)+'".')}}var d,b;if(this.__protocol=="XML-RPC"){if(!(r instanceof Array)){throw Error("Unable to pass associative arrays to XML-RPC services.")}var c=['<?xml version="1.0"?><methodCall><methodName>'+j+"</methodName>"];if(r){c.push("<params>");for(var n=0;n<r.length;n++){c.push("<param>"+this.__toXMLRPC(r[n])+"</param>")}c.push("</params>")}c.push("</methodCall>");b=c.join("")}else{d={version:"1.1",method:j,id:rpc.requestCount};if(r){d.params=r}b=this.__toJSON(d)}var h;if(window.XMLHttpRequest){h=new XMLHttpRequest()}else{if(window.ActiveXObject){try{h=new ActiveXObject("Msxml2.XMLHTTP")}catch(f){h=new ActiveXObject("Microsoft.XMLHTTP")}}}h.open("POST",this.__serviceURL,this.__isAsynchronous,this.__authUsername,this.__authPassword);if(this.__protocol=="XML-RPC"){h.setRequestHeader("Content-Type","text/xml");h.setRequestHeader("Accept","text/xml")}else{h.setRequestHeader("Content-Type","application/json");h.setRequestHeader("Accept","application/json")}if(this.__isAsynchronous){h.send(b);var q=this;var l={id:rpc.requestCount};h.onreadystatechange=function(){if(h.readyState==4){if(q.__protocol=="XML-RPC"){try{var i=q.__getXMLRPCResponse(h,l.id)}catch(t){alert("XML-RPC Error! "+t.message)}q.__doCallback(i)}else{var i=q.__evalJSON(h.responseText,q.__isResponseSanitized);if(!i.id){i.id=l.id}q.__doCallback(i)}}};return undefined}else{h.send(b);var a;if(this.__protocol=="XML-RPC"){a=this.__getXMLRPCResponse(h,rpc.requestCount)}else{a=this.__evalJSON(h.responseText,this.__isResponseSanitized)}if(a.error){throw Error('Unable to call "'+j+'". Server responsed with error (code '+a.error.code+"): "+a.error.message)}this.__upgradeValuesFromJSON(a);return a.result}}}catch(f){var m=false;if(o){m=o(f)}if(k){k()}if(!m){throw f}}};rpc.pendingRequests={};rpc.callbacks={};rpc.ServiceProxy.prototype.__doCallback=function(d){if(typeof d!="object"){throw Error("The server did not respond with a response object.")}if(!d.id){throw Error("The server did not respond with the required response id for asynchronous calls.")}if(!rpc.pendingRequests[d.id]){throw Error('Fatal error with RPC code: no ID "'+d.id+'" found in pendingRequests.')}if(rpc.pendingRequests[d.id].scriptElement){var c=rpc.pendingRequests[d.id].scriptElement;c.parentNode.removeChild(c)}if(rpc.callbacks[d.id]){delete rpc.callbacks["r"+d.id]}var a=[];if(d.error!==undefined){var h=new Error(d.error.message);h.code=d.error.code;if(rpc.pendingRequests[d.id].onException){try{if(!rpc.pendingRequests[d.id].onException(h)){a.push(h)}}catch(b){a.push(h);a.push(b)}}else{a.push(h)}}else{if(d.result!==undefined){this.__upgradeValuesFromJSON(d);if(rpc.pendingRequests[d.id].onSuccess){try{rpc.pendingRequests[d.id].onSuccess(d.result)}catch(h){if(rpc.pendingRequests[d.id].onException){try{if(!rpc.pendingRequests[d.id].onException(h)){a.push(h)}}catch(b){a.push(h);a.push(b)}}else{a.push(h)}}}}}try{if(rpc.pendingRequests[d.id].onComplete){rpc.pendingRequests[d.id].onComplete(d)}}catch(h){if(rpc.pendingRequests[d.id].onException){try{if(!rpc.pendingRequests[d.id].onException(h)){a.push(h)}}catch(b){a.push(h);a.push(b)}}else{a.push(h)}}delete rpc.pendingRequests[d.id];if(a.length){var g;var f="There "+(a.length==1?"was 1 uncaught exception":"were "+a.length+" uncaught exceptions")+": ";for(var e=0;e<a.length;e++){if(e){f+="; "}f+=a[e].message;if(a[e].code){g=a[e].code}}var h=new Error(f);h.code=g;throw h}};rpc.ServiceProxy.prototype.__toJSON=function(f){switch(typeof f){case"number":return isFinite(f)?f.toString():"null";case"boolean":return f.toString();case"string":var a={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\","/":"/"};return'"'+f.replace(/([\x00-\x1f\\"])/g,function(h,g){var i=a[g];if(i){return i}i=g.charCodeAt();return"\\u00"+rpc.zeroPad(i.toString(16))})+'"';case"object":if(f===null){return"null"}else{if(f instanceof Array){var d=["["];for(var c=0;c<f.length;c++){if(c){d.push(",")}d.push(this.__toJSON(f[c]))}d.push("]");return d.join("")}else{if(f instanceof Date){switch(this.__dateEncoding){case"classHinting":return'{"__jsonclass__":["Date",['+f.valueOf()+"]]}";case"@timestamp@":case"@ticks@":return'"@'+f.valueOf()+'@"';case"ASP.NET":return'"\\/Date('+f.valueOf()+')\\/"';default:return'"'+rpc.dateToISO8601(f)+'"'}}else{if(f instanceof Number||f instanceof String||f instanceof Boolean){return this.__toJSON(f.valueOf())}else{var e={}.hasOwnProperty?true:false;var d=["{"];for(var b in f){if(!e||f.hasOwnProperty(b)){if(d.length>1){d.push(",")}d.push(this.__toJSON(b)+":"+this.__toJSON(f[b]))}}d.push("}");return d.join("")}}}}}throw new TypeError('Unable to convert the value of type "'+typeof(f)+'" to JSON.')};rpc.isJSON=function(a){var b=a.replace(/\\./g,"@").replace(/"[^"\\\n\r]*"/g,"");return(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(b)};rpc.ServiceProxy.prototype.__evalJSON=function(json,sanitize){json=json.replace(/^\/\*-secure-([\s\S]*)\*\/\s*$/,"$1");var err;try{if(!sanitize||rpc.isJSON(json)){return eval("("+json+")")}}catch(e){err=e}throw new SyntaxError("Badly formed JSON string: "+json+" ... "+(err?err.message:""))};rpc.ServiceProxy.prototype.__upgradeValuesFromJSON=function(d){var c,b={}.hasOwnProperty?true:false;for(var a in d){if(!b||d.hasOwnProperty(a)){if(typeof d[a]=="string"){if(this.__decodeISO8601&&(c=d[a].match(/^(?:(\d\d\d\d)-(\d\d)(?:-(\d\d)(?:T(\d\d)(?::(\d\d)(?::(\d\d)(?:\.(\d+))?)?)?)?)?)$/))){d[a]=new Date(0);if(c[1]){d[a].setUTCFullYear(parseInt(c[1]))}if(c[2]){d[a].setUTCMonth(parseInt(c[2]-1))}if(c[3]){d[a].setUTCDate(parseInt(c[3]))}if(c[4]){d[a].setUTCHours(parseInt(c[4]))}if(c[5]){d[a].setUTCMinutes(parseInt(c[5]))}if(c[6]){d[a].setUTCMilliseconds(parseInt(c[6]))}}else{if(c=d[a].match(/^@(\d+)@$/)){d[a]=new Date(parseInt(c[1]))}else{if(c=d[a].match(/^\/Date\((\d+)\)\/$/)){d[a]=new Date(parseInt(c[1]))}}}}else{if(d[a] instanceof Object){if(d[a].__jsonclass__ instanceof Array){if(d[a].__jsonclass__[0]=="Date"){if(d[a].__jsonclass__[1] instanceof Array&&d[a].__jsonclass__[1][0]){d[a]=new Date(d[a].__jsonclass__[1][0])}else{d[a]=new Date()}}}else{this.__upgradeValuesFromJSON(d[a])}}}}}};rpc.ServiceProxy.prototype.__toXMLRPC=function(e){var a=["<value>"];switch(typeof e){case"number":if(!isFinite(e)){a.push("<nil/>")}else{if(parseInt(e)==Math.ceil(e)){a.push("<int>");a.push(e.toString());a.push("</int>")}else{a.push("<double>");a.push(e.toString());a.push("</double>")}}break;case"boolean":a.push("<boolean>");a.push(e?"1":"0");a.push("</boolean>");break;case"string":a.push("<string>");a.push(htmlentities(e));a.push("</string>");break;case"object":if(e===null){a.push("<nil/>")}else{if(e instanceof Array){a.push("<array><data>");for(var c=0;c<e.length;c++){a.push(this.__toXMLRPC(e[c]))}a.push("</data></array>")}else{if(e instanceof Date){a.push("<dateTime.iso8601>"+rpc.dateToISO8601(e)+"</dateTime.iso8601>")}else{if(e instanceof Number||e instanceof String||e instanceof Boolean){return rpc.dateToISO8601(e.valueOf())}else{a.push("<struct>");var d={}.hasOwnProperty?true:false;for(var b in e){if(!d||e.hasOwnProperty(b)){a.push("<member>");a.push("<name>"+b+"</name>");a.push(this.__toXMLRPC(e[b]));a.push("</member>")}}a.push("</struct>")}}}}break;default:throw new TypeError('Unable to convert the value of type "'+typeof(e)+'" to XML-RPC.')}a.push("</value>");return a.join("")};rpc.ServiceProxy.prototype.__parseXMLRPC=function(c){if(c.childNodes.length==1&&c.childNodes.item(0).nodeType==3){return c.childNodes.item(0).nodeValue}for(var m=0;m<c.childNodes.length;m++){if(c.childNodes.item(m).nodeType==1){var o=c.childNodes.item(m);switch(o.nodeName.toLowerCase()){case"i4":case"int":var r=parseInt(o.firstChild.nodeValue);if(isNaN(r)){throw Error("XML-RPC Parse Error: The value provided as an integer '"+o.firstChild.nodeValue+"' is invalid.")}return r;case"double":var t=parseFloat(o.firstChild.nodeValue);if(isNaN(t)){throw Error("XML-RPC Parse Error: The value provided as a double '"+o.firstChild.nodeValue+"' is invalid.")}return t;case"boolean":if(o.firstChild.nodeValue!="0"&&o.firstChild.nodeValue!="1"){throw Error("XML-RPC Parse Error: The value provided as a boolean '"+o.firstChild.nodeValue+"' is invalid.")}return Boolean(parseInt(o.firstChild.nodeValue));case"string":if(!o.firstChild){return""}return o.firstChild.nodeValue;case"datetime.iso8601":var p,d=new Date(0);if(p=o.firstChild.nodeValue.match(/^(?:(\d\d\d\d)-(\d\d)(?:-(\d\d)(?:T(\d\d)(?::(\d\d)(?::(\d\d)(?:\.(\d+))?)?)?)?)?)$/)){if(p[1]){d.setUTCFullYear(parseInt(p[1]))}if(p[2]){d.setUTCMonth(parseInt(p[2]-1))}if(p[3]){d.setUTCDate(parseInt(p[3]))}if(p[4]){d.setUTCHours(parseInt(p[4]))}if(p[5]){d.setUTCMinutes(parseInt(p[5]))}if(p[6]){d.setUTCMilliseconds(parseInt(p[6]))}return d}throw Error("XML-RPC Parse Error: The provided value does not match ISO8601.");case"base64":try{var v=o.firstChild.nodeValue;return v.decode("base64")}catch(q){throw Error("Not able to parse base64 data yet.")}case"nil":return null;case"struct":var l={};for(var u,h=0;u=o.childNodes.item(h);h++){if(u.nodeType==1&&u.nodeName=="member"){var a="";c=null;for(var b,f=0;b=u.childNodes.item(f);f++){if(b.nodeType==1){if(b.nodeName=="name"){a=b.firstChild.nodeValue}else{if(b.nodeName=="value"){c=b}}}}if(a&&c){l[a]=this.__parseXMLRPC(c)}}}return l;case"array":var n=[];var g=o.firstChild;while(g&&(g.nodeType!=1||g.nodeName!="data")){g=g.nextSibling}if(!g){new Error("XML-RPC Parse Error: Expected 'data' element as sole child element of 'array'.")}c=g.firstChild;while(c){if(c.nodeType==1){if(c.nodeName=="value"){n.push(this.__parseXMLRPC(c))}else{throw Error("XML-RPC Parse Error: Illegal element child '"+c.nodeName+"' of an array's 'data' element.")}}c=c.nextSibling}return n;default:throw Error("XML-RPC Parse Error: Illegal element '"+o.nodeName+"' child of the 'value' element.")}}}return""};rpc.ServiceProxy.prototype.__getXMLRPCResponse=function(e,f){var a={};if(!e.responseXML){throw Error("Malformed XML document.")}var d=e.responseXML.documentElement;if(d.nodeName!="methodResponse"){throw Error("Invalid XML-RPC document.")}var c=d.getElementsByTagName("value")[0];if(c.parentNode.nodeName=="param"&&c.parentNode.parentNode.nodeName=="params"){a.result=this.__parseXMLRPC(c)}else{if(c.parentNode.nodeName=="fault"){var b=this.__parseXMLRPC(c);a.error={code:b.faultCode,message:b.faultString}}else{throw Error("Invalid XML-RPC document.")}}if(!a.result&&!a.error){throw Error("Malformed XML-RPC methodResponse document.")}a.id=f;return a};rpc.toQueryString=function(e){if(!(e instanceof Object||e instanceof Array)||e instanceof Date){throw Error("You must supply either an array or object type to convert into a query string. You supplied: "+e.constructor)}var d="";var c={}.hasOwnProperty?true:false;for(var b in e){if(c&&e.hasOwnProperty(b)){if(e[b] instanceof Array){for(var a=0;a<e[b].length;a++){if(d){d+="&"}d+=encodeURIComponent(b)+"=";if(e[b][a] instanceof Date){d+=encodeURIComponent(rpc.dateToISO8601(e[b][a]))}else{if(e[b][a] instanceof Object){throw Error("Unable to pass nested arrays nor objects as parameters while in making a cross-site request. The object in question has this constructor: "+e[b][a].constructor)}else{d+=encodeURIComponent(String(e[b][a]))}}}}else{if(d){d+="&"}d+=encodeURIComponent(b)+"=";if(e[b] instanceof Date){d+=encodeURIComponent(rpc.dateToISO8601(e[b]))}else{if(e[b] instanceof Object){throw Error("Unable to pass objects as parameters while in making a cross-site request. The object in question has this constructor: "+e[b].constructor)}else{d+=encodeURIComponent(String(e[b]))}}}}}return d};rpc.toArray=function(b){if(b instanceof Array){return b}var c=[];for(var a=0;a<b.length;a++){c.push(b[a])}return c};rpc.dateToISO8601=function(a){return a.getUTCFullYear()+"-"+rpc.zeroPad(a.getUTCMonth()+1)+"-"+rpc.zeroPad(a.getUTCDate())+"T"+rpc.zeroPad(a.getUTCHours())+":"+rpc.zeroPad(a.getUTCMinutes())+":"+rpc.zeroPad(a.getUTCSeconds())+"."+rpc.zeroPad(a.getUTCMilliseconds(),3)};rpc.zeroPad=function(b,a){if(!a){a=2}b=(b==undefined?"":String(b));while(b.length<a){b="0"+b}return b};
