/*  oTextbox: The textbox or password field in which the watermark should be applied
    sText: The text to be displayed in the textbox when the textbox is empty
    oCss: An associative array that applies css classes to the tabs. Keys to the array are:
          blur_color, focus_color
*/
function Watermark(oTextbox, sText, oCss)
{
    var oThis = this;
    
    this.textbox = Util.Get(oTextbox);
    
    if (this.textbox.getAttribute('type') == 'password')
    {
		this.fake_password = document.createElement('input');
		this.fake_password.setAttribute('type', 'text');
		this.fake_password.className = this.textbox.className;
		this.fake_password.style.color = oCss.blur_color;
		this.fake_password.style.width = this.textbox.style.width;
		this.fake_password.value = sText;
		this.fake_password.tabIndex = parseInt(oThis.textbox.getAttribute('tabindex')) + 1;
		
		Util.AddEvent(this.fake_password, 'focus',
			function() {
				oThis.fake_password.style.display = 'none';
				oThis.textbox.style.display = '';
				oThis.textbox.focus();
			}
		);
    
		this.textbox.parentNode.insertBefore(this.fake_password, this.textbox);
		
		this.textbox.style.display = 'none';
		Util.AddEvent(this.textbox, 'blur',
			function() {
				if (oThis.textbox.value == '') {
					oThis.fake_password.style.display = '';
					oThis.textbox.style.display = 'none';
				}
			}
		);
		
    } else {
    
		this.text = sText;
		this.css = oCss;

		Util.AddEvent(this.textbox, 'focus', function() { oThis.focus(); } );
		Util.AddEvent(this.textbox, 'blur', function() { oThis.blur(); } );
	    
		this.blur();
    }
}

Watermark.prototype.focus = function()
{
    if (this.textbox.value == this.text) {
        this.textbox.style.color = this.css.focus_color;
        this.textbox.value = '';
    }
};

Watermark.prototype.blur = function()
{
    if (this.textbox.value == '') {
        this.textbox.value = this.text;
        this.textbox.style.color = this.css.blur_color;
    }
};