var CocoCmdExecuter  = Class.create();
CocoCmdExecuter.prototype = 
{
	// attributes
	_php_url: '../../php_helpers/commands/run_async_cmd.php',
	_params: null,
	_executed: false,
	_oid: null,
	_result:null,
	
	// construction
	initialize: function()
	{
		this._params = "";
	},

	
	// methods
	addParameter: function(param_name, param_value)
	{
		if (this._params != "")
			this._params += '&';
		this._params += param_name + '=' + param_value;
	},
	
	execCommand: function(cmd_name)
	{
		
		var post_vars = "cmd=" + cmd_name + "&" + this._params;
	
		
		var opt = 
		{
			method: 'post',
			postBody: post_vars,
			owner: this,
			onSuccess: this.catchResults.bind(this),
			on404: function(t) { alert('Error 404: location "' + t.statusText + '" was not found.'); },
			onFailure: function(t) { alert('Error ' + t.status + ' -- ' + t.statusText); }
		};
			
		req = new Ajax.Request(this._php_url, opt);
				
	},
	
	catchResults: function(t)
	{		
		if (t.responseXML == null)
		{ // error ocurred on PHP
		  alert ("noXML: " + t.responseText);
		  return;
		}

		node_oid = t.responseXML.documentElement.getElementsByTagName("oid")[0];
		node_res = t.responseXML.getElementsByTagName("result")[0];
		
		if (sett_mgr.getBrowser() == "Internet Explorer")
		{
			this._oid = node_oid.text;
			this._result = node_res.text;
		}
		else
		{
			this._oid = node_oid.textContent;
			this._result = node_res.textContent;
		}
			

		this._executed = true;
		this.onCmdExecuted();
	},

	// to redefine
	onCmdExecuted: function()
	{
		alert(this._result);
	}
};