
var MARD_NODATA_CHANGE="#0#";function JobSched(_1,_2){this.speed=_1||5000;this._bundle_handler=_2;this.seq=0;this._i_id=undefined;this._jobs=new Array();this._bundle=new Array();this._bundle_empty=true;this._start_time=0;this._stop_time=0;this._profiling_avg_duration=0;this._profiling_max_duration=0;JobSched.prototype.cont=function(){if(typeof(this._i_id)==="undefined"){var _3=this;this._i_id=setInterval(function(){_3.do_work(_3);},this.speed);_3.do_work(_3);}};JobSched.prototype.pause=function(){if(typeof(this._i_id)!=="undefined"){clearInterval(this._i_id);this._i_id=undefined;this._start_time=0;this._stop_time=0;}};JobSched.prototype.get_speed=function(){return(this.speed);};JobSched.prototype.get_sequence=function(){return(this.seq);};JobSched.prototype.is_active=function(){if(typeof(this._i_id)!=="undefined"){return(true);}else{return(false);}};JobSched.prototype.next_interval=function(){if(this._start_time>0){return(new Date(this._start_time+Number(this.speed)));}else{return(new Date(0));}};this.__lock=false;JobSched.prototype.do_work=function(_4){_4._start_time=new Date().getTime();_4._stop_time=0;_4._bundle=new Array();_4._bundle_empty=true;if(_4.__lock===true){return;}
try{_4.__lock=true;_4.seq=_4.seq+1;_4.now=Number(new Date());for(var i in _4._jobs){if((_4.seq%_4._jobs[i].interval)===0||_4.seq==1){if(typeof(_4._jobs[i].limit)==="undefined"){if(typeof(_4._jobs[i].start)!=="undefined"){if(_4._jobs[i].start<_4.now){_4._execute_job(_4,i);}}else{_4._execute_job(_4,i);}}else{if(_4._jobs[i].limit>0){if(typeof(_4._jobs[i].start)!=="undefined"){if(_4._jobs[i].start<_4.now){_4._jobs[i].limit=_4._jobs[i].limit-1;_4._execute_job(_4,i);}}else{_4._jobs[i].limit=_4._jobs[i].limit-1;_4._execute_job(_4,i);}}else{delete _4._jobs[i];}}}}
_4._execute_bundled_jobs(_4);}
catch(e){var _6=new Error("JobSched error. "+e);}
finally{_4.__lock=false;_4._stop_time=new Date().getTime();var _7=((_4._stop_time-_4._start_time)/1000);_4._profiling_avg_duration=(_4._profiling_avg_duration+_7)/2;if(_7>_4._profiling_max_duration){_4._profiling_max_duration=_7;}}};JobSched.prototype._handle_executed_bundled_jobs=function(_8,_9){var _a=undefined;try{_a=JSON.decode(_9);for(var i in _a){var _c=_a[i].result;var _d=_a[i].http_code;if(_c!==MARD_NODATA_CHANGE){_8._jobs[_a[i].id].md5=_a[i].md5;_8._jobs[_a[i].id].func(_c,_d);}else{}}}
catch(e){}};JobSched.prototype._execute_bundled_jobs=function(_e){if(typeof(_e._bundle_handler)!="undefined"&&_e._bundle_empty==false){_e.remote_call(_e._bundle_handler,function(_f){_e._handle_executed_bundled_jobs(_e,_f);},_e._bundle);}};JobSched.prototype._execute_job=function(_10,id){if(typeof(_10._jobs[id].url)=="undefined"){if(typeof(_10._jobs[id].args)=="function"){_10._jobs[id].func(_10._jobs[id].args());}else{_10._jobs[id].func(_10._jobs[id].args);}}else{if(_10._jobs[id].exec_bundled==true){_10._bundle[id]=_10.clone(id);if(typeof(_10._jobs[id].args)=="function"){_10._bundle[id].args=_10._jobs[id].args();}
_10._bundle_empty=false;}else{if(typeof(_10._jobs[id].args)=="function"){_10.remote_call(_10._jobs[id].url,_10._jobs[id].func,_10._jobs[id].args(),_10._jobs[id].timeout);}else{_10.remote_call(_10._jobs[id].url,_10._jobs[id].func,_10._jobs[id].args,_10._jobs[id].timeout);}}}};this._REMOTE_CALL_ASYNC=true;this._REMOTE_CALL_TIMEOUT=this.speed*0.8;JobSched.prototype.remote_call=function(url,_13,_14,_15){var _16=null;var _17=undefined;if(typeof XMLHttpRequest!="undefined"){_16=new XMLHttpRequest();}
if(!_16){try{_16=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){try{_16=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){_16=null;}}}
if(_16){_16.open("POST",url,this._REMOTE_CALL_ASYNC);if(typeof(_15)=="undefined"){_15=this._REMOTE_CALL_TIMEOUT;}
_17=setTimeout(function(){_16.abort();},_15);_16.onreadystatechange=function(){if(_16.readyState==4){clearTimeout(_17);_13(_16.responseText,_16.status);}};var _18="";if(typeof(_14)=="object"){var _19=new Array();for(var _1a in _14){_19.push(_14[_1a]);}
_18=JSON.encode(_19);delete _19;}else{_18=JSON.encode(_14);}
_16.setRequestHeader("X-Requested-With","XMLHttpRequest");_16.setRequestHeader("Content-Type","text/plain");_16.send(_18);}};JobSched.prototype.add=function(id,_1c){if(typeof(this._jobs[id])!="undefined"){return(undefined);}
if(_1c.exec_bundled==true&&typeof(this._bundle_handler)=="undefined"){}
var _1d={id:undefined,func:undefined,args:undefined,url:undefined,exec_bundled:false,interval:1,timeout:undefined,limit:undefined,start:undefined,md5:""};_1d.func=_1c.func;_1d.id=id;if(_1c.args){_1d.args=_1c.args;}
if(_1c.url){_1d.url=_1c.url;}
if(_1c.exec_bundled){_1d.exec_bundled=_1c.exec_bundled;}
if(_1c.interval){_1d.interval=Number(_1c.interval);}
if(_1c.timeout){_1d.timeout=Number(_1c.timeout);}
if(_1c.limit){_1d.limit=Number(_1c.limit);}
if(_1c.start){_1d.start=Number(_1c.start);}
this._jobs[id]=_1d;return(this._jobs[id]);};JobSched.prototype.del=function(id){if(this._jobs[id]!=undefined){this._jobs[id].limit=0;delete this._jobs[id];}};JobSched.prototype.get_job=function(id){return(this._jobs[id]);};JobSched.prototype.list_jobs=function(){var _20=new Array();for(var id in this._jobs){_20.push(this._jobs[id]);}
return(_20);};JobSched.prototype.clone=function(id){var _23=new Object();for(myvar in this._jobs[id]){_23[myvar]=this._jobs[id][myvar];}
return(_23);};}
var _MARD_LOADED=true;