var Action = {

	STATE_INITIALIZED : 100,
	STATE_IN_QUEUE    : 101,
	STATE_PROCESSING  : 102,
	STATE_COMPLETED   : 0,
	STATE_ERROR       : 1,
	
	instance : function(
		sType,
		aData,
		aAddData,
		oDirector,
		sFunctionName,
		sErrorFunctionName
		) {

		this.iState = Action.STATE_INITIALIZED;
		this.iId  = 0;
		this.sType = sType;
		this.aData = aData;
		this.aAddData = aAddData;		
		this.oDirector = oDirector;
		this.sFunctionName = sFunctionName;
		this.sErrorFunctionName = sErrorFunctionName;
		
	}

};

Action.instance.prototype = {
	
	setId : function(iId) {
	
		this.iId = iId;
	
	},
	
	getId : function() {
	
		return this.iId;
	
	},
	
	getType : function() {
	
		return this.sType;
	
	},
	
	setState : function(iState) {
	
		this.iState = iState;
	
	},
	
	getState : function() {
	
		return this.iState;
	
	},
	
	getXml : function() {
	
		return '<action id="' + this.getId() + '" type="' + this.getType() + '"><data>' + this.dataToXml() + '</data></action>';
	
	},
	
	dataToXml : function() {			
	
		var sXml = '';
	
		for(var i in this.aData) {
		
			sXml += '<' + i + '>' + this.aData[i] + '</' + i + '>'
		
		}
		
		return sXml;
	
	},
			
	processResult : function(oActionXml) {
		
		switch(this.getState()) {
		
			case Action.STATE_COMPLETED:
				
				var oDataXml = oActionXml.getElementsByTagName('data')[0];
				
				if(oDataXml) {										
					this.executeResultFunction(Common.Xml.toArray(oDataXml));
				}
				else {					
					this.executeResultFunction(null);
				}
				
			break;						
			
			default:
															
				this.executeErrorFunction(this.getState());						
			
			break;
		
		}
	
	},
	
	executeResultFunction : function(aResult) {
		
		if(this.oDirector && this.oDirector[this.sFunctionName]) {		
			this.oDirector[this.sFunctionName](aResult, this.aAddData);			
		}
	
	},
	
	executeErrorFunction : function(sSign) {
		
		if(this.oDirector && this.oDirector[this.sErrorFunctionName]) {		
			this.oDirector[this.sErrorFunctionName](sSign, this.aAddData);			
		}
	
	}
	
}