var escapeJSONString=(function(){var c=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,d={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};
return function(a){c.lastIndex=0;
return c.test(a)?'"'+a.replace(c,function(f){var b=d[f];
return typeof b==="string"?b:"\\u"+("0000"+f.charCodeAt(0).toString(16)).slice(-4)
})+'"':'"'+a+'"'
}
})();
function toJSON(m){var j="$_$jabsorbed$813492";
var k;
var n=[];
function p(){var a;
while(k){a=k[j].prev;
delete k[j];
k=a
}}var l={};
var i;
function o(f,g,e){var h=[],c,d,v,a,b;
if(f===null||f===undefined){return"null"
}else{if(typeof f==="string"){return escapeJSONString(f)
}else{if(typeof f==="number"){return f.toString()
}else{if(typeof f==="boolean"){return f.toString()
}else{if(f[j]){c=[e];
v=g;
while(v){if(d){d.unshift(v[j].ref)
}if(v===f){a=v;
d=[a[j].ref]
}c.unshift(v[j].ref);
v=v[j].parent
}if(a){if(JSONRpcClient.fixupCircRefs){c.shift();
d.shift();
n.push([c,d]);
return l
}else{p();
throw new Error("circular reference detected!")
}}else{if(JSONRpcClient.fixupDuplicates){d=[f[j].ref];
v=f[j].parent;
while(v){d.unshift(v[j].ref);
v=v[j].parent
}c.shift();
d.shift();
n.push([c,d]);
return l
}}}else{f[j]={parent:g,prev:k,ref:e};
k=f
}if(f.constructor===Date){if(f.javaClass){return'{javaClass: "'+f.javaClass+'", time: '+f.valueOf()+"}"
}else{return'{javaClass: "java.util.Date", time: '+f.valueOf()+"}"
}}else{if(f.constructor===Array){for(b=0;
b<f.length;
b++){i=o(f[b],f,b);
h.push(i===l?null:i)
}return"["+h.join(", ")+"]"
}else{for(var w in f){if(w===j){}else{if(f[w]===null||f[w]===undefined){h.push('"'+w+'": null')
}else{if(typeof f[w]=="function"){}else{i=o(f[w],f,w);
if(i!==l){h.push(escapeJSONString(w)+": "+i)
}}}}}return"{"+h.join(", ")+"}"
}}}}}}}i=o(m,null,"root");
p();
if(n.length){return{json:i,fixups:n}
}else{return{json:i}
}}function JSONRpcClient(){var i=0,k,j,o,p,n,l=(typeof arguments[0]),m=true;
if(l==="function"){this.readyCB=arguments[0];
i++
}else{if(arguments[0]&&l==="object"&&arguments[0].length){this._addMethods(arguments[0]);
i++;
m=false
}}this.serverURL=arguments[i];
this.user=arguments[i+1];
this.pass=arguments[i+2];
this.objectID=0;
if(m){this._addMethods(["system.listMethods"]);
k=JSONRpcClient._makeRequest(this,"system.listMethods",[]);
if(this.readyCB){p=this;
k.cb=function(b,a){if(!a){p._addMethods(b)
}p.readyCB(b,a)
}
}if(!this.readyCB){o=JSONRpcClient._sendRequest(this,k);
this._addMethods(o)
}else{JSONRpcClient.async_requests.push(k);
JSONRpcClient.kick_async()
}}}JSONRpcClient.prototype.createCallableProxy=function(j,k){var l,m,n,i,h;
l=new JSONRPCCallableProxy(j,k);
for(i in JSONRpcClient.knownClasses[k]){l[i]=JSONRpcClient.bind(JSONRpcClient.knownClasses[k][i],l)
}return l
};
function JSONRPCCallableProxy(){this.objectID=arguments[0];
this.javaClass=arguments[1];
this.JSONRPCType="CallableReference"
}JSONRpcClient.knownClasses={};
JSONRpcClient.Exception=function(d){var e;
for(var f in d){if(d.hasOwnProperty(f)){this[f]=d[f]
}}if(this.trace){e=this.trace.match(/^([^:]*)/);
if(e){this.name=e[0]
}}if(!this.name){this.name="JSONRpcClientException"
}};
JSONRpcClient.Exception.CODE_REMOTE_EXCEPTION=490;
JSONRpcClient.Exception.CODE_ERR_CLIENT=550;
JSONRpcClient.Exception.CODE_ERR_PARSE=590;
JSONRpcClient.Exception.CODE_ERR_NOMETHOD=591;
JSONRpcClient.Exception.CODE_ERR_UNMARSHALL=592;
JSONRpcClient.Exception.CODE_ERR_MARSHALL=593;
JSONRpcClient.Exception.prototype=new Error();
JSONRpcClient.Exception.prototype.toString=function(e,f){var d="";
if(this.name){d+=this.name
}if(this.message){d+=": "+this.message
}if(d.length==0){d="no exception information given"
}return d
};
JSONRpcClient.default_ex_handler=function(f){var a,e="";
for(a in f){e+=a+"\t"+f[a]+"\n"
}alert(e)
};
JSONRpcClient.toplevel_ex_handler=JSONRpcClient.default_ex_handler;
JSONRpcClient.profile_async=false;
JSONRpcClient.max_req_active=1;
JSONRpcClient.requestId=1;
JSONRpcClient.fixupCircRefs=true;
JSONRpcClient.fixupDuplicates=true;
JSONRpcClient.transformDates=false;
JSONRpcClient.transformDateWithoutHint=false;
JSONRpcClient.javaDateClasses={"java.util.Date":true,"java.sql.Date":true,"java.sql.Time":true,"java.sql.Timestamp":true};
JSONRpcClient.bind=function(c,d){return function(){return c.apply(d,arguments)
}
};
JSONRpcClient._createMethod=function(e,f){var d=function(){var h=[],a;
for(var c=0;
c<arguments.length;
c++){h.push(arguments[c])
}if(typeof h[0]=="function"){a=h.shift()
}var b=JSONRpcClient._makeRequest(this,f,h,this.objectID,a);
if(!a){return JSONRpcClient._sendRequest(e,b)
}else{JSONRpcClient.async_requests.push(b);
JSONRpcClient.kick_async();
return b.requestId
}};
return d
};
JSONRpcClient.prototype.createObject=function(){var l=[],i=null,g,h,j;
for(var k=0;
k<arguments.length;
k++){l.push(arguments[k])
}if(typeof l[0]=="function"){i=l.shift()
}g=l[0]+".$constructor";
h=l[1];
j=JSONRpcClient._makeRequest(this,g,h,0,i);
if(i===null){return JSONRpcClient._sendRequest(this,j)
}else{JSONRpcClient.async_requests.push(j);
JSONRpcClient.kick_async();
return j.requestId
}};
JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX=".ref";
JSONRpcClient.prototype._addMethods=function(n,t){var x,r,p,w,z,u=[],v,y,i,q;
for(var s=0;
s<n.length;
s++){r=this;
p=n[s].split(".");
i=n[s].indexOf("[");
q=n[s].indexOf("]");
if((n[s].substring(0,JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX.length)==JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX)&&(i!=-1)&&(q!=-1)&&(i<q)){v=n[s].substring(i+1,q)
}else{for(w=0;
w<p.length-1;
w++){x=p[w];
if(r[x]){r=r[x]
}else{r[x]={};
r=r[x]
}}}x=p[p.length-1];
if(v){z=JSONRpcClient._createMethod(this,x);
if(!JSONRpcClient.knownClasses[v]){JSONRpcClient.knownClasses[v]={}
}JSONRpcClient.knownClasses[v][x]=z
}else{z=JSONRpcClient._createMethod(this,n[s]);
if((!r[x])&&(!t)){r[x]=JSONRpcClient.bind(z,this)
}u.push(z)
}v=null
}return u
};
JSONRpcClient._getCharsetFromHeaders=function(g){var h,i,e;
try{h=g.getResponseHeader("Content-type");
i=h.split(/\s*;\s*/);
for(e=0;
e<i.length;
e++){if(i[e].substring(0,8)=="charset="){return i[e].substring(8,i[e].length)
}}}catch(j){}return"UTF-8"
};
JSONRpcClient.async_requests=[];
JSONRpcClient.async_inflight={};
JSONRpcClient.async_responses=[];
JSONRpcClient.async_timeout=null;
JSONRpcClient.num_req_active=0;
JSONRpcClient._async_handler=function(){var e,d;
JSONRpcClient.async_timeout=null;
while(JSONRpcClient.async_responses.length>0){e=JSONRpcClient.async_responses.shift();
if(e.canceled){continue
}if(e.profile){e.profile.dispatch=new Date()
}try{e.cb(e.result,e.ex,e.profile)
}catch(f){JSONRpcClient.toplevel_ex_handler(f)
}}while(JSONRpcClient.async_requests.length>0&&JSONRpcClient.num_req_active<JSONRpcClient.max_req_active){d=JSONRpcClient.async_requests.shift();
if(d.canceled){continue
}JSONRpcClient._sendRequest(d.client,d)
}};
JSONRpcClient.kick_async=function(){if(!JSONRpcClient.async_timeout){JSONRpcClient.async_timeout=setTimeout(JSONRpcClient._async_handler,0)
}};
JSONRpcClient.cancelRequest=function(c){if(JSONRpcClient.async_inflight[c]){JSONRpcClient.async_inflight[c].canceled=true;
return true
}var d;
for(d in JSONRpcClient.async_requests){if(JSONRpcClient.async_requests[d].requestId==c){JSONRpcClient.async_requests[d].canceled=true;
return true
}}for(d in JSONRpcClient.async_responses){if(JSONRpcClient.async_responses[d].requestId==c){JSONRpcClient.async_responses[d].canceled=true;
return true
}}return false
};
JSONRpcClient._makeRequest=function(i,p,n,k,j){var m={};
m.client=i;
m.requestId=JSONRpcClient.requestId++;
var l="{id:"+m.requestId+",method:";
if((k)&&(k>0)){l+='".obj['+k+"]."+p+'"'
}else{l+='"'+p+'"'
}if(j){m.cb=j
}if(JSONRpcClient.profile_async){m.profile={submit:new Date()}
}var o=toJSON(n);
l+=",params:"+o.json;
if(o.fixups){l+=",fixups:"+toJSON(o.fixups).json
}m.data=l+"}";
return m
};
JSONRpcClient._sendRequest=function(f,h){var e;
if(h.profile){h.profile.start=new Date()
}e=JSONRpcClient.poolGetHTTPRequest();
JSONRpcClient.num_req_active++;
e.open("POST",f.serverURL,!!h.cb,f.user,f.pass);
try{e.setRequestHeader("Content-type","text/plain")
}catch(g){}if(h.cb){e.onreadystatechange=function(){var b;
if(e.readyState==4){e.onreadystatechange=function(){};
b={cb:h.cb,result:null,ex:null};
if(h.profile){b.profile=h.profile;
b.profile.end=new Date()
}else{b.profile=false
}try{b.result=f._handleResponse(e)
}catch(a){b.ex=a
}if(!JSONRpcClient.async_inflight[h.requestId].canceled){JSONRpcClient.async_responses.push(b)
}delete JSONRpcClient.async_inflight[h.requestId];
JSONRpcClient.kick_async()
}}
}else{e.onreadystatechange=function(){}
}JSONRpcClient.async_inflight[h.requestId]=h;
try{e.send(h.data)
}catch(g){JSONRpcClient.poolReturnHTTPRequest(e);
JSONRpcClient.num_req_active--;
throw new JSONRpcClient.Exception({code:JSONRpcClient.Exception.CODE_ERR_CLIENT,message:"Connection failed"})
}if(!h.cb){delete JSONRpcClient.async_inflight[h.requestId];
return f._handleResponse(e)
}return null
};
JSONRpcClient.prototype._handleResponse=function(e){if(!this.charset){this.charset=JSONRpcClient._getCharsetFromHeaders(e)
}var g,h,j;
try{g=e.status;
h=e.statusText;
j=e.responseText
}catch(i){JSONRpcClient.poolReturnHTTPRequest(e);
JSONRpcClient.num_req_active--;
JSONRpcClient.kick_async();
throw new JSONRpcClient.Exception({code:JSONRpcClient.Exception.CODE_ERR_CLIENT,message:"Connection failed"})
}JSONRpcClient.poolReturnHTTPRequest(e);
JSONRpcClient.num_req_active--;
if(g!=200){throw new JSONRpcClient.Exception({code:g,message:h})
}return this.unmarshallResponse(j)
};
JSONRpcClient.prototype.unmarshallResponse=function(data){function applyFixups(obj,fixups){function findOriginal(ob,original){for(var i=0,j=original.length;
i<j;
i++){ob=ob[original[i]]
}return ob
}function applyFixup(ob,fixups,value){var j=fixups.length-1;
for(var i=0;
i<j;
i++){ob=ob[fixups[i]]
}ob[fixups[j]]=value
}for(var i=0,j=fixups.length;
i<j;
i++){applyFixup(obj,fixups[i][0],findOriginal(obj,fixups[i][1]))
}}function transformDate(obj){function hasOnlyProperty(obj,prop){var i,count=0;
if(obj.hasOwnProperty(prop)){for(i in obj){if(obj.hasOwnProperty(i)){count++;
if(count>1){return
}}}return true
}}var i,d;
if(obj&&typeof obj==="object"){if((obj.javaClass&&JSONRpcClient.javaDateClasses[obj.javaClass])){d=new Date(obj.time);
if(obj.javaClass!=="java.util.Date"){d.javaClass=obj.javaClass
}return d
}else{if(JSONRpcClient.transformDateWithoutHint&&hasOnlyProperty(obj,"time")){return new Date(obj.time)
}else{for(i in obj){if(obj.hasOwnProperty(i)){obj[i]=transformDate(obj[i])
}}return obj
}}}else{return obj
}}var obj;
try{eval("obj = "+data)
}catch(e){throw new JSONRpcClient.Exception({code:550,message:"error parsing result"})
}if(obj.error){throw new JSONRpcClient.Exception(obj.error)
}var r=obj.result;
var i,tmp;
if(r){if(r.objectID&&r.JSONRPCType=="CallableReference"){return this.createCallableProxy(r.objectID,r.javaClass)
}else{r=JSONRpcClient.extractCallableReferences(this,JSONRpcClient.transformDates?transformDate(r):r);
if(obj.fixups){applyFixups(r,obj.fixups)
}}}return r
};
JSONRpcClient.extractCallableReferences=function(f,g){var i,j,h;
for(i in g){if(typeof(g[i])=="object"){j=JSONRpcClient.makeCallableReference(f,g[i]);
if(j){g[i]=j
}else{j=JSONRpcClient.extractCallableReferences(f,g[i]);
g[i]=j
}}if(typeof(i)=="object"){j=JSONRpcClient.makeCallableReference(f,i);
if(j){h=g[i];
delete g[i];
g[j]=h
}else{j=JSONRpcClient.extractCallableReferences(f,i);
h=g[i];
delete g[i];
g[j]=h
}}}return g
};
JSONRpcClient.makeCallableReference=function(d,c){if(c&&c.objectID&&c.javaClass&&c.JSONRPCType=="CallableReference"){return d.createCallableProxy(c.objectID,c.javaClass)
}return null
};
JSONRpcClient.http_spare=[];
JSONRpcClient.http_max_spare=8;
JSONRpcClient.poolGetHTTPRequest=function(){var b=JSONRpcClient.http_spare.pop();
if(b){return b
}return JSONRpcClient.getHTTPRequest()
};
JSONRpcClient.poolReturnHTTPRequest=function(b){if(JSONRpcClient.http_spare.length>=JSONRpcClient.http_max_spare){delete b
}else{JSONRpcClient.http_spare.push(b)
}};
JSONRpcClient.msxmlNames=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","Microsoft.XMLHTTP"];
JSONRpcClient.getHTTPRequest=function(){try{JSONRpcClient.httpObjectName="XMLHttpRequest";
return new XMLHttpRequest()
}catch(c){}for(var d=0;
d<JSONRpcClient.msxmlNames.length;
d++){try{JSONRpcClient.httpObjectName=JSONRpcClient.msxmlNames[d];
return new ActiveXObject(JSONRpcClient.msxmlNames[d])
}catch(c){}}JSONRpcClient.httpObjectName=null;
throw new JSONRpcClient.Exception({code:0,message:"Can't create XMLHttpRequest object"})
};