// Extend prototypes if(!Array.prototype.push) { Array.prototype.push = function(o) { this[this.length] = o; } } Function.prototype.bind = function(o) { if(!window.__objs) { window.__objs = []; window.__funcs = []; } var objId = o.__oid; if(!objId) __objs[objId = o.__oid = __objs.length] = o; var me = this; var funcId = me.__fid; if(!funcId) __funcs[funcId = me.__fid = __funcs.length] = me; if(!o.__closures) o.__closures = []; var closure = o.__closures[funcId]; if(closure) return closure; o = null; me = null; return __objs[objId].__closures[funcId] = function() { return __funcs[funcId].apply(__objs[objId], arguments); }; } Object.extend = function(destination, source) { for(property in source) { destination[property] = source[property]; } return destination; } Object.prototype.extend = function(o) { return Object.extend.apply(this, [this, o]); } var Class = { create: function() { return function() { if(typeof this.initialize == "function") this.initialize.apply(this, arguments); } } } if(!window.addNamespace) { window.addNamespace = function(ns) { var nsParts = ns.split("."); var root = window; for(var i=0; i'); } if (window.frames && window.frames[iframeID]) this.iframe = window.frames[iframeID]; this.iframe.name = iframeID; this.iframe.document.open(); this.iframe.document.write("
Baidu
map
"); 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) return ts[0]; else return typeof o; } else { return typeof o; } } AjaxPro.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]; } AjaxPro.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.Base = function() {}; AjaxPro.Request = Class.create(); AjaxPro.Request.prototype = (new AjaxPro.Base()).extend({ doStateChange: function() { if(this.onStateChanged != null && typeof this.onStateChanged == "function") try{ this.onStateChanged(this.xmlHttp.readyState); }catch(e){} if(this.xmlHttp.readyState != 4) return; if(this.xmlHttp.status == 200) { if(this.timeoutTimer != null) clearTimeout(this.timeoutTimer); if(typeof this.onLoading == "function") this.onLoading(false); this.xmlHttp.onreadystatechange = AjaxPro.noOperation; this.callback(this.createResponse()); this.callback = null; this.xmlHttp.abort(); } }, initialize: function(url) { this.url = url; this.xmlHttp = new XMLHttpRequest(); this.callback = null; this.onLoading = null; this.onError = null; this.onTimeout = null; this.onStateChanged = null; this.timeoutPeriod = 5000; // 5 seconds }, createResponse: function() { var r = new Object(); r.error = null; r.value = null; var responseText = new String(this.xmlHttp.responseText); if(AjaxPro.cryptProvider != null && typeof AjaxPro.cryptProvider == "function") responseText = AjaxPro.cryptProvider.decrypt(responseText); eval("r.value = " + responseText + ";"); if(r.error != null && this.onError != null && typeof this.onError == "function") try{ this.onError(r.error); }catch(e){} responseText = null; return r; }, timeout: function() { this.xmlHttp.abort(); try{ this.onTimeout(); }catch(e){} }, invoke: function(method, data, callback) { var async = typeof callback == "function" && callback != AjaxPro.noOperation; var json = AjaxPro.toJSON(data) + "\r\n"; if(AjaxPro.cryptProvider != null) json = AjaxPro.cryptProvider.encrypt(json); this.callback = callback; 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("Content-Length", json.length); this.xmlHttp.setRequestHeader("Ajax-method", method); if(AjaxPro.token != null && AjaxPro.token.length > 0) this.xmlHttp.setRequestHeader("Ajax-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), this.timeoutPeriod); this.xmlHttp.send(json); json = null; data = null; delete json; delete data; if(!async) { return this.createResponse(); } return true; } }); addNamespace("Ajax.Web"); Ajax.Web.NameValueCollection = function() { this.__type = "System.Collections.Specialized.NameValueCollection"; this.add = function(key, value) { if(this[key] == null) { this[key] = value; } } this.getKeys = function() { var keys = []; for(key in this) if(typeof this[key] != "function") keys.push(key); return keys; } this.getValue = function(key) { return this[key]; } this.toJSON = function() { var o = this; o.toJSON = null; delete o.toJSON; return AjaxPro.toJSON(o); } } addNamespace("Ajax.Web"); Ajax.Web.DataTable = function(columns, rows) { this.__type = "System.Data.DataTable, System.Data"; this.Columns = new Array(); this.Rows = new Array(); this.addColumn = function(name, type) { var c = new Object(); c.Name = name; c.__type = type; this.Columns.push(c); } this.toJSON = function() { var dt = new Object(); dt.Columns = []; for(var i=0; i