﻿/* ********************************************************** */
/* OpenAuthenticateLogin command                              */        
/* ********************************************************** */
(function () {
    $(document).ready(function() {
        // Retrieve.
        var command = GuiController.getCommand('OpenAuthenticateLogin');
        if (!command) { 
            return;
        }
        
        // onInvoke handler.        
        command.onInvoke = function() {
            ASPxClientEdit.ClearGroup('CredentialsLoginValidationGroup', true);
            _credentialsLoginPopupControl.Show();
        };
    });
})();

/* ********************************************************** */
/* CancelAuthenticateLogin command                            */        
/* ********************************************************** */
(function () {
    $(document).ready(function() {
        // Retrieve.
        var command = GuiController.getCommand('CancelAuthenticateLogin');
        if (!command) { 
            return;
        }
        
        // onInvoke handler.        
        command.onInvoke = function() {
            ASPxClientEdit.ClearGroup('CredentialsLoginValidationGroup', true);
            _credentialsLoginPopupControl.Hide();
        };
    });
})();

/* ********************************************************** */
/* AuthenticateLogin command                                  */        
/* ********************************************************** */
(function () {
    $(document).ready(function() {
        // Retrieve.
        var command = GuiController.getCommand('AuthenticateLogin');
        if (!command) {
            return;
        }
        
        // validateInvoke handler.        
        command.validateInvoke = function() {   
            var result = -1;
            if (ASPxClientEdit.ValidateGroup('CredentialsLoginValidationGroup', true) === false) {
                return 100;
            } 
            return result;
        };

        // onInvoked handler.        
        command.onInvoked = function() {   
            _credentialsLoginPopupControl.Hide();
            ASPxClientEdit.ClearGroup('CredentialsLoginValidationGroup', true);
            command.displaySuccessMessage();
        };
    });
})();

/* ********************************************************** */
/* OpenAuthenticateCredentialsChange command                  */        
/* ********************************************************** */
(function () {
    $(document).ready(function() {
        // Retrieve.
        var command = GuiController.getCommand('OpenAuthenticateCredentialsChange');
        if (!command) { 
            return;
        }
        
        // onInvoke handler.        
        command.onInvoke = function() {
            GuiController.invokeCommand('CancelAuthenticateLogin');
            _credentialsChangePopupControl.Show();
        };
    });
})();

/* ********************************************************** */
/* CancelAuthenticateCredentialsChange command                */        
/* ********************************************************** */
(function () {
    $(document).ready(function() {
        // Retrieve.
        var command = GuiController.getCommand('CancelAuthenticateCredentialsChange');
        if (!command) { 
            return;
        }
        
        // onInvoke handler.        
        command.onInvoke = function() {
            if (window['_credentialsChangePopupControl']) {
                ASPxClientEdit.ClearGroup('CredentialsChangeValidationGroup', true);
                _credentialsChangePopupControl.Hide();
            }
            command.processRedirect();
        };
    });
})();

/* ********************************************************** */
/* AuthenticateCredentialsChange command                      */        
/* ********************************************************** */
(function () {
    $(document).ready(function() {
        // Retrieve.
        var command = GuiController.getCommand('AuthenticateCredentialsChange');
        if (!command) {
            return;
        }
        
        // validateInvoke handler.        
        command.validateInvoke = function() {   
            var result = -1;
            if (ASPxClientEdit.ValidateGroup('CredentialsChangeValidationGroup', true) === false) {
                result = 100; 
            } 
            else if (_cc_passwordTextbox.GetValue() === _cc_newPasswordTextBox.GetValue()) {
                result = 0;
            }
            else if (_cc_newPasswordTextBox.GetValue() !== _cc_newPasswordConfirmTextBox.GetValue()) {
                result = 1;
            }
            return result;
        };

        // onInvoked handler.        
        command.onInvoked = function() {   
            ASPxClientEdit.ClearGroup('CredentialsChangeValidationGroup', true);
            command.displaySuccessMessage();
            if (window['_credentialsChangePopupControl']) {
                _credentialsChangePopupControl.Hide();
            }
        };
    });
})();

/* ********************************************************** */
/* OpenAuthenticateCredentialsForgotten command               */        
/* ********************************************************** */
(function () {
    $(document).ready(function() {
        // Retrieve.
        var command = GuiController.getCommand('OpenAuthenticateCredentialsForgotten');
        if (!command) { 
            return;
        }
        
        // onInvoke handler.        
        command.onInvoke = function() {
            GuiController.invokeCommand('CancelAuthenticateLogin');
            _credentialsForgottenPopupControl.Show();
        };
    });
})();

/* ********************************************************** */
/* CancelAuthenticateCredentialsForgotten command             */        
/* ********************************************************** */
(function () {
    $(document).ready(function() {
        // Retrieve.
        var command = GuiController.getCommand('CancelAuthenticateCredentialsForgotten');
        if (!command) { 
            return;
        }
        
        // onInvoke handler.        
        command.onInvoke = function() {
            ASPxClientEdit.ClearGroup('CredentialsForgottenValidationGroup', true);
            _credentialsForgottenPopupControl.Hide();
        };
    });
})();

/* ********************************************************** */
/* AuthenticateCredentialsForgotten command                   */        
/* ********************************************************** */
(function () {
    $(document).ready(function() {
        // Retrieve.
        var command = GuiController.getCommand('AuthenticateCredentialsForgotten');
        if (!command) {
            return;
        }
        
        // validateInvoke handler.        
        command.validateInvoke = function() {   
            var result = -1;
            if (ASPxClientEdit.ValidateGroup('CredentialsForgottenValidationGroup', true) === false) {
                return 100;
            } 
            return result;
        };
        
        // onInvoked handler.        
        command.onInvoked = function() {   
            command.displaySuccessMessage();
            _credentialsForgottenPopupControl.Hide();
            ASPxClientEdit.ClearGroup('CredentialsForgottenValidationGroup', true);                              
        };
    });
})();