
function AjaxHandler(mtd,handler,debug,displayErrors,addRequestVars)
{this.async_image='/images/loading.gif';this.async_msg='';this._method=mtd;this._handler=handler;this._debug=debug;this._displayErrors=displayErrors;this._addRequestVars=addRequestVars;this.call=function(func,params)
{var data=this._prepareData(func,params);var xmlHttpRequest=this._getXmlHttpRequestObject();var finalData=this._prepareXmlHttpRequest(xmlHttpRequest,params,data);xmlHttpRequest.send(finalData);if(!this._paramsHaveCallbackFunction(params))
return this._decodeResponse(xmlHttpRequest.responseText).response;}
this.getTagWithId=function(id)
{var tag=$(id);if(!tag)
alert("Tag with id '"+id+"' not found!");return tag;}
this.replace=function(id,content)
{this.getTagWithId(id).update(content);}
this.replaceSync=function(id,func,params)
{var parameters=new Array();for(var i=2;i<this.replaceSync.arguments.length;++i)
parameters.push(this.replaceSync.arguments[i]);ajax.replace(id,ajax.call(func,parameters));}
this.replaceAsync=function(id,func,params)
{this.showLoader(id);var parameters=new Array();for(var i=2;i<this.replaceAsync.arguments.length;++i)
parameters.push(this.replaceAsync.arguments[i]);parameters.push(function(content){ajax.replace(id,content);});ajax.call(func,parameters);}
this.showLoader=function(id)
{if(this.async_image)
sync_wait='<img src="'+this.async_image+'" class="img_middle">&nbsp;';if(this.async_msg)
sync_wait+=this.async_msg;if(sync_wait)
this.replace(id,sync_wait);}
this.getFormData=function(form)
{if(typeof form=='string')
form=$(form);if(!form)
return;var parameters=new Object();for(i=0;form.elements[i];++i)
{var element=form.elements[i];if(element.name)
{var value=element.value;switch(element.type)
{case'checkbox':if(element.checked){value=element.value?element.value:'on';}
else
continue;break;case'radio':if(!element.checked)
continue;break;}
if(element.name.match(/\[\]$/))
{var name=element.name.replace(/\[\]$/,'');if(!parameters[name])
parameters[name]=new Array();if(element.options)
{for(j=0;element.options[j];++j)
if(element.options[j].selected)
parameters[name].push(element.options[j].value);}
else
{if(element.value&&element.checked)
parameters[name].push(element.value);else
parameters[name].push(value);}}
else
parameters[element.name]=value;}}
return parameters;}
this._getXmlHttpRequestObject=function()
{var xmlHttpRequest=false;if(window.XMLHttpRequest){xmlHttpRequest=new XMLHttpRequest();}
else if(window.ActiveXObject){try{xmlHttpRequest=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e)
{try{xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){}}}
if(xmlHttpRequest.overrideMimeType){xmlHttpRequest.overrideMimeType("text/json");}
return xmlHttpRequest;}
this._prepareXmlHttpRequest=function(xmlHttpRequest,params,data)
{var callbackFunction=this._getCallbackFunction(params);var handler;var finalData;var load_js_files=0;if(this._method=='GET')
{handler=this._handler+'?'+data+'&'+this._addRequestVars;finalData=null;}
else{handler=this._handler;finalData=data+'&'+this._addRequestVars;}
xmlHttpRequest.open(this._method,handler,callbackFunction!=null);if(this._method=="POST")
{xmlHttpRequest.setRequestHeader("Method","POST "+this._handler+" HTTP/1.1");xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xmlHttpRequest.setRequestHeader("Content-Length",finalData.length);}
xmlHttpRequest.onreadystatechange=function()
{if(xmlHttpRequest.readyState==4)
{try
{var response=ajax._decodeResponse(xmlHttpRequest.responseText);if(!response&&ajax._displayErrors){alert("AJAX error:\n"+'leere Antwort erhalten');return;}
else if(!response)
return;}
catch(e)
{if(ajax._displayErrors)
alert("AJAX error:\nUnknown response from server!\n\n"+xmlHttpRequest.responseText);return;}
if(response.errorCode==0&&callbackFunction!=null){if(ajax._debug){alert("AJAX debug info:\n\nServer response: "+xmlHttpRequest.responseText);}
if(response.js_files.length>0){load_js_files+=response.js_files.length;response.js_files.map(function(file){var script_tags=$$('script');for(i=0;script_tags[i];++i)
{if(!script_tags[i].src){continue;}
if(script_tags[i].src.match(file)){load_js_files--;return;}}
var js_element=new Element("script",{'language':'JavaScript','type':'text/javascript','src':file}).observe('load',function(){load_js_files--;});var head=$$('head')[0];head.appendChild(js_element);});}
if(load_js_files==0)
callbackFunction(response.response);else{var load_js_files_interval=neu=window.setInterval(function(){if(load_js_files==0){window.clearInterval(load_js_files_interval);callbackFunction(response.response);}},100);}}
else if(response.errorCode!=0&&ajax._displayErrors){alert("AJAX error:\n"+response.errorMessage);}}}
return finalData;}
this._paramsHaveCallbackFunction=function(params)
{if(typeof(params)=="object"&&params.length>0)
return(typeof(params[params.length-1])=="function");return false;}
this._getCallbackFunction=function(params)
{if(this._paramsHaveCallbackFunction(params))
return params[params.length-1];return null;}
this._prepareParams=function(params)
{var preparedParams=new Array();if(typeof(params)=="object"&&params.length>0)
{var end=this._paramsHaveCallbackFunction(params)?1:0;for(var i=0;i<params.length-end;i++)
preparedParams.push(params[i]);}
return preparedParams;}
this._prepareData=function(func,params)
{var data=new Object();data["params"]=this._prepareParams(params);data["func"]=func;return"ajax="+encodeURIComponent(Object.toJSON(data));}
this._decodeResponse=function(responseText)
{return responseText.evalJSON(false);}}

// Cache: 2012-02-08 07:04:18 | MTime: 2010-05-21 11:57:42 | Packer: JSMin | AjaxHandler.class.js

/**
 * Compressed by Runtime-Minimizer | © 2011 by PHPdevelopment.de
 */
