function FormValidator() 
{
    this.Rules = new Array();
}

FormValidator.prototype.addRule = function(ruleName, params)
    {
        var r = new Array();

        r['rule'] = ruleName;
        r['params'] = params;

        this.Rules.push(r);

        return true;
    }

FormValidator.prototype.validateAll = function()
    {
        var result = true;
        var i = 0;

        for (i = 0; i < this.Rules.length; i++)
        {
            result = result && this[this.Rules[i]['rule']](this.Rules[i]['params']);
        }
        return result;
    }


    ///////////////////////////////////////////////////////////////////////////
    //
    // Rules functions

FormValidator.prototype.NotEmptyField = function(params)
    {
        return null != document.getElementById(params[0]) && "" != document.getElementById(params[0]).value;
    }

FormValidator.prototype.MatchRegexp = function(params)
    {
        var r = new RegExp(params[1], params[2]);
        return document.getElementById(params[0]) && r.test(document.getElementById(params[0]).value);
    }

FormValidator.prototype.IsEqual = function(params)
    {
        return null != document.getElementById(params[0]) && 
               null != document.getElementById(params[1]) &&
               document.getElementById(params[0]).value == document.getElementById(params[1]).value;
    }

FormValidator.prototype.IsInteger = function(params)
    {
        return null != document.getElementById(params[0]) && NaN != parseInt(document.getElementById(params[0]).value);
    }

FormValidator.prototype.IsFloat = function(params)
    {
        return null != document.getElementById(params[0]) && NaN != parseFloat(document.getElementById(params[0]).value);
    }

FormValidator.prototype.LongerOrEqual = function(params)
    {
        return null != document.getElementById(params[0]) && params[1] <= document.getElementById(params[0]).value.length;
    }
