// JavaScript Document
// Ajax connection

var brakepoint = 'victor';
var ajaxRequest = function(u, m, s)
{

	this.url		= u;
	this.method		= m || "GET";
	this.async		= s || true;
	this.body		= null;
	this.head		= false;
	
	var _this = this;
	
	//------------------------------------------------------------
	try {
		this.request = new XMLHttpRequest();	
	}catch(e){
		try {
			this.request = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			this.request = false;	
		}
	}
	
	//------------------------------------------------------------
	this.doRequest = function()
	{
		if(!this.url)
		{
			this.onError("keine URL gesetzt");
			return false;
		}
		if(!this.method)
		{
			this.method = "GET";
		}else{
			this.method = this.method.toUpperCase();
		}
		if(!this.request)
		{
			this.onError("kein Verbindungsobjekt gesetzt");
			return false;
		}
		
		this.request.open(this.method, this.url, this.async);
		
		if(this.method == "POST")
		{
			this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
		}
		if(this.head)
		{
			for(var i=0; i<this.head.length; i+=2)
			{
				this.request.setRequestHeader(this.head[i], this.head[i+1]);
			}
		}
		this.request.onreadystatechange = this.checkState;
		this.request.send(this.body);
	}
	
	//------------------------------------------------------------
	this.onSuccess = function(txt, xml)
	{
	//	alert(txt);
	}
	
	//------------------------------------------------------------
	this.onError = function(msg)
	{
		//alert("Fehler: "+msg);
	}
	
	//------------------------------------------------------------
	this.checkState = function()
	{
		if(_this.request.readyState<4)
		{
			return false;
		}
		if(_this.request.status==200 || _this.request.status == 304)
		{
			_this.onSuccess(_this.request.responseText, _this.request.responseXML);
		}
		else
		{
	//		_this.onError("Fehler bei der Datenuebertragung");
		}
	}
}
