/**
 * 
 */
function Customer(id, init){
	
	this.complete = false;
	//private properties
	
	var that = this;
	
	//private methods
	var retrieveData = function(data){
		$.each(data, function(name, value){
			that[name] = value;
		});
		that.complete = true;		
	}
	
	//public methods
	
	this.getCustomerPositions = function(status, asObject){
		var positionsArray  = new Array();
		var recievePositions = function(data){
			if(asObject){
				
				$.each(data, function(key, props){
					var positionObj = {};
					props['assetId']    =   props['assetIdObj'];
					props['optionId']   =  props['optionIdObj'];
					props['customerId'] =  props['customerIdObj'];
					
					delete props['assetIdObj'];
					delete props['optionIdObj'];
					delete  props['customerIdObj']
					
					var positionObj = new PositionPlatform(false, props, false, 'open', {'expired':Flow.onPositionExpired}, {'rateChanged': Flow.onPositionNewRateRecieved, 'payoutCalculated': Flow.onPositionCurrentPayoutCalculated });
					
					delete positionObj.assetId;
					
					positionObj.optionId = new Option(false, props['optionId'], false, 'platform', 'open');
					positionObj.optionId.assetId = new Asset(false, props['assetId']);
					
					positionObj.customerId  = flowPage.getCustomer();
					
					positionObj.initLS();
					positionsArray.push(positionObj);
					
				});
				
			}
		}
		AjxMgr.request(AjxMgr.pathAjax + 'getCustomerPositions', 'POST', {id: that.id, status: status}, 'json', false, recievePositions);
		return positionsArray;
	}	
	
	if(!init) AjxMgr.request(AjxMgr.pathAjax + 'getCustomers' , 'POST', {'current': true}, 'json', false, retrieveData);
	else retrieveData(init);
		
}

//static methods
/**
 * get asset as object
 */
Customer.getCustomers = function(ids){
	var assetArr = new Array();
	var retrieveData = function(data){
		$.each(data, function(key, props){
			assetArr.push(new Customer(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;
}
/*
 * 
 */
Customer.getCurrent = function(){
	var currentCustomer = null;
	var retrieveData = function(data){
		currentCustomer = new Customer(false, data);
	}
	AjxMgr.request(AjxMgr.pathAjax + 'getCustomers' , 'POST', {current: true}, 'json', false, retrieveData);
	
	return currentCustomer;
}


