private void TestAccount(TraktAccount account)
        {
            TraktResponse response = null;
            if (NewAccount)
            {
                if (lblTestConnect != null)
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.CreatingAccount);

                GUIWindowManager.Process();
                response = TraktAPI.TraktAPI.CreateAccount(account);
            }
            else
            {
                if (lblTestConnect != null)
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, Translation.SigningIntoAccount);

                GUIWindowManager.Process();
                response = TraktAPI.TraktAPI.TestAccount(account);
            }

            if (response.Status == "failure")
            {
                string errorMessage = string.IsNullOrEmpty(response.Error) ? response.Message : response.Error;
                GUIUtils.ShowNotifyDialog(Translation.Error, errorMessage);
                if (lblTestConnect != null)
                    GUIControl.SetControlLabel(GetID, lblTestConnect.GetID, string.Empty);
            }
            else
            {
                // Save New Account Settings
                TraktSettings.Username = account.Username;
                TraktSettings.Password = account.Password;
                if (!TraktSettings.UserLogins.Exists(u => u.Username == TraktSettings.Username))
                {
                    TraktSettings.UserLogins.Add(new TraktAuthentication { Username = TraktSettings.Username, Password = TraktSettings.Password });
                }
                TraktSettings.AccountStatus = ConnectionState.Connected;
                HideAccountControls();
                InitProperties();

                // clear caches
                // watch lists are stored by user so dont need clearing.
                GUITraktFriends.ClearCache();
                GUICalendar.ClearCache();
                GUIRecommendationsMovies.ClearCache();
                GUIRecommendationsShows.ClearCache();
            }
        }
        protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType)
        {
            // wait for any background action to finish
            if (GUIBackgroundTask.Instance.IsBusy) return;

            switch (controlId)
            {
                // Disconnect
                case ((int)SkinControls.Disconnect):
                    DisconnectAccount();
                    break;

                case ((int)SkinControls.Create):
                    ShowAccountControls(true);
                    break;

                case ((int)SkinControls.Login):
                    bool autoLogin = ShowLoginMenu();
                    ShowAccountControls(false);
                    if (autoLogin)
                    {
                        GUIControl.SetControlLabel(GetID, btnUsername.GetID, this.Username);
                        GUIControl.SetControlLabel(GetID, btnPassword.GetID, GetMaskedPassword(this.Password));
                        TraktAccount account = new TraktAccount
                        {
                            Username = this.Username,
                            Password = this.Password
                        };
                        TestAccount(account);
                    }
                    break;

                case ((int)SkinControls.Username):
                    string username = Username;
                    if (GUIUtils.GetStringFromKeyboard(ref username))
                    {
                        Username = username;
                        GUIControl.SetControlLabel(GetID, btnUsername.GetID, username);
                    }
                    break;

                case ((int)SkinControls.Password):
                    string password = Password;
                    if (GUIUtils.GetStringFromKeyboard(ref password, true))
                    {
                        Password = password;
                        GUIControl.SetControlLabel(GetID, btnPassword.GetID, GetMaskedPassword(password));
                    }
                    break;

                case ((int)SkinControls.EmailButton):
                    string email = Email;
                    if (GUIUtils.GetStringFromKeyboard(ref email))
                    {
                        Email = email;
                        GUIControl.SetControlLabel(GetID, btnEmail.GetID, email);
                    }
                    break;

                case ((int)SkinControls.Ok):
                    if (ValidateFields())
                    {
                        TraktAccount account = new TraktAccount
                        {
                            Username = this.Username,
                            Password = this.Password.GetSha1(),
                            Email = this.Email
                        };
                        TestAccount(account);
                    }
                    break;

                case ((int)SkinControls.Cancel):
                    HideAccountControls();
                    break;

                default:
                    break;
            }
            base.OnClicked(controlId, control, actionType);
        }