protected void DebateList_ItemCommand(object source, TreeListCommandEventArgs e)
 {
     if (e.CommandName == "replyMessage")
     {
         if (e.Item is TreeListDetailTemplateItem)
         {
             TreeListDetailTemplateItem itm = e.Item as TreeListDetailTemplateItem;
             if (!Request.IsAuthenticated)
             {
                 needLoginLblTop.Visible    = true;
                 needLoginLblBottom.Visible = true;
                 needLoginLblTop.Text       = "<div class='dnnFormMessage dnnFormWarning'>" +
                                              Localization.GetString("LoggedIn", LocalResourceFile) +
                                              "  <a href='" + ConfigurationManager.AppSettings["DomainName"] + /*"/" +
                                                                                                                * System.Threading.Thread.CurrentThread.CurrentCulture.Name +*/
                                              "/login.aspx?returnurl=" + HttpUtility.UrlEncode(Request.Url.PathAndQuery) + "'>" +
                                              Localization.GetString("Login", LocalResourceFile) + "</a></div>";
                 needLoginLblBottom.Text = needLoginLblTop.Text;
             }
             else
             {
                 itm.CssClass = "whiteBack";
                 LinkButton newPostBtn = (LinkButton)itm.FindControl("newPostBtn");
                 newPostBtn.CssClass = "newPostActive";
                 TreeListDataItem parentPost = itm.ParentItem;
                 parentPost.IsChildInserted = true;
                 DebateList.Rebind();
             }
         }
     }
 }
        /*****************       Version 2 functions                   **************************/


        protected void DebateList_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
        {
            if (e.Item is TreeListDataItem)
            {
                TreeListDataItem itm = e.Item as TreeListDataItem;
                itm["PostType"].Text = "<img src='" + ModulePath + getImageIconUrl(itm["PostType"].Text) + "'>";

                HyperLink userProfile = new HyperLink();
                userProfile.NavigateUrl = DotNetNuke.Common.Globals.UserProfileURL(Convert.ToInt32(itm["UserId"].Text));


                if (!itm["Post_Author"].Text.Equals("&nbsp;"))
                {
                    userProfile.Text = itm["Post_Author"].Text + " " + itm.GetDataKeyValue("ID");
                    itm["Post_Author"].Controls.Add(userProfile);
                }
                else
                {
                    itm["Post_Author"].Text = "guest";
                }


                if (itm.IsChildInserted)
                {
                    itm.CssClass = "whiteBack";
                }
            }
            else if (e.Item is TreeListDetailTemplateItem)
            {
                TreeListDetailTemplateItem itm = e.Item as TreeListDetailTemplateItem;

                HiddenField hiddenpostId = (HiddenField)itm.FindControl("hiddenPostID");

                /*LinkButton printPostBtn = (LinkButton)itm.FindControl("printPostLink");
                 * printPostBtn.Attributes.Add("onclick", "openSelectedPostPrinter(" + hiddenpostId.Value + ");return false;");*/


                if (DotNetNuke.Security.PortalSecurity.IsInRoles("Pilot Leaders"))
                {
                    HyperLink publishPost = (HyperLink)itm.FindControl("publishPost");
                    HyperLink deletePost  = (HyperLink)itm.FindControl("deletePost");
                    publishPost.Visible = true;
                    deletePost.Visible  = true;
                    string href = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("Thread") + 7) + ATC.Tools.URLParam("Thread");

                    /* if post is published admins can unpublish or delete */
                    deletePost.NavigateUrl = href + "&PostAction=Delete&Post=" + hiddenpostId.Value;
                    if (itm.ParentItem["IsPublished"].Text == "1")
                    {
                        publishPost.NavigateUrl = href + "&PostAction=Reject&Post=" + hiddenpostId.Value;
                        publishPost.Text        = "Unpublish";
                    }
                    else // Post unpublished
                    {
                        publishPost.NavigateUrl = href + "&PostAction=Accept&Post=" + hiddenpostId.Value;
                        publishPost.Text        = "Re-publish";
                    }
                }

                if (statusLbl.Visible) // Thread is closed
                {
                    LinkButton newPostBtn = (LinkButton)itm.FindControl("newPostBtn");
                    newPostBtn.Enabled  = false;
                    notifyCheck.Visible = false;
                    notifyLabel.Visible = false;
                }
                else
                {
                    if (itm.ParentItem.IsChildInserted)
                    {
                        //itm.CssClass = "whiteBack";
                        LinkButton newPostBtn = (LinkButton)itm.FindControl("newPostBtn");
                        newPostBtn.CssClass = "newPostActive";
                    }
                }
            }
            else if (e.Item is TreeListEditFormInsertItem)
            {
                /* If a new discussion is to be created, the post type can only be issue*/
                if (DebateList.IsItemInserted)
                {
                    TreeListEditFormInsertItem itm = e.Item as TreeListEditFormInsertItem;
                    RadioButton Issue   = (itm.FindControl("IssueRadio") as RadioButton);
                    RadioButton Alter   = (itm.FindControl("AlterRadio") as RadioButton);
                    RadioButton Pro     = (itm.FindControl("ProRadio") as RadioButton);
                    RadioButton Con     = (itm.FindControl("ConRadio") as RadioButton);
                    RadioButton Comment = (itm.FindControl("CommentRadio") as RadioButton);
                    Comment.Checked = false;
                    Issue.Checked   = true;
                    Alter.Enabled   = false;
                    Pro.Enabled     = false;
                    Con.Enabled     = false;
                    Comment.Enabled = false;
                }
            }
        }