var InputPrompt = Class.create({
  initialize: function(element) {
    this.element = $(element);
    this.element.observe('focus', this.focus.bind(this));
    this.element.observe('blur', this.blur.bind(this));
    if($(this.element.form))
      $(this.element.form).observe('submit', this.submit.bind(this));
    this.prompt = element.readAttribute('prompt');
    this.element.inputPromptObj = this;
    this.blur();
  },
  focus: function() {
    setTimeout(function() {
      if (this.element.value == this.prompt)
        this.element.value = '';
      this.element.setStyle({color: 'black'});
    }.bind(this), 100);
  },
  blur: function() {
    if (this.element.value == '' || this.element.value == this.prompt) {
      this.element.value = this.prompt;
      this.element.setStyle({color: 'gray'});
    }
  },
  submit: function() {
    if (this.element.value == this.prompt)
      this.element.value = '';
  }
});
function setupInputPrompts() {
  $$('input[prompt]').each(function(element) {
    if (!element.inputPromptObj)
      new InputPrompt(element);
  });
}
Event.observe(window, 'load', setupInputPrompts);
