function cIM() { this.DEFAULT_URL = im_path + 'controller.php?action='; this.connector = XMLTools; this._onmouseup = document.onmouseup; this.isExecuteForm = false; this.id = []; this._handler = false; this.json = false; } cIM.prototype.cExecute = function (url, handler, params, form) { var _this = this; if ( this.isExecuteForm ) { _this.isExecuteForm = false; document.onmouseup = this._onmouseup; } if ( form ) { //this.cExecuteForm(url, form); return; } url = _this.DEFAULT_URL + url; var _date = new Date(); var id = url + '&thread_time=' + _date.getHours() + _date.getMinutes() + _date.getSeconds() + _date.getMilliseconds(); if ( _this.id[id] ) return false; else _this.id[id] = handler; if ( params ) method = "POST"; else method = "GET"; handler = _this._interface; _this.connector.request(id, url, method, handler, params); } cIM.prototype._interface = function(data, url) { data = data.getElementsByTagName('retorno').item(0); data = data.firstChild.nodeValue; if ( /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(data) ) { eval('data = ' + data); if ( cIM.json ) cIM.json = false; else data = json2array(data); } var handler = cIM.id[url]; cIM.id[url] = false; delete cIM.id[url]; handler(data); } var cIM = new cIM; function json2array(pObject) { var retorno = []; for( var i in pObject ) if( pObject[i].constructor == Object ) { retorno[i] = []; retorno[i] = json2array(pObject[i]); } else retorno[i] = pObject[i]; return retorno; } function json2str(pObject) { var retorno = '{'; for( var i in pObject ) if( pObject[i].constructor == Object ) retorno += '\'' + i + '\':' + json2str(pObject[i]) + ','; else retorno += '\'' + i + '\':\'' + pObject[i] + '\','; retorno = retorno.substr(0, (retorno.length - 1)); retorno += '}'; return retorno; }