﻿/* ********************************************************** */
/* 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) {
                _userNameLoginTextBox.SetFocus();
                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();
            }
			var textBoxUserNameLogin = window['_userNameLoginTextBox'];
			if (textBoxUserNameLogin !== undefined) {
				textBoxUserNameLogin.Focus();
			}
            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');
			// restoring initial header text
			var textControlItem = GuiController.getCachedValue('LoginText2')
			if (textControlItem !== undefined){
				var labelHeader = window['_formHeaderLabel'];
					if (labelHeader !== undefined) {						
						labelHeader.SetText(textControlItem);
					}
			}
            _credentialsForgottenPopupControl.Show();
			var secretQuestionLabel = window['_passwordQuestionAnswerLabel'];
            if (secretQuestionLabel !== undefined) {
				secretQuestionLabel.SetClientVisible(false);
				secretQuestionLabel.SetText('');
				var textBoxAnswer = window['_passwordQuestionAnswerTextBox'];
				if (textBoxAnswer !== undefined) {
					textBoxAnswer.SetClientVisible(false);
					textBoxAnswer.SetText('');
				}
				var textBoxUserName = window['_userNameForgottenTextBox'];
				if (textBoxUserName !== undefined) {
					textBoxUserName.SetEnabled(true); 
					textBoxUserName.Focus();
				}
				var textBoxEMail = window['_emailAddressTextBox'];
				if (textBoxEMail !== undefined) {
					textBoxEMail.SetEnabled(true); 
				}				
			}
        };
    });
})();

/* ********************************************************** */
/* 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();
			var textBoxUserNameLogin = window['_userNameLoginTextBox'];
			if (textBoxUserNameLogin !== undefined) {
				textBoxUserNameLogin.Focus();
			}
        };
    });
})();

/* ********************************************************** */
/* 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);                              
        };
    });
})();
