var emailPreg=/^([a-zA-Z0-9\-\.\_]+?)@([a-zA-Z0-9\-\.?]+)\.([a-z]{2,4}?)$/;
function checkRegisterForm(Form){
	
	if (Form.password){		
		if (!Form.password.value){
			return this.Error('Введите пароль', Form.password);
		}
		else{
			this.Passed(Form.password);
		}
	}	
	
	if (!Form.last_name.value){		
		return this.Error('Введите свою фамилию',Form.last_name);
		
	}
	else this.Passed(Form.last_name);
	
	if (!Form.first_name.value) return this.Error('Введите свое имя',Form.first_name);
	else this.Passed(Form.first_name);
	
	if (!Form.patronymic.value) return this.Error('Введите свое имя',Form.patronymic);
	else this.Passed(Form.patronymic);
	
	if (Form.email){
		if (!Form.email.value) return this.Error('Введите свое email',Form.email);
		else if (!emailPreg.test(Form.email.value)) return this.Error('Введите свое email',Form.email);
		else this.Passed(Form.email);
	}
	if (!Form.password){
		if (Form.user_password.value.length<2){
			return this.Error('Введите свой пароль',Form.user_password);
		}
		else {
			this.Passed(Form.user_password);		
		}
		
		if (Form.user_password.value!=Form.user_password_confirm.value) return this.Error('Введите подтверждение',Form.user_password_confirm);
		else this.Passed(Form.user_password_confirm);
		if (Form._keyword){
			if (!Form._keyword.value)  return this.Error('Введите ключевое слово', Form._keyword);
			else this.Passed(Form._keyword)	;	
		}
	}
	
	
	return true;
}

function afPassed(Input){
	attachClass(DOM(Input.id+'_status'),'ok');
	detachClass(DOM(Input.id+'_status'),'req');
	DOM('submit').value='Зарегистрироваться';
}

function afError(Message, Input){	
	if (Input){
		attachClass(DOM(Input.id+'_status'),'req');
		detachClass(DOM(Input.id+'_status'),'ok');		
		DOM('submit').value='Заполнены не все обязательные поля';
	}	
}

var fc=new FormControl(
'regForm', 
checkRegisterForm,
afError, 
afPassed
);

