App.Views.Account = Backbone.View.extend({
	template: _.template( $('#account-template').html() ),
	model:null,

	 initialize: function(){
	 	_.bindAll(this,'render','onDeleteAccount')
	 },

	 render:function(){
	 	var html = this.template( this.model.toJSON() );
	 	this.$el.append( html );
	 	return this;
	 },

	events : {
		'click #put-account-settings' : 'onSaveAccount',
		'click #delete-account' : 'onDeleteAccount'
	},

	onSaveAccount : function(e){
		var accountName = this.$el.find('#account-real-name').val();
		var replyAddress = this.$el.find('#account-reply-to-address').val();
		var accountSignature = this.$el.find('#account-signature').val();

		this.model.attributes.accountName = accountName;
		this.model.attributes.replyAddress = replyAddress;
		this.model.attributes.signature = accountSignature;
		this.model.save();
		App.alert('Account Settings Saved', 'alert-info');
	},

	onDeleteAccount : function(e){
		this.model.destroy();
		App.alert('Account Deleted', 'alert-info');
		App.settingsChrome.verticalBar.render();
		$('button.account-settings-button').click();
	}
});