Function.prototype.bindAJAX = function() {
	if (arguments.length < 2 && arguments[0] === undefined) {
		return this;
	}
	var __method = this, args = [], argnum = arguments.length, arg = 0, object = null;
	for (arg = 0; arg < argnum; arg++) {
		arg ? args.push(arguments[arg]) : object = arguments[arg];
	}
	return function() { return __method.apply(object, args); }
};
var AJAX = {
	'XML': 1,
	'STREAMING' : 2,
	'PERSISTENT' : 4,
	'SYNCHRONOUS': 8,
	'clients': [],
	'count': 0,
	'server': false,
	'backPath': '',
	'lang': 'default',
	'beuser': 0,
	'configure': function(params) {
		for (var p in params) {
			this[p] = params[p];
		}
	},
	'params': function (prm, pre) {
		var ps = '',
			pf = (typeof(pre) == 'string') ? pre : '',
			pn;
		if (typeof(prm) == 'object') {
			for(p in prm) { 
				if(typeof(prm[p]) == 'function') continue;
				pn = pf ? (pf + '[' + p + ']') : p;
				if (typeof(prm[p]) == 'object') { 
					ps += AJAX.params(prm[p], pn);
				} else { 
					ps += '&' + pn + '=' + encodeURIComponent(prm[p]);
				}
			}
		}
		return ps;
	},
	'transport': function() {
		var xO;
		try {
			xO = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xO = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (oc) {
				xO = null;
			}
		};
		if (!xO && (typeof XMLHttpRequest != 'undefined')) {
			xO = new XMLHttpRequest();
		}
		return xO ? {'_transport' : xO} : null;
	},
	
	'client': function (hdl, options, url) {
		var transport = AJAX.transport();
		transport._persistent	= (options & AJAX.PERSISTENT) > 0;
		transport._streaming	= (options & AJAX.STREAMING) > 0;
		transport._synchronous	= (options & AJAX.SYNCHRONOUS) > 0;
		transport._xml			= (options & AJAX.XML) > 0;
		transport._server		= url;
		transport._id			= AJAX.clients.length;
		transport.query			= false;
		transport.result		= null;
		transport.responseText	= null;
		transport.responseXML	= null;
		transport.readyState	= 0;
		
		if (typeof(hdl) == 'function') {
			transport._handler	= hdl;
		} else if (hdl) {
			if (self[hdl]) {
				transport._handler	= self[hdl];
			} else {
				transport._handler	= new Function('ajax', hdl);
			}
		} else {
			transport._handler	= function() {};
		}
		
		if (!transport._handler) {
			transport._orsc		= function() {};
		} else {
			transport._orsc		= function() {
				this.readyState		= this._transport.readyState;
				this.responseText	= this._transport.responseText;
				this.responseXML	= this._transport.responseXML;
				if (this._streaming ? (this.readyState < 3) : (this.readyState != 4)) {
					return;
				}
				if (this._xml) {
					this.result = this.responseXML;
				} else {
					eval(this.responseText);
					this.result = result;
				}
				this._handler(this);
				this.query			= false;
				if (!this._persistent && (this.readyState == 4)) {
					AJAX.kill(this._id);
				}
			}
		}

		transport.request		= function(params) {
			params = (typeof(params) != 'object') ? {} : params;
			params['backPath']	= AJAX.backPath;
			params['lang']		= AJAX.lang;
			params['beuser']	= AJAX.beuser;
			this.query = this._server + AJAX.params(params);
			this._transport.open('GET', this.query, !this._synchronous);
			this._transport.onreadystatechange = this._orsc.bindAJAX(transport);
			this._transport.send(null);
			if (this._synchronous && this._orsc) {
				this._orsc.apply(transport);
			}
			return this._synchronous ? this.result : true;
		}
		
		this.clients.push(transport);
		++this.count;
		return transport;
	},
	'kill': function(id) {
		delete this.clients[id];
		--this.count;
	},
	'request': function(params, hdl, options, url) { 
		var client = AJAX.client(hdl, (typeof(options) == 'undefined') ? 0 : options, (((typeof(url) == 'undefined') || !url) ? AJAX.server : url));
		return params ? client.request(params) : client;
	},
	'tce': function(data, cmd, options) {
		var params = {'cmd':'EXT:tw_betools/class.tx_twbetools_ajax.php:tx_twbetools_ajax::tce', 'tce':{'data': data || {}, 'cmd': cmd || {}}};
		return this.request(params, false, options);
	}
};
AJAX.configure({'server':'http://www.tools-promotion.de/index.php?type=187','backPath':false,'lang':'de','beuser':0});;
