function xmlhttp(myname) { "use strict"; var $ajax_xmlhttp = false; var $ajax_callback = null; var $ajax_response = null; var _ajax_url = null; var _ajax_method = "GET"; // GET or POST var _ajax_mode = true; var _ajax_config = false; var _ajax_ctrl = null; var _ajax_responseText = null; var _ajax_responseType = null; var _ajax_myName = false; var _ajax_fifo = null; var _send_unselect = true; var _send_disabled = true var _send_stack = new Array(); this.dump = function() { var $alert = ""; $alert += "url: "+_ajax_url+"\n"; $alert += "mode: "+((_ajax_mode)?"true (async)":"false (sync)")+"\n"; $alert += "config: "+((_ajax_config)?"true":"false")+"\n"; $alert += "myName: "+((_ajax_myName)? _ajax_myName:"null")+"\n"; $alert += "callback: "+(($ajax_callback)? $ajax_callback:"null")+"\n"; alert($alert); } this.myName = function() { if ( _ajax_myName != false ) return true; for ( var o in window ) { if ( window[o] == this ) { _ajax_myName = o; return true; } } if ( _ajax_myName == false ) { alert("unable to install catch program\nobject not found in global name space\ndont use prefix \"var\" inside of functions"); $ajax_xmlhttp = false; return false; } if (typeof(window[_ajax_myName]) != "function") { alert(_ajax_myName+"::init() fatal error -- "+e); $ajax_xmlhttp = false; return false; } }; this.server = function(ctrl) { if (this.myName()) { if ( typeof(ctrl) != "undefined" ) { $ajax_xmlhttp.open("HEAD",ctrl,false); $ajax_xmlhttp.onreadystatechange = function() { if (this.readyState == this.DONE) { if (this.status != 200) { alert("fatal error -- " + this.status + " unable to access to server");// != 404); $ajax_xmlhttp = false; } } }; $ajax_xmlhttp.send(null); _ajax_url = ctrl; } else if (_ajax_url != null) { return _ajax_url; } else { $ajax_xmlhttp = false; return false; } } }; this.callback = function(ctrl) { if (typeof(ctrl) != "undefined") { this.myName(); $ajax_callback = ctrl; } else { $ajax_callback = null; } }; this.method = function(ctrl) { if (typeof(ctrl) != "undefined") { this.myName(); var UC_ctrl = ctrl.toUpperCase(); if ( UC_ctrl == "GET" || UC_ctrl == "POST" ) { _ajax_method = ctrl; } } }; this.mode = function(ctrl) { if(typeof(ctrl) == "boolean") ctrl = (ctrl===true) ? "sync":"async"; var lc_ctrl = (typeof(ctrl) != "undefined") ? ctrl.toLowerCase() : "async"; var choise = ",,sync,async,fifo,"; if (choise.indexOf(","+lc_ctrl+",") > 0) { _ajax_ctrl = lc_ctrl; } }; this.responseType = function(ctrl) { if ("responseType" in this) { _ajax_responseType = ctrl; } else { } } this.init = function (url, mycatch, type, mode) { this.myName(); if ( $ajax_xmlhttp ) { this.server(url); this.callback(mycatch); var $method = (typeof(type) != "undefined") ? type : "GET"; this.method($method); var $mode = (typeof(mode) != "undefined") ? mode : ((typeof($ajax_callback) === "function") ?false:true); this.mode($mode); this.config(); _ajax_config = true; if ($ajax_xmlhttp == false) return false; return true; } else { alert("xmlhttp.js [203] "+_ajax_myName+"::init fatal error -- no xmlhttp object"); return false; } }; this.xmlhttp_catch = function () { if ( $ajax_xmlhttp.readyState == 1 ) { } else if ( $ajax_xmlhttp.readyState == 4 && $ajax_xmlhttp.status != 0) { if ( $ajax_xmlhttp.status == 200 ) { _ajax_responseText = $ajax_xmlhttp.responseText; if ( typeof(this.responseText) == "string" ) { if ( _ajax_responseText.substr(0,2) == "({" ) { var $e; try { var answ = _ajax_responseText; if (answ.indexOf("\n") > -1) { var answ2 = answ.replace(/\n/g,' '); // replace \n by HTML-Code LF; $e = eval(answ2); } else { $e = eval(answ); } _ajax_responseText = $e; } catch(e) { var $alert = "error in 251"; $alert += "\n"+_ajax_responseText+"\n"; for ( var p in e ) { $alert += "\n"+p+" "+e[p]; } alert($alert); } } } if ( _ajax_mode == false ) { return; } if ( $ajax_callback !== null ) { $ajax_callback(_ajax_responseText); } else { alert("xmlhttp.js [274] "+_ajax_myName+"::xmlhttp_catch()\n catched:\""+_ajax_responseText+"\""); } } else { var $e = new Object(); $e["call"] = "error"; $e["HTMLstatus"] = $ajax_xmlhttp.status; $e["readyState"] = $ajax_xmlhttp.readyState; $e["responseText"] = $ajax_xmlhttp.responseText; $e["url"] = _ajax_url; $ajax_callback($e); } if ( typeof(_ajax_fifo) == "object" && _ajax_fifo !== null) { if ( _ajax_fifo.length > 0 ) { var url = _ajax_fifo.shift(); } if ( _ajax_fifo.length > 0 ) { if ( _ajax_method == "POST" ) { var text = _ajax_fifo[0]; $ajax_xmlhttp.open("POST",_ajax_url,_ajax_mode); if (_ajax_responseType != null && "responseType" in this) { $ajax_xmlhttp.responseType = _ajax_responseType; } $ajax_xmlhttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded"); $ajax_xmlhttp.setRequestHeader( "Content-length", text.length ); $ajax_xmlhttp.send(text); } else { var url = _ajax_fifo[0]; $ajax_xmlhttp.open("GET",url,true); $ajax_xmlhttp.send(null); } } } } else { } }; this.response = function() { if (typeof($ajax_xmlhttp.getResponseHeader) == "function") { } var answ = $ajax_xmlhttp.responseText; if ( answ.substr(0,2) == "({" ) { var $e; var $try = ""; try { if (answ.indexOf("\n") > -1) { $try = "try with LF"; var answ2 = answ.replace(/\n/g,' '); // replace \n by HTML-Code LF; $e = eval(answ2); } else { $try = "try without LF"; $e = eval(answ); } } catch(e) { var $alert = "error in 363 "+$try; $alert += "\n"+e; $alert += "\n"+answ+"\n"; for ( var p in e ) { $alert += "\n"+p+" "+e[p]; } alert($alert); } if ( typeof($e) == "object" ) { $e["HTMLstatus"] = 200; _ajax_responseText = $e; return $e; } } _ajax_responseText = $ajax_xmlhttp.responseText; return $ajax_xmlhttp.responseText; }; this.config = function() { this.myName(); if ( _ajax_ctrl == "sync" ) { _ajax_mode = false; _ajax_fifo = null; } else if ( _ajax_ctrl == "async" ) { _ajax_mode = true; _ajax_fifo = null; } else if ( _ajax_ctrl == "fifo" ) { _ajax_mode = true; _ajax_fifo = new Array(); } var p = _ajax_myName + ".response"; $ajax_response = eval(p); if ( _ajax_mode ) { $ajax_xmlhttp.onreadystatechange = this.xmlhttp_catch; } if ( _ajax_mode ) { if ( typeof($ajax_callback) == "function" ) { _ajax_config = true; return true; } else { alert("xmlhttp.js [420] "+_ajax_myName+"::init: fatal error -- schedule not defined "+typeof($ajax_callback)); $ajax_xmlhttp = false; return false; } } else { _ajax_config = true; return true; } }; this.push = function (o) { _send_stack.push(o); } this.send = function (o) { if (_ajax_config == false) { this.config(); } if (typeof(o) != "undefined") _send_stack.push(o); if ( $ajax_xmlhttp !== false ) { var xtr = ""; var texte = ""; var _http_text = ""; while (_send_stack.length > 0) { var _text = _send_stack.pop(); if ( typeof(_text) == "object" ) { if ( _text.tagName && _text.tagName == "FORM" ) { if (!_text.name) _text.name = "ajaxform_"+ Math.floor(Math.random()*10000); for ( var i = 0; i < document.forms[_text.name].elements.length; i++ ) { var cb = ""; if (document.forms[_text.name].elements[i].isArray) { } if (document.forms[_text.name].elements[i].name && document.forms[_text.name].elements[i].name != "") { var element_i = document.forms[_text.name].elements[i]; var vtmp = element_i.value; var t = encodeURIComponent(vtmp); var key = element_i.name; var type = element_i.type; var dis = element_i.disabled; var mm = xtr + key + "=" + t; if ( type == "radio" || type == "checkbox" ) { if (vtmp.indexOf("|") > 0) { if (element_i.checked == false) { mm = xtr + key + "=" + encodeURIComponent(vtmp.split("|")[1]); } else { mm = xtr + key + "=" + encodeURIComponent(vtmp.split("|")[0]); } } else { if (element_i.checked == false) mm = ""; } cb = "("+i+": \""+element_i.checked+"\")"; } if ( !_send_disabled && dis == true) mm=""; if ( !_send_disabled && type == "button") mm=""; if (mm != "") { _http_text += mm; xtr = "&"; } } } } else { for ( var key in _text ) { var tmp = _text[key]; var t = encodeURIComponent(tmp); var mm = xtr + key + "=" + t; _http_text += mm; xtr = "&"; } } } } if ( _ajax_method == "GET" ) { var url; if ( _http_text != "" ) { url = _ajax_url + ( ( _ajax_url.indexOf("?") > 0 ) ? "&" : "?" ) + _http_text; } if ( typeof(url) !== "undefined" ) { if ( typeof(_ajax_fifo) == "object" && _ajax_fifo !== null ) { var len = _ajax_fifo.push(url); if ( _ajax_fifo.length > 1 ) { } else { $ajax_xmlhttp.open("GET",url,true); $ajax_xmlhttp.send(null); } } else { $ajax_xmlhttp.open("GET",url,_ajax_mode); $ajax_xmlhttp.send(null); if (_ajax_mode) { return null; } else { $ret = this.response(); return $ret; } } } } else if ( _ajax_method == "POST" ) { if ( typeof(_http_text) != "undefined" ) { if (typeof(_ajax_fifo) == "object" && _ajax_fifo !== null) { var len = _ajax_fifo.push(_http_text); } if (_ajax_fifo !== null && _ajax_fifo.length > 1 ) { } else { $ajax_xmlhttp.open ( _ajax_method, _ajax_url, _ajax_mode ); if (_ajax_responseType != null && _ajax_mode) { $ajax_xmlhttp.responseType = _ajax_responseType; } $ajax_xmlhttp.setRequestHeader ( "Content-Type", "application/x-www-form-urlencoded"); $ajax_xmlhttp.setRequestHeader ( "Content-length", _http_text.length ); $ajax_xmlhttp.send(_http_text); if (_ajax_mode) return; var $ret = this.response(); return $ret; } } else { alert("xmlhttp.js [609] "+_ajax_myName+"::send() fatal error -- undefined request for POST"); return false; } } else { alert("xmlhttp.js [615] "+_ajax_myName+"::send() fatal error -- unsupported mode "+_ajax_method); return false; } } else { alert("xmlhttp.js [621] "+_ajax_myName+"::send fatal error -- no xmlhttp object"); return false; } }; this.show = function () { return _ajax_url; }; try { if ( window.XMLHttpRequest ) { $ajax_xmlhttp = new XMLHttpRequest(); } else if ( window.ActiveXObject ) { $ajax_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } } catch(e) {} if ( typeof($ajax_xmlhttp) != "object" ) { alert("fatal error -- Your browser does not support XMLHTTP."); $ajax_xmlhttp = false; return false; } if (typeof (myname) != "undefined") { _ajax_myName = myname; } } if ( typeof(view) == "undefined" ) { view = function() { var _argv = view.arguments; var e = _argv[0]; var n = (_argv.length > 1) ? _argv[1] : 0; n++; if ( typeof(e) == "object" ) { var _view = ""; var _sp = ""; for (i=0; i