var Account = Class.create({
	initialize: function(frm) {
		this.frm = $(frm);
		this.frm.observe('submit', this.login.bindAsEventListener(this));
		new Tip(this.frm, 'Логин и/или пароль введены не верно', {style: 'error-submit', title: 'Ошибка'});
		this.updateDiscount();
	},
	loginOnCreate: function() {
		$('account-login').hide();
		$('account-loader').show();
		this.frm.prototip.hide();
	},
	loginOnSuccess: function(req) {
		$('account-loader').hide();
		var res = req.responseText;
		if (res == 1) {
			$('account-data').show();
			this.updateDiscount();
			if (calc) {
				calc.checkDiscount();
			}
		} else {
			$('account-login').show();
			this.frm.prototip.show();
		}
	},
	login: function(e) {
		new Ajax.Request('/ajax/login.php', {
			parameters: this.frm.serialize(),
			onCreate: this.loginOnCreate.bindAsEventListener(this),
			onSuccess: this.loginOnSuccess.bindAsEventListener(this)
		});
		e.stop();
	},
	updateDiscount: function() {
		new Ajax.Updater('discount-val', '/ajax/discount.php');
	}
});
