function AJAX (id,url,handler,type,method,parameters,text,showProgress) {
	this.id = id;
	this.url = url;
	if (handler instanceof Array) {
		this.handler = handler[0];
		this.context = handler[1];
	} else
		this.handler = handler;
	this.type = type;
	this.method = method;
	this.parameters = parameters;
	this.showProgress = showProgress;
	this.status = 0;
	this.request = 0;
	this.supported = true;
	if (global.console != null) {
		text = text ? text : "Lade ...";
		global.console.addLoader(text);
		this.text = text;
	}
	
	if (global.activeWindowLoaded == false) global.asyncStack = this.id;
	
	this.load();
}

AJAX.prototype.load = function () {
	var self = this;
	this.AJAXObject = null;
	try {
		this.AJAXObject = new XMLHttpRequest();
	} catch (e) {
		try {
			this.AJAXObject = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			this.AJAXObject = "Browserfehler: Ihr Browser unterstützt AJAX nicht.";
			this.supported = false;
			return this.AJAXObject;
		}
	}
	
	// Parameter encoden (Parameter müssen als Array übergeben worden sein) (nur, wenn nicht vom Typ file)
	
	if (this.method !== "file" && this.parameters instanceof Object) {
		var parameters = [];
		
		for (key in this.parameters) {
			parameters.push(encodeURIComponent(key) + "=" + encodeURIComponent(this.parameters[key]));
		}
		
		this.parameters = parameters.join("&");
	}
	
	if (this.method === "file") {
		this.AJAXObject.open("post",this.url,true);
		this.AJAXObject.send(this.parameters);
	} else if (this.method === "get") {
		this.AJAXObject.open("get",this.url + "?" + this.parameters,true);
		this.AJAXObject.send(null);
	} else if (this.method === "post") {
		this.AJAXObject.open("post",this.url,true);
		this.AJAXObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.AJAXObject.send(this.parameters);
	}
	
	if (typeof this.showProgress !== "undefined" && this.showProgress) {
		this.AJAXObject.upload.addEventListener("progress",function (event) {
			if (event.lengthComputable) {
				var status = parseInt((event.loaded / event.total) * 100);
				if (global.console != null) {
					global.console.addLoader(self.text + " (" + status + " %)");
				}
								
				if (status === 100 && self.onFinishUpload instanceof Function) {
					self.onFinishUpload();
				}
			}
		});
	}
	
	this.AJAXObject.onreadystatechange = function () { self.change.call(self); };
}

AJAX.prototype.change = function () {
	this.status = this.AJAXObject.readyState;
	this.request = this.AJAXObject.status;
	if (this.AJAXObject.readyState == 4) {
		if (global.console != null)
			global.console.finishLoader();
		
		
		this.success = true;
				
		if (this.AJAXObject.responseXML.getElementsByTagName("success")[0].firstChild.data == "false" && global.console != null) {
			for (var i = 0; i < this.AJAXObject.responseXML.getElementsByTagName("errormsg").length; i++) {
				this.success = false;
				global.console.addError(201,this.AJAXObject.responseXML.getElementsByTagName("errormsg")[i].firstChild.data);
			}
		}
		
		for (var i = 0; i < this.AJAXObject.responseXML.getElementsByTagName("warningmsg").length; i++) {
			global.console.addWarning(201,this.AJAXObject.responseXML.getElementsByTagName("warningmsg")[i].firstChild.data);
		}
				
		if (this.handler instanceof Function) {
			if (this.context) {
				this.handler.call(this.context,this.success,this.AJAXObject.responseXML);
			} else
				this.handler(this.success,this.AJAXObject.responseXML);
		}
		global.asyncStack = this.id;
	}
}
