
window.addEvent('domready', function() {
	$$('.clearonfocus').each(function(item) {

		$extend(item, {
			hasDefaultValue: function() { return this.value == this.defaultValue; },
			isEmpty: function() { return this.value == ''; },
			clearDefault: function() {
				if (!this.hasDefaultValue()) return;
				this.value = '';
				this.removeClass('clearonfocus');
			},
			restoreDefault: function() {
				if (!this.isEmpty()) return;
				this.addClass('clearonfocus');
				this.value = this.defaultValue;
			},
			analyzeDefault: function() {
				if (!item.hasDefaultValue()) item.removeClass('clearonfocus');
				item.restoreDefault();
			}
		});
		item.analyzeDefault();

		item.addEvents({
			focus: item.clearDefault.bind(item),
			blur: item.restoreDefault.bind(item)
		});

	});
});
