var ajax = new Object();
var handle = 0;

ajax.laden = function (url,post_data,func) {
	this.url = url;
	this.post_data = post_data;
	this.xhr = null;
	this.onload = func;
	this.loadXMLDoc(url,post_data);
}

ajax.laden.prototype = {
	loadXMLDoc:function(url,post_data) {
		try {
			this.xhr = new ActiveXObject ("MSXML2.XMLHTTP");
		} catch (e) {
			try {
				this.xhr = new ActiveXObject ("Microsoft.XMLHTTP");
			} catch (E) {
				this.xhr = false;
			}
		}
		if (!this.xhr && typeof XMLHttpRequest != "undefinded") {
			this.xhr = new XMLHttpRequest();
		}
		if (this.xhr) {
			if (post_data == "") post_data = null;
			try {
				var loader = this;
				this.xhr.onreadystatechange=function() {
					loader.onReadyState.call(loader);
				}
				this.xhr.open("POST",url,true);
				this.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				this.xhr.send(encodeURI(post_data));
			} catch (err) {
				alert("FEHLER");
			}
		}
	},
	onReadyState:function(){
		var xhr=this.xhr;
		var ready= xhr.readyState;
		var httpStatus = "";
		if (ready == 4) {
			httpStatus = xhr.status;
			if (httpStatus == 200 || httpStatus==0) {
				this.onload.call(this);
			}else {
				alert("HTTPREQUESTFEHLER!!!");
			}
		}
	}
}
function setMain() {
	responseText = this.xhr.responseText;
	responseXML = this.xhr.responseXML;
//	alert(response);
//	document.getElementById("haupt").innerHTML=response;
}

function sendFormular (uri, formular, content, funktion) {
	var x = 0;
	var str = "";
	for (x=0; x < formular.elements.length;x++) {
		switch(formular.elements[x].type) {
			case "text":
			case "textarea":
			case "hidden":
			case "password":
				str += formular.elements[x].name + "=" + escape(formular.elements[x].value) + "&";
				break;
			case "checkbox":
				if (formular.elements[x].checked) {
					str += formular.elements[x].name + "=" + escape(formular.elements[x].value) + "&";
				}
				break;
			case "select-one":
				str += formular.elements[x].name + "=" + formular.elements[x].options[formular.elements[x].selectedIndex].value + "&";
				break;
		}
	}
	str = str.substr(0,(str.length - 1));
	if (content != "") str += content;
	test = new ajax.laden (uri,str,funktion);
}
