var ajaxCallOn = 0; var ajaxCallOff = 0; var maintainanceArr = new Array(); function encodeStr(str){ if(isNaN(str) && !isArray(str) && typeof(str)!='function') { str = str.replace(/&/g, '##AND##'); str = str.replace('=', '##EQUAL##'); str = str.replace('?', '##QUESTION##'); str = str.replace('%', '##PERCENT##'); } return str; } function decodeStr(str){ str = str.replace('##AND##', '&'); str = str.replace('##EQUAL##', '='); str = str.replace('##QUESTION##', '?'); str = str.replace('##PERCENT##','%'); return str; } function AjaxInit(){ var AjaxObj = false; if(window.XMLHttpRequest){ AjaxObj = new XMLHttpRequest(); }else if(window.ActiveXObject){ AjaxObj=new ActiveXObject("Msxml2.XMLHTTP"); if (!AjaxObj){ AjaxObj=new ActiveXObject("Microsoft.XMLHTTP"); } } return(AjaxObj); } function ajaxVars(){ this.vars = new Array(); this.fnVars = new Array(); this.dbVars = new Array(); this.sendMethod = 'POST'; this.gotoFunction = ''; this.xmlData = ''; this.status = 'loadingDiv'; this.AjaxPostSQL = AjaxPostSQL; this.createData = createData; this.errorData = errorData; this.sqlTracer = sqlTracer; this.xmlOpener = xmlOpener; this.maintainance = maintainance; this.externalErrors = externalErrors; this.phpFile = "/lib/ajax.data.php"; } function AjaxPostSQL(){ var pageUrl = this.phpFile; if(pageUrl.indexOf('?') < 0) { pageUrl += '?'; }else{ pageUrl += '&'; } pageUrl += 'random=' + Math.random(); var queryStr = '&dbVars=' + this.dbVars; for(key in this.vars){ queryStr += '&' + key + '=' + encodeStr(this.vars[key]); } if(this.sendMethod == 'GET') { pageUrl += queryStr; } var Ajax = AjaxInit(); try{ var callObj = this; Ajax.open(this.sendMethod, pageUrl); Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-1'); str = ''; for(key in Ajax) { str += key + "\n"; } Ajax.onreadystatechange = function(){ var loadingObj = document.getElementById(callObj.status); if (Ajax.readyState == 4 && (Ajax.status == 200)){ if(loadingObj){ loadingObj.innerHTML = 'Fertig.'; showStatusNew(loadingObj.id,'Fertig'); } handleAjax(Ajax, callObj); }else if(Ajax.readyState == 1){ if(loadingObj){ showStatusNew(loadingObj.id, 'Die Verbindung mit dem Server wird aufgebaut. Bitte haben Sie einen Moment Geduld.'); //loadingObj.innerHTML = "Die Verbindung mit dem Server wird aufgebaut. Bitte haben Sie einen Moment Geduld."; } }else if(Ajax.readyState < 4){ if(loadingObj){ showStatusNew(loadingObj.id, 'Die Daten werden geladen. Bitte haben Sie einen Moment Geduld.'); //loadingObj.innerHTML = "Die Daten werden geladen. Bitte haben Sie einen Moment Geduld."; } }else{ var statusLostObj = document.getElementById('statusLost'); if(statusLostObj){ statusLostObj.style.visibility = 'visible'; statusLostObj.style.display = 'block'; } } } Ajax.send(queryStr); } catch(e){ alert('Error: Unable to contact the server.'); } } function handleAjax(Ajax, callObj){ var response = Ajax.responseXML.documentElement; var dataObj = response.getElementsByTagName('row'); var errorObj = response.getElementsByTagName('sqlerror'); var textObj = response.getElementsByTagName('textdata'); switch(callObj.vars['action']) { case "update": case "modify": if(Ajax.responseText.indexOf('maintainance()') >= 0){ callObj.maintainance(); break; } } dataArr = callObj.createData(dataObj,textObj); callObj.errorData(errorObj, dataObj, textObj); callObj.xmlData = Ajax.responseText; var xmlLinkObj = document.getElementById('xmlLink'); if(xmlLinkObj) { xmlLinkObj.href = "javascript:void(0);"; xmlLinkObj.mainObj = callObj; xmlLinkObj.onclick = function(e) { var hiddenObj = document.getElementById('xmlajaxdata'); hiddenObj.value = this.mainObj.xmlData; this.mainObj.xmlOpener(); } } eval(callObj.gotoFunction + '(dataArr, callObj.fnVars)'); } function createData(rowObj, textObj){ if(rowObj.length > 0) { var str = ''; var dataArr = new Array(); var str = ''; for(var i=0; i 0) { var errLen = errorTags.length; for(var i=0; i 0) { var ajaxVar = new ajaxVars(); ajaxVar.vars['sql_type'] = "select"; ajaxVar.vars['sql_what'] = "id, filename,count(filename)"; ajaxVar.vars['sql_from'] = "binary_data"; ajaxVar.vars['sql_where'] = "and active=1 and parent_id=0 and table_name!='category'"; ajaxVar.vars['sql_where'] += "and (filename like '"+txt+"%')"; ajaxVar.vars['sql_group'] = "filename"; ajaxVar.vars['action'] = "db_fetch_array"; ajaxVar.gotoFunction = 'createSelect'; ajaxVar.fnVars['txtObj'] = txtObj; ajaxVar.AjaxPostSQL(); } } function createSelect(dataArr, fnVars){ var selObjArr = document.getElementsByTagName('select'); for(i=0;i= 0){ this.txtObj.value = this.options[this.selectedIndex].text; } } } } } function hideStatusNew(divId, err){ var loadingObj = document.getElementById(divId); if(loadingObj) { loadingObj.style.visibility = 'hidden'; loadingObj.style.cursor = 'default'; loadingObj.innerHTML = err; // loadingObj.childNodes[1].innerHTML = err; } } function showStatusNew(divId, err){ var bodyObj = document.getElementsByTagName('body')[0]; var divObj = document.getElementById('statusMsg'); if(!divObj){ var divObj = document.createElement('DIV'); divObj.id = "statusMsg"; divObj.className = 'msgAlert'; divObj.style.top = "0px"; } divObj.innerHTML = ''+err+'    '; bodyObj.insertBefore(divObj, bodyObj.firstChild); var sLeft = parseInt(bodyObj.offsetWidth,10) - parseInt(divObj.offsetWidth,10); divObj.style.left = sLeft + 'px'; setTimeout("remMyAlert()",1000); } function remMyAlert() { var bodyObj = document.getElementsByTagName('body')[0]; var statusObj = document.getElementById('statusMsg'); if(statusObj){ bodyObj.removeChild(statusObj); } }