
document.observe("dom:loaded", function() { 
	$$('input[type="text"]').each(function(f) {
		f.addClassName("idleField");
		f.observe('focus', function(ev) { this.removeClassName('idleField').addClassName('focusedField'); });
		f.observe('blur', function(ev) { this.removeClassName('focusedField').addClassName('idleField'); });
	});
});

document.observe("dom:loaded", function() { 
	$$('input[type="password"]').each(function(f) {
		f.addClassName("idleField");
		f.observe('focus', function(ev) { this.removeClassName('idleField').addClassName('focusedField'); });
		f.observe('blur', function(ev) { this.removeClassName('focusedField').addClassName('idleField'); });
	});
});

document.observe("dom:loaded", function() { 
	$$('textarea').each(function(f) {
		f.addClassName("idleField");
		f.observe('focus', function(ev) { this.removeClassName('idleField').addClassName('focusedField'); });
		f.observe('blur', function(ev) { this.removeClassName('focusedField').addClassName('idleField'); });
	});
});



var inactive_color = '#BBB';
var default_fields_values = new Hash();

function observeFormField(field) {
	field.observe('focus', function(ev) { 

	  if (!default_fields_values[this.id]) {
	    default_fields_values[this.id] = { value: this.value, color: this.getStyle('color') };
	  }
		// Prepare it for typing
	  if (this.value == default_fields_values[this.id]['value']) {
	    this.value = '';
	    this.style.color = default_fields_values[this.id]['color'];
	  }
	  this.observe('blur', function(ev) { 
			// If blank, then revert to the default value and color.
	    if (this.value == '') {
	      this.style.color = inactive_color;
	      this.value = default_fields_values[this.id]['value'];
	    }
	  });	

	});
}

document.observe("dom:loaded", function() { 
  $$('input[type="text"]').each(function(field) { observeFormField(field); });
});

document.observe("dom:loaded", function() { 
  $$('input[type="password"]').each(function(field) { observeFormField(field); });
});

document.observe("dom:loaded", function() { 
  $$('textarea').each(function(field) { observeFormField(field); });
});


