// ajax
// komunikacja za pomoca AJAX, przetwarzanie odpowiedzi w postaci JSON

function json_get(action, processor, params, is_cms)
{
	$(function() 
	{
		if(is_cms)
		{
			var url_str = "/units/diet_calc/DC_ajax_controller.php";
		}
		else
		{
			var url_str = "/" + cDC_PATH + "DC_ajax_controller.php";
		}
		
		$.ajax(
		{
		   type: "GET",
		   url: url_str,
		   data: 'action=' + action + '&' + params,
		   success: function(result)
		   {
               try {
		   		the_object = eval( "(" + result + ")" );
				processor(the_object);
               } catch(e){
                   alert(result);
               }
		   }
		});
	});
}

function json_post(action, processor, params, is_cms)
{	
	$(function() 
	{
		if(is_cms)
		{
			var url_str = "/units/diet_calc/DC_ajax_controller.php";
		}
		else
		{
			var url_str = "/" + cDC_PATH + "DC_ajax_controller.php";
		}
		
		$.ajax(
		{
		   type: "POST",
		   url: url_str,
		   data: 'action=' + action + '&' + params,
		   success: function(result)
		   {
               try {
		   		the_object = eval( "(" + result + ")" );
				processor(the_object);
               } catch(e){
                   alert(result);
               }
		   }
		});
	});
}
