/**
 * @author kazumasa.kaneko
 */
var DUI = {};
DUI.ShowPrompt = Class.create();
DUI.ShowPrompt.prototype = {
    initialize: function(ele, prompt) {
        this.element = $(ele);
        this.prompt = prompt;
        Event.observe(this.element, "focus", this.onfocus.bind(this));
        Event.observe(this.element, "blur", this.onblur.bind(this));
        Event.observe(this.element.form, "submit", this.onsubmit.bind(this));
        this.showPrompt();
    },
    onfocus: function() {
        this.hidePrompt();
    },
    onblur: function() {
        this.showPrompt();
    },
    onsubmit: function() {
        this.hidePrompt();
    },
    hidePrompt: function() {
        if (this.isEmpty) {
            this.element.value = "";
        }
    },
    showPrompt: function() {
        this.isEmpty = this.element.value.length == 0;
        if (this.isEmpty) {
            this.element.value = this.prompt;
        }
    }
};

