﻿
// TextBoxWatermark class - shows and hides default text within a textbox

var TextBoxWatermark = new Class(
{
    initialize: function(textbox, watermark, watermarkClass)
    {
        this._textBox = textbox;
        this._watermark = watermark;
        this._watermarkClass = watermarkClass;
        if (this._textBox.value == this._watermark)
        {
            this._textBox.addClass(this._watermarkClass);
        }
        this._textBox.addEvent('focus', this.onTextBoxFocus.bind(this));
        this._textBox.addEvent('blur', this.onTextBoxBlur.bind(this));
    },

    onTextBoxFocus: function(e)
    {
        if (this._textBox.value == this._watermark)
        {
            this._textBox.value = '';
            this._textBox.removeClass(this._watermarkClass);
        }
    },

    onTextBoxBlur: function(e)
    {
        if (!this._textBox.value)
        {
            this._textBox.value = this._watermark;
            this._textBox.addClass(this._watermarkClass);
        }
    }
});