function RuleTypeLengthWidgetType(id, value, operator, length)
{
    this.widgetType = 'RuleTypeLengthWidgetType';

    this.value    = value;
    this.length   = null;
    this.operator = null;
    this.plain    = false;
    this.widgetid = '';

    if (typeof length !== 'undefined' && length !== null) {
        this.setLength(length);
    }

    if (typeof operator !== 'undefined' && operator !== null) {
        this.setOperator(operator);
    }

}

RuleTypeLengthWidgetType.prototype = {

    reset: function()
    {
        this.simpleResult = false;
        this.widget       = null;
        this.value        = null;
        this.server       = true;
        this.client       = true;
        this.errors       = [];

    },

    setValue: function(val)
    {
        this.value = val;

    },

    setWidgetid: function(wid)
    {
        this.widgetid = wid;

    },

    setLength: function(len)
    {
        this.length = len;

    },

    setPlain: function(plain)
    {
        // Set this to true, if value = length to check instead of a str.
        this.plain = plain;

    },

    setOperator: function(op)
    {
        this.operator = op;
        switch (op) {
            case '==':
                this.opDesc = 'equal to';
            break;
            case '!=':
                this.opDesc = 'no equal to';
            break;
            case '>' :
                this.opDesc = 'larger than';
            break;
            case '<' :
                this.opDesc = 'smaller than';
            break;
            case '>=':
                this.opDesc = 'equal or larger than';
            break;
            case '<=':
                this.opDesc = 'equal or smaller than';
            break;
            default:
                this.opDesc = '';
            break;
        }

    },


    validate: function()
    {
        this.errors = [];
        var result  = false;
        var length  = this.value.length;
        if (this.plain === true) {
            length = this.value;
        }

        var evalStr = ['result = (', length, ' ', this.operator, ' ', this.length, ');'].join('');

        eval(evalStr);
        if (result === true) {
            return true;
        } else {
            var msg = ['The length of "', this.value, '" is not ', this.opDesc, ' ', this.length, '.'].join('');
            this.errors.push(msg);
            return false;
        }

    },

    getErrors: function()
    {
        return this.errors;
    }


};
