﻿//=================================================================================
function getContent(sURL,sParams,sID,sFunction,errorFunction)
{
	var ip_address = $("#ip_address").html();
	var sCheck = String(Math.random() * 25);
	if(sParams == null)sParams = 'dummy='+ sCheck;
	else sParams = sParams + '&dummy='+ sCheck;
	//alert(sURL);
	$.ajax({
		type: "POST",   
		url: sURL,
		data: sParams, 
		async: false,
		success: function(content){
			var bOK = true;
			//alert(content);
			if(content.substring(0,sCheck.length) == sCheck){
				bOK = true;
				content = content.substring(sCheck.length,content.length); 
				}
			if(ip_address == '80.150.30.114' && debug)alert(content + " nach " + sID);
			// wenn gueltige Pruefung im Request einen Fehler ergibt -> Fehler anzeigen
			if(content.substring(0,6) == "#ERROR"){
				bOK = false;
				Show_Error(content,errorFunction);
				}		
			if(bOK && sID != null){
					if($("#"+sID).is("input"))$("#"+sID).val(content);
					if($("#"+sID).is("span"))$("#"+sID).html(content);
					if($("#"+sID).is("div"))$("#"+sID).html(content);						
				}
			if(bOK && sFunction != null)eval(sFunction);
			}
	});	
	
}
//=================================================================================
function getContentArray(sURL,sParams,sID,sFunction,errorFunction)
{
	var ip_address = $("#ip_address").html();
	var sCheck = String(Math.random() * 25);
	if(sParams == null)sParams = 'dummy='+ sCheck;
	else sParams = sParams + '&dummy='+ sCheck;
	//alert(sURL);
	$.ajax({
		type: "POST",   
		url: sURL,
		data: sParams, 
		async: false,
		success: function(content){
			var bOK = true;
			if(ip_address == '80.150.30.114' && debug)alert(content);
			if(content.substring(0,sCheck.length) == sCheck){
				bOK = true;
				content = content.substring(sCheck.length,content.length); 
				}
			//alert(content + " nach " + sID);
			// wenn gueltige Pruefung im Request einen Fehler ergibt -> Fehler anzeigen
			if(content.substring(0,6) == "#ERROR"){
				bOK = false;
				Show_Error(content,errorFunction);
				}		
				
			if(bOK)content = eval(content);
			// get all named variables
			for(var i = 0; i < sID.length && bOK; i++){
				var thisvalue = content[0][sID[i]];
				if(sID[i] != null){
					if($("#"+sID[i]).is("input"))$("#"+sID[i]).val(thisvalue);
					if($("#"+sID[i]).is("span"))$("#"+sID[i]).html(thisvalue);
					if($("#"+sID[i]).is("div"))$("#"+sID[i]).html(thisvalue);						
					}
				}
				//
			if(bOK && sFunction != null)eval(sFunction);	
		}
	});	
}
//=================================================================================
function Show_Error(errorNumber,errorFunction){
	//
	var sMessage = "";
	var errorNumberPart1 = "";
	if(errorNumber == "#ERROR_Login")
		{
		sMessage = "Zugriff verweigert! Die Zugangsdaten sind nicht korrekt!";
		}
	else if(errorNumber.indexOf('|') > 0)
		{ // 
		var params = errorNumber.split('|');
		sMessage = params[1];
		errorNumberPart1 = params[0];
		}
	else
		{
		sMessage = "Fehler in der Datenabfrage";
		}
// Meldung anzeigen	
	
	Show_Message(sMessage);
	if(errorFunction != null)eval(errorFunction); 
	// Module aktualisieren, welche Sitzungabhaengig sind
	//if(errorNumberPart1 == "#ERROR_Session")Refresh_Modules();
}
//=================================================================================
