// XHR.JS // function XHR(div, url, ind) { this.req = null; this.div = (div!=null) ? div : ''; this.server = (url!=null) ? url : ''; if (ind==null) this.busy = "
"; this.init = function(url, parameters, target, spin) { this.url = (url!=null && url!='') ? url : this.server; this.params = (parameters!=null) ? parameters : ''; this.target = (target!=null && target!='') ? target : this.div; this.spin = (spin!=null) ? spin : true; } this.init(url, '', div, true); this.run = function(parameters, target, spin) { this.req = null; if (this.url=='') { // alert('?Server not configured'); return false; } if (window.XMLHttpRequest) { // Mozilla, Safari,... this.req = new XMLHttpRequest(); if (this.req.overrideMimeType) this.req.overrideMimeType('text/html'); } else if (window.ActiveXObject) { // IE try { this.req = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) { try { this.req = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) {} } } if (!this.req) { // alert('?Cannot create XMLHTTP instance'); return false; } var uri = this.url; if (parameters==null) parameters = this.params; var method = (parameters!=null && parameters!='') ? 'POST' : 'GET'; if (target!=null && target!='') this.target = target; if (spin!=null) this.spin = spin; var self = this; this.req.onreadystatechange = function() { var result, html='', js=''; if (self.req.readyState!=4) return; if (self.req.status==200) result = self.req.responseText; else result = '?XHR: ' + self.req.status + ' ' + self.req.statusText; while (result.length>0) { var i = result.indexOf(''); if (i==-1) { html += result; break; } html += result.substr(0, i); result = result.substr(i+11); i = result.indexOf(''); if (i==-1) i = result.length; js += result.substr(0, i); result = result.substr(i+14); } if (typeof(self.target)=='function') self.target(html, js); else { document.getElementById(self.target).innerHTML = html; try { eval(js); } catch(e) {}; } } if (this.spin && this.busy!=null && typeof(this.target)!='function') document.getElementById(this.target).innerHTML = this.busy; this.req.open(method, uri, true); if (method=='POST') try { this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); } catch(e) {}; this.req.send(parameters); } this.getParams = function(subform) { if (this.url=='') { // alert('?Server not configured'); return false; } if (subform==null || subform=='') subform = this.target; var obj = document.getElementById(subform) var parmstr=''; tags = obj.getElementsByTagName('INPUT'); for (i=0; i