   function disableBtn(btnID, newText) {
        var btn = document.getElementById(btnID);
        var oldValue = btn.value;
        btn.disabled = true;
        btn.value = newText;

        //get rid of the Page_Validators is not defined error
        if (HasPageValidators()) {
            if (Page_Validators != undefined && Page_Validators != null) {
                //Looping through the whole validation collection.
                for (var i = 0; i < Page_Validators.length; i++) {
                    ValidatorEnable(Page_Validators[i]);
                    //if condition to check whether the validation was successfull or not.
                    if (!Page_Validators[i].isvalid) {
                        FailValidators(btn, oldValue);
                        break;
                    }
                    else {
                        var isValidationOk = Page_IsValid;
                        if (navigator.appName !== 'Microsoft Internet Explorer') {
                            EnableOnUnload(btnID, btn.value);
                        }

                        if (isValidationOk !== null) {
                            //            //page was valid
                            if (isValidationOk) {
                                btn.disabled = true;
                                btn.value = newText;
                                btn.style.background = "url(/images/loader.gif)";
                            }
                            else { //page was not valid
                                btn.disabled = false;
                            }
                        }

                    }
                }
            }
        }
        else {
            setTimeout("SetImage('" + btnID + "')", 10);
                        btn.disabled = true;
                        btn.value = newText;
        }
    }

    //set the background image of the button

    function FailValidators(btn, oldValue) {
        btn.disabled = false;
        btn.value = oldValue;
    }

    function HasPageValidators() {
        var hasValidators = false;

        try {
            if (Page_Validators.length > 0) {
                hasValidators = true;
            }
        }
        catch (error) {
        }

        return hasValidators;
    }

function SetImage(btnID) {
    var btn = document.getElementById(btnID);
    btn.style.background = 'url(/images/loader.gif)';
}

//enable the button and restore the original text value
function EnableOnUnload(btnID, btnText) {
    window.onunload = function() {
        var btn = document.getElementById(btnID);
        btn.disabled = false;
        btn.value = btnText;
    }
}
