var email, Email = Class.create();
Email.prototype = {
	initialize: function(){
		this.field = $('email_email');

		this.field.onkeyup = this.key_up.bindAsEventListener(this);

		if(this.field.up(0).className == 'SPAN'){
			this.field_with_errors = this.field.up(0);
			this.explanation = this.field_with_errors.down('div');
			
			this.check();
		} else {
			this.field_with_errors = new Element('span', { 'class': 'field_with_errors'});
			this.explanation = new Element('div', { 'class': 'explanation' });
			
			this.field.wrap(this.field_with_errors);
			this.field_with_errors.insert(this.explanation);
		}
	},
	
	key_up: function(){
		if(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{2,})){1,3}$/.test(this.field.value)){
			this.set_state(true);
		} else {
			this.set_state(false);
		}
	},
	
	set_state: function(state){
		if(state){
			this.field_with_errors.addClassName('validated');
		} else {
			this.field_with_errors.removeClassName('validated');
		}
	}
}