/**
 * Applies to any text fields with a class of "cleartext"
 * Automatically clears out the default text on focus.
 * Replaces the default text on blur, if no changes were made.
 */
function ClearText(el) {
	this.el = el;
	this.initialText = el.value;

	this.focused = function() {
		if (el.value == this.initialText) {
			// Text hasn't been changed yet
			el.value = '';
		} else {
			// Text has been changed
			Element.removeClassName(el,'unchanged');
		}
	}
	this.blurred = function() {
		if (el.value == this.initialText || el.value == '') {
			// No change
			el.value = this.initialText;
			Element.addClassName(el,'unchanged');
		} else {
			// Change
			Element.removeClassName(el,'unchanged');
		}
	}
	Event.observe(el, 'focus', this.focused.bind(this));
	Event.observe(el, 'blur', this.blurred.bind(this));
}
var cleartext = {
	'input.cleartext' : function(el) {
		new ClearText(el);
	}
}
Behaviour.register(cleartext);