vivvoForgotPassForm = Class.create();

Object.extend(vivvoForgotPassForm.prototype, {
	element : null,
	initialize : function(){
		if (!$('forgot_password_form')){
			return false;
		}
		this.element = $('forgot_password_form');
		this.element.observe('submit', this.sendData.bindAsEventListener(this));
	}, 
	sendData : function(){
		if (!this.validate()){
			return false;
		}
		var _ = this;
		var url = 'index.php';
		var params = this.element.serialize();
		document.body.style.cursor = 'wait';
		new Ajax.Updater($('forgot_form_holder'), url, {
			parameters : params,
			evalScripts : true,
			insertion : 'top',
			onComplete : function(){
				document.body.style.cursor = 'default';
				if (!($('forgot_form_holder').down('.error'))){ // if no error returned, remove the form
					_.element.remove();
					$('forgot_form_holder').down('div.fp_info').remove();
					$('forgot_form_holder').down('div.inline_error').remove();
				}
			}
		});
	},
	validate : function(){
		var error = '';
		if ($(this.element.elements['LOGIN_username']).value=='' && $(this.element.elements['LOGIN_email']).value == ''){
			if ($$('.inline_error').length>0){
				$$('.inline_error')[0].remove();
			}
			Element.insert($('forgot_form_holder'), {top : '<div class="inline_error">' + vivvo.lang['LNG_ERROR_2712'] + '</div>'});
			return false;
		} else {
			return true;
		}
	} 
});
var vivvoForgotPasswordForm;
document.observe('dom:loaded', function(){
	vivvoForgotPasswordForm = new vivvoForgotPassForm();
});