function AJAXController() { this.sendPost = sendPost; this.sendForm = sendForm; this.addListener = addListener; listListener = new Array(); errors = {100:'Continue', 101:'Switching Protocols', 201:'Created', 202:'Accepted', 203:'Non-Authoritative Information', 204:'No Content', 205:'Reset Content', 206:'Partial Content', 300:'Multiple Choices', 301:'Moved Permanently', 302:'Found', 303:'See Other', 304:'Not Modified', 305:'Use Proxy', 307:'Temporary Redirect', 400:'Bad Request', 401:'Unauthorized', 402:'Payment Required', 403:'Forbidden', 404:'Not found', 405:'Method Not Allowed', 406:'Not Acceptable', 407:'Proxy Authentication Required', 408:'Request Timeout', 409:'Conflict', 410:'Gone', 411:'Length Required', 412:'Precondition Failed', 413:'Request Entity Too Large', 414:'Request-URI Too Large', 415:'Unsupported Media Type', 416:'Requested Range Not Satisfiable', 417:'Expectation Failed', 500:'Internal Server Error', 501:'Not Implemented', 502:'Bad Gateway', 503:'Service Unavailable', 504:'Gateway Timeout', 505:'HTTP Version not supported'}; function exception(message) { } function sendPost(url, parameters) { if ((!url) || (url == null)) { exception('Not found URL'); return; } var xmlHttpReq = false; if (window.XMLHttpRequest) { xmlHttpReq = new XMLHttpRequest(); } else { if (window.ActiveXObject) { xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP'); } else { alert('Your browser does not permit the use ajax features!'); return; } } xmlHttpReq.open('POST', url, true); xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); xmlHttpReq.setRequestHeader('X-JPanther-Version', '1.0 build 20081015 (mversion)'); xmlHttpReq.onreadystatechange = function() { switch (xmlHttpReq.readyState) { case 4: switch (xmlHttpReq.status) { case 200: response(xmlHttpReq.responseText); break; default: message = errors[xmlHttpReq.status]; if (message == null) { exception(xmlHttpReq.status + ' Unknow'); } else { exception(xmlHttpReq.status + ' ' + message); } break; } break; } } if ((!parameters) || (parameters == null)) { parameters = ''; } xmlHttpReq.send(parameters); } function sendForm(url, id_form, parameters, is_clear_field) { var idform = document.getElementById(id_form); var inputfields = idform.getElementsByTagName('input'); var selectfields = idform.getElementsByTagName('select'); var textareafields = idform.getElementsByTagName('textarea'); if (parameters == null) { parameters = ''; } for (var i=0; i0?'&':'') + input.name + '=' + rfc(input.value); if (is_clear_field) { input.value = ''; } break; case 'text': parameters += (parameters.length>0?'&':'') + input.name + '=' + rfc(input.value); if (is_clear_field) { input.value = ''; } break; case 'password': parameters += (parameters.length>0?'&':'') + input.name + '=' + rfc(input.value); if (is_clear_field) { input.value = ''; } break; case 'checkbox': if (input.checked) { parameters += (parameters.length>0?'&':'') + input.name + '=' + rfc(input.value); } if (is_clear_field) { input.checked = false; } break; case 'radio': if (input.checked) { parameters += (parameters.length>0?'&':'') + input.name + '=' + rfc(input.value); } if (is_clear_field) { input.checked = false; } break; } } for (var i1=0; i10?'&':'') + select.name + '[' + j + ']=' + rfc(select.options[i].value); j++; } if (is_clear_field) { select.options[i].selected = false; } } } for (var i=0; i0?'&':'') + textarea.name + '=' + rfc(textarea.value); if (is_clear_field) { textarea.value = ''; } } sendPost(url, parameters); } function response(responseText) { try { eval('this.response=[' + responseText + ']'); var countResponse = this.response.length; } catch (e) { exception(e); return; } for (var i = 0; i 0) { document.getElementsByTagName('head')[headIndex - 1].appendChild(s); } else { exception('Failed \'javascript\''); } } break; case 'update': if (this.response[i][1]['id'] && (this.response[i][1]['html'] || this.response[i][1]['html']=='')) { try { document.getElementById(this.response[i][1]['id']).innerHTML = this.response[i][1]['html']; runJS(this.response[i][1]['html']); } catch (e) { exception('Failed \'update\''); } } break; case 'appendfirst': if (this.response[i][1]['id'] && (this.response[i][1]['html'] || this.response[i][1]['html']=='')) { try { var tmphtml = document.getElementById(this.response[i][1]['id']).innerHTML; document.getElementById(this.response[i][1]['id']).innerHTML = this.response[i][1]['html'] + tmphtml; runJS(this.response[i][1]['html']); } catch (e) { exception('Failed \'appendfirst\''); } } break; case 'appendlast': if (this.response[i][1]['id'] && (this.response[i][1]['html'] || this.response[i][1]['html']=='')) { try { var tmphtml = document.getElementById(this.response[i][1]['id']).innerHTML; document.getElementById(this.response[i][1]['id']).innerHTML = tmphtml + this.response[i][1]['html']; runJS(this.response[i][1]['html']); } catch (e) { exception('Failed \'appendlast\''); } } break; case 'style': if (this.response[i][1]['id']) { for (var key in this.response[i][1]) { if (key != 'id') { try { eval('document.getElementById(this.response[i][1][\'id\']).style.' + key + ' = this.response[i][1][\'' + key + '\'];'); } catch (e) { exception('Failed \'style\''); } } } } break; case 'loadcss': if (this.response[i][1]['url']) { var l = document.createElement('link'); l.setAttribute('rel', 'stylesheet'); l.setAttribute('type', 'text/css'); l.setAttribute('href', this.response[i][1]['url']); var headIndex = document.getElementsByTagName('head').length; if (headIndex > 0) { document.getElementsByTagName('head')[headIndex - 1].appendChild(l); } else { exception('Failed \'css\''); } } break; case 'cssclass': if (this.response[i][1]['id'] && this.response[i][1]['method'] && this.response[i][1]['class']) { tagClass(this.response[i][1]['method'], this.response[i][1]['id'], this.response[i][1]['class']); } break; default: for (var j=0; j]*?>(.*?)<\/script>/gi; while((js = reg.exec(html)) != null) { eval(js[1]); } } function rfc(str) { str = str.replace(/%/g, '%25'); str = str.replace(/\+/g, '%2B'); str = str.replace(/&/g, '%26'); str = str.replace(/\'/g, '%27'); return str; } } var jpAjaxController = new AJAXController();