CocoCmdExecuter = function(){
	this.initialize();
}

$.extend(CocoCmdExecuter.prototype, {
	// attributes
    _php_url: '/php_helpers/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 cceObj = this;
    	
    	// perform the ajax post here
    	$.ajax({
    		url: this._php_url,
    		type: "POST",
    		dataType: "xml",
    		data: post_vars,
    		success: function(t) { cceObj.catchResults(t); },
    		error: function(t, textStatus) { cceObj.onErrorOccured(t, textStatus); }
    	});
    },
    
    catchResults: function(t)
	{		
	    var cceObj = this;
	    
	    $(t).find("cmd").each(function()
		{
			cceObj._oid = $(this).find("oid").text();
			cceObj._result = $(this).find("result").text();
		});
		
		this._executed = true;
		this.onCmdExecuted();
	},
	
	onErrorOccured: function(t, textStatus)
	{
		alert(t.responseText);
	},
	
	// to redefine
	onCmdExecuted: function()
	{
	    alert(this._result);	    
	}
});
