/// <summary>
        /// ResetMotivationDetailCodeFilter
        /// </summary>
        private static void ResetMotivationDetailCodeFilter(TCmbAutoPopulated ACmbMotivationDetailCode,
            ref string AMotivationDetail,
            bool AActiveOnly)
        {
            if ((ACmbMotivationDetailCode.Count == 0) && (ACmbMotivationDetailCode.Filter != null)
                && (!ACmbMotivationDetailCode.Filter.Contains("1 = 2")))
            {
                AMotivationDetail = string.Empty;
                ACmbMotivationDetailCode.RefreshLabel();

                if (AActiveOnly)
                {
                    //This is needed as the code in TFinanceControls.ChangeFilterMotivationDetailList looks for presence of the active only prefix
                    ACmbMotivationDetailCode.Filter = AMotivationDetailTable.GetMotivationStatusDBName() + " = true And 1 = 2";
                }
                else
                {
                    ACmbMotivationDetailCode.Filter = "1 = 2";
                }

                return;
            }

            if (ACmbMotivationDetailCode.Count > 0)
            {
                AMotivationDetail = ACmbMotivationDetailCode.GetSelectedString();
            }

            if (AActiveOnly)
            {
                ACmbMotivationDetailCode.Filter = AMotivationDetailTable.GetMotivationStatusDBName() + " = true";
            }
            else
            {
                ACmbMotivationDetailCode.Filter = string.Empty;
            }

            ACmbMotivationDetailCode.SetSelectedString(AMotivationDetail);
            ACmbMotivationDetailCode.RefreshLabel();
        }
        /// <summary>
        /// Call when the Motivation Detail changes
        /// </summary>
        public static void OnMotivationDetailChanged(GiftBatchTDSAGiftDetailRow ACurrentDetailRow,
            GiftBatchTDS AMainDS,
            Int32 ALedgerNumber,
            TFrmPetraEditUtils APetraUtilsObject,
            TCmbAutoPopulated ACmbKeyMinistries,
            TCmbAutoPopulated ACmbMotivationDetailCode,
            TtxtAutoPopulatedButtonLabel ATxtDetailRecipientKey,
            Int64 ARecipientKey,
            TtxtAutoPopulatedButtonLabel AtxtDetailRecipientLedgerNumber,
            TextBox ATxtDetailCostCentreCode,
            TextBox ATxtDetailAccountCode,
            TextBox ATxtDetailRecipientKeyMinistry,
            CheckBox AChkDetailTaxDeductible,
            TextBox ATxtDeductibleAccount,
            string AMotivationGroup,
            ref string AMotivationDetail,
            ref bool AMotivationDetailChangedFlag,
            bool ARecipientKeyChangingFlag,
            bool ACreatingNewGiftFlag,
            bool AInEditModeFlag,
            bool ABatchUnpostedFlag,
            bool ATaxDeductiblePercentageEnabledFlag,
            bool AAutoPopulatingGift,
            out bool ADoTaxUpdate,
            out string AAutoPopComment)
        {
            ADoTaxUpdate = false;
            AAutoPopComment = null;

            if (!ABatchUnpostedFlag || !AInEditModeFlag || ATxtDetailRecipientKeyMinistry.Visible)
            {
                return;
            }

            Int64 MotivationRecipientKey = 0;
            AMotivationDetail = ACmbMotivationDetailCode.GetSelectedString();

            if (AMotivationDetail.Length > 0)
            {
                AMotivationDetailRow motivationDetail = (AMotivationDetailRow)AMainDS.AMotivationDetail.Rows.Find(
                    new object[] { ALedgerNumber, AMotivationGroup, AMotivationDetail });

                ACmbMotivationDetailCode.RefreshLabel();

                if (motivationDetail != null)
                {
                    RetrieveMotivationDetailAccountCode(motivationDetail,
                        ATxtDetailAccountCode,
                        ATxtDeductibleAccount,
                        ATaxDeductiblePercentageEnabledFlag);

                    MotivationRecipientKey = motivationDetail.RecipientKey;

                    // if motivation detail autopopulation is set to true
                    if (motivationDetail.Autopopdesc)
                    {
                        AAutoPopComment = motivationDetail.MotivationDetailDesc;
                    }

                    // set tax deductible checkbox if motivation detail has been changed by the user (i.e. not a row change)
                    if (!APetraUtilsObject.SuppressChangeDetection || ARecipientKeyChangingFlag)
                    {
                        AChkDetailTaxDeductible.Checked = motivationDetail.TaxDeductible;
                    }

                    if (ATaxDeductiblePercentageEnabledFlag)
                    {
                        if (string.IsNullOrEmpty(motivationDetail.TaxDeductibleAccount))
                        {
                            MessageBox.Show(Catalog.GetString("This Motivation Detail does not have an associated Tax Deductible Account. " +
                                    "This can be added in Finance / Setup / Motivation Details.\n\n" +
                                    "Unless this is changed it will be impossible to assign a Tax Deductible Percentage to this gift."),
                                Catalog.GetString("Incomplete Motivation Detail"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        ADoTaxUpdate = true;
                    }
                }
                else
                {
                    AChkDetailTaxDeductible.Checked = false;
                }
            }

            if (!ACreatingNewGiftFlag && !AAutoPopulatingGift && (MotivationRecipientKey > 0))
            {
                AMotivationDetailChangedFlag = true;
                PopulateKeyMinistry(ACurrentDetailRow,
                    ACmbKeyMinistries,
                    ATxtDetailRecipientKey,
                    AtxtDetailRecipientLedgerNumber,
                    AMotivationDetailChangedFlag,
                    MotivationRecipientKey);
                AMotivationDetailChangedFlag = false;
            }
            else if (ARecipientKey == 0)
            {
                UpdateRecipientKeyText(0, ACurrentDetailRow, AMotivationGroup, AMotivationDetail);
            }

            if (ARecipientKey == 0)
            {
                RetrieveMotivationDetailCostCentreCode(AMainDS, ALedgerNumber, ATxtDetailCostCentreCode, AMotivationGroup, AMotivationDetail);
            }
            else
            {
                string NewCCCode = TRemote.MFinance.Gift.WebConnectors.RetrieveCostCentreCodeForRecipient(ALedgerNumber,
                    ARecipientKey,
                    ACurrentDetailRow.RecipientLedgerNumber,
                    ACurrentDetailRow.DateEntered,
                    AMotivationGroup,
                    AMotivationDetail);

                if (ATxtDetailCostCentreCode.Text != NewCCCode)
                {
                    ATxtDetailCostCentreCode.Text = NewCCCode;
                }
            }
        }