package com.afi.estimator.util
{
    
    import flash.events.Event;
    import flash.events.EventDispatcher;
    
    import spark.components.DropDownList;
    import spark.components.TextInput;
    
    public class ValidationUtil
        extends EventDispatcher
    {
        // Event type to trigger validation on current form
        public static const VALIDATE:String = "VALIDATE";
        
        // Singleton instance
        public static var instance:ValidationUtil = new ValidationUtil();
        
        // Will dispatch the event that all views.ui.ErrorAlert instances listen for
        public static function trigger():void {
            instance.dispatchEvent(new Event(VALIDATE));
        }
        
        // Tests that the input is not whitespace and that it is not the default either
        public static function validateTI(input:String, defaultInput:String = null):Boolean {
            return !StrUtil.isWhiteSpace(input) &&
                   input != defaultInput;
        }
        
        // Prompt index is -1, so we test against that
        public static function validateDDL(index:int):Boolean {
            return index != -1;
        }
        
        // Expects the default selectedValue of the RadioButtonGroup to be null
        public static function validateRBG(selectedValue:Object):Boolean {
            return selectedValue != null;
        }
    }
}