// Client stub for the geocodes PHP Class function geocodes(callback) { mode = 'sync'; if (callback) { mode = 'async'; } this.className = 'geocodes'; this.dispatcher = new HTML_AJAX_Dispatcher(this.className,mode,callback,'/ajax_search_server.php?','JSON'); } geocodes.prototype = { Sync: function() { this.dispatcher.Sync(); }, Async: function(callback) { this.dispatcher.Async(callback); }, get: function() { return this.dispatcher.doCall('get',arguments); }, get1: function() { return this.dispatcher.doCall('get1',arguments); }, getStates: function() { return this.dispatcher.doCall('getStates',arguments); }, get1State: function() { return this.dispatcher.doCall('get1State',arguments); }, getCounties: function() { return this.dispatcher.doCall('getCounties',arguments); }, get1County: function() { return this.dispatcher.doCall('get1County',arguments); }, getCities: function() { return this.dispatcher.doCall('getCities',arguments); }, get1City: function() { return this.dispatcher.doCall('get1City',arguments); }, breakUpGeocode: function() { return this.dispatcher.doCall('breakUpGeocode',arguments); }, getKeywordMatches: function() { return this.dispatcher.doCall('getKeywordMatches',arguments); } } // Main.js if (!String.fromCharCode && !String.prototype.fromCharCode) { String.prototype.fromCharCode = function(code) { var h = code.toString(16); if (h.length == 1) { h = '0' + h; } return unescape('%' + h); } } if (!String.charCodeAt && !String.prototype.charCodeAt) { String.prototype.charCodeAt = function(index) { var c = this.charAt(index); for (i = 1; i < 256; i++) { if (String.fromCharCode(i) == c) { return i; } } } } if (!Array.splice && !Array.prototype.splice) { Array.prototype.splice = function(s, d) { var max = Math.max, min = Math.min, a = [], // The return value array e, // element i = max(arguments.length - 2, 0), // insert count k = 0, l = this.length, n, // new length v, // delta x; // shift count s = s || 0; if (s < 0) { s += l; } s = max(min(s, l), 0); // start point d = max(min(typeof d == 'number' ? d : l, l - s), 0); // delete count v = i - d; n = l + v; while (k < d) { e = this[s + k]; if (!e) { a[k] = e; } k += 1; } x = l - s - d; if (v < 0) { k = s + i; while (x) { this[k] = this[k - v]; k += 1; x -= 1; } this.length = n; } else if (v > 0) { k = 1; while (x) { this[n - k] = this[l - k]; k += 1; x -= 1; } } for (k = 0; k < i; ++k) { this[s + k] = arguments[k + 2]; } return a; } } if (!Array.push && !Array.prototype.push) { Array.prototype.push = function() { for (var i = 0, startLength = this.length; i < arguments.length; i++) { this[startLength + i] = arguments[i]; } return this.length; } } if (!Array.pop && !Array.prototype.pop) { Array.prototype.pop = function() { return this.splice(this.length - 1, 1)[0]; } } var HTML_AJAX = { defaultServerUrl: false, defaultEncoding: 'Null', queues: false, clientPools: {}, httpClient: function(name) { if (name) { if (this.clientPools[name]) { return this.clientPools[name].getClient(); } } return this.clientPools['default'].getClient(); }, makeRequest: function(request) { if (!HTML_AJAX.queues[request.queue]) { var e = new Error('Unknown Queue: '+request.queue); if (HTML_AJAX.onError) { HTML_AJAX.onError(e); return false; } else { throw(e); } } else { var qn = request.queue; var q = HTML_AJAX.queues[qn]; HTML_AJAX.queues[request.queue].addRequest(request); return HTML_AJAX.queues[request.queue].processRequest(); } }, serializerForEncoding: function(encoding) { for(var i in HTML_AJAX.contentTypeMap) { if (encoding == HTML_AJAX.contentTypeMap[i] || encoding == i) { return eval("new HTML_AJAX_Serialize_"+i+";"); } } return new HTML_AJAX_Serialize_Null(); }, fullcall: function(url,encoding,className,method,callback,args, customHeaders, grab) { var serializer = HTML_AJAX.serializerForEncoding(encoding); var request = new HTML_AJAX_Request(serializer); if (callback) { request.isAsync = true; } request.requestUrl = url; request.className = className; request.methodName = method; request.callback = callback; request.args = args; if (customHeaders) { request.customHeaders = customHeaders; } if (grab) { request.grab = true; if (!args || !args.length) { request.requestType = 'GET'; } } return HTML_AJAX.makeRequest(request); }, call: function(className,method,callback) { var args = new Array(); for(var i = 3; i < arguments.length; i++) { args.push(arguments[i]); } return HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,className,method,callback,args); }, grab: function(url,callback) { return HTML_AJAX.fullcall(url,'Null',false,null,callback, '', false, true); }, replace: function(id) { var callback = function(result) { document.getElementById(id).innerHTML = result; } if (arguments.length == 2) { HTML_AJAX.grab(arguments[1],callback); } else { var args = new Array(); for(var i = 3; i < arguments.length; i++) { args.push(arguments[i]); } HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,arguments[1],arguments[2],callback,args, false, true); } }, append: function(id) { var callback = function(result) { document.getElementById(id).innerHTML += result; } if (arguments.length == 2) { HTML_AJAX.grab(arguments[1],callback); } else { var args = new Array(); for(var i = 3; i < arguments.length; i++) { args.push(arguments[i]); } HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,arguments[1],arguments[2],callback,args, false, true); } }, Open: function(request) { }, Load: function(request) { }, contentTypeMap: { 'JSON': 'application/json', 'Null': 'text/plain', 'Error': 'application/error', 'PHP': 'application/php-serialized', 'HA' : 'application/html_ajax_action', 'Urlencoded': 'application/x-www-form-urlencoded' }, requestComplete: function(request,error) { for(var i in HTML_AJAX.queues) { if (HTML_AJAX.queues[i].requestComplete) { HTML_AJAX.queues[i].requestComplete(request,error); } } }, formSubmit: function (form, target, customRequest) { if (typeof form == 'string') { form = document.getElementById(form); if (!form) { return false; } } if (typeof target == 'string') { target = document.getElementById('target'); } if (!target) { target = form; } var action = form.action; var el, type, value, name, nameParts, useValue = true; var out = '', tags = form.elements; childLoop: for (i in tags) { el = tags[i]; if (!el || !el.getAttribute) { continue; } name = el.getAttribute('name'); if (!name) { continue; } type = el.nodeName.toLowerCase(); switch (type) { case 'input': var inpType = el.getAttribute('type'); switch (inpType) { case 'submit': type = 'button'; break; case 'checkbox': case 'radio': if (el.checked) { value = 'checked'; useValue = false; break; } continue childLoop; case 'text': default: type = 'text'; break; } break; case 'button': case 'textarea': case 'select': break; default: continue childLoop; } if (useValue) { value = el.value; } out += escape(name) + '=' + escape(value) + '&'; useValue = true; } // end childLoop var callback = function(result) { target.innerHTML = result; } var serializer = HTML_AJAX.serializerForEncoding('Null'); var request = new HTML_AJAX_Request(serializer); request.isAsync = true; request.callback = callback; switch (form.method.toLowerCase()) { case 'post': var headers = {}; headers['Content-Type'] = 'application/x-www-form-urlencoded'; request.customHeaders = headers; request.requestType = 'POST'; request.requestUrl = action; request.args = out; break; default: if (action.indexOf('?') == -1) { out = '?' + out.substr(0, out.length - 1); } request.requestUrl = action+out; request.requestType = 'GET'; } if(customRequest) { for(var i in customRequest) { request[i] = customRequest[i]; } } HTML_AJAX.makeRequest(request); return true; } // end formSubmit() } function HTML_AJAX_Serialize_Null() {} HTML_AJAX_Serialize_Null.prototype = { contentType: 'text/plain; charset=UTF-8;', serialize: function(input) { return new String(input).valueOf(); }, unserialize: function(input) { return new String(input).valueOf(); } } function HTML_AJAX_Serialize_JSON() {} HTML_AJAX_Serialize_JSON.prototype = { contentType: 'application/json; charset=UTF-8', serialize: function(input) { return HTML_AJAX_JSON.stringify(input); }, unserialize: function(input) { try { return eval(input); } catch(e) { return HTML_AJAX_JSON.parse(input); } } } function HTML_AJAX_Serialize_Error() {} HTML_AJAX_Serialize_Error.prototype = { contentType: 'application/error; charset=UTF-8', serialize: function(input) { var ser = new HTML_AJAX_Serialize_JSON(); return ser.serialize(input); }, unserialize: function(input) { var ser = new HTML_AJAX_Serialize_JSON(); var data = new ser.unserialize(input); var e = new Error('PHP Error: '+data.errStr); for(var i in data) { e[i] = data[i]; } throw e; } } function HTML_AJAX_Queue_Immediate() {} HTML_AJAX_Queue_Immediate.prototype = { request: false, addRequest: function(request) { this.request = request; }, processRequest: function() { var client = HTML_AJAX.httpClient(); client.request = this.request; return client.makeRequest(); } } function HTML_AJAX_Queue_Interval_SingleBuffer(interval) { this.interval = interval; } HTML_AJAX_Queue_Interval_SingleBuffer.prototype = { request: false, _intervalId: false, addRequest: function(request) { this.request = request; }, processRequest: function() { if (!this._intervalId) { this.runInterval(); this.start(); } }, start: function() { var self = this; this._intervalId = setInterval(function() { self.runInterval() },this.interval); }, stop: function() { clearInterval(this._intervalId); }, runInterval: function() { if (this.request) { var client = HTML_AJAX.httpClient(); client.request = this.request; this.request = false; client.makeRequest(); } } } HTML_AJAX.queues = new Object(); HTML_AJAX.queues['default'] = new HTML_AJAX_Queue_Immediate(); // priorityQueue.js function HTML_AJAX_Queue_Priority_Item(item, time) { this.item = item; this.time = time; } HTML_AJAX_Queue_Priority_Item.prototype = { compareTo: function (other) { var ret = this.item.compareTo(other.item); if (ret == 0) { ret = this.time - other.time; } return ret; } } function HTML_AJAX_Queue_Priority_Simple(interval) { this.interval = interval; this.idleMax = 10; // keep the interval going with an empty queue for 10 intervals this.requestTimeout = 5; // retry uncompleted requests after 5 seconds this.checkRetryChance = 0.1; // check for uncompleted requests to retry on 10% of intervals this._intervalId = 0; this._requests = []; this._removed = []; this._len = 0; this._removedLen = 0; this._idle = 0; } HTML_AJAX_Queue_Priority_Simple.prototype = { isEmpty: function () { return this._len == 0; }, addRequest: function (request) { request = new HTML_AJAX_Queue_Priority_Item(request, new Date().getTime()); ++this._len; if (this.isEmpty()) { this._requests[0] = request; return; } for (i = 0; i < this._len - 1; i++) { if (request.compareTo(this._requests[i]) < 0) { this._requests.splice(i, 1, request, this._requests[i]); return; } } this._requests.push(request); }, peek: function () { return (this.isEmpty() ? false : this._requests[0]); }, requestComplete: function (request) { for (i = 0; i < this._removedLen; i++) { if (this._removed[i].item == request) { this._removed.splice(i, 1); --this._removedLen; out('removed from _removed'); return true; } } return false; }, processRequest: function() { if (!this._intervalId) { this._runInterval(); this._start(); } this._idle = 0; }, _runInterval: function() { if (Math.random() < this.checkRetryChance) { this._doRetries(); } if (this.isEmpty()) { if (++this._idle > this.idleMax) { this._stop(); } return; } var client = HTML_AJAX.httpClient(); if (!client) { return; } var request = this.peek(); if (!request) { this._requests.splice(0, 1); return; } client.request = request.item; client.makeRequest(); this._requests.splice(0, 1); --this._len; this._removed[this._removedLen++] = new HTML_AJAX_Queue_Priority_Item(request, new Date().getTime()); }, _doRetries: function () { for (i = 0; i < this._removedLen; i++) { if (this._removed[i].time + this._requestTimeout < new Date().getTime()) { this.addRequest(request.item); this._removed.splice(i, 1); --this._removedLen; return true; } } }, _start: function() { var self = this; this._intervalId = setInterval(function() { self._runInterval() }, this.interval); }, _stop: function() { clearInterval(this._intervalId); this._intervalId = 0; } }; // clientPool.js HTML_AJAX_Client_Pool = function(maxClients, startingClients) { this.maxClients = maxClients; this._clients = []; this._len = 0; while (--startingClients > 0) { this.addClient(); } } HTML_AJAX_Client_Pool.prototype = { isEmpty: function() { return this._len == 0; }, addClient: function() { if (this.maxClients != 0 && this._len > this.maxClients) { return false; } var key = this._len++; this._clients[key] = new HTML_AJAX_HttpClient(); return this._clients[key]; }, getClient: function () { for (i = 0; i < this._len; i++) { if (!this._clients[i].callInProgress()) { return this._clients[i]; } } var client = this.addClient(); if (client) { return client; } return false; }, removeClient: function (client) { for (i = 0; i < this._len; i++) { if (!this._clients[i] == client) { this._clients.splice(i, 1); return true; } } return false; }, clear: function () { this._clients = []; this._len = 0; } }; HTML_AJAX.clientPools['default'] = new HTML_AJAX_Client_Pool(0); // IframeXHR.js HTML_AJAX_IframeXHR_instances = new Object(); function HTML_AJAX_IframeXHR() { this._id = 'HAXHR_iframe_' + new Date().getTime(); HTML_AJAX_IframeXHR_instances[this._id] = this; } HTML_AJAX_IframeXHR.prototype = { onreadystatechange: null, // Event handler for an event that fires at every state change readyState: 0, // Object status integer: 0 = uninitialized 1 = loading 2 = loaded 3 = interactive 4 = complete responseText: '', // String version of data returned from server process responseXML: null, // DOM-compatible document object of data returned from server process status: 0, // Numeric code returned by server, such as 404 for "Not Found" or 200 for "OK" statusText: '', // String message accompanying the status code iframe: true, // flag for iframe _id: null, // iframe id, unique to object(hopefully) _url: null, // url sent by open _method: null, // get or post _async: null, // sync or async sent by open _headers: new Object(), //request headers to send, actually sent as form vars _response: new Object(), //response headers received _phpclass: null, //class to send _phpmethod: null, //method to send _history: null, // opera has to have history munging abort: function() { var iframe = document.getElementById(this._id); if (iframe) { document.body.removeChild(iframe); } if (this._timeout) { window.clearTimeout(this._timeout); } this.readyState = 1; if (typeof(this.onreadystatechange) == "function") { this.onreadystatechange(); } }, getAllResponseHeaders: function() { var string = ''; for (i in this._response) { string += i + ' : ' + this._response[i] + "\n"; } return string; }, getResponseHeader: function(header) { return (this._response[header] ? this._response[header] : null); }, setRequestHeader: function(label, value) { this._headers[label] = value; return; }, open: function(method, url, async, username, password) { if (!document.body) { throw('CANNOT_OPEN_SEND_IN_DOCUMENT_HEAD'); } if (!method || !url) { throw('NOT_ENOUGH_ARGUMENTS:METHOD_URL_REQUIRED'); } this._method = (method.toUpperCase() == 'POST' ? 'POST' : 'GET'); this._decodeUrl(url); this._async = async; if(!this._async && document.readyState && !window.opera) { throw('IE_DOES_NOT_SUPPORT_SYNC_WITH_IFRAMEXHR'); } this.readyState = 1; if(typeof(this.onreadystatechange) == "function") { this.onreadystatechange(); } }, send: function(content) { if (window.opera) { this._history = window.history.length; } var form = '
'; form = "javascript:document.write('" + form.replace(/\'/g,"\\'") + "');void(0);"; this.readyState = 2; if (typeof(this.onreadystatechange) == "function") { this.onreadystatechange(); } try { var iframe = document.createElement('iframe'); iframe.id = this._id; iframe.style.visibility = 'hidden'; iframe.style.border = '0'; iframe.style.width = '0'; iframe.style.height = '0'; if (document.all) { iframe.src = form; document.body.appendChild(iframe); } else { document.body.appendChild(iframe); iframe.src = form; } } catch(exception) { var html = ''; document.body.innerHTML += html; } if (this._async == true) { if (this.readyState < 3) { this.readyState = 3; if(typeof(this.onreadystatechange) == "function") { this.onreadystatechange(); } } } else { while (this.readyState != 4) { if (this.readyState < 3) { this.readyState = 3; if(typeof(this.onreadystatechange) == "function") { this.onreadystatechange(); } } } } }, isLoaded: function(headers, data) { this.readyState = 4; this.status = 200; this.statusText = 'OK'; this.responseText = data; this._response = headers; if (!this._response['Last-Modified']) { string += 'Last-Modified : ' + document.getElementById(this._id).lastModified + "\n"; } if (!this._response['Content-Type']) { string += 'Content-Type : ' + document.getElementById(this._id).contentType + "\n"; } if (window.opera && window.opera.version) { window.history.go(this._history - window.history.length); } if (typeof(this.onreadystatechange) == "function") { this.onreadystatechange(); } document.body.removeChild(document.getElementById(this._id)); }, _decodeUrl: function(querystring) { var url = unescape(location.href); url = url.substring(0, url.lastIndexOf("/") + 1); var item = querystring.split('?'); this._url = url + item[0].substring(item[0].lastIndexOf("/") + 1,item[0].length); if(item[1]) { item = item[1].split('&'); for (i in item) { var v = item[i].split('='); if (v[0] == 'c') { this._phpclass = v[1]; } else if (v[0] == 'm') { this._phpmethod = v[1]; } } } if (!this._phpclass || !this._phpmethod) { var cloc = window.location.href; this._url = cloc + (cloc.indexOf('?') >= 0 ? '&' : '?') + 'px=' + escape(HTML_AJAX_Util.absoluteURL(querystring)); } } } // serializer/UrlSerializer.js function HTML_AJAX_Serialize_Urlencoded() {} HTML_AJAX_Serialize_Urlencoded.prototype = { contentType: 'application/x-www-form-urlencoded; charset=UTF-8', base: '_HTML_AJAX', _keys: [], error: false, message: "", cont: "", serialize: function(input, _internal) { if (typeof input == 'undefined') { return ''; } if (!_internal) { this._keys = []; } var ret = '', first = true; for (i = 0; i < this._keys.length; i++) { ret += (first ? escape(this._keys[i]) : '[' + escape(this._keys[i]) + ']'); first = false; } ret += '='; switch (HTML_AJAX_Util.getType(input)) { case 'string': case 'number': ret += escape(input.toString()); break; case 'boolean': ret += (input ? '1' : '0'); break; case 'array': case 'object': ret = ''; for (i in input) { this._keys.push(i); ret += this.serialize(input[i], true) + '&'; this._keys.pop(); } ret = ret.substr(0, ret.length - 1); } return ret; }, unserialize: function(input) { if (!input.length || input.length == 0) { return; } if (!/^(\w+(\[[^\[\]]*\])*=[^&]*(&|$))+$/.test(input)) { this.raiseError("invalidly formed input", input); return; } input = input.split("&"); var pos, key, keys, val, _HTML_AJAX = []; if (input.length == 1) { return unescape(input[0].substr(this.base.length + 1)); } for (var i in input) { pos = input[i].indexOf("="); if (pos < 1 || input[i].length - pos - 1 < 1) { this.raiseError("input is too short", input[i]); return; } key = unescape(input[i].substr(0, pos)); val = unescape(input[i].substr(pos + 1)); key = key.replace(/\[((\d*\D+)+)\]/g, '["$1"]'); keys = key.split(']'); for (j in keys) { if (!keys[j].length || keys[j].length == 0) { continue; } try { if (eval('typeof ' + keys[j] + ']') == 'undefined') { var ev = keys[j] + ']=[];'; eval(ev); } } catch (e) { this.raiseError("error evaluating key", ev); return; } } try { eval(key + '="' + val + '";'); } catch (e) { this.raiseError("error evaluating value", input); return; } } return _HTML_AJAX; }, getError: function() { return this.message + "\n" + this.cont; }, raiseError: function(message, cont) { this.error = 1; this.message = message; this.cont = cont; } } // serializer/phpSerializer.js function HTML_AJAX_Serialize_PHP() {} HTML_AJAX_Serialize_PHP.prototype = { error: false, message: "", cont: "", defaultEncoding: 'UTF-8', contentType: 'application/php-serialized; charset: UTF-8', serialize: function(inp) { var type = HTML_AJAX_Util.getType(inp); var val; switch (type) { case "undefined": val = "N"; break; case "boolean": val = "b:" + (inp ? "1" : "0"); break; case "number": val = (Math.round(inp) == inp ? "i" : "d") + ":" + inp; break; case "string": val = "s:" + inp.length + ":\"" + inp + "\""; break; case "array": val = "a"; case "object": if (type == "object") { var objname = inp.constructor.toString().match(/(\w+)\(\)/); if (objname == undefined) { return; } objname[1] = this.serialize(objname[1]); val = "O" + objname[1].substring(1, objname[1].length - 1); } var count = 0; var vals = ""; var okey; for (key in inp) { okey = (key.match(/^[0-9]+$/) ? parseInt(key) : key); vals += this.serialize(okey) + this.serialize(inp[key]); count++; } val += ":" + count + ":{" + vals + "}"; break; } if (type != "object" && type != "array") val += ";"; return val; }, unserialize: function(inp) { this.error = 0; if (inp == "" || inp.length < 2) { this.raiseError("input is too short"); return; } var val, kret, vret, cval; var type = inp.charAt(0); var cont = inp.substring(2); var size = 0, divpos = 0, endcont = 0, rest = "", next = ""; switch (type) { case "N": // null if (inp.charAt(1) != ";") { this.raiseError("missing ; for null", cont); } rest = cont; break; case "b": // boolean if (!/[01];/.test(cont.substring(0,2))) { this.raiseError("value not 0 or 1, or missing ; for boolean", cont); } val = (cont.charAt(0) == "1"); rest = cont.substring(1); break; case "s": // string val = ""; divpos = cont.indexOf(":"); if (divpos == -1) { this.raiseError("missing : for string", cont); break; } size = parseInt(cont.substring(0, divpos)); if (size == 0) { if (cont.length - divpos < 4) { this.raiseError("string is too short", cont); break; } rest = cont.substring(divpos + 4); break; } if ((cont.length - divpos - size) < 4) { this.raiseError("string is too short", cont); break; } if (cont.substring(divpos + 2 + size, divpos + 4 + size) != "\";") { this.raiseError("string is too long, or missing \";", cont); } val = cont.substring(divpos + 2, divpos + 2 + size); rest = cont.substring(divpos + 4 + size); break; case "i": // integer case "d": // float var dotfound = 0; for (var i = 0; i < cont.length; i++) { cval = cont.charAt(i); if (isNaN(parseInt(cval)) && !(type == "d" && cval == "." && !dotfound++)) { endcont = i; break; } } if (!endcont || cont.charAt(endcont) != ";") { this.raiseError("missing or invalid value, or missing ; for int/float", cont); } val = cont.substring(0, endcont); val = (type == "i" ? parseInt(val) : parseFloat(val)); rest = cont.substring(endcont + 1); break; case "a": // array if (cont.length < 4) { this.raiseError("array is too short", cont); return; } divpos = cont.indexOf(":", 1); if (divpos == -1) { this.raiseError("missing : for array", cont); return; } size = parseInt(cont.substring(1, divpos - 1)); cont = cont.substring(divpos + 2); val = new Array(); if (cont.length < 1) { this.raiseError("array is too short", cont); return; } for (var i = 0; i + 1 < size * 2; i += 2) { kret = this.unserialize(cont, 1); if (this.error || kret[0] == undefined || kret[1] == "") { this.raiseError("missing or invalid key, or missing value for array", cont); return; } vret = this.unserialize(kret[1], 1); if (this.error) { this.raiseError("invalid value for array", cont); return; } val[kret[0]] = vret[0]; cont = vret[1]; } if (cont.charAt(0) != "}") { this.raiseError("missing ending }, or too many values for array", cont); return; } rest = cont.substring(1); break; case "O": // object divpos = cont.indexOf(":"); if (divpos == -1) { this.raiseError("missing : for object", cont); return; } size = parseInt(cont.substring(0, divpos)); var objname = cont.substring(divpos + 2, divpos + 2 + size); if (cont.substring(divpos + 2 + size, divpos + 4 + size) != "\":") { this.raiseError("object name is too long, or missing \":", cont); return; } var objprops = this.unserialize("a:" + cont.substring(divpos + 4 + size), 1); if (this.error) { this.raiseError("invalid object properties", cont); return; } rest = objprops[1]; var objout = "function " + objname + "(){"; for (key in objprops[0]) { objout += "this." + key + "=objprops[0]['" + key + "'];"; } objout += "}val=new " + objname + "();"; eval(objout); break; default: this.raiseError("invalid input type", cont); } return (arguments.length == 1 ? val : [val, rest]); }, getError: function() { return this.message + "\n" + this.cont; }, raiseError: function(message, cont) { this.error = 1; this.message = message; this.cont = cont; } } // Dispatcher.js function HTML_AJAX_Dispatcher(className,mode,callback,serverUrl,serializerType) { this.className = className; this.mode = mode; this.callback = callback; this.serializerType = serializerType; if (serverUrl) { this.serverUrl = serverUrl } else { this.serverUrl = window.location; } } HTML_AJAX_Dispatcher.prototype = { queue: 'default', timeout: 20000, priority: 0, doCall: function(callName,args) { var request = new HTML_AJAX_Request(); request.requestUrl = this.serverUrl; request.className = this.className; request.methodName = callName; request.timeout = this.timeout; request.contentType = this.contentType; request.serializer = eval('new HTML_AJAX_Serialize_'+this.serializerType); request.queue = this.queue; request.priority = this.priority; for(var i=0; i < args.length; i++) { request.addArg(i,args[i]); }; if ( this.mode == "async" ) { request.isAsync = true; if (this.callback[callName]) { var self = this; request.callback = function(result) { self.callback[callName](result); } } } else { request.isAsync = false; } return HTML_AJAX.makeRequest(request); }, Sync: function() { this.mode = 'sync'; }, Async: function(callback) { this.mode = 'async'; if (callback) { this.callback = callback; } } }; // HttpClient.js function HTML_AJAX_HttpClient() { } HTML_AJAX_HttpClient.prototype = { request: null, _timeoutId: null, init:function() { try { this.xmlhttp = new XMLHttpRequest(); } catch (e) { var XMLHTTP_IDS = new Array( 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ); var success = false; for (var i=0;i < XMLHTTP_IDS.length && !success; i++) { try { this.xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]); success = true; } catch (e) {} } if (!success) { try{ this.xmlhttp = new HTML_AJAX_IframeXHR(); this.request.iframe = true; } catch(e) { throw new Error('Unable to create XMLHttpRequest.'); } } } }, callInProgress: function() { switch ( this.xmlhttp.readyState ) { case 1: case 2: case 3: return true; break; default: return false; break; } }, makeRequest: function() { if (!this.xmlhttp) { this.init(); } try { if (this.request.Open) { this.request.Open(); } else if (HTML_AJAX.Open) { HTML_AJAX.Open(this.request); } var self = this; this.xmlhttp.open(this.request.requestType,this.request.completeUrl(),this.request.isAsync); if (this.request.customHeaders) { for (i in this.request.customHeaders) { this.xmlhttp.setRequestHeader(i, this.request.customHeaders[i]); } } if (this.request.customHeaders && !this.request.customHeaders['Content-Type']) { if(window.opera) { this.xmlhttp.setRequestHeader('Content-Type','text/plain; charset=utf-8'); this.xmlhttp.setRequestHeader('x-Content-Type',this.request.getContentType() + '; charset=utf-8'); } else { this.xmlhttp.setRequestHeader('Content-Type',this.request.getContentType() + '; charset=utf-8'); } } this.xmlhttp.onreadystatechange = function() { self._readyStateChangeCallback(); } var payload = this.request.getSerializedPayload(); if (payload) { this.xmlhttp.setRequestHeader('Content-Length', payload.length); } this.xmlhttp.send(payload); if (!this.request.isAsync) { if ( this.xmlhttp.status == 200 ) { HTML_AJAX.requestComplete(this.request); if (this.request.Load) { this.request.Load(); } else if (HTML_AJAX.Load) { HTML_AJAX.Load(this.request); } return this._decodeResponse(); } else { var e = new Error('['+this.xmlhttp.status +'] '+this.xmlhttp.statusText); e.headers = this.xmlhttp.getAllResponseHeaders(); this._handleError(e); } } else { var self = this; this._timeoutId = window.setTimeout(function() { self.abort(true); },this.request.timeout); } } catch (e) { this._handleError(e); } }, abort: function (automatic) { if (this.callInProgress()) { this.xmlhttp.abort(); if (automatic) { HTML_AJAX.requestComplete(this.request); this._handleError(new Error('Request Timed Out: time out was '+this.request.timeout+'ms')); } } }, _readyStateChangeCallback:function() { try { switch(this.xmlhttp.readyState) { case 1: break; case 2: if (this.request.Send) { this.request.Send(); } else if (HTML_AJAX.Send) { HTML_AJAX.Send(this.request); } break; case 3: if (this.request.Progress) { this.request.Progress(); } else if (HTML_AJAX.Progress ) { HTML_AJAX.Progress(this.request); } break; case 4: window.clearTimeout(this._timeoutId); if (this.xmlhttp.status == 200) { HTML_AJAX.requestComplete(this.request); if (this.request.Load) { this.request.Load(); } else if (HTML_AJAX.Load ) { HTML_AJAX.Load(this.request); } if (this.request.callback) { this.request.callback(this._decodeResponse()); } } else { var e = new Error('HTTP Error Making Request: ['+this.xmlhttp.status+'] '+this.xmlhttp.statusText); this._handleError(e); } break; } } catch (e) { this._handleError(e); } }, _decodeResponse: function() { var content = null; try { content = this.xmlhttp.getResponseHeader('X-Content-Type'); } catch(e) {} if(!content || content == null) { content = this.xmlhttp.getResponseHeader('Content-Type'); } if(content.indexOf(';') != -1) { content = content.substring(0, content.indexOf(';')); } var unserializer = HTML_AJAX.serializerForEncoding(content); return unserializer.unserialize(this.xmlhttp.responseText); }, _handleError: function(e) { HTML_AJAX.requestComplete(this.request,e); if (this.request.onError) { this.request.onError(e); } else if (HTML_AJAX.onError) { HTML_AJAX.onError(e,this.request); } else { throw e; } } } // Request.js function HTML_AJAX_Request(serializer) { this.serializer = serializer; } HTML_AJAX_Request.prototype = { serializer: null, isAsync: false, requestType: 'POST', requestUrl: '', className: null, methodName: null, timeout: 20000, args: null, callback: null, queue: 'default', priority: 0, customHeaders: {}, iframe: false, grab: false, addArg: function(name, value) { if ( !this.args ) { this.args = []; } if (!/[^a-zA-Z_0-9]/.test(name) ) { this.args[name] = value; } else { throw new Error('Invalid parameter name ('+name+')'); } }, getSerializedPayload: function() { return this.serializer.serialize(this.args); }, getContentType: function() { return this.serializer.contentType; }, completeUrl: function() { var url = new String(this.requestUrl); var delimiter = '?'; if (url.indexOf('?') >= 0) { delimiter = '&'; } if (this.className || this.methodName) { url += delimiter+'c='+escape(this.className)+'&m='+escape(this.methodName); } return url; }, compareTo: function(other) { if (this.priority == other.priority) { return 0; } return (this.priority > other.priority ? 1 : -1); } } // serializer/JSON.js Array.prototype.______array = '______array'; var HTML_AJAX_JSON = { org: 'http://www.JSON.org', copyright: '(c)2005 JSON.org', license: 'http://www.crockford.com/JSON/license.html', stringify: function (arg) { var c, i, l, s = '', v; switch (typeof arg) { case 'object': if (arg) { if (arg.______array == '______array') { for (i = 0; i < arg.length; ++i) { v = this.stringify(arg[i]); if (s) { s += ','; } s += v; } return '[' + s + ']'; } else if (typeof arg.toString != 'undefined') { for (i in arg) { v = arg[i]; if (typeof v != 'undefined' && typeof v != 'function') { v = this.stringify(v); if (s) { s += ','; } s += this.stringify(i) + ':' + v; } } return '{' + s + '}'; } } return 'null'; case 'number': return isFinite(arg) ? String(arg) : 'null'; case 'string': l = arg.length; s = '"'; for (i = 0; i < l; i += 1) { c = arg.charAt(i); if (c >= ' ') { if (c == '\\' || c == '"') { s += '\\'; } s += c; } else { switch (c) { case '\b': s += '\\b'; break; case '\f': s += '\\f'; break; case '\n': s += '\\n'; break; case '\r': s += '\\r'; break; case '\t': s += '\\t'; break; default: c = c.charCodeAt(); s += '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); } } } return s + '"'; case 'boolean': return String(arg); default: return 'null'; } }, parse: function (text) { var at = 0; var ch = ' '; function error(m) { throw { name: 'JSONError', message: m, at: at - 1, text: text }; } function next() { ch = text.charAt(at); at += 1; return ch; } function white() { while (ch) { if (ch <= ' ') { next(); } else if (ch == '/') { switch (next()) { case '/': while (next() && ch != '\n' && ch != '\r') {} break; case '*': next(); for (;;) { if (ch) { if (ch == '*') { if (next() == '/') { next(); break; } } else { next(); } } else { error("Unterminated comment"); } } break; default: error("Syntax error"); } } else { break; } } } function string() { var i, s = '', t, u; if (ch == '"') { outer: while (next()) { if (ch == '"') { next(); return s; } else if (ch == '\\') { switch (next()) { case 'b': s += '\b'; break; case 'f': s += '\f'; break; case 'n': s += '\n'; break; case 'r': s += '\r'; break; case 't': s += '\t'; break; case 'u': u = 0; for (i = 0; i < 4; i += 1) { t = parseInt(next(), 16); if (!isFinite(t)) { break outer; } u = u * 16 + t; } s += String.fromCharCode(u); break; default: s += ch; } } else { s += ch; } } } error("Bad string"); } function array() { var a = []; if (ch == '[') { next(); white(); if (ch == ']') { next(); return a; } while (ch) { a.push(value()); white(); if (ch == ']') { next(); return a; } else if (ch != ',') { break; } next(); white(); } } error("Bad array"); } function object() { var k, o = {}; if (ch == '{') { next(); white(); if (ch == '}') { next(); return o; } while (ch) { k = string(); white(); if (ch != ':') { break; } next(); o[k] = value(); white(); if (ch == '}') { next(); return o; } else if (ch != ',') { break; } next(); white(); } } error("Bad object"); } function number() { var n = '', v; if (ch == '-') { n = '-'; next(); } while (ch >= '0' && ch <= '9') { n += ch; next(); } if (ch == '.') { n += '.'; while (next() && ch >= '0' && ch <= '9') { n += ch; } } if (ch == 'e' || ch == 'E') { n += 'e'; next(); if (ch == '-' || ch == '+') { n += ch; next(); } while (ch >= '0' && ch <= '9') { n += ch; next(); } } v = +n; if (!isFinite(v)) { } else { return v; } } function word() { switch (ch) { case 't': if (next() == 'r' && next() == 'u' && next() == 'e') { next(); return true; } break; case 'f': if (next() == 'a' && next() == 'l' && next() == 's' && next() == 'e') { next(); return false; } break; case 'n': if (next() == 'u' && next() == 'l' && next() == 'l') { next(); return null; } break; } error("Syntax error"); } function value() { white(); switch (ch) { case '{': return object(); case '[': return array(); case '"': return string(); case '-': return number(); default: return ch >= '0' && ch <= '9' ? number() : word(); } } return value(); } }; // serializer/haSerializer.js function HTML_AJAX_Serialize_HA() {} HTML_AJAX_Serialize_HA.prototype = { unserialize: function(payload) { var actions = eval(payload); for(var i = 0; i < actions.length; i++) { var action = actions[i]; switch(action.action) { case 'prepend': this._prependAttr(action.id, action.attributes); break; case 'append': this._appendAttr(action.id, action.attributes); break; case 'assign': this._assignAttr(action.id, action.attributes); break; case 'clear': this._clearAttr(action.id, action.attributes); break; case 'create': this._createNode(action.id, action.tag, action.attributes, action.type); break; case 'replace': this._replaceNode(action.id, action.tag, action.attributes); break; case 'remove': this._removeNode(action.id); break; case 'script': this._insertScript(action.data); break; case 'alert': this._insertAlert(action.data); break; } } }, _prependAttr: function(id, attributes) { var node = document.getElementById(id); for (var i in attributes) { if(i == 'innerHTML') { node.innerHTML = attributes[i] + node.innerHTML; } else if(i == 'value') { node.value = attributes[i]; } else { var value = node.getAttribute(i); if(value) { node.setAttribute(i, attributes[i] + value); } else { node.setAttribute(i, attributes[i]); } } } }, _appendAttr: function(id, attributes) { var node = document.getElementById(id); for (var i in attributes) { if(i == 'innerHTML') { node.innerHTML += attributes[i]; } else if(i == 'value') { node.value = attributes[i]; } else { var value = node.getAttribute(i); if(value) { node.setAttribute(i, value + attributes[i]); } else { node.setAttribute(i, attributes[i]); } } } }, _assignAttr: function(id, attributes) { var node = document.getElementById(id); for (var i in attributes) { if(i == 'innerHTML') { node.innerHTML = attributes[i]; } else if(i == 'value') { node.value = attributes[i]; } else { node[i] = attributes[i]; } } }, _clearAttr: function(id, attributes) { var node = document.getElementById(id); for(var i = 0; i < attributes.length; i++) { if(attributes[i] == 'innerHTML') { node.innerHTML = ''; } else if(attributes[i] == 'value') { node.value = ''; } else { node.removeAttribute(attributes[i]); } } }, _createNode: function(id, tag, attributes, type) { var newnode = document.createElement(tag); for (var i in attributes) { if(i == 'innerHTML') { newnode.innerHTML = attributes[i]; } else if(i == 'value') { newnode.value = attributes[i]; } else { newnode.setAttribute(i, attributes[i]); } } switch(type) { case 'append': document.getElementById(id).appendChild(newnode); break case 'prepend': var parent = document.getElementById(id); var sibling = parent.firstChild; parent.insertBefore(newnode, sibling); break; case 'insertBefore': var sibling = document.getElementById(id); var parent = sibling.parentNode; parent.insertBefore(newnode, sibling); break; case 'insertAfter': var sibling = document.getElementById(id); var parent = sibling.parentNode; var next = sibling.nextSibling; if(next == null) { parent.appendChild(newnode); } else { parent.insertBefore(newnode, next); } break; } }, _replaceNode: function(id, tag, attributes) { var node = document.getElementById(id); var parent = node.parentNode; var newnode = document.createElement(tag); for (var i in attributes) { if(i == 'innerHTML') { newnode.innerHTML = attributes[i]; } else if(i == 'value') { newnode.value = attributes[i]; } } parent.replaceChild(newnode, node); }, _removeNode: function(id) { var node = document.getElementById(id); if(node) { var parent = node.parentNode; parent.removeChild(node); } }, _insertScript: function(data) { eval(data); }, _insertAlert: function(data) { alert(data); } } // Loading.js HTML_AJAX.Open = function(request) { var loading = document.getElementById('HTML_AJAX_LOADING'); if (!loading) { loading = document.createElement('div'); loading.id = 'HTML_AJAX_LOADING'; loading.innerHTML = 'Loading...'; loading.style.color = '#fff'; loading.style.position = 'absolute'; loading.style.top = 0; loading.style.right = 0; loading.style.backgroundColor = '#f00'; loading.style.border = '1px solid #f99'; loading.style.width = '80px'; loading.style.padding = '4px'; loading.style.fontFamily = 'Arial, Helvetica, sans'; document.body.insertBefore(loading,document.body.firstChild); } if (request.isAsync) { HTML_AJAX.onOpen_Timeout = window.setTimeout(function() { loading.style.display = 'block'; },500); } else { loading.style.display = 'block'; } } HTML_AJAX.Load = function(request) { if (HTML_AJAX.onOpen_Timeout) { window.clearTimeout(HTML_AJAX.onOpen_Timeout); HTML_AJAX.onOpen_Timeout = false; } var loading = document.getElementById('HTML_AJAX_LOADING'); if (loading) { loading.style.display = 'none'; } } // util.js var HTML_AJAX_Util = { registerEvent: function(element, event, handler) { if (typeof element.addEventListener != "undefined") { //Dom2 element.addEventListener(event, handler, false); } else if (typeof element.attachEvent != "undefined") { //IE 5+ element.attachEvent("on" + event, handler); } else { if (element["on" + event] != null) { var oldHandler = element["on" + event]; element["on" + event] = function(e) { oldHander(e); handler(e); }; } else { element["on" + event] = handler; } } }, eventTarget: function(event) { if (!event) var event = window.event; if (event.target) return event.target; // w3c if (event.srcElement) return event.srcElement; // ie 5 }, getType: function(inp) { var type = typeof inp, match; if(type == 'object' && !inp) { return 'null'; } if (type == "object") { if(!inp.constructor) { return 'object'; } var cons = inp.constructor.toString(); if (match = cons.match(/(\w+)\(/)) { cons = match[1].toLowerCase(); } var types = ["boolean", "number", "string", "array"]; for (key in types) { if (cons == types[key]) { type = types[key]; break; } } } return type; }, strRepeat: function(inp, multiplier) { var ret = ""; while (--multiplier > 0) ret += inp; return ret; }, varDump: function(inp, printFuncs, _indent, _recursionLevel) { if (!_recursionLevel) _recursionLevel = 0; if (!_indent) _indent = 1; var tab = this.strRepeat(" ", ++_indent); var type = this.getType(inp), out = type; var consrx = /(\w+)\(/; consrx.compile(); if (++_recursionLevel > 6) { return tab + inp + "Loop Detected\n"; } switch (type) { case "boolean": case "number": out += "(" + inp.toString() + ")"; break; case "string": out += "(" + inp.length + ") \"" + inp + "\""; break; case "function": if (printFuncs) { out += inp.toString().replace(/\n/g, "\n" + tab); } break; case "array": case "object": var atts = "", attc = 0; try { for (k in inp) { atts += tab + "[" + (/\D/.test(k) ? "\"" + k + "\"" : k) + "]=>\n" + tab + this.varDump(inp[k], printFuncs, _indent, _recursionLevel); ++attc; } } catch (e) {} if (type == "object") { var objname, objstr = inp.toString(); if (objname = objstr.match(/^\[object (\w+)\]$/)) { objname = objname[1]; } else { try { objname = inp.constructor.toString().match(consrx)[1]; } catch (e) { objname = 'unknown'; } } out += "(" + objname + ") "; } out += "(" + attc + ") {\n" + atts + this.strRepeat(" ", _indent - 1) +"}"; break; } return out + "\n"; }, quickPrint: function(input) { var ret = ""; for(var i in input) { ret += i+':'+input[i]+"\n"; } return ret; }, getAllElements: function(parentElement) { if( document.all) { if(!parentElement) { var allElements = document.all; } else { var allElements = [], rightName = new RegExp( parentElement, 'i' ), i; for( i=0; i