var escapeJSONChar=function(){var B=["\b","\t","\n","\f","\r"];return function(A){if(A=='"'||A=="\\"){return"\\"+A}if(A.charCodeAt(0)>=32){return A}for(var D=0;D<B.length;D++){if(A==B[D]){return"\\"+A}}return A}}();function escapeJSONString(F){var E=F.split("");for(var D=0;D<E.length;D++){E[D]=escapeJSONChar(E[D])}return'"'+E.join("")+'"'}function toJSON(L){var I="$_$jabsorbed$813492";var J;var M=[];function O(){var A;while(J){A=J[I].prev;delete J[I];J=A}}var K={};var P;function N(S,T,H){var A=[],F,G,B,D,E;if(S===null||S===undefined){return"null"}else{if(typeof S==="string"){return escapeJSONString(S)}else{if(typeof S==="number"){return S.toString()}else{if(typeof S==="boolean"){return S.toString()}else{if(S[I]){F=[H];B=T;while(B){if(G){G.unshift(B[I].ref)}if(B===S){D=B;G=[D[I].ref]}F.unshift(B[I].ref);B=B[I].parent}if(D){if(JSONRpcClient.fixupCircRefs){F.shift();G.shift();M.push([F,G]);return K}else{O();throw new Error("circular reference detected!")}}else{if(JSONRpcClient.fixupDuplicates){G=[S[I].ref];B=S[I].parent;while(B){G.unshift(B[I].ref);B=B[I].parent}F.shift();G.shift();M.push([F,G]);return K}}}else{S[I]={parent:T,prev:J,ref:H};J=S}if(S.constructor===Date){return'{javaClass: "java.util.Date", time: '+S.valueOf()+"}"}else{if(S.constructor===Array){for(E=0;E<S.length;E++){P=N(S[E],S,E);A.push(P===K?null:P)}return"["+A.join(", ")+"]"}else{for(var C in S){if(C===I){}else{if(S[C]===null||S[C]===undefined){A.push('"'+C+'": null')}else{if(typeof S[C]=="function"){}else{P=N(S[C],S,C);if(P!==K){A.push(escapeJSONString(C)+": "+P)}}}}}return"{"+A.join(", ")+"}"}}}}}}}P=N(L,null,"root");O();if(M.length){return{json:P,fixups:M}}else{return{json:P}}}function JSONRpcClient(){var P=0,J,I,N,O,M,K=(typeof arguments[0]),L=true;if(K==="function"){this.readyCB=arguments[0];P++}else{if(arguments[0]&&K==="object"&&arguments[0].length){this._addMethods(arguments[0]);P++;L=false}}this.serverURL=arguments[P];this.user=arguments[P+1];this.pass=arguments[P+2];this.objectID=0;if(L){this._addMethods(["system.listMethods"]);J=JSONRpcClient._makeRequest(this,"system.listMethods",[]);if(this.readyCB){O=this;J.cb=function(B,A){if(!A){O._addMethods(B)}O.readyCB(B,A)}}if(!this.readyCB){N=JSONRpcClient._sendRequest(this,J);this._addMethods(N)}else{JSONRpcClient.async_requests.push(J);JSONRpcClient.kick_async()}}}JSONRpcClient.prototype.createCallableProxy=function(I,J){var K,L,M,H,N;K=new JSONRPCCallableProxy(I,J);for(H in JSONRpcClient.knownClasses[J]){K[H]=JSONRpcClient.bind(JSONRpcClient.knownClasses[J][H],K)}return K};function JSONRPCCallableProxy(){this.objectID=arguments[0];this.javaClass=arguments[1];this.JSONRPCType="CallableReference"}JSONRpcClient.knownClasses={};JSONRpcClient.Exception=function(F){var D;for(var E in F){if(F.hasOwnProperty(E)){this[E]=F[E]}}if(this.trace){D=this.trace.match(/^([^:]*)/);if(D){this.name=D[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(D,E){var F="";if(this.name){F+=this.name}if(this.message){F+=": "+this.message}if(F.length==0){F="no exception information given"}return F};JSONRpcClient.default_ex_handler=function(C){var D="";for(a in C){D+=a+"\t"+C[a]+"\n"}alert(D)};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.bind=function(D,C){return function(){return D.apply(C,arguments)}};JSONRpcClient._createMethod=function(D,E){var F=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,E,H,this.objectID,A);if(!A){return JSONRpcClient._sendRequest(D,B)}else{JSONRpcClient.async_requests.push(B);JSONRpcClient.kick_async();return B.requestId}};return F};JSONRpcClient.prototype.createObject=function(){var K=[],H=null,L,G,I;for(var J=0;J<arguments.length;J++){K.push(arguments[J])}if(typeof K[0]=="function"){H=K.shift()}L=K[0]+".$constructor";G=K[1];I=JSONRpcClient._makeRequest(this,L,G,0,H);if(H===null){return JSONRpcClient._sendRequest(this,I)}else{JSONRpcClient.async_requests.push(I);JSONRpcClient.kick_async();return I.requestId}};JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX=".ref";JSONRpcClient.prototype._addMethods=function(S,X){var O,V,T,N,Q,Y=[],Z,P,R,U;for(var W=0;W<S.length;W++){V=this;T=S[W].split(".");R=S[W].indexOf("[");U=S[W].indexOf("]");if((S[W].substring(0,JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX.length)==JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX)&&(R!=-1)&&(U!=-1)&&(R<U)){Z=S[W].substring(R+1,U)}else{for(N=0;N<T.length-1;N++){O=T[N];if(V[O]){V=V[O]}else{V[O]={};V=V[O]}}}O=T[T.length-1];if(Z){Q=JSONRpcClient._createMethod(this,O);if(!JSONRpcClient.knownClasses[Z]){JSONRpcClient.knownClasses[Z]={}}JSONRpcClient.knownClasses[Z][O]=Q}else{Q=JSONRpcClient._createMethod(this,S[W]);if((!V[O])&&(!X)){V[O]=JSONRpcClient.bind(Q,this)}Y.push(Q)}Z=null}return Y};JSONRpcClient._getCharsetFromHeaders=function(F){var G,H,J;try{G=F.getResponseHeader("Content-type");H=G.split(/\s*;\s*/);for(J=0;J<H.length;J++){if(H[J].substring(0,8)=="charset="){return H[J].substring(8,H[J].length)}}}catch(I){}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 D,F;JSONRpcClient.async_timeout=null;while(JSONRpcClient.async_responses.length>0){D=JSONRpcClient.async_responses.shift();if(D.canceled){continue}if(D.profile){D.profile.dispatch=new Date()}try{D.cb(D.result,D.ex,D.profile)}catch(E){JSONRpcClient.toplevel_ex_handler(E)}}while(JSONRpcClient.async_requests.length>0&&JSONRpcClient.num_req_active<JSONRpcClient.max_req_active){F=JSONRpcClient.async_requests.shift();if(F.canceled){continue}JSONRpcClient._sendRequest(F.client,F)}};JSONRpcClient.kick_async=function(){if(!JSONRpcClient.async_timeout){JSONRpcClient.async_timeout=setTimeout(JSONRpcClient._async_handler,0)}};JSONRpcClient.cancelRequest=function(D){if(JSONRpcClient.async_inflight[D]){JSONRpcClient.async_inflight[D].canceled=true;return true}var C;for(C in JSONRpcClient.async_requests){if(JSONRpcClient.async_requests[C].requestId==D){JSONRpcClient.async_requests[C].canceled=true;return true}}for(C in JSONRpcClient.async_responses){if(JSONRpcClient.async_responses[C].requestId==D){JSONRpcClient.async_responses[C].canceled=true;return true}}return false};JSONRpcClient._makeRequest=function(P,O,M,J,I){var L={};L.client=P;L.requestId=JSONRpcClient.requestId++;var K="{id:"+L.requestId+",method:";if((J)&&(J>0)){K+='".obj['+J+"]."+O+'"'}else{K+='"'+O+'"'}if(I){L.cb=I}if(JSONRpcClient.profile_async){L.profile={submit:new Date()}}var N=toJSON(M);K+=",params:"+N.json;if(N.fixups){K+=",fixups:"+toJSON(N.fixups).json}L.data=K+"}";return L};JSONRpcClient._sendRequest=function(E,G){var H;if(G.profile){G.profile.start=new Date()}H=JSONRpcClient.poolGetHTTPRequest();JSONRpcClient.num_req_active++;H.open("POST",E.serverURL,!!G.cb,E.user,E.pass);try{H.setRequestHeader("Content-type","text/plain")}catch(F){}if(G.cb){H.onreadystatechange=function(){var B;if(H.readyState==4){H.onreadystatechange=function(){};B={cb:G.cb,result:null,ex:null};if(G.profile){B.profile=G.profile;B.profile.end=new Date()}else{B.profile=false}try{B.result=E._handleResponse(H)}catch(A){B.ex=A}if(!JSONRpcClient.async_inflight[G.requestId].canceled){JSONRpcClient.async_responses.push(B)}delete JSONRpcClient.async_inflight[G.requestId];JSONRpcClient.kick_async()}}}else{H.onreadystatechange=function(){}}JSONRpcClient.async_inflight[G.requestId]=G;try{H.send(G.data)}catch(F){JSONRpcClient.poolReturnHTTPRequest(H);JSONRpcClient.num_req_active--;throw new JSONRpcClient.Exception({code:JSONRpcClient.Exception.CODE_ERR_CLIENT,message:"Connection failed"})}if(!G.cb){delete JSONRpcClient.async_inflight[G.requestId];return E._handleResponse(H)}return null};JSONRpcClient.prototype._handleResponse=function(J){if(!this.charset){this.charset=JSONRpcClient._getCharsetFromHeaders(J)}var F,G,I;try{F=J.status;G=J.statusText;I=J.responseText}catch(H){JSONRpcClient.poolReturnHTTPRequest(J);JSONRpcClient.num_req_active--;JSONRpcClient.kick_async();throw new JSONRpcClient.Exception({code:JSONRpcClient.Exception.CODE_ERR_CLIENT,message:"Connection failed"})}JSONRpcClient.poolReturnHTTPRequest(J);JSONRpcClient.num_req_active--;if(F!=200){throw new JSONRpcClient.Exception({code:F,message:G})}return this.unmarshallResponse(I)};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 transform_date(obj){var hint,foo,num,i,jsDate;if(obj&&typeof obj==="object"){hint=obj.hasOwnProperty("javaClass");foo=hint?obj.javaClass==="java.util.Date":obj.hasOwnProperty("time");num=0;if(!hint&&foo){for(i in obj){if(obj.hasOwnProperty(i)){num++}}}if(hint&&foo||foo&&num===1){jsDate=new Date(obj.time);return jsDate}else{for(i in obj){if(obj.hasOwnProperty(i)){obj[i]=transform_date(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?transform_date(r):r);if(obj.fixups){applyFixups(r,obj.fixups)}}}return r};JSONRpcClient.extractCallableReferences=function(J,F){var H,I,G;for(H in F){if(typeof (F[H])=="object"){I=JSONRpcClient.makeCallableReference(J,F[H]);if(I){F[H]=I}else{I=JSONRpcClient.extractCallableReferences(J,F[H]);F[H]=I}}if(typeof (H)=="object"){I=JSONRpcClient.makeCallableReference(J,H);if(I){G=F[H];delete F[H];F[I]=G}else{I=JSONRpcClient.extractCallableReferences(J,H);G=F[H];delete F[H];F[I]=G}}}return F};JSONRpcClient.makeCallableReference=function(C,D){if(D&&D.objectID&&D.javaClass&&D.JSONRPCType=="CallableReference"){return C.createCallableProxy(D.objectID,D.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(D){}for(var C=0;C<JSONRpcClient.msxmlNames.length;C++){try{JSONRpcClient.httpObjectName=JSONRpcClient.msxmlNames[C];return new ActiveXObject(JSONRpcClient.msxmlNames[C])}catch(D){}}JSONRpcClient.httpObjectName=null;throw new JSONRpcClient.Exception({code:0,message:"Can't create XMLHttpRequest object"})};