protected void TerminationDialogueButtonSet_OnClick(Object sender, EventArgs eventArgs)
        {
            if (!TerminationDialogueSetAddressTerminationDate.SelectedDate.HasValue)
            {
                TerminationDialogueSetAddressTerminationDate.SelectedDate = null;

                return;
            }

            long terminatedEntityAddressId = Convert.ToInt64(TerminationDialogueTerminatedEntityAddressId.Text);

            Client.Core.Entity.EntityAddress currentEntityAddress = MercuryApplication.EntityAddressGet(terminatedEntityAddressId, false);

            if (Convert.ToDateTime(TerminationDialogueSetAddressTerminationDate.SelectedDate) < currentEntityAddress.EffectiveDate)
            {
                TerminationDialogueSetAddressTerminationDate.SelectedDate = null;

                return;
            }

            DateTime newTerminationDate = Convert.ToDateTime(TerminationDialogueSetAddressTerminationDate.SelectedDate);

            MercuryApplication.EntityAddressTerminate(currentEntityAddress, newTerminationDate);

            Mercury.Client.Core.Member.Member member = MercuryApplication.MemberGetByEntityId(currentEntityAddress.EntityId, true);



            //InitializeMemberAddresses (member, false);

            TerminationDialogueSetAddressTerminationDate.SelectedDate = null;

            return;
        }
        protected void ButtonOk_OnClick(Object sender, EventArgs e)
        {
            Telerik.Web.UI.GridDataItem selectedGridItem = (Telerik.Web.UI.GridDataItem)EntitySendCorrespondenceInformationGrid.SelectedItems[0];

            Telerik.Web.UI.DataKey selectedDataKey = selectedGridItem.OwnerTableView.DataKeyValues[selectedGridItem.ItemIndex];


            System.Text.RegularExpressions.Regex expressionValidator;

            Int64 correspondenceId = 0;

            Client.Core.Reference.Correspondence correspondence = null;

            Client.Core.Entity.EntityContactInformation entityContactInformation = null;


            #region Validation

            if (String.IsNullOrEmpty(SendCorrespondenceSelection.SelectedValue))
            {
                ActionResponseLabel.Text = "** No Correspondence selected to send.";

                return;
            }

            if (!Int64.TryParse(SendCorrespondenceSelection.SelectedValue, out correspondenceId))
            {
                ActionResponseLabel.Text = "** No Correspondence Selected.";

                return;
            }

            correspondence = MercuryApplication.CorrespondenceGet(correspondenceId, true);

            if (correspondence == null)
            {
                ActionResponseLabel.Text = "** Unable to retreive correspondence.";

                return;
            }

            if (!SendCorrespondenceDate.SelectedDate.HasValue)
            {
                ActionResponseLabel.Text = "** No valid send date selected.";

                return;
            }

            if (CorrespondenceUseAlternativeFaxNumber.Checked)
            {
                String faxPattern = @"^([\(]{1}[0-9]{3}[\)]{1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?)?[0-9]{3}(\.|\-| )?[0-9]{4}$";

                expressionValidator = new System.Text.RegularExpressions.Regex(faxPattern);

                if (!expressionValidator.IsMatch(CorrespondenceAlternateFaxNumber.Text))
                {
                    ActionResponseLabel.Text = "** No valid alternate FAX number provided, or not in correct format.";

                    return;
                }
            }

            if (CorrespondenceUseAlternativeEmail.Checked)
            {
                String emailPattern = @"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$";

                expressionValidator = new System.Text.RegularExpressions.Regex(emailPattern);

                if (!expressionValidator.IsMatch(CorrespondenceAlternateEmail.Text))
                {
                    ActionResponseLabel.Text = "** No valid alternate email provided, or not in correct format.";

                    return;
                }
            }


            #endregion


            ActionResponseLabel.Text = String.Empty;


            entityCorrespondence = new Mercury.Client.Core.Entity.EntityCorrespondence(MercuryApplication);

            entityCorrespondence.EntityId = Int64.Parse(selectedDataKey["EntityId"].ToString());

            entityCorrespondence.RelatedEntityId = (RelatedEntity != null) ? RelatedEntity.Id : 0;


            entityCorrespondence.CorrespondenceId = correspondence.Id;

            entityCorrespondence.CorrespondenceName = correspondence.Name;

            entityCorrespondence.CorrespondenceVersion = correspondence.Version;


            entityCorrespondence.ReadyToSendDate = SendCorrespondenceDate.SelectedDate.Value;

            entityCorrespondence.Attention = SendCorrespondenceAttention.Text;

            entityCorrespondence.Remarks = SendCorrespondenceRemarks.Text;


            Boolean useAlternateInformation = false;

            useAlternateInformation |= CorrespondenceUseAlternativeAddress.Checked;

            useAlternateInformation |= CorrespondenceUseAlternativeFaxNumber.Checked;

            useAlternateInformation |= CorrespondenceUseAlternativeEmail.Checked;


            if (!useAlternateInformation)
            {
                Mercury.Server.Application.EntityContactType contactType;

                contactType = (Mercury.Server.Application.EntityContactType)Convert.ToInt32(selectedDataKey["ContactType"].ToString());

                switch (contactType)
                {
                case Mercury.Server.Application.EntityContactType.ByMail:

                    entityCorrespondence.ContactType = contactType;

                    entityCorrespondence.EntityAddressId = Convert.ToInt64(selectedDataKey["AddressId"].ToString());

                    Client.Core.Entity.EntityAddress entityAddress = MercuryApplication.EntityAddressGet(entityCorrespondence.EntityAddressId, false);

                    if (entityAddress != null)
                    {
                        entityCorrespondence.AddressLine1 = entityAddress.Line1;

                        entityCorrespondence.AddressLine2 = entityAddress.Line2;

                        entityCorrespondence.AddressCity = entityAddress.City;

                        entityCorrespondence.AddressState = entityAddress.State;

                        entityCorrespondence.AddressZipCode = entityAddress.ZipCode;
                    }

                    break;

                case Mercury.Server.Application.EntityContactType.Facsimile:

                    entityCorrespondence.ContactType = contactType;

                    entityCorrespondence.EntityContactInformationId = Convert.ToInt64(selectedDataKey["AddressId"].ToString());

                    entityContactInformation = MercuryApplication.EntityContactInformationGet(entityCorrespondence.EntityContactInformationId, true);

                    if (entityContactInformation != null)
                    {
                        entityCorrespondence.ContactFaxNumber = entityContactInformation.Number;
                    }

                    break;

                case Mercury.Server.Application.EntityContactType.Email:

                    entityCorrespondence.ContactType = contactType;

                    entityCorrespondence.EntityContactInformationId = Convert.ToInt64(selectedDataKey["AddressId"].ToString());

                    entityContactInformation = MercuryApplication.EntityContactInformationGet(entityCorrespondence.EntityContactInformationId, true);

                    if (entityContactInformation != null)
                    {
                        entityCorrespondence.ContactEmail = entityContactInformation.Email;
                    }

                    break;

                case Mercury.Server.Application.EntityContactType.InPerson:

                    entityCorrespondence.ContactType = contactType;

                    break;

                default:

                    ActionResponseLabel.Text = "Check selection. Unknown or unhandled contact type: " + contactType.ToString();

                    return;
                }
            }

            else if (CorrespondenceUseAlternativeAddress.Checked)
            {
                entityCorrespondence.ContactType = Mercury.Server.Application.EntityContactType.ByMail;

                entityCorrespondence.EntityAddressId = 0;

                entityCorrespondence.EntityContactInformationId = 0;

                entityCorrespondence.AddressLine1 = CorrespondenceAlternateAddressLine1.Text;

                entityCorrespondence.AddressLine2 = CorrespondenceAlternateAddressLine2.Text;

                entityCorrespondence.AddressCity = CorrespondenceAlternateAddressCity.Text;

                entityCorrespondence.AddressState = CorrespondenceAlternateAddressState.Text;

                entityCorrespondence.AddressZipCode = CorrespondenceAlternateAddressZipCode.Text;
            }

            else if (CorrespondenceUseAlternativeFaxNumber.Checked)
            {
                entityCorrespondence.ContactType = Mercury.Server.Application.EntityContactType.Facsimile;

                entityCorrespondence.EntityAddressId = 0;

                entityCorrespondence.EntityContactInformationId = 0;

                entityCorrespondence.ContactFaxNumber = CorrespondenceAlternateFaxNumber.Text;
            }

            else if (CorrespondenceUseAlternativeEmail.Checked)
            {
                entityCorrespondence.ContactType = Mercury.Server.Application.EntityContactType.Email;

                entityCorrespondence.EntityAddressId = 0;

                entityCorrespondence.EntityContactInformationId = 0;

                entityCorrespondence.ContactEmail = CorrespondenceAlternateEmail.Text;
            }

            else
            {
                ActionResponseLabel.Text = "Unable to determine method. Please check your selection.";

                return;
            }

            if (SendCorrespondence != null)
            {
                SendCorrespondence(this, new SendCorrespondenceEntityEventArgs(Entity, RelatedEntity, entityCorrespondence));
            }

            return;
        }
        protected void EntityAddressTerminateWindow_ButtonOk_OnClick(Object sender, EventArgs e)
        {
            Boolean success = true;


            if (!EntityAddressTerminateTerminationDate.SelectedDate.HasValue)
            {
                EntityAddressTerminateTerminationDate.SelectedDate = null;

                EntityAddressTerminateResponse.Text = "Unable to determine the requested Termination Date.";

                return;
            }


            Int64 terminatedEntityAddressId = Convert.ToInt64(EntityAddressTerminateId.Text);

            Client.Core.Entity.EntityAddress currentEntityAddress = MercuryApplication.EntityAddressGet(terminatedEntityAddressId, false);

            if (Convert.ToDateTime(EntityAddressTerminateTerminationDate.SelectedDate) < currentEntityAddress.EffectiveDate)
            {
                EntityAddressTerminateTerminationDate.SelectedDate = null;

                EntityAddressTerminateResponse.Text = "The requested Termination Date is not valid.";

                return;
            }


            success = MercuryApplication.EntityAddressTerminate(currentEntityAddress, EntityAddressTerminateTerminationDate.SelectedDate.Value);


            if (success)
            {
                EntityAddressHistoryGrid_ManualDataRebind();

                EntityAddressTerminateTerminationDate.SelectedDate = null;


                Telerik.Web.UI.RadAjaxManager telerikAjaxManager = (Telerik.Web.UI.RadAjaxManager)Page.FindControl("TelerikAjaxManager");

                if (telerikAjaxManager != null)
                {
                    telerikAjaxManager.ResponseScripts.Add("EntityAddressTerminateWindow_Close ();");
                }
            }

            else
            {
                if (MercuryApplication.LastException != null)
                {
                    EntityAddressTerminateResponse.Text = MercuryApplication.LastException.Message;
                }

                else
                {
                    EntityAddressTerminateResponse.Text = "Unknown exception occurreed. Unable to Terminate.";
                }
            }

            return;
        }