﻿YAHOO.namespace("Hollow.Widget");

(function() {
  
  YAHOO.Hollow.Widget.Wipable = function(field, cfg){
    cfg = (cfg) ? cfg : {};
    this.field = YAHOO.util.Dom.get(field);
    this.initialValue = (cfg.initialValue) ? cfg.initialValue : this.field.value;
    
    YAHOO.util.Event.addListener(this.field, "click", this.handleFocus, this, true);
  };

  YAHOO.Hollow.Widget.Wipable.prototype = {
    handleFocus: function(item){
      if(this.shouldWipe()){
        this.wipe();
      }
      else {
        this.highlight();
      }
    },
    
    highlight: function(){
      this.field.select();
    },
    
    wipe: function(){
      this.field.value = "";
    },
    
    shouldWipe: function(){
      return(this.initialValue == this.field.value);
    }
    
  };  
})();
