var  errClassBG		= 'errorInputBackground';

Prototype.emailValidate		= Class.create();
Prototype.emailValidate.prototype = {
	initialize: function(controlID) {
		this.control			= $$( '#' + controlID )[0];
		this.registerCallbacks();
	},
	
	registerCallbacks: function() {
		this.valueChangeHandlerPointer		= this.verifyEmail.bindAsEventListener(this);
		Event.observe(this.control, 'keyup', this.valueChangeHandlerPointer, false);
	},
	
	dispose: function() {
		Event.stopObserving(this.control, 'keyup', this.valueChangeHandlerPointer, false);
		this.valueChangeHandlerPointer		= null;
	},
	
	verifyEmail: function() {
		if (this.control.value == null || this.control.value.length == 0 || this.isValidEmail()) {
			this.control.className		= this.control.className.replace(errClassBG, '');
		} else {
			if (this.control.className.indexOf(errClassBG) == -1) { 
				this.control.className	= this.control.className + ' ' + errClassBG;
			}
		}
	},
	
	isValidEmail: function() {
		var emailChk	= /^([^@\s]*)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		return emailChk.test(this.control.value);
	}
}


// Keeps a textarea (or other field) to a selected amount of size
Prototype.maxLength			= Class.create();
Prototype.maxLength.prototype = {
	initialize: function(controlID, maxSize) {
		this.control			= $$( '#' + controlID )[0];
		this.maxSize			= maxSize;
		this.registerCallbacks();
	},
	
	registerCallbacks: function() {
		this.valueChangeHandlerPointer		= this.checkLength.bindAsEventListener(this);
		Event.observe(this.control, 'keypress', this.valueChangeHandlerPointer, false);
	},
	
	dispose: function() {
		Event.stopObserving(this.control, 'keypress', this.valueChangeHandlerPointer, false);
		this.valueChangeHandlerPointer		= null;
	},
	
	checkLength: function(event) {
		var  value		= this.control.value;
		if (value == null || value.length < this.maxSize) {
			return event.keyCode;
		} else {
			return false;
		}
	}
}

