

function request_object()
{
	this.counter=0;
	this.time2url=false;
	this.param=new function() { this.name=new Array(); this.value=new Array(); }
	
	this.setoptions = function(arg)
	{
		if (arg[0])	this.url	=	arg[0];	else if (!this.url)	this.url	=	'';
		if (arg[1])	this.func	=	arg[1];	else if (!this.func)	this.func	=	false;
		if (arg[2])	this.start	=	arg[2];	else if (!this.start)	this.start	=	false;
		if (arg[3])	this.methode	=	arg[3];	else if (!this.methode)	this.methode	=	'GET';
		if (arg[4])	this.asynchr	=	arg[4];	else if (!this.asynchr)	this.asynchr	=	true;
	}
	
	this.request = function()
	{
		this.setoptions(this.request.arguments);
		this.counter++;
		ajax.request(this.url, this.func, this.methode, this.paramstring(), this.asynchr, this.time2url);
	}
	
	this.setparam = function(name, value)
	{
		var pos=this.param.name.length;
		this.param.name[pos]=name;
		this.param.value[pos]=value;
	}
	
	this.seturl = function(url)
	{
		this.url=url;
	}
	
	this.setfunction = function(func)
	{
		this.func=func;
	}
	
	this.setmethode = function(methode)
	{
		this.methode=methode;
	}
	
	this.setasynchronous = function(asynchr)
	{
		this.asynchr=asynchr;
	}
	
	this.addtime2url = function()
	{
		if (this.addtime2url.arguments.length > 0)
		this.time2url=this.addtime2url.arguments[0];
		
		else
		this.time2url=true;
	}
	
	this.paramstring = function()
	{
		var str='';
		
		for (a=0; this.param.name[a]; a++)
		{
			if (a > 0) str+='&';
			str+=encodeURIComponent(this.param.name[a])+'='+encodeURIComponent(this.param.value[a]);
		}
		
		return str;
	}
	
	this.setoptions(request_object.arguments);
	if (this.start) this.request();
}




var ajax=new function()
{
	this.arr=new Array();
	
	this.request = function(url, func, methode, parameters, asynchronous, time2url)
	{
		if (!this.request.arguments[2]) methode='GET';
		if (!this.request.arguments[3]) parameters='';
		if (!this.request.arguments[4]) asynchronous=true;
		if (!this.request.arguments[5]) time2url=false;
		
		var now = new Date();
		var urltime='time'+now.getTime()+'='+now.getTime();
		
		if (url.indexOf('?') == -1) var urlsuffix='?';
		else var urlsuffix='&';
		
		var pos=ajax.arr.length;
		ajax.arr[pos]=new function() { this.XHR=ajax.new_XHR_object(); }
		ajax.arr[pos].func=func;
		ajax.arr[pos].XHR.onreadystatechange=new Function('if (ajax.arr['+pos+'].XHR.readyState == 4) { if (ajax.arr['+pos+'].func != false) { if (ajax.arr['+pos+'].XHR.status == 200) { ajax.arr['+pos+'].func(ajax.arr['+pos+'].XHR, '+pos+'); } else { ajax.arr['+pos+'].func(false); } } } ');
		
		if (methode == 'GET' && parameters != '')
		{
			var urlstring=url+urlsuffix+parameters;
			if (time2url) urlstring+='&'+urltime;
		}
		else
		{
			var urlstring=url;
			if (time2url) urlstring+=urlsuffix+urltime;
		}
		
		if (methode == 'POST' && parameters != '') var postparameters=parameters;
		else var postparameters=null;
		
		ajax.arr[pos].XHR.open(methode, urlstring, asynchronous);
		if (methode == 'POST') ajax.arr[pos].XHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		//ajax.arr[pos].XHR.setRequestHeader('Cache-Control', 'no-cache');
		ajax.arr[pos].XHR.send(parameters);
	}
	
	this.new_XHR_object = function()
	{
		var http_request = null;

		if(window.XMLHttpRequest) // Not IE
		{
			http_request = new XMLHttpRequest();

			if (http_request.overrideMimeType)
			{
				http_request.overrideMimeType('text/xml');
			}

			return http_request;
		}
		else if(window.ActiveXObject) // IE
		{
			try
			{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {}
			}

			return http_request;
		}
		else
		{
			alert("Your browser doesn't support the XmlHttpRequest object. Better upgrade to Firefox.");
		}
	}
}

