/**
 * @author: ideatronic
 */
var Idea = {
    DefaultValue: {}
}

Idea.DefaultValue = function(el_id, el_value)
{
    this.el = document.getElementById(el_id);
    this.defaultValue = el_value;
    this.valueHasChanged = false;
    this.form = this.getForm();
    this.initDefaultValue();
}

Idea.DefaultValue.prototype = {
    getForm: function()
    {
        if (this.el.parentNode.tagName == 'FORM') 
            return this.el.parentNode;
    },
    
    initDefaultValue: function()
    {
        var $this = this;
        
        if (!this.el.value)
            this.el.value = this.defaultValue;
        else 
            this.valueHasChanged = true;
        
        this.el.onfocus = function()
        {
            if (!$this.valueHasChanged) 
			{
				this.value = '';
			}
        };
        
        this.el.onblur = function()
        {
            if (!$this.valueHasChanged) 
            {
                this.value = $this.defaultValue;
            }
        };
        
        this.el.onchange = function()
        {
            $this.valueHasChanged = true;
        };
        
		$(this.form).addEvent('submit', function()
        {
            if ($this.el.value == $this.defaultValue) 
                $this.el.value = '';
        });
        
    }
}

