Event.observe(window,'load', function() {
	document.getElementById("clear_password").style.display = "block";
	document.getElementById("password").style.display = "none";
	
  $$('input.clearonfocus').map(function(element) {
    element.setAttribute("autocomplete", "off")
		
    var form = element.up('form')
    if(form) {
      if(!form.clearOnFocusElements) {
        form.clearOnFocusElements = []
      } 
      form.clearOnFocusElements.push(new ClearOnFocus(element))
    }
    return form
  })
})

var ClearOnFocus = Class.create()
Object.extend(ClearOnFocus.prototype, { 
  initialize: function(element) { 
    this.element = $(element)
    this.originalValue = $F(element)
    this.element.observe('blur', this.onBlur.bind(this))
    this.element.observe('focus', this.onFocus.bind(this))
  }, 
  onFocus: function(event) { 
    if($F(this.element) == this.originalValue) { 
      this.element.value = ''
      this.element.removeClassName('clearonfocus')
    }
		if (this.element.id == "clear_password"){
			document.getElementById("clear_password").style.display = "none";
			document.getElementById("password").style.display = "block";
			document.getElementById("password").focus();
		}
  }, 
  onBlur: function(event) { 
    if($F(this.element).match(/^\s*$/)) { 
      this.element.value = this.originalValue
      this.element.addClassName('clearonfocus')
    } 
		if (this.element.id == "password" && this.element.value.length == 0){
			document.getElementById("clear_password").style.display = "block";
			document.getElementById("password").style.display = "none";
		}
  } 
})
