
// ===== Click Clear =====
// Author: Nick Merwin (nickmerwin@gmail.com)
// License: MIT
// Requirements: Prototype >1.6
// Usage: 
// * give input elements a class "click_clear"
// * give password fields a name that includes "password" (i.e. "user_password") 
//    and set type="text"
// * set alt attribute to default text
// * call ClickClear.init() after DOM loaded
var ClickClear = {
  inputs: {},
  init:function(){
    $$('.click_clear').each((function(input){
      if(input.value == "" || input.value == null) input.value = input.getAttribute('alt');
      this.inputs[input.id] = input.observe('focus',(function(e){
        var input = Event.element(e);
        if(input.value == this.inputs[input.id]) {
          input.value = "";
          if(/password/.test(input.name)) input.type = "password";
        }
      }).bind(this)).observe('blur',(function(e){
        var input = Event.element(e);
        if(input.value == "") {
          input.value = this.inputs[input.id];
          if(/password/.test(input.name)) input.type = "text";
        }
      }).bind(this)).alt;
    }).bind(this));
  }
}
// ===== end ClickClear =====