
var StbasMessageForm = Class.create({

	initialize: function(id) {
		this.id = id;
		this.form = $(this.id);
		Event.observe(this.form, 'submit', this.onSubmit.bindAsEventListener(this));
	},

	onSubmit: function(event) {
		Event.stop(event);

		if (this.getName().blank()) {
			window.alert('Вы не указали имя!');
		} else if (this.getContent().blank()) {
			window.alert('Вы не заполнили текст сообщения !');
		} else if (this.getPhone().blank()) {
			window.alert('Вы не указали телефон!');
		};

		Form.request(this.form, {
			onCreate: function(request) {
				Form.disable(this.form);
			}.bind(this),

			onFailure: function(request) {
				window.alert('Не удалось отправить форму!');
				Form.enable(this.form);
			}.bind(this),

			onSuccess: function(request) {
				window.alert('Форма отправлена успешно, спасибо!');
				Form.enable(this.form);
			}.bind(this)
		});
	},

	getField: function(field) {
		return $F(this.id + '-' + field);
	},

	getName: function() {
		return this.getField('name');
	},

	getEmail: function() {
		return this.getField('email');
	},

	getPhone: function() {
		return this.getField('phone');
	},

	getContent: function() {
		return this.getField('content');
	}

});
