// Form element plug-ins
Element.addMethods({
	// clearOnClick()
	// Any input or textarea element with the class "clear-on-click" will have the following behaviour:
	// - The label preceding the input element will be hidden, and the label's text will be used as the input element's value
	// - If the input element's value equals the text of the label, focusing on the input will clear the text
	// - If the input element's value is empty, un-focusing on the element will re-load the label's text into it's input
	clearOnClick: function(element) {
		var text = element.readAttribute('title');

		element.setValue(text);
		
		element.observe('focus', function() {
			if (this.getValue() == text) this.clear();
		});
		
		element.observe('blur', function() {
			if (this.getValue().blank()) this.setValue(text);
		});
		
		return element;
	}
});

// Invoke the "Clear on Click" plugin on any input field or textarea that has the class 'clear-on-click'
document.observe("dom:loaded", function() {
	$$('.clear-on-click').invoke('clearOnClick');
});