
function ajaxClassCall(phpClass, classMethod, params, targetId) {
	var myFunction = function(){
		var req = new Request({
			method: 'get',
			url: 'index.php',
			onComplete: function(reqContent) {
				if ($(targetId) == null) alert("target nicht gefunden: "+ targetId);
				$(targetId).empty();
				$(targetId).innerHTML = reqContent.replace("&amp;", "&");
			}
		});
		req.send("class="+phpClass+"&method="+classMethod+"&params="+params);
	};
	myFunction.delay(50);
}

function ajaxClassCallFeedback(phpClass, classMethod, params, targetId) {
	//show progressbar
	var size = $(targetId).getSize();
	var daElement = new Element("div", {style: "padding-bottom: "+ (size.y / 2) +"px; width: "+ (size.x) +"px; padding-top: "+ (size.y / 2) +"px;  position: absolute; z-index: 5; background-color: #CCC; height: 10px; opacity: 0.6; text-align: center;"});
	daElement.set("class", "pageloader");
	daElement.innerHTML = "<img src=\"/resources/icons/progressbar_microsoft.gif\" alt=\"wait ...\" />";
	daElement.inject($(targetId), "top");

	// send request
	ajaxClassCall(phpClass, classMethod, params, targetId);
}

function ajaxClassCallSmallFeedback(phpClass, classMethod, params, targetId) {
	//show progressbar
	var size = $(targetId).getSize();
	var daElement = new Element("div", {style: "width: "+ (size.x) +"px; height: "+ (size.y) +"; position: absolute; z-index: 5; overflow: hidden; background-color: #CCC; opacity: 0.6; text-align: center;"});
	daElement.innerHTML = "<img src=\"/resources/icons/progressbar_microsoft.gif\" alt=\"wait ...\" />";
	daElement.inject($(targetId), "top");

	// send request
	ajaxClassCall(phpClass, classMethod, params, targetId);
}

function ajaxJsonRequest(className, method, params, path) {
		var req = new Request.JSON({
			url: "index.php?class="+className+"&method="+method+"&params="+params+"&path="+path,
			onComplete: function(responseJSON, responseText) {
				if (responseJSON == null) { alert(responseText); return; }
				//
				if (responseJSON.alertMsg != null) {
					alert(responseJSON.alertMsg);
				}
				if (responseJSON.changeHTML != null) {
	                var changeHTML = JSON.decode(responseJSON.changeHTML);
	                $each(changeHTML, function(content, target) {
	                    if (target == null) target = targetId;
	                    if ($(target) == null) alert("target nicht gefunden: "+ target);
	                    //
	                    $(target).innerHTML = content;
	                });
	            }
			}
		}).get();
}

function reloadComboBox(className, method, params, targetComboId) {
	var combo = $(targetComboId);
	var selectedValue;
	for (var i = 0; i < combo.length; i++) {
		if (combo.options[i].selected == true) selectedValue = combo.options[i].value;
	}
	//
	var req = new Request.JSON({
		url: "index.php?class="+className+"&method="+method+"&params="+params,
		onComplete: function(responseJSON, responseText) {
			if (responseJSON == null) { alert(responseText); return; }
			//
			var combo = $(targetComboId);
			while (combo.length > 0) {
			    combo.options[combo.length - 1] = null;
			}
			$each(responseJSON, function(value, id) {
				var item = new Option(value, id, false, (id == selectedValue));
				combo.options[combo.length] = item;
			});
			
	}}).get();
}