// JavaScript Document

var RED_Ajax = {
	req 		: null,
	url			: null,
	method		: 'GET',
	async		: true,
	body		: null,
	headers		: [],
	timer		: null,
	
	responseXML		: null,
	responseText	: null,
	
	init		: function()
					{
						this.req = (window.XMLHttpRequest)
									?
									new XMLHttpRequest()
									:
									((window.ActiveXObject)
									?
									new ActiveXObject('Microsoft.XMLHTTP')
									:
									null
									);
						if(this.req != null)
						{
							this.req.onreadystatechange = this.response;
							//this.req.onreadystatechange = function(){alert(42)};
						}
					},
	run			: function(u,m,f,b)
					{
						this.method = m || this.method;
						this.async = f || this.async;
						this.body = b || this.body;
						
						this.url = u;
						
						if(this.req != null)
						{
							this.req.open(this.method, this.url, this.async);
							if(this.headers.length > 0)
							{
								for(var i=0; i<this.headers.length; i+=2)
								{
									this.req.setRequestHeader(this.headers[i], this.headers[i+1]);
								}
							}
							this.req.send(this.body);
						}
					},
	header		: function(k,v)
					{
						if(k != null)
						{
							this.headers.push(k);
							this.headers.push(v);
						}
					},
	response	: function()
					{
						var a = RED_Ajax.req;
						
						switch(a.readyState)
						{
							case 1:
								break;
							case 2:
								this.timer = window.setTimeout('this.error', 10000);
								break;
							case 3: 
								this.timer = window.setTimeout('this.error', 10000);
								break;
							case 4:
								window.clearTimeout(this.timer);
								
								if(a.status==200 || a.statusText=='OK')
								{
									RED_Ajax.responseXML = a.responseXML;
									RED_Ajax.responseText = a.responseText;
									
									RED_Ajax.callback();
								}
						}
					},
	callback	: function(){},
	error		: function()
						{
							alert('Die Zeit ist um!');
							this.req.abort();
						},
	update		: function(){}
}
