function Form(element)
{
    if (!element.addEventHandler)
        Control(element);
        
    element.addControl = Form.prototype.addControl;
    element.checkForm  = Form.prototype.checkForm;
    
    element.controls   = [];
    element.cancelled  = false;
    
    element.addEventHandler("submit", function() { if (!element.checkForm()) return false; });

    return element;
}

Form.prototype.addControl = function(control, message)
{
    this.controls[this.controls.length] =
    {
        "control": control,
        "message": message
    };
};

Form.prototype.checkForm = function()
{
    for (var i = 0; i < this.controls.length; ++i)
    {
        with (this.controls[i])
        {
            // Don't use isValid, just in case it's out of date.
            if (control.isVisible() && control.validate(control.getValue()) == null)
            {
                control.focus();
                alert(message);
                
                return false;
            }
        }
        
    }
    return true;
};
