﻿// Include a warning icon on all invalid RadTextBox fields.
if (Sys) Sys.Application.add_init(function() {
if (typeof (ValidatorUpdateDisplay) != "undefined") {
        // wrap ValidatorUpdateDisplay in a custom function
        OriginalValidatorUpdateDisplay = ValidatorUpdateDisplay;
        ValidatorUpdateDisplay = function(val) {
            // call the original
            OriginalValidatorUpdateDisplay(val);
            if (typeof val.controltovalidate != "undefined" && !val.isvalid) {
                try {
                    var el = $find(val.controltovalidate);
                    if (el) {
                        // see if we have a RadTextBox
                        if (typeof el._invalid == "boolean" && typeof el.updateCssClass == "function") {
                            // set the invalid style
                            el._invalid = true;
                            el.updateCssClass();
                            // add a couple of new event handlers for this validator
                            if (!el['deqEventHandlersAdded_' + val.id]) {
                                // clear the invalid style on focus
                                if (typeof el.add_focus == "function") {
                                    el.add_focus(function(s, e) {
                                        el._invalid = false;
                                        el.updateCssClass();
                                    });
                                }
                                // force revalidate on blur (even if the text has not changed)
                                if (typeof el.add_blur == "function" && typeof ValidatorValidate == "function") {
                                    el.add_blur(function(s, e) {
                                        ValidatorValidate(val);
                                    });
                                }
                                // set the flag so multiple event handlers are not added
                                el['deqEventHandlersAdded_' + val.id] = true;
                            }
                        }
                    }
                } catch (err) { }
            }
        };
    }
}); else alert("'Sys' not available - warning-icon.js not loaded!");
