addNamespace("AjaxPro");Object.extend(AjaxPro, { noOperation: function() {}, cryptProvider: null, queue: null, token: "", version: "6.5.9.1", ID: "AjaxPro", noActiveX: false, timeoutPeriod: 5000, queue: null, typeOf: function(o) { if(o != null && o.__type) { var ts = this.__type.split(','); if(ts.length > 0) return ts[0]; else return typeof o; } else { return typeof o; } }, getInstance: function(className, o) { if(o == null) o = window; var c = className.split("."); if(c.length > 1) return AjaxPro.getInstance(className.substr(className.indexOf(".") +1), o[c[0]]); return o[className]; }, toJSON: function(o) { if(o == null) return "null"; switch(o.constructor) { case String: var s = o; // .encodeURI(); s = '"' + s.replace(/(["\\])/g, '\\$1') + '"'; s = s.replace(/\n/g,"\\n"); s = s.replace(/\r/g,"\\r"); return s; case Array: var v = []; for(var i=0; i0) return "{" + v.join(",") + "}"; else return "{}"; } return o.toString(); } } });AjaxPro.IFrameXmlHttp = Class.create(); AjaxPro.IFrameXmlHttp.prototype = { onreadystatechange: null, headers: [], method: "POST", url: null, async: true, iframe: null, status: 0, readyState: 0, responseText: null, abort: function() { }, readystatechanged: function() { var doc = this.iframe.contentDocument || this.iframe.document; if(doc.readyState == "complete") { this.status = 200; this.readyState = 4; this.responseText = doc.body.res; this.onreadystatechange(); return; } setTimeout(this.readystatechanged.bind(this), 1); }, open: function(method, url, async) { if(async == false) { alert("Synchronous call using IFrameXMLHttp is not supported."); return; } if(this.iframe == null) { var iframeID = "hans"; if (document.createElement && document.documentElement && (window.opera || navigator.userAgent.indexOf('MSIE 5.0') == -1)) { var ifr = document.createElement('iframe'); ifr.setAttribute('id', iframeID); ifr.style.visibility = 'hidden'; ifr.style.position = 'absolute'; ifr.style.width = ifr.style.height = ifr.borderWidth = '0px'; this.iframe = document.getElementsByTagName('body')[0].appendChild(ifr); } else if (document.body && document.body.insertAdjacentHTML) { document.body.insertAdjacentHTML('beforeEnd', ''); } if (window.frames && window.frames[iframeID]) this.iframe = window.frames[iframeID]; this.iframe.name = iframeID; this.iframe.document.open(); this.iframe.document.write("
"); this.iframe.document.close(); } this.method = method; this.url = url; this.async = async; }, setRequestHeader: function(name, value) { for(var i=0; i= 0) tag = "textarea"; if(doc.all) { ele = doc.createElement("<" + tag + " name=\"" + name + "\" />"); }else{ ele = doc.createElement(tag); ele.setAttribute("name", name); } ele.setAttribute("value", value); form.appendChild(ele); ele = null; }, send: function(data) { if(this.iframe == null) { // alert("Connection must be opened before sending data."); return; } var doc = this.iframe.contentDocument || this.iframe.document; var form = doc.createElement("form"); doc.body.appendChild(form); form.setAttribute("action", this.url); form.setAttribute("method", this.method); for(var i=0; i 0) { eval("r.value = " + responseText + ";"); } } // Mozilla/Firefox bug, if the header does not exists the browser will // throw an exception. /* if(this.xmlHttp.getResponseHeader(AjaxPro.ID + "-Cache") == "server") { r.isCached = true; } */ return r; }, timeout: function() { this.duration = new Date().getTime() - this.__start; this.abort(); try{ this.onTimeout(this.duration, this); }catch(e){} }, invoke: function(method, args, callback, context) { this.__start = new Date().getTime(); if(this.xmlHttp == null) this.xmlHttp = new XMLHttpRequest(); this.isRunning = true; this.method = method; this.args = args; this.callback = callback; this.context = context; if(MS.Debug.enabled == true) MS.Debug.trace("Invoking " + method + "..."); var async = typeof callback == "function" && callback != AjaxPro.noOperation; var json = AjaxPro.toJSON(args) + ""; if(AjaxPro.cryptProvider != null) json = AjaxPro.cryptProvider.encrypt(json); if(async) { this.xmlHttp.onreadystatechange = this.doStateChange.bind(this); if(typeof this.onLoading == "function") this.onLoading(true); } this.xmlHttp.open("POST", this.url, async); this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); this.xmlHttp.setRequestHeader(AjaxPro.ID + "-Method", method); if(AjaxPro.token != null && AjaxPro.token.length > 0) this.xmlHttp.setRequestHeader(AjaxPro.ID + "-Token", AjaxPro.token); if(MS.Browser.isIE) this.xmlHttp.setRequestHeader("Accept-Encoding", "gzip, deflate"); else this.xmlHttp.setRequestHeader("Connection", "close"); // Mozilla Bug #246651 if(this.onTimeout != null && typeof this.onTimeout == "function") this.timeoutTimer = setTimeout(this.timeout.bind(this), AjaxPro.timeoutPeriod); this.xmlHttp.send(json); json = null; args = null; delete json; delete args; if(!async) { return this.createResponse(); } return true; } };AjaxPro.RequestQueue = Class.create(); AjaxPro.RequestQueue.prototype = { process: function() { this.timer = null; if(this.queue.length == 0) return; for(var i=0; i 0; i++) { if(this.requests[i].isRunning == false) { var r = this.queue.shift(); this.requests[i].url = r[0]; this.requests[i].onLoading = r[3].length >2 && r[3][2] != null && typeof r[3][2] == "function" ? r[3][2] : AjaxPro.onLoading; this.requests[i].onError = r[3].length >3 && r[3][3] != null && typeof r[3][3] == "function" ? r[3][3] : AjaxPro.onError; this.requests[i].onTimeout = r[3].length >4 && r[3][4] != null && typeof r[3][4] == "function" ? r[3][4] : AjaxPro.onTimeout; this.requests[i].onStateChanged = r[3].length >5 && r[3][5] != null && typeof r[3][5] == "function" ? r[3][5] : AjaxPro.onStateChanged; if(MS.Debug.enabled == true) MS.Debug.trace("Using http connection " + i + " for method " + r[1] + " (" + this.queue.length + " waiting)."); this.requests[i].invoke(r[1], r[2], this.requests[i].callbackHandle, r); r = null; } } if(this.queue.length > 0 && this.timer == null) { this.timer = setTimeout(this.process.bind(this), 100); } }, initialize: function() { this.queue = []; this.requests = []; this.timer = null; for(var i=0; i<2; i++) { // max 2 http connections this.requests[i] = new AjaxPro.Request(); this.requests[i].callback = function(res) { var r = res.context; res.context = r[3][1]; try { r[3][0](res, this); }catch(e){alert(e.description);} }; this.requests[i].callbackHandle = this.requests[i].callback.bind(this.requests[i]); } }, add: function(url, method, args, e) { this.queue.push([url, method, args, e]); if(MS.Debug.enabled == true) MS.Debug.trace(method + " added to queue"); if(this.timer == null) { this.timer = setTimeout(this.process.bind(this), 1); } }, abort: function() { this.queue.length = 0; if (this.timer != null) { clearTimeout(this.timer); } this.timer = null; for(var i=0; i