var Class={
create: function() {
return function() { 
this.init.apply(this, arguments)
}
}
};
Function.prototype.bind=function(obj) {
var __method=this;
return function() { 
return __method.apply(obj, arguments)
}
};
Ajax=Class.create();
Ajax.prototype={
init: function(options) {
options.url=options.url.replace(/(#.*)$/, '');
this.params=options.params || '';
this.targetEl=options.targetEl || null;
this.onComplete=options.onComplete || null;
this.onError=options.onError || null;
this.errorEl=options.errorEl || null;
this.showIndicator=options.showIndicator || false;
this.url=options.url;
this.transport=this._getTransport();
this.cache=new Array();
this.userData=options.userData;
if (this.url && this.params) {
this._request(options.url);
}
},
_getTransport: function() {
return new XMLHttpRequest();
try {
return new XMLHttpRequest();
} catch (e) {
alert('Leider konnte keine XmlHttp-Verbindung aufgebaut werden. Bitte wende Dich unter "Hilfe und Kontakt" an den Support.\nCouldn\'n open a XmlHttp-Connection. Please contact us at "Help and Contact".');
}
},
request: function(params) {
if (this.cacheRequest(params)) return true;
this._request(this.url);
},
cacheRequest: function(params) {
this.params=params;
if (this.cache[params]) {
this.responseText=this.cache[params];
this._onComplete();
return true;
}
return false;
},
_request: function(url) {
this.transport.open('post', url, true);
this.transport.onreadystatechange=this._onChange.bind(this);
this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
var params=this.params;
params += '&_charset_=UTF-8';
this.transport.send(params);
if (this.showIndicator) {
this.targetEl.innerHTML='<div class="ajaxIndicator"></div>';
}
},
_onChange: function() {
if (this.transport.readyState == 4 && this.transport.status == 200) {
this.responseText=this.transport.responseText;
this.cache[this.params]=this.responseText;
this._onComplete();
this.transport.onreadystatechange=function() {};
} 
if (this.transport.readyState == 4 && this.transport.status != 200) {
if (this.errorEl) {
setTimeout(function() { 
this.errorEl.innerHTML=this.transport.responseText;
if (this.errorEl.scrollIntoView) {
this.errorEl.scrollIntoView(true);
}	
}.bind(this), 23);
}
if (this.onError)  {
setTimeout(function(){ this.onError(this.transport)}.bind(this), 23);
}
this.transport.onreadystatechange=function() {};
}
},
_onComplete: function() {
if (this.onComplete) {
setTimeout(function(){ this.onComplete(this.transport)}.bind(this), 23);
}
else if (this.targetEl) {
setTimeout(function() { this.targetEl.innerHTML=this.responseText; 
if (typeof this.targetEl.scrollIntoView !='undefined'){this.targetEl.scrollIntoView(true);	}}.bind(this), 23);
}
}
};

