MenuProcessorAjax = function(){}

MenuProcessorAjax.prototype.handleSuccess = function(o)
{
	var div = document.getElementById( String(o.argument.target) );
	//alert(o.responseText);
	if(null != div)
		div.innerHTML = o.responseText;

	if( o.argument.onComplete != undefined )
	{
		eval(o.argument.onComplete);
	}
}

MenuProcessorAjax.prototype.handleFailure = function(o)
{
	//alert( o.responseText );
}

MenuProcessorAjax.prototype.startRequest = function( arg )
{
	var params = "";
	//prepare arguments
	for( param in arg.params )
	{
		params = params + param + "=" + arg.params[param] + "&";
	}
	///alert(params);

    YAHOO.util.Connect.asyncRequest('POST', arg.action, {
        success:this.handleSuccess,
        failure:this.handleFailure,
        scope: MenuProcessorAjax,
        argument: arg } , params);
}
//////////////////////////////////////////////////////

HistoryProcessorAjax = function(){}

HistoryProcessorAjax.prototype.handleSuccess = function(o)
{
	var div = document.getElementById( String(o.argument.target) );
	//alert(o.responseText);
	if(div)
		div.innerHTML = o.responseText;
}

HistoryProcessorAjax.prototype.handleFailure = function(o)
{
	//alert( o.responseText );
}

HistoryProcessorAjax.prototype.startRequest = function( history, action )
{
	var params = "";
	params = 'target=' + history.target;
	params = params +'&descriere=' + history.descriere;
	params = params +'&action=' + action;
	if( history.clear  )
	{
		params = params +'&clear=' + history.clear;
	}
	//alert(params);

    YAHOO.util.Connect.asyncRequest('POST', "actions/fillhistory.php", {
        success:this.handleSuccess,
        failure:this.handleFailure,
        scope: HistoryProcessorAjax,
        argument: history } , params);
}
//////////////////////////////////////////////////////
var MenuActionsManager = {
		startActions:function( actions )
		{
			var actiuni;
			try
			{
				//alert(actions);
				if (typeof actions == 'string')
					actiuni = YAHOO.lang.JSON.parse(actions);
				else
					actiuni = actions;
			}catch( e )
			{
				alert("json bad format");
				alert(actions);
				return;
			}

			for ( var j in actiuni.clear )
			{
				var div = document.getElementById(actiuni.clear[j]);
				if( null != div)
				{
					div.innerHTML = "";
				}
			}

			for( i=0; i<actiuni.actions.size(); i++ )
			{
				obj  = new MenuProcessorAjax();
				obj.startRequest( actiuni.actions[i] );

			}

			if( actiuni.history  )
			{
				obj2  = new HistoryProcessorAjax();
				obj2.startRequest( actiuni.history, actions );
			}
		}
}
