



/****** DEPRECATED ******/
/**
 * This has been moved to the top_level package. For any future development please reference this class there.
 */




/**
 * Sets up a text field with default-text and an optional error message append after the input.
 
 * @param _field_jq jQuery object referencing the text-input or textarea to be affected.
 
 * @param _init_str String initially set as the fields value and checked 
 * on blur event used to set changed property.
 
 * @param _error_message A message ( if required ) 
 * that can be displayed if input validation fails for this field.
 
 * @param _error_css_class_names CSS class names added to error message.
 
 * @property changed - Weather field value has changed from initial value.
 * @property error_box - jQuery object for box containing error message.
 */
var

TextField = function( _field_jq, _init_str, _error_message, _error_css_class_names )
{
    var
    _self = this,
    _field_value,
    _field_index = 0;
    
    _self.field_jq    = _field_jq;
    _self.default_str = _init_str;
    
    _error_css_class_names = _error_css_class_names || 'err';
    
    // PARAM FOR INITIAL STRING TO MAKE SURE FF ISN'T REPLACING IT WITH PRIOR ENTRY
    if( _init_str ) _field_jq.val( _init_str );
    
    // There's a value - implement default text functionality:
    if( Boolean(_init_str) )
    {
        // EVENT HANDLERS
        _field_jq
            .focus(function() // BLANK ON FOCUS IF NOT CHANGED
            {
                if( !_self.changed ) _field_jq.val('');
            })
            .blur(function()
            {
                _field_value = _field_jq.val();
            
                // Field string is same as initial string or empty:
                if( _field_value == _init_str || _field_value == '' )
                {
                     // RESTORE INITIAL VALUE & SET CHANGED PROPERTY TO FALSE
                    _field_jq.val( _init_str );
                    _self.changed = false;
                }
                else // IT'S CHANGED!
                {
                    _self.changed = true;
                }
                
            });
    }
    
    // IF ERROR MESSAGE IS SET
    if( _error_message )
    {
        _self.error_box = jQuery( modo.EL.D )
            .html( _error_message )
            .addClass( _error_css_class_names )
            .hide();
        
        _self.error_box.insertAfter( _field_jq );
    }
};

/**
 * Hides or shows error message if it's changed or not, if an error message's been set.
 
 * @param _show_error Weather to display error box depending on changed property.
 
 * @returns Boolean changed property.
 */

TextField.prototype.hasChanged = function( _show_error )
{
    var _self = this;
    if( _show_error )
    {
        if( !_self.changed )
        {
            if( _self.error_box ) _self.error_box.show();
        }else{
            if( _self.error_box ) _self.error_box.hide();
        }
    }
    return _self.changed;
};

TextField.prototype.resetDefaultStr = function()
{
    var _self = this;
    
    _self.field_jq.val( _self.default_str );
    _self.changed = false;
}
