/**
 * 	when we alredy have the data of assets then 
 *  we have to pass via `init` var, in other hand,
 *  if we want retrieve data from server we just need to pass the `id` of the asset
 */
function Asset(id, init){
	
	this.complete = false;
	
	//private properties
	
	var that = this;
	
	var _booleanFields = new Array('bmoEnabled');
	//private methods
	var retrieveData = function(data){
		$.each(data, function(name, value){
			ansInArray = $.inArray(name, _booleanFields);
			if(typeof ansInArray != 'undefined' && ansInArray != -1){
				value = parseInt(value);
			}
			that[name] = value;
		});
		that.complete = true;
	}
	
	//public methods
	this.loadOptions = function(status, order, asObject, step, stepChangeCallbacks){
		
		var optionsArr = new Array();
		var order = order || 'id';
		var recieveOptions = function(data){
           
            
			if(asObject){
				
				$.each(data, function(key, props){
					optionsArr.push(new Option(false, props, {assetId: that}, 'platform', step, stepChangeCallbacks));
				});
			}
			else
				optionsArr = data;
		}
		AjxMgr.request(AjxMgr.pathAjax + 'getAssetsOptions', 'POST', {id: this.id, status: status, order:order}, 'json', false, recieveOptions);
		console.log('return data')
		return optionsArr;
	}
	
	
	if(!(init)) AjxMgr.request(AjxMgr.pathAjax + 'getAssets' , 'POST', {ids: id}, 'json', false, retrieveData);
	else retrieveData(init);

	
}

//static methods
/**
 * get asset as object
 */
Asset.getAssets = function(ids){
	var assetArr = new Array();
	var retrieveData = function(data){
		$.each(data, function(key, props){
			assetArr.push(new Asset(false, props));
		});
	}
	//synchronic call, but the browser 
	//did not stop because of threading approach
	
	AjxMgr.request(AjxMgr.pathAjax + 'getAssets', 'POST', {ids: JSON.stringify(ids)}, 'json', false, retrieveData);
	return assetArr;
}


//Asset.factory = function(){
//	AjxMgr.call('rpcProxy/getPositionInfo', 'POST', 'json', true, function(){alert('ok')})
//		
//	//return new Asset({name: AppData.name, id: AppData.id});
//};
