function __api(_method,_params,_callback,_dwo){ _dwo = _dwo || false; // don't wait on, for some system cron calls var xmlhttp = new XMLHttpRequestObj(); if (xmlhttp == null){ alert ("Browser does not support HTTP Request"); return; } xmlhttp.sc = __request_stateChanged; xmlhttp.cb = _callback; if(!_dwo){ if(typeof __data != "undefined"){ if(typeof __data.w != "undefined"){ xmlhttp.w = __data.w.waitFor(_method); } } } var _url = "http://gemlit.com/e/api.php?a="+_method+"&"+_params; // _method is in MODULE.METHOD_NAME format xmlhttp.x.onreadystatechange=function(){xmlhttp.sc()}; xmlhttp.x.open("GET",_url,true); xmlhttp.x.send(null); } function __request(_url,_callback){ var xmlhttp = new XMLHttpRequestObj(); if (xmlhttp == null){ alert ("Browser does not support HTTP Request"); return; } xmlhttp.sc = __request_stateChanged; xmlhttp.cb = _callback; xmlhttp.x.onreadystatechange=function(){xmlhttp.sc()}; xmlhttp.x.open("GET",_url,true); xmlhttp.x.send(null); } function __request_stateChanged(){ if (this.x.readyState==4){ this.x.onreadystatechange = __nofunc; if(typeof this.w != "undefined"){ __data.w.endOf(this.w) } if((this.x.responseText.substring(0,5)=="error")||(this.x.responseText=="")){ showSysMsg(this.x.responseText); return }; this.cb(this.x.responseText); } } // ========================================== VIZUALISATION OF "waiting..." function WaitingViz(_timeout){ var me = this; me._timeout = _timeout; me._w = new Array(); me._i = 0; me._len = 0; if(typeof __cron != "undefined"){ __cron.push(function(){me.checkTimeout()}) } } WaitingViz.prototype.checkTimeout = function(){ var me = this; var now_ = new Date().getTime(); for(var i in me._w){ if(now_ > (me._w[i].sent + me._timeout)){ // request timedout showSysMsg('warning: request timeout.releasing #'+me._w[i].id); me.endOf(me._w[i].id); } } } WaitingViz.prototype.isWaiting = function(){ if(this._len==0){return false}else{return true} } WaitingViz.prototype.waitFor = function(caller_){ var me = this; caller_ = caller_ || ''; var a = new Array(); a.id = me._i; a.caller = caller_; a.sent = new Date().getTime(); me._w[me._i] = a; me._i++; me._len++; if(me._len == 1){ me.onBeginWaiting() } return (me._i-1); } WaitingViz.prototype.endOf = function(id){ var me = this; if(typeof id == "undefined"){ return } if(typeof me._w[id] == "undefined"){ return } delete me._w[id]; me._len--; if(me._len == 0){ me.onBeginIdle() } } WaitingViz.prototype.onBeginWaiting = function(){ $("blocker").style.height = document.body.scrollHeight + "px"; $("blocker").style.width = document.body.scrollWidth + "px"; $('blocker').style.zIndex = 9999999; $('blocker').style.cursor = 'wait'; } WaitingViz.prototype.onBeginIdle = function(){ $('blocker').style.zIndex = -1; $('blocker').style.cursor = ''; }