App.Collections.Account = Backbone.Collection.extend({
	model: App.Models.Account,
	url: App.baseUrl + '/inbox/account'
});

App.Collections.Account.prototype.getPrimaryAccount = function(){
	for(var i = 0; i < this.length; i++){ 
		var model = this.at(i);
		if(model.get('primary')){
			return model;
		}
	}
}

App.Collections.Account.prototype.getActiveAccount = function(){
	for(var i = 0; i < this.length; i++){
		var model = this.at(i);
		if(model.get('isActive')){
			return model;
		}
	}
	return this.getPrimaryAccount();
}

App.Collections.Account.prototype.setActiveAccount = function(cid){
	for(var i = 0; i < this.length; i++){
		this.at(i).set('isActive', false);
	}

	if (cid > 0)
	{
		this.get(cid).set('isActive',true);
	}
}

App.Collections.Account.prototype.getAccountName = function(id){
	switch(id){
		case 0:
		case -1:
			return 'Charter';
		default:
			return this.get(id).get('accountName');
	}
};
