﻿function ValidatePage() {
    Page_ClientValidate(); // ASP.NET validation client API
    changeBorderOnValidation();
}

function changeBorderOnValidation() {
    //Reset the hidden field
    //var hdn = document.getElementById('hdnFailedControlNames');
    var hdn = $('#hdnFailedControlNames');
    var inlineStyles;
    hdn.value = "";
    var i;
    // Loop throgh all validators
    for (i = 0; i < Page_Validators.length; i++) {
        var c = Page_Validators[i]; // get individual validator
        // get the control associated with the validator
        var ctrl = document.getElementById(c.controltovalidate);
        if (ctrl != null) // if found the control
        {
            if (c.isvalid) // if validation passed
            {
                // and also the control's name
                // is not stored in the hidden field,
                if (hdn.value.indexOf(ctrl.name) == -1) {
                    // then strip off the error style
                    // so the control can use its
                    // original style
                    ctrl.className = ctrl.className.replace("borderRed", "");
                } // otherwise, don't do anything about the style.
            }
            else  // if validation failed
            {
                // if the error style has not been added yet
                if (ctrl.className.indexOf("borderRed") == -1) {
                    // then add the error style in front of
                    // the control's original style
                    ctrl.className = 'borderRed ' + ctrl.className;
                } // otherwise, if the error style was already
                // added before, then no need to add it again.

                // now store the failed control name
                // in the hidden field.
                hdn.value = hdn.value + ctrl.name + "|";
            }
        }
    }
}

//document.onkeyup = changeBorderOnValidation();
//document.onclick = changeBorderOnValidation();
