function AYAX() { this.request; this.url; this.params; this.func; this.method = "POST"; this.type = 'json'; this.response; this.post = function (_params) { this.params = _params; this.makeRequest(); } this.makeRequest = function() { this.request = false; if (window.XMLHttpRequest) { this.request = new XMLHttpRequest(); if (this.request.overrideMimeType) { switch (this.type) { case 'html': this.request.overrideMimeType('text/html'); break; case 'xml': this.request.overrideMimeType('text/xml'); break; case 'text': this.request.overrideMimeType('text/plain'); break; case 'json': default: this.request.overrideMimeType('application/json'); break; } } } else if (window.ActiveXObject) { try { this.request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { this.request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!this.request) { alert("ERROR: Your Browser do not support AJAX or JavaScript disabled."); return false; } var self = this; this.request.onreadystatechange = function() { switch (self.request.readyState) { case 0: // Uninitialized break; case 1: // Loading //document.body.style.cursor = 'wait'; //window.statusbar.text = 'aYAx - Transfering Data'; break; case 2: // Loaded break; case 3: // Interactive break; case 4: // Done! if (self.request.status == 200) { if (self.type == 'xml') { self.response = self.request.responseXML; } else if (self.type == 'json') { self.response = (self.request.responseText) ? eval('('+self.request.responseText+')') : ''; } else { self.response = self.request.responseText; } self.func(self.response); } else { alert('There was a problem with the request.'); } break; } } switch (this.method.toUpperCase()) { case "GET": this.request.open('GET', this.url, true); this.request.send(null); break; case "POST": default: var params = ''; var exceptions = new Object(); // to skip custom prototypes if (this.params) { for (key in this.params) { if (!exceptions[key]) params += '&' + key + '=' + encodeURIComponent(this.params[key]); } } this.request.open('POST', this.url, true); this.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8"); this.request.setRequestHeader("Content-length", params.length); this.request.setRequestHeader("Connection", "close"); this.request.send(params); break; } } } function create_json_select(array, name, text, value) { var select = document.createElement("SELECT"); select.name = name; for (var i = 0; i < array.length; i++) { select.options[i] = new Option(array[i][text], array[i][value]); if (array[i]['selected']) { select.options[i].selected = true; } } return select; } function getFormData(o) { var ps = ''; var formTags = ['INPUT','SELECT','TEXTAREA']; var formData = new Object; for (i = 0; i < formTags.length; i++) { ct = o.getElementsByTagName(formTags[i]); if(ct.length > 0) { for(j = 0; j < ct.length; j++) { if(ct[j].name != 'undefined' && ct[j].name != '' && ct[j].name != null) { if((ct[j].type != 'checkbox' && ct[j].type != 'radio') || ct[j].checked) { if(ps.length > 0) { ps += "&"; } ps += ct[j].name + "=" + escape(ct[j].value); } } } } } formData.action = o.action; formData.params = ps; return formData; }