function Ajax(url, args, method, dataType, EvalJSON){
	//inform the user the system is working by changing the cursor
	$("body").css("cursor", "progress") ;

	if(method	== null) method		= 'GET';
	if(dataType == null) dataType 	= 'HTML';
	if(EvalJSON == null) EvalJSON 	= false;
	
	$.ajax({
		type: method,
		url: url,
		data: args,
		dataType: dataType,
	
		error: function (xhr, ajaxOptions, thrownError){
			//reset the cursor to default
			$("body").css("cursor", "auto");
			
			if(thrownError == 'Not Found')
				ShowBox('De opgevraagde pagina werd niet gevonden!', 'error');
			else if(thrownError.length == 0)
				ShowBox("Niet geregistreerde fout, zorg ervoor dat het opgevraagde bestand via een relatief pad gaat! Geeft u deze fout door aan de systeembeheerders!",'error');
			else
				ShowBox("Verbindingsfout: "+thrownError, 'error');
		},
		
		success: function(response){
			if(EvalJSON){
				window.EvalJSON(response);
			}
			
			//reset the cursor to default
			$("body").css("cursor", "auto");
		}
	});
}

//JSON.parse also eval's the script. Find a way to decode first and then Eval() as theelemnts must first be written to the document!
function EvalJSON(data) {
	try {
		
		var response = JSON.parse(data);

	}catch (e) {
		loadjscssfile("../system/scripts_js/highlighter.js", "js");
		loadjscssfile("../system/scripts_css/highlighter.css", "css");

		jsonError = "Er is een fout opgetreden in het verwerken van het geretourneerde JSON-object. Het gehele antwoord van het systeem is hieronder te vinden."
		+ "<div style='margin-left:-60px;margin-top:20px;'>"
		+ "<pre class='htmlCode'>"+$('<span>').text(data).html()+"</pre></div>";
				
		ShowBox(jsonError, "error", 700);
		
		setTimeout('$("pre.htmlCode").snippet("html",{style:"ide-codewarrior"})',1000);
		
		
		return;
	}

	if (response.refresh != null){
		for (i in response.refresh){
			Refresh(response, i);
		}
	}
	if (response.messageBox != null) {
		for(i in response.messageBox)
			ShowBox(response.messageBox[i][0], response.messageBox[i][1]);
	}
	
	if (response.javascript != null) {
		for(i in response.javascript){	
			eval(response.javascript[i]);
		}
	}
}

function Refresh(response, number) {
	var rand = number;
	var el = $('#'+response.refresh[rand][0]);
	
	var total = response.refresh.length;
				
				
	if (response.refresh[rand][2] == 'true'){
		el.wrap( '<div id="animation_tmp'+rand+'"></div>' );
	
		$('#animation_tmp'+rand).css({height:el.outerHeight()});
		// fade out inner div
		el.fadeOut(300 , function(){
			// change the div content
			el.html(response.refresh[rand][1]);
				
			// give the outer div the same width as the inner div with a smooth animation
			$('#animation_tmp'+rand+'').animate({height: el.outerHeight()+'px'}, 300, function(){
				// show the inner div
				el.fadeIn(300, function() {
					el.unwrap();
				
					//eval javascript tags only when animation is complete (rand + 1 for 0-index offset)
					if (response.RefreshJavascript != null && ((parseInt(rand)+1) == total)) {
						for(j in response.RefreshJavascript){	
							eval(response.RefreshJavascript[j]);
						}
					}
				});
			});
		});
	} else {
		el.html(response.refresh[rand][1]);	
		
		//eval javascript tags only when animation is complete (rand + 1 for 0-index offset)
		if (response.RefreshJavascript != null && ((parseInt(rand)+1) == total)) {
			for(j in response.RefreshJavascript){	
				eval(response.RefreshJavascript[j]);
			}
		}
	}
}





