var myHTTPRequest = undefined;

function newHTTPRequest() { // creates a new http-request-object and returns it
	if (window.XMLHttpRequest) { // Browser: Mozilla
		myHTTPRequest = new XMLHttpRequest();
		if (myHTTPRequest.overrideMimeType) {
			myHTTPRequest.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // Browser: MSIE
		try {
			myHTTPRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				myHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {}
		}
	}

	return myHTTPRequest;
}


function setContainerContent(theHTMLCode,theContainer) { // sets content of our container
	try {
		if (document.all)
			document.all[theContainer].innerHTML = theHTMLCode;
		if (document.layers)
			document.layers[theContainer].innerHTML = theHTMLCode;
		if (document.getElementById)
			document.getElementById(theContainer).innerHTML = theHTMLCode;
	} catch(e) {}
}


function ajaxAction(actionURL,targetContainer) {
	myHTTPRequest = undefined;
	myHTTPRequest = newHTTPRequest();

	var url = ajax_basedomain + actionURL;

	if (!myHTTPRequest) {
		// error - could not create HTTPRequest
		return false;
	}

	// setup callback function
	myHTTPRequest.onreadystatechange = function onreadystatechange() {
		if (myHTTPRequest.readyState == 1) { // ReadyState: Loading
			setContainerContent(ajax_messagewait,targetContainer);
		} else if (myHTTPRequest.readyState == 4) { // ReadyState: Completed
			if (myHTTPRequest.status == 200) { // HTTP-Status 200 = OK
				if (myHTTPRequest.responseText != '') { // ok, we have a reply
					// put new content into container
					setContainerContent(myHTTPRequest.responseText,targetContainer);
				} else {
					setContainerContent('debug '+myHTTPRequest.status+" - "+myHTTPRequest.readyState,targetContainer);
				}
			} else {
				// something went wrong - tell user it did not work out
				setContainerContent(ajax_errormessage,targetContainer);
			}
		}
	};

	// post the request
	myHTTPRequest.open('GET',url,true);
	myHTTPRequest.send(null);
}

