
function array_copy_stringable(src){var copy=new Array();for(var i=0;i<src.length;i++){if(typeof src=="string"){var x=src[i].replace(/%/g,"%P");copy[i]=x.replace(/,/g,"%C");}else{copy[i]=src[i];}}
return copy;}
if(typeof XMLHttpRequest=="undefined")XMLHttpRequest=function(){try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(e){}
try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(e){}
try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}
try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}
throw new Error("This browser does not support XMLHttpRequest.")};function RPCClient(url,objectname,sessionid){this.url=url;this.selfname=objectname;this.sessionid=sessionid;this.requests=0;this.debug_callback=null;this.rpciframevisible=false;this.callbacks=new Array();var bodyelement=document.getElementsByTagName('BODY');this.body=bodyelement[0];this.threadid=Math.floor(Math.random()*65535);this.rpcthreads=new Array();this.create_thread();try{var xmlhttp=new XMLHttpRequest();this.has_xmlhttp=true;}catch(e){this.has_xmlhttp=false;}}
RPCClient.prototype.debug=function(s){if(this.debug_callback!=null)this.debug_callback('RPC',s);}
RPCClient.prototype.debug_server=function(s){if(this.debug_callback!=null)this.debug_callback('Server',s);}
RPCClient.prototype.set_callback=function(execmethod,callback_code){this.callbacks[execmethod]=callback_code;}
RPCClient.prototype._execute=function(progressive,iframemode,args){var execmethod=args[0];this.debug('Execute: '+execmethod+'('+args.slice(1).toString()+')');this.requests++;var requestid=this.requests;var rnd=Math.floor(Math.random()*1000000);args.shift();args.unshift(requestid);args.unshift(this.callbacks[execmethod]);args.unshift(this.selfname);var rpc_params=encodeURIComponent?encodeURIComponent(args.serialize()):escape(args.serialize());var rpc_url=this.url+'?s='+this.sessionid+'&m='+execmethod+'&r='+requestid+'&r1='+rnd;var totalurllength=rpc_params.length+rpc_url.length;var must_post=(totalurllength>950)||(rpc_params.length>512)||progressive||iframemode;if(must_post&&(!this.has_xmlhttp||progressive||iframemode)){progressive=true;iframemode=true;}
rpc_url+='&h='+(progressive?1:0);if(!must_post&&!this.has_xmlhttp)rpc_url+='&p='+rpc_params;if(iframemode&&!progressive)rpc_url+='&n=1';if(this.has_xmlhttp&&!iframemode&&!progressive){this.json_request(rpc_url+'&j=1','p='+rpc_params,this.callbacks[execmethod],requestid);}else{thread=this.available_thread(iframemode,must_post);thread.rpcbusy=true;if(must_post){this.debug('POST: '+rpc_url+' ('+rpc_params+')');thread.form=this.create_thread_form(thread,rpc_url,rpc_params);thread.form.submit();}else{this.debug('GET:  '+rpc_url);var forcenewwin=0;if(forcenewwin||(window.location.href.indexOf('&rpcnewwindow=1')!=-1)){window.open(rpc_url);}else{thread.src=rpc_url;}}}
this.debug('-- Complete\n');}
RPCClient.prototype.json_request=function(url,postdata,callback,requestid){try{var xmlhttp=new XMLHttpRequest();}catch(e){return false;}
xmlhttp.open("POST",url,true);xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xmlhttp.send(postdata);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){if(xmlhttp.responseText.match(/\<[^\>]+\>(Warning|Fatal error|Parse error)\<\/[^\>]+\>/i)){alert('AJAX request failed: '+xmlhttp.responseText);}
var responses=xmlhttp.responseText.split("{type=\"jmk\"}\n");for(var ji=0;ji<responses.length;ji++){var responsetext=responses[ji];if(!responsetext.length)continue;var jsonobj=!(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(responsetext.replace(/"(\\.|[^"\\])*"/g,'')))&&eval('('+responsetext+')');if(!jsonobj){alert('Invalid response received from server: '+responsetext);}else if(jsonobj.type=='error'){alert('Error: '+jsonobj.error);}else{var callbackmethod=eval(callback);var callbackobj=null;if((p=callback.lastIndexOf('.'))>=0)callbackobj=eval(callback.substring(0,p));callbackmethod.apply(callbackobj,jsonobj.data);}}}else{alert("AJAX request failed ("+xmlhttp.status+").");}
xmlhttp=null;}};return true;}
RPCClient.prototype.create_thread_form=function(thread,url,params){var threadid=thread.id;var formid='form_'+threadid;var newform=document.createElement('form');newform.style.display='none';newform.setAttribute('id',formid);newform.setAttribute('name',formid);newform.setAttribute('target',threadid);newform.setAttribute('method','post');newform.setAttribute('action',url);var newfield=document.createElement('input');newfield.setAttribute('name','p');newfield.setAttribute('value',params);newfield.setAttribute('type','hidden');newform.appendChild(newfield);this.body.appendChild(newform);return newform;}
RPCClient.prototype.execute=function(){var args=array_copy_stringable(arguments);this._execute(false,false,args);}
RPCClient.prototype.execute_progressive=function(){var args=array_copy_stringable(arguments);this._execute(true,true,args);}
RPCClient.prototype.execute_raw=function(){var args=array_copy_stringable(arguments);this._execute(false,true,args);}
RPCClient.prototype.set_request_state=function(requestid,newstate){this.requeststates[requestid]=newstate;}
RPCClient.prototype.create_thread=function(iframemode,postmode){this.threadid++;threadid="js_rpc"+this.threadid;if(iframemode){if(document.all){newthread=document.createElement('<iframe name="'+threadid+'" id="'+threadid+'" style="'+(this.rpciframevisible?'position:absolute;left:5px;top:5px;width:300px;height:100px;border:1px solid red;padding:5px;background-color:white':'display:none')+'" '+(postmode?'type="text/javascript" ':'')+'/>');}else{newthread=document.createElement('IFRAME');if(!postmode)newthread.setAttribute('type','text/javascript');}
if(!this.rpciframevisible){newthread.style.display='none';}else{newthread.style.position='absolute';newthread.style.left='5px';newthread.style.top='5px';newthread.style.width='300px';newthread.style.height='100px';newthread.style.border='1px solid red';newthread.style.padding='5px';newthread.style.backgroundColor='white';}}else{newthread=document.createElement('SCRIPT');newthread.setAttribute('type','text/javascript');}
newthread.setAttribute('id',threadid);newthread.setAttribute('name',threadid);newthread.setAttribute('rpcbusy',false);newthread.setAttribute('isiframe',iframemode?true:false);this.body.appendChild(newthread);this.rpcthreads.push(newthread);return newthread;}
RPCClient.prototype.available_thread=function(iframemode,postmode){for(var i=0;i<this.rpcthreads.length;i++){if(!this.rpcthreads[i].rpcbusy&&(this.rpcthreads[i].isiframe==iframemode)){return this.rpcthreads[i];}}
return this.create_thread(iframemode,postmode);}
RPCClient.prototype.error=function(msg){alert(msg);}
RPCClient.prototype.authfailure=function(){alert('RPC failure: Your session has timed out due to inactivity.  Please login again to continue.');}