
Array.prototype.______array='______array';var JSON={org:'http://www.JSON.org',copyright:'(c)2005 JSON.org',license:'http://www.crockford.com/JSON/license.html',stringify:function(arg){var c,i,l,s='',v;switch(typeof arg){case'object':if(arg){if(arg.______array=='______array'){for(i=0;i<arg.length;++i){v=this.stringify(arg[i]);if(s){s+=',';}
s+=v;}
return'['+s+']';}else if(typeof arg.toString!='undefined'){for(i in arg){v=arg[i];if(typeof v!='undefined'&&typeof v!='function'){v=this.stringify(v);if(s){s+=',';}
s+=this.stringify(i)+':'+v;}}
return'{'+s+'}';}}
return'null';case'number':return isFinite(arg)?String(arg):'null';case'string':l=arg.length;s='"';for(i=0;i<l;i+=1){c=arg.charAt(i);if(c>=' '){if(c=='\\'||c=='"'){s+='\\';}
s+=c;}else{switch(c){case'\b':s+='\\b';break;case'\f':s+='\\f';break;case'\n':s+='\\n';break;case'\r':s+='\\r';break;case'\t':s+='\\t';break;default:c=c.charCodeAt();s+='\\u00'+Math.floor(c/16).toString(16)+
(c%16).toString(16);}}}
return s+'"';case'boolean':return String(arg);default:return'null';}},parse:function(text){var at=0;var ch=' ';function error(m){throw{name:'JSONError',message:m,at:at-1,text:text};}
function next(){ch=text.charAt(at);at+=1;return ch;}
function white(){while(ch!=''&&ch<=' '){next();}}
function str(){var i,s='',t,u;if(ch=='"'){outer:while(next()){if(ch=='"'){next();return s;}else if(ch=='\\'){switch(next()){case'b':s+='\b';break;case'f':s+='\f';break;case'n':s+='\n';break;case'r':s+='\r';break;case't':s+='\t';break;case'u':u=0;for(i=0;i<4;i+=1){t=parseInt(next(),16);if(!isFinite(t)){break outer;}
u=u*16+t;}
s+=String.fromCharCode(u);break;default:s+=ch;}}else{s+=ch;}}}
error("Bad string");}
function arr(){var a=[];if(ch=='['){next();white();if(ch==']'){next();return a;}
while(ch){a.push(val());white();if(ch==']'){next();return a;}else if(ch!=','){break;}
next();white();}}
error("Bad array");}
function obj(){var k,o={};if(ch=='{'){next();white();if(ch=='}'){next();return o;}
while(ch){k=str();white();if(ch!=':'){break;}
next();o[k]=val();white();if(ch=='}'){next();return o;}else if(ch!=','){break;}
next();white();}}
error("Bad object");}
function num(){var n='',v;if(ch=='-'){n='-';next();}
while(ch>='0'&&ch<='9'){n+=ch;next();}
if(ch=='.'){n+='.';while(next()&&ch>='0'&&ch<='9'){n+=ch;}}
if(ch=='e'||ch=='E'){n+='e';next();if(ch=='-'||ch=='+'){n+=ch;next();}
while(ch>='0'&&ch<='9'){n+=ch;next();}}
v=+n;if(!isFinite(v)){error("Bad number");}else{return v;}}
function word(){switch(ch){case't':if(next()=='r'&&next()=='u'&&next()=='e'){next();return true;}
break;case'f':if(next()=='a'&&next()=='l'&&next()=='s'&&next()=='e'){next();return false;}
break;case'n':if(next()=='u'&&next()=='l'&&next()=='l'){next();return null;}
break;}
error("Syntax error");}
function val(){white();switch(ch){case'{':return obj();case'[':return arr();case'"':return str();case'-':return num();default:return ch>='0'&&ch<='9'?num():word();}}
return val();}};var escapeJSONChar=function()
{var escapeChars=["\b","\t","\n","\f","\r"];return function(c){if(c=="\""||c=="\\")
{return"\\"+c;}
if(c.charCodeAt(0)>=32)
{return c;}
for(var i=0;i<escapeChars.length;i++)
{if(c==escapeChars[i])
{return"\\"+c;}}
return c;};}();function escapeJSONString(s)
{var parts=s.split("");for(var i=0;i<parts.length;i++)
{parts[i]=escapeJSONChar(parts[i]);}
return"\""+parts.join("")+"\"";}
function toJSON(o)
{var marker="$_$jabsorbed$813492";var markerHead;var fixups=[];function removeMarkers()
{var next;while(markerHead)
{next=markerHead[marker].prev;delete markerHead[marker];markerHead=next;}}
var omitCircRefOrDuplicate={};var json;function subObjToJSON(o,p,ref)
{var v=[],fixup,original,parent,circRef,i;if(o===null||o===undefined)
{return"null";}
else if(typeof o==='string')
{return escapeJSONString(o);}
else if(typeof o==='number')
{return o.toString();}
else if(typeof o==='boolean')
{return o.toString();}
else
{if(o[marker])
{fixup=[ref];parent=p;while(parent)
{if(original)
{original.unshift(parent[marker].ref);}
if(parent===o)
{circRef=parent;original=[circRef[marker].ref];}
fixup.unshift(parent[marker].ref);parent=parent[marker].parent;}
if(circRef)
{if(JSONRpcClient.fixupCircRefs)
{fixup.shift();original.shift();fixups.push([fixup,original]);return omitCircRefOrDuplicate;}
else
{removeMarkers();throw new Error("circular reference detected!");}}
else
{if(JSONRpcClient.fixupDuplicates)
{original=[o[marker].ref];parent=o[marker].parent;while(parent)
{original.unshift(parent[marker].ref);parent=parent[marker].parent;}
fixup.shift();original.shift();fixups.push([fixup,original]);return omitCircRefOrDuplicate;}}}
else
{o[marker]={parent:p,prev:markerHead,ref:ref};markerHead=o;}
if(o.constructor===Date)
{return'{javaClass: "java.util.Date", time: '+o.valueOf()+'}';}
else if(o.constructor===Array)
{for(i=0;i<o.length;i++)
{json=subObjToJSON(o[i],o,i);v.push(json===omitCircRefOrDuplicate?null:json);}
return"["+v.join(", ")+"]";}
else
{for(var attr in o)
{if(attr===marker)
{}
else if(o[attr]===null||o[attr]===undefined)
{v.push("\""+attr+"\": null");}
else if(typeof o[attr]=="function")
{}
else
{json=subObjToJSON(o[attr],o,attr);if(json!==omitCircRefOrDuplicate)
{v.push(escapeJSONString(attr)+": "+json);}}}
return"{"+v.join(", ")+"}";}}}
json=subObjToJSON(o,null,"root");removeMarkers();if(fixups.length)
{return{json:json,fixups:fixups};}
else
{return{json:json};}}
function JSONRpcClient()
{var arg_shift=0,req,_function,methods,self,name,arg0type=(typeof arguments[0]),doListMethods=true;if(arg0type==="function")
{this.readyCB=arguments[0];arg_shift++;}
else if(arguments[0]&&arg0type==="object"&&arguments[0].length)
{this._addMethods(arguments[0]);arg_shift++;doListMethods=false;}
this.serverURL=arguments[arg_shift];this.user=arguments[arg_shift+1];this.pass=arguments[arg_shift+2];this.objectID=0;if(doListMethods)
{this._addMethods(["system.listMethods"]);req=JSONRpcClient._makeRequest(this,"system.listMethods",[]);if(this.readyCB)
{self=this;req.cb=function(result,e)
{if(!e)
{self._addMethods(result);}
self.readyCB(result,e);};}
if(!this.readyCB)
{methods=JSONRpcClient._sendRequest(this,req);this._addMethods(methods);}
else
{JSONRpcClient.async_requests.push(req);JSONRpcClient.kick_async();}}}
JSONRpcClient.prototype.createCallableProxy=function(objectID,javaClass)
{var cp,req,methodNames,name,i;cp=new JSONRPCCallableProxy(objectID,javaClass);for(name in JSONRpcClient.knownClasses[javaClass])
{cp[name]=JSONRpcClient.bind(JSONRpcClient.knownClasses[javaClass][name],cp);}
return cp;};function JSONRPCCallableProxy()
{this.objectID=arguments[0];this.javaClass=arguments[1];this.JSONRPCType="CallableReference";}
JSONRpcClient.knownClasses={};JSONRpcClient.Exception=function(errorObject)
{var m;for(var prop in errorObject)
{if(errorObject.hasOwnProperty(prop))
{this[prop]=errorObject[prop];}}
if(this.trace)
{m=this.trace.match(/^([^:]*)/);if(m)
{this.name=m[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(code,msg)
{var str="";if(this.name)
{str+=this.name;}
if(this.message)
{str+=": "+this.message;}
if(str.length==0)
{str="no exception information given";}
return str;};JSONRpcClient.default_ex_handler=function(e)
{var str="";for(a in e)
{str+=a+"\t"+e[a]+"\n";}
alert(str);};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(functionName,context)
{return function(){return functionName.apply(context,arguments);};};JSONRpcClient._createMethod=function(client,methodName)
{var serverMethodCaller=function()
{var args=[],callback;for(var i=0;i<arguments.length;i++)
{args.push(arguments[i]);}
if(typeof args[0]=="function")
{callback=args.shift();}
var req=JSONRpcClient._makeRequest(this,methodName,args,this.objectID,callback);if(!callback)
{return JSONRpcClient._sendRequest(client,req);}
else
{JSONRpcClient.async_requests.push(req);JSONRpcClient.kick_async();return req.requestId;}};return serverMethodCaller;};JSONRpcClient.prototype.createObject=function()
{var args=[],callback=null,constructorName,_args,req;for(var i=0;i<arguments.length;i++)
{args.push(arguments[i]);}
if(typeof args[0]=="function")
{callback=args.shift();}
constructorName=args[0]+".$constructor";_args=args[1];req=JSONRpcClient._makeRequest(this,constructorName,_args,0,callback);if(callback===null)
{return JSONRpcClient._sendRequest(this,req);}
else
{JSONRpcClient.async_requests.push(req);JSONRpcClient.kick_async();return req.requestId;}};JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX=".ref";JSONRpcClient.prototype._addMethods=function(methodNames,dontAdd)
{var name,obj,names,n,method,methods=[],javaClass,tmpNames,startIndex,endIndex;for(var i=0;i<methodNames.length;i++)
{obj=this;names=methodNames[i].split(".");startIndex=methodNames[i].indexOf("[");endIndex=methodNames[i].indexOf("]");if((methodNames[i].substring(0,JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX.length)==JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX)&&(startIndex!=-1)&&(endIndex!=-1)&&(startIndex<endIndex))
{javaClass=methodNames[i].substring(startIndex+1,endIndex);}
else
{for(n=0;n<names.length-1;n++)
{name=names[n];if(obj[name])
{obj=obj[name];}
else
{obj[name]={};obj=obj[name];}}}
name=names[names.length-1];if(javaClass)
{method=JSONRpcClient._createMethod(this,name);if(!JSONRpcClient.knownClasses[javaClass])
{JSONRpcClient.knownClasses[javaClass]={};}
JSONRpcClient.knownClasses[javaClass][name]=method;}
else
{method=JSONRpcClient._createMethod(this,methodNames[i]);if((!obj[name])&&(!dontAdd))
{obj[name]=JSONRpcClient.bind(method,this);}
methods.push(method);}
javaClass=null;}
return methods;};JSONRpcClient._getCharsetFromHeaders=function(http)
{var contentType,parts,i;try
{contentType=http.getResponseHeader("Content-type");parts=contentType.split(/\s*;\s*/);for(i=0;i<parts.length;i++)
{if(parts[i].substring(0,8)=="charset=")
{return parts[i].substring(8,parts[i].length);}}}
catch(e)
{}
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 res,req;JSONRpcClient.async_timeout=null;while(JSONRpcClient.async_responses.length>0)
{res=JSONRpcClient.async_responses.shift();if(res.canceled)
{continue;}
if(res.profile)
{res.profile.dispatch=new Date();}
try
{res.cb(res.result,res.ex,res.profile);}
catch(e)
{JSONRpcClient.toplevel_ex_handler(e);}}
while(JSONRpcClient.async_requests.length>0&&JSONRpcClient.num_req_active<JSONRpcClient.max_req_active)
{req=JSONRpcClient.async_requests.shift();if(req.canceled)
{continue;}
JSONRpcClient._sendRequest(req.client,req);}};JSONRpcClient.kick_async=function()
{if(!JSONRpcClient.async_timeout)
{JSONRpcClient.async_timeout=setTimeout(JSONRpcClient._async_handler,0);}};JSONRpcClient.cancelRequest=function(requestId)
{if(JSONRpcClient.async_inflight[requestId])
{JSONRpcClient.async_inflight[requestId].canceled=true;return true;}
var i;for(i in JSONRpcClient.async_requests)
{if(JSONRpcClient.async_requests[i].requestId==requestId)
{JSONRpcClient.async_requests[i].canceled=true;return true;}}
for(i in JSONRpcClient.async_responses)
{if(JSONRpcClient.async_responses[i].requestId==requestId)
{JSONRpcClient.async_responses[i].canceled=true;return true;}}
return false;};JSONRpcClient._makeRequest=function(client,methodName,args,objectID,cb)
{var req={};req.client=client;req.requestId=JSONRpcClient.requestId++;var obj="{id:"+req.requestId+",method:";if((objectID)&&(objectID>0))
{obj+="\".obj["+objectID+"]."+methodName+"\"";}
else
{obj+="\""+methodName+"\"";}
if(cb)
{req.cb=cb;}
if(JSONRpcClient.profile_async)
{req.profile={submit:new Date()};}
var j=toJSON(args);obj+=",params:"+j.json;if(j.fixups)
{obj+=",fixups:"+toJSON(j.fixups).json;}
req.data=obj+"}";return req;};JSONRpcClient._sendRequest=function(client,req)
{var http;if(req.profile)
{req.profile.start=new Date();}
http=JSONRpcClient.poolGetHTTPRequest();JSONRpcClient.num_req_active++;http.open("POST",client.serverURL,!!req.cb,client.user,client.pass);try
{http.setRequestHeader("Content-type","text/plain");}
catch(e)
{}
if(req.cb)
{http.onreadystatechange=function()
{var res;if(http.readyState==4)
{http.onreadystatechange=function()
{};res={cb:req.cb,result:null,ex:null};if(req.profile)
{res.profile=req.profile;res.profile.end=new Date();}
else
{res.profile=false;}
try
{res.result=client._handleResponse(http);}
catch(e)
{res.ex=e;}
if(!JSONRpcClient.async_inflight[req.requestId].canceled)
{JSONRpcClient.async_responses.push(res);}
delete JSONRpcClient.async_inflight[req.requestId];JSONRpcClient.kick_async();}};}
else
{http.onreadystatechange=function()
{};}
JSONRpcClient.async_inflight[req.requestId]=req;try
{http.send(req.data);}
catch(e)
{JSONRpcClient.poolReturnHTTPRequest(http);JSONRpcClient.num_req_active--;throw new JSONRpcClient.Exception({code:JSONRpcClient.Exception.CODE_ERR_CLIENT,message:"Connection failed"});}
if(!req.cb)
{delete JSONRpcClient.async_inflight[req.requestId];return client._handleResponse(http);}
return null;};JSONRpcClient.prototype._handleResponse=function(http)
{if(!this.charset)
{this.charset=JSONRpcClient._getCharsetFromHeaders(http);}
var status,statusText,data;try
{status=http.status;statusText=http.statusText;data=http.responseText;}
catch(e)
{JSONRpcClient.poolReturnHTTPRequest(http);JSONRpcClient.num_req_active--;JSONRpcClient.kick_async();throw new JSONRpcClient.Exception({code:JSONRpcClient.Exception.CODE_ERR_CLIENT,message:"Connection failed"});}
JSONRpcClient.poolReturnHTTPRequest(http);JSONRpcClient.num_req_active--;if(status!=200)
{throw new JSONRpcClient.Exception({code:status,message:statusText});};return this.unmarshallResponse(data);};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(client,root)
{var i,tmp,value;for(i in root)
{if(typeof(root[i])=="object")
{tmp=JSONRpcClient.makeCallableReference(client,root[i]);if(tmp)
{root[i]=tmp;}
else
{tmp=JSONRpcClient.extractCallableReferences(client,root[i]);root[i]=tmp;}}
if(typeof(i)=="object")
{tmp=JSONRpcClient.makeCallableReference(client,i);if(tmp)
{value=root[i];delete root[i];root[tmp]=value;}
else
{tmp=JSONRpcClient.extractCallableReferences(client,i);value=root[i];delete root[i];root[tmp]=value;}}}
return root;};JSONRpcClient.makeCallableReference=function(client,value)
{if(value&&value.objectID&&value.javaClass&&value.JSONRPCType=="CallableReference")
{return client.createCallableProxy(value.objectID,value.javaClass);}
return null;};JSONRpcClient.http_spare=[];JSONRpcClient.http_max_spare=8;JSONRpcClient.poolGetHTTPRequest=function()
{var http=JSONRpcClient.http_spare.pop();if(http)
{return http;}
return JSONRpcClient.getHTTPRequest();};JSONRpcClient.poolReturnHTTPRequest=function(http)
{if(JSONRpcClient.http_spare.length>=JSONRpcClient.http_max_spare)
{delete http;}
else
{JSONRpcClient.http_spare.push(http);}};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
{if(typeof mashkit!='undefined')
{if(mashkit.isThickClient){return new mashkit._base.ClientProxyXhr("text");}else
{JSONRpcClient.httpObjectName="XMLHttpRequest";return new XMLHttpRequest();}}else
{JSONRpcClient.httpObjectName="XMLHttpRequest";return new XMLHttpRequest();}}
catch(e){}
for(var i=0;i<JSONRpcClient.msxmlNames.length;i++)
{try
{JSONRpcClient.httpObjectName=JSONRpcClient.msxmlNames[i];return new ActiveXObject(JSONRpcClient.msxmlNames[i]);}
catch(e)
{}}
JSONRpcClient.httpObjectName=null;throw new JSONRpcClient.Exception({code:0,message:"Can't create XMLHttpRequest object"});};


