/**
 * Fill empty input field with
 * @version:  01.01.01 Alpha
 * @modified: 2009-07-06 15:58:00
 */
var triggerEmpty = newClass({
    sFrmId  : null,
    sName   : null,
    oElm    : null,
    sText   : '',

    init : function(sIdForm, sName, sText)
    {
        this.sFrmId = sIdForm;
        this.sName  = sName;
        this.sText  = sText;
    },
    onready : function()
    {
        var form, inp;
        form = this.$('form#' + this.sFrmId);
        if (form) {
            this.oElm  = this.$(form.elm.elements[this.sName]);
        }
        if (!this.oElm) {
            return;
        }

        inp = this.oElm.elm;
        if (inp.value == '' || inp.value == this.sText) {
            inp.value = this.sText;
            this.oElm.addClass('shadowText');
        }
        this.oElm.addListener(this, "onfocus");
        this.oElm.addListener(this, "onblur");
        form.addListener(this, "onsubmit");
    },
    onfocus : function(evtWr)
    {
        this._clearField();
    },
    onblur : function(evtWr)
    {
        if (this.oElm.elm.value == '') {
            this.oElm.elm.value = this.sText;
            this.oElm.addClass('shadowText');
        }
    },
    onsubmit : function(evtWr)
    {
        this._clearField();
    },
    _clearField : function()
    {
        var sText = this.sText.substr(0, this.oElm.elm.value.length);
        if (this.oElm.elm.value == sText) {
            this.oElm.elm.value = '';
            this.oElm.removeClass('shadowText');
        }
    },
    config : {
    }
});

