private void ClearProperties()
    {
        // Clear actions
        save = null;
        saveAnother = null;
        saveAndClose = null;
        approve = null;
        reject = null;
        checkin = null;
        checkout = null;
        undoCheckout = null;
        archive = null;
        delete = null;
        prop = null;
        spellcheck = null;
        publish = null;
        newVersion = null;
        applyWorkflow = null;

        mStep = null;

        // Clear security result
        DocumentManager.ClearProperties();
    }
    private void ReloadMenu()
    {
        if (StopProcessing)
        {
            return;
        }

        // Raise event handler
        RaiseOnBeforeReloadMenu();

        // Handle several reloads
        ClearProperties();

        var showWorkflowButtons = HandleWorkflow;
        if (!HideStandardButtons)
        {
            if (Step == null)
            {
                // Do not handle workflow
                HandleWorkflow = false;
            }

            bool hideSave = false;

            // If content should be refreshed
            if (DocumentManager.RefreshActionContent)
            {
                // Display action message
                if (Step != null)
                {
                    WorkflowActionInfo action = WorkflowActionInfoProvider.GetWorkflowActionInfo(Step.StepActionID);
                    string name = (action != null) ? action.ActionDisplayName : Step.StepDisplayName;
                    string str = (action != null) ? "workflow.actioninprogress" : "workflow.stepinprogress";
                    string text = string.Format(ResHelper.GetString(str, ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(name, ResourceCulture)));
                    text = ScriptHelper.GetLoaderInlineHtml(Page, text);

                    InformationText = text;
                    EnsureRefreshScript();
                    hideSave = true;
                }
            }

            // Handle save action
            if (ShowSave && !hideSave)
            {
                save = new SaveAction
                {
                    OnClientClick = RaiseGetClientValidationScript(ComponentEvents.SAVE, DocumentManager.ConfirmChanges ? DocumentManager.GetAllowSubmitScript() : null),
                    Tooltip = ResHelper.GetString("EditMenu.Save", ResourceCulture)
                };

                // If not allowed to save, disable the save item
                if (!AllowSave)
                {
                    save.OnClientClick = null;
                    save.Enabled = false;
                }

                // New version
                if (DocumentManager.IsActionAllowed(DocumentComponentEvents.CREATE_VERSION))
                {
                    newVersion = new HeaderAction
                                     {
                                         Text = ResHelper.GetString("EditMenu.NewVersionIcon", ResourceCulture),
                                         Tooltip = ResHelper.GetString("EditMenu.NewVersion", ResourceCulture),
                                         EventName = DocumentComponentEvents.CREATE_VERSION
                                     };
                }
            }

            // Document update
            if (DocumentManager.Mode == FormModeEnum.Update)
            {
                if (Node != null)
                {
                    string submitScript = DocumentManager.GetSubmitScript();

                    #region "Workflow actions"

                    if (HandleWorkflow)
                    {
                        // Check-out action
                        if (ShowCheckOut && DocumentManager.IsActionAllowed(DocumentComponentEvents.CHECKOUT))
                        {
                            checkout = new DocumentCheckOutAction();
                        }

                        // Undo check-out action
                        if (ShowUndoCheckOut && DocumentManager.IsActionAllowed(DocumentComponentEvents.UNDO_CHECKOUT))
                        {
                            undoCheckout = new DocumentUndoCheckOutAction
                                {
                                    OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.UNDO_CHECKOUT, "if(!confirm(" + ScriptHelper.GetString(ResHelper.GetString("EditMenu.UndoCheckOutConfirmation", ResourceCulture)) + ")) { return false; }"),
                                };
                        }

                        // Check-in action
                        if (ShowCheckIn && DocumentManager.IsActionAllowed(DocumentComponentEvents.CHECKIN))
                        {
                            checkin = new DocumentCheckInAction
                                {
                                    OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.CHECKIN, submitScript),
                                };

                            // Add check-in comment
                            AddCommentAction(DocumentComponentEvents.CHECKIN, checkin);
                        }

                        // Approve action
                        if (DocumentManager.IsActionAllowed(DocumentComponentEvents.APPROVE))
                        {
                            if ((Step == null) || Step.StepIsEdit)
                            {
                                if (ShowSubmitToApproval)
                                {
                                    approve = new DocumentApproveAction
                                        {
                                            Text = ResHelper.GetString("EditMenu.IconSubmitToApproval", ResourceCulture),
                                            Tooltip = ResHelper.GetString("EditMenu.SubmitToApproval", ResourceCulture),
                                            OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.APPROVE, submitScript)
                                        };
                                }
                            }
                            else
                            {
                                if (ShowApprove)
                                {
                                    approve = new DocumentApproveAction
                                        {
                                            OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.APPROVE, submitScript)
                                        };
                                }
                            }
                        }

                        // Reject action
                        if (ShowReject && DocumentManager.IsActionAllowed(DocumentComponentEvents.REJECT))
                        {
                            var prevSteps = WorkflowManager.GetPreviousSteps(Node);
                            int prevStepsCount = prevSteps.Count;

                            if (prevStepsCount > 0)
                            {
                                reject = new DocumentRejectAction
                                    {
                                        OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.REJECT, submitScript)
                                    };

                                // For workflow managers allow reject to specified step
                                if (WorkflowManager.CanUserManageWorkflow(CurrentUser, Node.NodeSiteName))
                                {
                                    if (prevStepsCount > 1)
                                    {
                                        foreach (var s in prevSteps)
                                        {
                                            reject.AlternativeActions.Add(new DocumentRejectAction
                                                {
                                                    Text = string.Format(ResHelper.GetString("EditMenu.RejectTo", ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(s.StepDisplayName, ResourceCulture))),
                                                    OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.REJECT, submitScript),
                                                    CommandArgument = s.RelatedHistoryID.ToString()
                                                });
                                        }
                                    }
                                }

                                // Add reject comment
                                AddCommentAction(DocumentComponentEvents.REJECT, reject);
                            }
                        }

                        // Get next step info
                        List<WorkflowStepInfo> steps = DocumentManager.NextSteps;
                        int stepsCount = steps.Count;
                        WorkflowInfo workflow = DocumentManager.Workflow;
                        List<WorkflowTransitionInfo> transitions = null;

                        // Handle multiple next steps
                        if (approve != null)
                        {
                            string actionName = DocumentComponentEvents.APPROVE;
                            bool publishStepVisible = false;

                            // Get next approval step info
                            var approveSteps = steps.FindAll(s => !s.StepIsArchived);
                            int approveStepsCount = approveSteps.Count;
                            if (approveStepsCount > 0)
                            {
                                var nextS = approveSteps[0];

                                // Only one next step
                                if (approveStepsCount == 1)
                                {
                                    if (nextS.StepIsPublished)
                                    {
                                        publishStepVisible = true;
                                        actionName = DocumentComponentEvents.PUBLISH;
                                        approve.Text = ResHelper.GetString("EditMenu.IconPublish", ResourceCulture);
                                        approve.Tooltip = ResHelper.GetString("EditMenu.Publish", ResourceCulture);
                                    }

                                    // There are also archived steps
                                    if (stepsCount > 1)
                                    {
                                        // Set command argument
                                        approve.CommandArgument = nextS.StepID.ToString();
                                    }

                                    // Process action appearance
                                    ProcessAction(approve, Step, nextS);
                                }
                                // Multiple next steps
                                else
                                {
                                    // Check if not all steps publish steps
                                    if (approveSteps.Exists(s => !s.StepIsPublished))
                                    {
                                        approve.Tooltip = ResHelper.GetString("EditMenu.ApproveMultiple", ResourceCulture);
                                    }
                                    else
                                    {
                                        actionName = DocumentComponentEvents.PUBLISH;
                                        approve.Text = ResHelper.GetString("EditMenu.IconPublish", ResourceCulture);
                                        approve.Tooltip = ResHelper.GetString("EditMenu.ApproveMultiple", ResourceCulture);
                                    }

                                    // Make action inactive
                                    approve.Inactive = true;

                                    // Process action appearance
                                    ProcessAction(approve, Step, null);

                                    string itemText = (Step == null) || Step.StepIsEdit ? "EditMenu.SubmitTo" : "EditMenu.ApproveTo";
                                    string itemDesc = (Step == null) || Step.StepIsEdit ? "EditMenu.SubmitToApproval" : "EditMenu.Approve";

                                    foreach (var s in approveSteps)
                                    {
                                        DocumentApproveAction app = new DocumentApproveAction
                                            {
                                                Text = string.Format(ResHelper.GetString(itemText, ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(s.StepDisplayName, ResourceCulture))),
                                                Tooltip = ResHelper.GetString(itemDesc, ResourceCulture),
                                                OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.APPROVE, submitScript),
                                                CommandArgument = s.StepID.ToString()
                                            };

                                        if (s.StepIsPublished)
                                        {
                                            publishStepVisible = true;
                                            app.Text = string.Format(ResHelper.GetString("EditMenu.PublishTo", ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(s.StepDisplayName, ResourceCulture)));
                                            app.Tooltip = ResHelper.GetString("EditMenu.Publish", ResourceCulture);
                                        }

                                        // Process action appearance
                                        ProcessAction(app, Step, s);

                                        // Add step
                                        approve.AlternativeActions.Add(app);
                                    }
                                }

                                // Display direct publish button
                                if (WorkflowManager.CanUserManageWorkflow(CurrentUser, Node.NodeSiteName) && !publishStepVisible && Step.StepAllowPublish)
                                {
                                    // Add approve action as a alternative action
                                    if ((approve.AlternativeActions.Count == 0) && !nextS.StepIsPublished)
                                    {
                                        // Make action inactive
                                        approve.Tooltip = ResHelper.GetString("EditMenu.ApproveMultiple", ResourceCulture);
                                        approve.Inactive = true;

                                        // Add approve action
                                        string itemText = Step.StepIsEdit ? "EditMenu.SubmitTo" : "EditMenu.ApproveTo";
                                        string itemDesc = Step.StepIsEdit ? "EditMenu.SubmitToApproval" : "EditMenu.Approve";
                                        DocumentApproveAction app = new DocumentApproveAction
                                            {
                                                Text = string.Format(ResHelper.GetString(itemText, ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(nextS.StepDisplayName, ResourceCulture))),
                                                Tooltip = ResHelper.GetString(itemDesc, ResourceCulture),
                                                OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.APPROVE, submitScript),
                                                CommandArgument = nextS.StepID.ToString()
                                            };

                                        // Process action appearance
                                        ProcessAction(app, Step, nextS);

                                        approve.AlternativeActions.Add(app);
                                    }

                                    // Add direct publish action
                                    publish = new DocumentPublishAction
                                        {
                                            OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.PUBLISH, submitScript),
                                        };

                                    // Process action appearance
                                    ProcessAction(approve, Step, nextS);

                                    approve.AlternativeActions.Add(publish);
                                }

                                // Add approve comment
                                AddCommentAction(actionName, approve);
                            }
                            else
                            {
                                bool displayAction = false;
                                if (!workflow.IsBasic && (Step != null) && !Step.StepAllowBranch)
                                {
                                    // Transition exists, but condition doesn't match
                                    transitions = WorkflowManager.GetStepTransitions(Step, WorkflowTransitionTypeEnum.Manual);
                                    if (transitions.Count > 0)
                                    {
                                        WorkflowStepInfo s = WorkflowStepInfoProvider.GetWorkflowStepInfo(transitions[0].TransitionEndStepID);
                                        if (!s.StepIsArchived)
                                        {
                                            // Publish text
                                            if (s.StepIsPublished)
                                            {
                                                approve.Text = ResHelper.GetString("EditMenu.IconPublish", ResourceCulture);
                                                approve.Tooltip = ResHelper.GetString("EditMenu.Publish", ResourceCulture);
                                            }

                                            // Inform user
                                            displayAction = true;
                                            approve.Enabled = false;

                                            // Process action appearance
                                            ProcessAction(approve, Step, null);
                                        }
                                    }
                                }

                                if (!displayAction)
                                {
                                    // There is not next step
                                    approve = null;
                                }
                            }
                        }

                        // Archive action
                        if ((ShowArchive || ForceArchive) && DocumentManager.IsActionAllowed(DocumentComponentEvents.ARCHIVE))
                        {
                            // Get next archive step info
                            var archiveSteps = steps.FindAll(s => s.StepIsArchived);
                            int archiveStepsCount = archiveSteps.Count;

                            archive = new DocumentArchiveAction
                                {
                                    OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.ARCHIVE, "if(!confirm(" + ScriptHelper.GetString(ResHelper.GetString("EditMenu.ArchiveConfirmation", ResourceCulture)) + ")) { return false; }" + submitScript),
                                };

                            // Multiple archive steps
                            if (archiveStepsCount > 1)
                            {
                                // Make action inactive
                                archive.Tooltip = ResHelper.GetString("EditMenu.ArchiveMultiple", ResourceCulture);
                                archive.OnClientClick = null;
                                archive.Inactive = true;

                                const string itemText = "EditMenu.ArchiveTo";
                                const string itemDesc = "EditMenu.Archive";

                                foreach (var s in archiveSteps)
                                {
                                    DocumentArchiveAction arch = new DocumentArchiveAction
                                        {
                                            Text = string.Format(ResHelper.GetString(itemText, ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(s.StepDisplayName, ResourceCulture))),
                                            Tooltip = ResHelper.GetString(itemDesc, ResourceCulture),
                                            OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.ARCHIVE, "if(!confirm(" + ScriptHelper.GetString(ResHelper.GetString("EditMenu.ArchiveConfirmation", ResourceCulture)) + ")) { return false; }" + submitScript),
                                            CommandArgument = s.StepID.ToString()
                                        };

                                    // Process action appearance
                                    ProcessAction(arch, Step, s);

                                    // Add step
                                    archive.AlternativeActions.Add(arch);
                                }

                                // Add archive comment
                                AddCommentAction(DocumentComponentEvents.ARCHIVE, archive);
                            }
                            else if (archiveStepsCount == 1)
                            {
                                var nextS = archiveSteps[0];

                                // There are also approve steps
                                if (stepsCount > 1)
                                {
                                    // Set command argument
                                    archive.CommandArgument = nextS.StepID.ToString();
                                }

                                // Process action appearance
                                ProcessAction(archive, Step, nextS);

                                // Add archive comment
                                AddCommentAction(DocumentComponentEvents.ARCHIVE, archive);
                            }
                            else
                            {
                                bool displayAction = ForceArchive;
                                if (!workflow.IsBasic && !Step.StepAllowBranch)
                                {
                                    // Transition exists, but condition doesn't match
                                    if (transitions == null)
                                    {
                                        transitions = WorkflowManager.GetStepTransitions(Step, WorkflowTransitionTypeEnum.Manual);
                                    }

                                    if (transitions.Count > 0)
                                    {
                                        WorkflowStepInfo s = WorkflowStepInfoProvider.GetWorkflowStepInfo(transitions[0].TransitionEndStepID);
                                        if (s.StepIsArchived)
                                        {
                                            // Inform user
                                            displayAction = true;
                                            archive.Enabled = false;

                                            // Process action appearance
                                            ProcessAction(archive, Step, null);
                                        }
                                    }
                                }

                                if (!displayAction)
                                {
                                    // There is not next step
                                    archive = null;
                                }
                                else
                                {
                                    // Add archive comment
                                    AddCommentAction(DocumentComponentEvents.ARCHIVE, archive);
                                }
                            }
                        }
                    }

                    // Display Apply workflow button if user has permission to manage workflow and the button should be displayed and document is not linked
                    if (DisplayApplyWorkflowButton(showWorkflowButtons))
                    {
                        ScriptHelper.RegisterDialogScript(Page);

                        applyWorkflow = new HeaderAction
                        {
                            Text = ResHelper.GetString("WorkflowProperties.Apply", ResourceCulture),
                            Tooltip = ResHelper.GetString("EditMenu.WorkflowApply", ResourceCulture),
                            OnClientClick = string.Format("modalDialog('{0}','ApplyWorkflow', 770, 200, null, null, true); return false;", URLHelper.ResolveUrl("~/CMSModules/Workflows/Pages/ApplyWorkflow.aspx?documentid=" + Node.DocumentID)),
                            ButtonStyle = ButtonStyle.Default
                        };
                    }

                    #endregion

                    // Delete action
                    if (AllowSave && ShowDelete)
                    {
                        delete = new DeleteAction
                        {
                            OnClientClick = RaiseGetClientValidationScript(ComponentEvents.DELETE, "Delete_" + ClientID + "(" + NodeID + "); return false;")
                        };
                    }

                    // Properties action
                    if (ShowProperties)
                    {
                        prop = new HeaderAction
                        {
                            Text = ResHelper.GetString("EditMenu.IconProperties", ResourceCulture),
                            Tooltip = ResHelper.GetString("EditMenu.Properties", ResourceCulture),
                            OnClientClick = "Properties(" + NodeID + "); return false;",
                            ButtonStyle = ButtonStyle.Default
                        };
                    }
                }
            }
            // Ensure create another action
            else if (DocumentManager.Mode == FormModeEnum.Insert)
            {
                if (AllowSave && ShowCreateAnother)
                {
                    string saveAnotherScript = DocumentManager.GetSaveAnotherScript();
                    saveAnother = new SaveAction
                    {
                        RegisterShortcutScript = false,
                        Text = ResHelper.GetString("editmenu.iconsaveandanother", ResourceCulture),
                        Tooltip = ResHelper.GetString("EditMenu.SaveAndAnother", ResourceCulture),
                        OnClientClick = RaiseGetClientValidationScript(ComponentEvents.SAVE, (DocumentManager.ConfirmChanges ? DocumentManager.GetAllowSubmitScript() : "") + saveAnotherScript),
                        CommandArgument = "another"
                    };
                }
            }

            // Ensure spell check action
            if (AllowSave && ShowSave && ShowSpellCheck)
            {
                spellcheck = new HeaderAction
                {
                    Text = ResHelper.GetString("EditMenu.IconSpellCheck", ResourceCulture),
                    Tooltip = ResHelper.GetString("EditMenu.SpellCheck", ResourceCulture),
                    OnClientClick = "SpellCheck_" + ClientID + "(spellURL); return false;",
                    RedirectUrl = "#",
                    ButtonStyle = ButtonStyle.Default
                };
            }

            if (AllowSave && ShowSaveAndClose)
            {
                string saveAndCloseScript = DocumentManager.GetSaveAndCloseScript();
                saveAndClose = new SaveAction
                {
                    RegisterShortcutScript = false,
                    Text = ResHelper.GetString("editmenu.iconsaveandclose", ResourceCulture),
                    Tooltip = ResHelper.GetString("EditMenu.SaveAndClose", ResourceCulture),
                    OnClientClick = RaiseGetClientValidationScript(ComponentEvents.SAVE, (DocumentManager.ConfirmChanges ? DocumentManager.GetAllowSubmitScript() : "") + saveAndCloseScript),
                    CommandArgument = "saveandclose"
                };
            }
        }

        // Add actions in correct order
        menu.ActionsList.Clear();

        AddAction(saveAndClose);
        AddAction(save);
        AddAction(saveAnother);
        AddAction(newVersion);
        if (HandleWorkflow)
        {
            AddAction(checkout);
            AddAction(undoCheckout);
            AddAction(checkin);
            AddAction(reject);
            AddAction(approve);
            AddAction(archive);
        }
        AddAction(spellcheck);
        AddAction(delete);
        AddAction(prop);
        AddAction(convert);
        AddAction(applyWorkflow);

        // Show temporary to set correct visibility of checkbox for sending e-mails
        plcControls.Visible = true;

        // Set e-mails checkbox
        chkEmails.Visible = WorkflowManager.CanUserManageWorkflow(CurrentUser, DocumentManager.SiteName) && ((approve != null) || (reject != null) || (archive != null));
        if (chkEmails.Visible)
        {
            chkEmails.ResourceString = ResHelper.GetString("WorfklowProperties.SendMail", ResourceCulture);
            if (!DocumentManager.Workflow.SendEmails(DocumentManager.SiteName, WorkflowEmailTypeEnum.Unknown))
            {
                chkEmails.Enabled = false;
                chkEmails.ToolTip = ResHelper.GetString("wf.emails.disabled", ResourceCulture);
            }
        }

        // Hide placeholder if there is no visible functional control
        plcControls.Visible = pnlRight.Controls.Cast<Control>().Any(c => (c.Visible && !(c is LiteralControl)));

        // Add extra actions
        if (mExtraActions != null)
        {
            foreach (HeaderAction action in mExtraActions)
            {
                AddAction(action);
            }
        }

        // Set the information text
        if (!String.IsNullOrEmpty(InformationText))
        {
            lblInfo.Text = InformationText;
            lblInfo.CssClass = "LeftAlign EditMenuInfo";
            lblInfo.Visible = true;
        }
    }
    private void ReloadMenu()
    {
        if (StopProcessing)
        {
            return;
        }

        // Handle several reloads
        ClearProperties();

        if (!HideStandardButtons)
        {
            if (Step == null)
            {
                // Do not handle workflow
                HandleWorkflow = false;
            }

            bool hideSave = false;

            // If content should be refreshed
            if (DocumentManager.RefreshActionContent)
            {
                // Display action message
                WorkflowActionInfo action = WorkflowActionInfoProvider.GetWorkflowActionInfo(Step.StepActionID);
                string name = (action != null) ? action.ActionDisplayName : Step.StepDisplayName;
                string str = (action != null) ? "workflow.actioninprogress" : "workflow.stepinprogress";
                string text = string.Format(ResHelper.GetString(str, ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(name, ResourceCulture)));
                text = String.Concat("<img style=\"vertical-align:bottom;\" src=\"", UIHelper.GetImageUrl(Page, "Design/Preloaders/preload16.gif"), "\" alt=\"", text, "\" />&nbsp;<span>", text, "</span>");

                InformationText = text;
                EnsureRefreshScript();
                hideSave = true;
            }

            // Handle save action
            if (ShowSave && !hideSave)
            {
                save = new SaveAction(Page)
                {
                    OnClientClick = RaiseGetClientValidationScript(ComponentEvents.SAVE, DocumentManager.ConfirmChanges ? DocumentManager.GetAllowSubmitScript() : null),
                    Tooltip = ResHelper.GetString("EditMenu.Save", ResourceCulture)
                };

                // If not allowed to save, disable the save item
                if (!AllowSave)
                {
                    save.OnClientClick = null;
                    save.Enabled = false;
                }

                // New version
                if (DocumentManager.IsActionAllowed(DocumentComponentEvents.CREATE_VERSION))
                {
                    newVersion = new HeaderAction
                                     {
                                         Text = ResHelper.GetString("EditMenu.NewVersionIcon", ResourceCulture),
                                         Tooltip = ResHelper.GetString("EditMenu.NewVersion", ResourceCulture),
                                         ImageUrl = UIHelper.GetImageUrl(Page, "CMSModules/CMS_Content/EditMenu/newversion.png"),
                                         SmallImageUrl = UIHelper.GetImageUrl(Page, "CMSModules/CMS_Content/EditMenu/16/newversion.png"),
                                         EventName = DocumentComponentEvents.CREATE_VERSION
                                     };
                }
            }

            // Document update
            if (DocumentManager.Mode == FormModeEnum.Update)
            {
                if (Node != null)
                {
                    string submitScript = DocumentManager.GetSubmitScript();

                    #region "Workflow actions"

                    if (HandleWorkflow)
                    {
                        // Check-out action
                        if (ShowCheckOut && DocumentManager.IsActionAllowed(DocumentComponentEvents.CHECKOUT))
                        {
                            checkout = new DocumentCheckOutAction(Page)
                            {
                                Tooltip = ResHelper.GetString("EditMenu.CheckOut", ResourceCulture),
                            };
                        }

                        // Undo check-out action
                        if (ShowUndoCheckOut && DocumentManager.IsActionAllowed(DocumentComponentEvents.UNDO_CHECKOUT))
                        {
                            undoCheckout = new DocumentUndoCheckOutAction(Page)
                            {
                                Tooltip = ResHelper.GetString("EditMenu.UndoCheckout", ResourceCulture),
                                OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.UNDO_CHECKOUT, "if(!confirm(" + ScriptHelper.GetString(ResHelper.GetString("EditMenu.UndoCheckOutConfirmation")) + ")) { return false; }"),
                            };
                        }

                        // Check-in action
                        if (ShowCheckIn && DocumentManager.IsActionAllowed(DocumentComponentEvents.CHECKIN))
                        {
                            checkin = new DocumentCheckInAction(Page)
                            {
                                Tooltip = ResHelper.GetString("EditMenu.CheckIn", ResourceCulture),
                                OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.CHECKIN, submitScript),
                            };

                            // Add check-in comment
                            AddCommentAction(DocumentComponentEvents.CHECKIN, checkin);
                        }

                        // Approve action
                        if (DocumentManager.IsActionAllowed(DocumentComponentEvents.APPROVE))
                        {
                            if (Step.StepIsEdit)
                            {
                                if (ShowSubmitToApproval)
                                {
                                    approve = new DocumentApproveAction(Page)
                                    {
                                        Text = ResHelper.GetString("EditMenu.IconSubmitToApproval", ResourceCulture),
                                        Tooltip = ResHelper.GetString("EditMenu.SubmitToApproval", ResourceCulture),
                                        OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.APPROVE, submitScript),
                                    };
                                }
                            }
                            else
                            {
                                if (ShowApprove)
                                {
                                    approve = new DocumentApproveAction(Page)
                                    {
                                        Tooltip = ResHelper.GetString("EditMenu.Approve", ResourceCulture),
                                        OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.APPROVE, submitScript),
                                    };
                                }
                            }
                        }

                        // Reject action
                        if (ShowReject && DocumentManager.IsActionAllowed(DocumentComponentEvents.REJECT))
                        {
                            var prevSteps = WorkflowManager.GetPreviousSteps(Node);
                            int prevStepsCount = prevSteps.Count;

                            if (prevStepsCount > 0)
                            {
                                reject = new DocumentRejectAction(Page)
                                {
                                    Tooltip = ResHelper.GetString("EditMenu.Reject", ResourceCulture),
                                    OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.REJECT, submitScript)
                                };

                                // For workflow managers allow reject to specified step
                                if (WorkflowManager.CanUserManageWorkflow(CurrentUser, Node.NodeSiteName))
                                {
                                    if (prevStepsCount > 1)
                                    {
                                        foreach (var s in prevSteps)
                                        {
                                            reject.AlternativeActions.Add(new DocumentRejectAction(Page)
                                                                                {
                                                                                    Text = string.Format(ResHelper.GetString("EditMenu.RejectTo", ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(s.StepDisplayName, ResourceCulture))),
                                                                                    Tooltip = ResHelper.GetString("EditMenu.Reject", ResourceCulture),
                                                                                    OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.REJECT, submitScript),
                                                                                    CommandArgument = s.RelatedHistoryID.ToString()
                                                                                });
                                        }
                                    }
                                }

                                // Add reject comment
                                AddCommentAction(DocumentComponentEvents.REJECT, reject);
                            }
                        }

                        // Get next step info
                        List<WorkflowStepInfo> steps = DocumentManager.NextSteps;
                        int stepsCount = steps.Count;
                        WorkflowInfo workflow = DocumentManager.Workflow;

                        // Handle multiple next steps
                        if (approve != null)
                        {
                            string actionName = DocumentComponentEvents.APPROVE;
                            bool publishStepVisible = false;

                            // Get next approval step info
                            var approveSteps = steps.FindAll(s => !s.StepIsArchived);
                            int aprroveStepsCount = approveSteps.Count;
                            if (aprroveStepsCount > 0)
                            {
                                var nextS = approveSteps[0];

                                // Only one next step
                                if (aprroveStepsCount == 1)
                                {
                                    if (nextS.StepIsPublished)
                                    {
                                        publishStepVisible = true;
                                        actionName = DocumentComponentEvents.PUBLISH;
                                        approve.Text = ResHelper.GetString("EditMenu.IconPublish", ResourceCulture);
                                        approve.Tooltip = ResHelper.GetString("EditMenu.Publish", ResourceCulture);
                                    }

                                    // There are also archived steps
                                    if (stepsCount > 1)
                                    {
                                        // Set command argument
                                        approve.CommandArgument = nextS.StepID.ToString();
                                    }

                                    // Process action appearance
                                    ProcessAction(approve, Step, nextS);
                                }
                                // Multiple next steps
                                else
                                {
                                    // Check if not all steps publish steps
                                    if (approveSteps.Exists(s => !s.StepIsPublished))
                                    {
                                        approve.Tooltip = ResHelper.GetString("EditMenu.ApproveMultiple", ResourceCulture);
                                    }
                                    else
                                    {
                                        actionName = DocumentComponentEvents.PUBLISH;
                                        approve.Text = ResHelper.GetString("EditMenu.IconPublish", ResourceCulture);
                                        approve.Tooltip = ResHelper.GetString("EditMenu.ApproveMultiple", ResourceCulture);
                                    }

                                    // Make action inactive
                                    approve.OnClientClick = null;
                                    approve.Inactive = true;

                                    // Process action appearance
                                    ProcessAction(approve, Step, null);

                                    string itemText = Step.StepIsEdit ? "EditMenu.SubmitTo" : "EditMenu.ApproveTo";
                                    string itemDesc = Step.StepIsEdit ? "EditMenu.SubmitToApproval" : "EditMenu.Approve";

                                    foreach (var s in approveSteps)
                                    {
                                        DocumentApproveAction app = new DocumentApproveAction(Page)
                                                        {
                                                            Text = string.Format(ResHelper.GetString(itemText, ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(s.StepDisplayName, ResourceCulture))),
                                                            Tooltip = ResHelper.GetString(itemDesc, ResourceCulture),
                                                            OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.APPROVE, submitScript),
                                                            CommandArgument = s.StepID.ToString()
                                                        };

                                        if (s.StepIsPublished)
                                        {
                                            publishStepVisible = true;
                                            app.Text = string.Format(ResHelper.GetString("EditMenu.PublishTo", ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(s.StepDisplayName, ResourceCulture)));
                                            app.Tooltip = ResHelper.GetString("EditMenu.Publish", ResourceCulture);
                                        }

                                        // Process action appearance
                                        ProcessAction(app, Step, s);

                                        // Add step
                                        approve.AlternativeActions.Add(app);
                                    }
                                }

                                // Display direct publish button
                                if (WorkflowManager.CanUserManageWorkflow(CurrentUser, Node.NodeSiteName) && !publishStepVisible && Step.StepAllowPublish)
                                {
                                    // Add approve action as a alternative action
                                    if ((approve.AlternativeActions.Count == 0) && !nextS.StepIsPublished)
                                    {
                                        // Make action inactive
                                        approve.Tooltip = ResHelper.GetString("EditMenu.ApproveMultiple", ResourceCulture);
                                        approve.OnClientClick = null;
                                        approve.Inactive = true;

                                        // Add approve action
                                        string itemText = Step.StepIsEdit ? "EditMenu.SubmitTo" : "EditMenu.ApproveTo";
                                        string itemDesc = Step.StepIsEdit ? "EditMenu.SubmitToApproval" : "EditMenu.Approve";
                                        DocumentApproveAction app = new DocumentApproveAction(Page)
                                        {
                                            Text = string.Format(ResHelper.GetString(itemText, ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(nextS.StepDisplayName, ResourceCulture))),
                                            Tooltip = ResHelper.GetString(itemDesc, ResourceCulture),
                                            OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.APPROVE, submitScript),
                                            CommandArgument = nextS.StepID.ToString()
                                        };

                                        // Process action appearance
                                        ProcessAction(app, Step, nextS);

                                        approve.AlternativeActions.Add(app);
                                    }

                                    // Add direct publish action
                                    publish = new DocumentPublishAction(Page)
                                    {
                                        Tooltip = ResHelper.GetString("EditMenu.ApprovePublish", ResourceCulture),
                                        OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.PUBLISH, submitScript),
                                    };

                                    // Process action appearance
                                    ProcessAction(approve, Step, nextS);

                                    approve.AlternativeActions.Add(publish);
                                }

                                // Add approve comment
                                AddCommentAction(actionName, approve);
                            }
                            else
                            {
                                bool displayAction = false;
                                if (!workflow.IsBasic && !Step.StepAllowBranch)
                                {
                                    // Transition exists, but condition doesn't match
                                    var transitions = WorkflowManager.GetStepTransitions(Step, WorkflowTransitionTypeEnum.Manual);
                                    if (transitions.Count > 0)
                                    {
                                        WorkflowStepInfo s = WorkflowStepInfoProvider.GetWorkflowStepInfo(transitions[0].TransitionEndStepID);
                                        if (!s.StepIsArchived)
                                        {
                                            // Publish text
                                            if (s.StepIsPublished)
                                            {
                                                publishStepVisible = true;
                                                actionName = DocumentComponentEvents.PUBLISH;
                                                approve.Text = ResHelper.GetString("EditMenu.IconPublish", ResourceCulture);
                                                approve.Tooltip = ResHelper.GetString("EditMenu.Publish", ResourceCulture);
                                            }

                                            // Inform user
                                            displayAction = true;
                                            approve.Enabled = false;

                                            // Process action appearance
                                            ProcessAction(approve, Step, null);
                                        }
                                    }
                                }

                                if (!displayAction)
                                {
                                    // There is not next step
                                    approve = null;
                                }
                            }
                        }

                        // Archive action
                        if ((ShowArchive || ForceArchive) && DocumentManager.IsActionAllowed(DocumentComponentEvents.ARCHIVE))
                        {
                            // Get next archive step info
                            var archiveSteps = steps.FindAll(s => s.StepIsArchived);
                            int archiveStepsCount = archiveSteps.Count;

                            archive = new DocumentArchiveAction(Page)
                            {
                                Tooltip = ResHelper.GetString("EditMenu.Archive", ResourceCulture),
                                OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.ARCHIVE, "if(!confirm(" + ScriptHelper.GetString(ResHelper.GetString("EditMenu.ArchiveConfirmation")) + ")) { return false; }" + submitScript)
                            };

                            // Multiple archive steps
                            if (archiveStepsCount > 1)
                            {
                                // Make action inactive
                                archive.Tooltip = ResHelper.GetString("EditMenu.ArchiveMultiple", ResourceCulture);
                                archive.OnClientClick = null;
                                archive.Inactive = true;

                                const string itemText = "EditMenu.ArchiveTo";
                                const string itemDesc = "EditMenu.Archive";

                                foreach (var s in archiveSteps)
                                {
                                    DocumentArchiveAction arch = new DocumentArchiveAction(Page)
                                                    {
                                                        Text = string.Format(ResHelper.GetString(itemText, ResourceCulture), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(s.StepDisplayName, ResourceCulture))),
                                                        Tooltip = ResHelper.GetString(itemDesc, ResourceCulture),
                                                        OnClientClick = RaiseGetClientValidationScript(DocumentComponentEvents.ARCHIVE, "if(!confirm(" + ScriptHelper.GetString(ResHelper.GetString("EditMenu.ArchiveConfirmation")) + ")) { return false; }" + submitScript),
                                                        CommandArgument = s.StepID.ToString()
                                                    };

                                    // Process action appearance
                                    ProcessAction(arch, Step, s);

                                    // Add step
                                    archive.AlternativeActions.Add(arch);
                                }

                                // Add archive comment
                                AddCommentAction(DocumentComponentEvents.ARCHIVE, archive);
                            }
                            else if (archiveStepsCount == 1)
                            {
                                var nextS = archiveSteps[0];

                                // There are also approve steps
                                if (stepsCount > 1)
                                {
                                    // Set command argument
                                    archive.CommandArgument = nextS.StepID.ToString();
                                }

                                // Process action appearance
                                ProcessAction(archive, Step, nextS);

                                // Add archive comment
                                AddCommentAction(DocumentComponentEvents.ARCHIVE, archive);
                            }
                            else
                            {
                                bool displayAction = ForceArchive;
                                if (!workflow.IsBasic && !Step.StepAllowBranch)
                                {
                                    // Transition exists, but condition doesn't match
                                    var transitions = WorkflowManager.GetStepTransitions(Step, WorkflowTransitionTypeEnum.Manual);
                                    if (transitions.Count > 0)
                                    {
                                        WorkflowStepInfo s = WorkflowStepInfoProvider.GetWorkflowStepInfo(transitions[0].TransitionEndStepID);
                                        if (s.StepIsArchived)
                                        {
                                            // Inform user
                                            displayAction = true;
                                            archive.Enabled = false;

                                            // Process action appearance
                                            ProcessAction(archive, Step, null);
                                        }
                                    }
                                }

                                if (!displayAction)
                                {
                                    // There is not next step
                                    archive = null;
                                }
                                else
                                {
                                    // Add archive comment
                                    AddCommentAction(DocumentComponentEvents.ARCHIVE, archive);
                                }
                            }
                        }
                    }

                    #endregion

                    // Delete action
                    if (AllowSave && ShowDelete)
                    {
                        delete = new DeleteAction(Page)
                        {
                            OnClientClick = RaiseGetClientValidationScript(ComponentEvents.DELETE, "Delete_" + ClientID + "(" + NodeID + "); return false;"),
                            Tooltip = ResHelper.GetString("EditMenu.Delete", ResourceCulture)
                        };
                    }

                    // Properties action
                    if (ShowProperties)
                    {
                        properties = new HeaderAction
                                         {
                                             CssClass = IsLiveSite ? null : "MenuItemEdit",
                                             Text = ResHelper.GetString("EditMenu.IconProperties", ResourceCulture),
                                             Tooltip = ResHelper.GetString("EditMenu.Properties", ResourceCulture),
                                             OnClientClick = "Properties(" + NodeID + "); return false;",
                                             ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/properties.png"),
                                             SmallImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/16/properties.png"),
                                         };
                    }

                    // Convert action
                    if (Node.IsWireframe() && (CMSContext.ViewMode == ViewModeEnum.EditForm))
                    {
                        convert = new HeaderAction
                                      {
                                          CssClass = IsLiveSite ? null : "MenuItemEdit",
                                          Text = ResHelper.GetString("EditMenu.IconConvert", ResourceCulture),
                                          Tooltip = ResHelper.GetString("EditMenu.Convert|EditMenu.IconConvert", ResourceCulture),
                                          OnClientClick = "ConvertDocument(" + Node.NodeParentID + ", " + Node.DocumentID + "); return false;",
                                          ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/convert.png"),
                                          SmallImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/16/convert.png"),
                                      };
                    }
                }
            }
            // Ensure create another action
            else if (DocumentManager.Mode == FormModeEnum.Insert)
            {
                if (AllowSave && ShowCreateAnother)
                {
                    string saveAnotherScript = DocumentManager.GetSaveAnotherScript();
                    saveAnother = new SaveAction(Page)
                    {
                        RegisterShortcutScript = false,
                        Text = ResHelper.GetString("editmenu.iconsaveandanother", ResourceCulture),
                        Tooltip = ResHelper.GetString("EditMenu.SaveAndAnother", ResourceCulture),
                        OnClientClick = RaiseGetClientValidationScript(ComponentEvents.SAVE, (DocumentManager.ConfirmChanges ? DocumentManager.GetAllowSubmitScript() : "") + saveAnotherScript),
                        ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/saveandanother.png"),
                        SmallImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/16/saveandanother.png"),
                        CommandArgument = "another"
                    };
                }
            }

            // Ensure spell check action
            if (AllowSave && ShowSave && ShowSpellCheck)
            {
                spellcheck = new HeaderAction
                                 {
                                     CssClass = IsLiveSite ? null : "MenuItemEdit",
                                     Text = ResHelper.GetString("EditMenu.IconSpellCheck", ResourceCulture),
                                     Tooltip = ResHelper.GetString("EditMenu.SpellCheck", ResourceCulture),
                                     OnClientClick = "SpellCheck_" + ClientID + "(spellURL); return false;",
                                     ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/spellcheck.png"),
                                     SmallImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/16/spellcheck.png"),
                                     RedirectUrl = "#"
                                 };
            }

            if (AllowSave && ShowSaveAndClose)
            {
                string saveAndCloseScript = DocumentManager.GetSaveAndCloseScript();
                saveAndClose = new SaveAction(Page)
                {
                    RegisterShortcutScript = false,
                    Text = ResHelper.GetString("editmenu.iconsaveandclose", ResourceCulture),
                    Tooltip = ResHelper.GetString("EditMenu.SaveAndClose", ResourceCulture),
                    OnClientClick = RaiseGetClientValidationScript(ComponentEvents.SAVE, (DocumentManager.ConfirmChanges ? DocumentManager.GetAllowSubmitScript() : "") + saveAndCloseScript),
                    ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/saveandclose.png"),
                    SmallImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/16/saveandclose.png"),
                    CommandArgument = "saveandclose"
                };
            }

            // Ensure correct design with backward compatibility
            if (string.IsNullOrEmpty(LinkCssClass))
            {
                if (!IsLiveSite)
                {
                    menu.LinkCssClass = "MenuItemEdit";
                }
            }
            else
            {
                menu.LinkCssClass = LinkCssClass;
            }
        }

        // Add actions in correct order
        menu.ActionsList.Clear();

        AddAction(saveAndClose);
        AddAction(save);
        AddAction(saveAnother);
        AddAction(newVersion);
        if (HandleWorkflow)
        {
            AddAction(checkout);
            AddAction(undoCheckout);
            AddAction(checkin);
            AddAction(reject);
            AddAction(approve);
            AddAction(archive);
        }
        AddAction(spellcheck);
        AddAction(delete);
        AddAction(properties);
        AddAction(convert);

        // Set e-mails checkbox
        plcEmails.Visible = WorkflowManager.CanUserManageWorkflow(CurrentUser, DocumentManager.SiteName) && ((approve != null) || (reject != null) || (archive != null));
        if (plcEmails.Visible && !DocumentManager.Workflow.SendEmails(DocumentManager.SiteName, WorkflowEmailTypeEnum.Unknown))
        {
            chkEmails.Enabled = false;
            chkEmails.ToolTip = GetString("wf.emails.disabled");
        }

        // Add remove wireframe action
        if (ShowRemoveWireframe)
        {
            AddAction(new HeaderAction
                          {
                              CssClass = "MenuItemEdit",
                              Text = ResHelper.GetString("Wireframe.Remove"),
                              Tooltip = ResHelper.GetString("Wireframe.Remove", ResourceCulture),
                              ImageUrl = UIHelper.GetImageUrl(Page, "CMSModules/CMS_Content/EditMenu/removewireframe.png"),
                              SmallImageUrl = UIHelper.GetImageUrl(Page, "CMSModules/CMS_Content/EditMenu/16/removewireframe.png"),
                              CommandName = "RemoveWireframe",
                              OnClientClick = "return confirm('" + GetString("Wireframe.ConfirmRemove") + "')"
                          });
        }

        // Add create wireframe action
        if (ShowCreateWireframe)
        {
            TreeNode node = DocumentManager.Node;
            if ((node != null) && (node.NodeWireframeTemplateID <= 0))
            {
                // Add create wireframe action
                AddAction(new HeaderAction
                              {
                                  CssClass = "MenuItemEdit",
                                  Text = GetString("Wireframe.Create"),
                                  Tooltip = GetString("Wireframe.Create"),
                                  ImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/createwireframe.png"),
                                  SmallImageUrl = GetImageUrl("CMSModules/CMS_Content/EditMenu/16/createwireframe.png"),
                                  RedirectUrl = String.Format("~/CMSModules/Content/CMSDesk/Properties/CreateWireframe.aspx?nodeid={0}&culture={1}", node.NodeID, node.DocumentCulture)
                              });
            }
        }

        // Add extra actions
        if (mExtraActions != null)
        {
            foreach (HeaderAction action in mExtraActions)
            {
                AddAction(action);
            }
        }

        // Set the information text
        if (!String.IsNullOrEmpty(InformationText))
        {
            lblInfo.Text = InformationText;
            lblInfo.CssClass = "LeftAlign EditMenuInfo";
            lblInfo.Visible = true;
        }
    }