/**
 * JS Class for the Rule Type Number Widget.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program as the file license.txt. If not, see
 * <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
 *
 * @package    CMS
 * @subpackage Widget
 * @author     Squiz Pty Ltd <products@squiz.net>
 * @copyright  2010 Squiz Pty Ltd (ACN 084 670 600)
 * @license    http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt GPLv2
 */

function RuleTypeNumberWidgetType(id, value)
{
    this.value    = null;
    this.widgetid = '';

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

}

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

    },

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

    },

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

    },

    validate: function()
    {
        // Check if this is a numberic value.
        var val = Number(this.value);
        if (isNaN(val) === true) {
            return false;
        }

        // Is integer?
        var checkVal = parseInt(this.value, 10);
        if (val === checkVal) {
            return true;
        }

        // Is float?
        checkVal = parseFloat(this.value);
        if (val === checkVal) {
            return true;
        }

        return false;

    },

    getErrors: function()
    {
        return this.errors;

    }

};

