Imports CharterDotCom.CommonEntities.Library.Enumerations
Imports CharterDotCom.WebSite.Library
Imports CharterDotCom.CommonEntities.Library
' Imports CharterDotCom.Common.Logging

Partial Class Customers_Support
    Inherits CharterCMSPage

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        If Not IsPostBack Then
            SetContentKeys()
        End If

        'If Not IsPostBack Then
        '    If Not (Request.QueryString(QueryStringName.ProductItem) Is Nothing) Then
        '        ' TAKE FROM THE OLD PAGE LOAD IF NECESSARY
        '    ElseIf Not (Request.QueryString(QueryStringName.MenuItem) Is Nothing) Then
        '        ' TAKE FROM THE OLD PAGE LOAD IF NECESSARY
        '    ElseIf Not (Request.QueryString(QueryStringName.NonProductItem) Is Nothing) Then
        '        'Some part of it MOVED TO BrowseSupport.ascx.vb (part that relates with the control
        '    ElseIf Not (Request.QueryString(QueryStringName.SupportArticleID) Is Nothing) Then
        '        ' TAKE FROM THE OLD PAGE LOAD IF NECESSARY
        '    ElseIf Not (Request.QueryString(QueryStringName.FolderID) Is Nothing) Then
        '        ' TAKE FROM THE OLD PAGE LOAD IF NECESSARY
        '    End If
        'End If


        If Not (Application("IntelliResponse_ENABLED") Is Nothing) Then
            If Application("IntelliResponse_ENABLED").ToString().Trim().ToLower() = "t" Then
                ucSearchSupport.Visible = False
            End If
        End If


    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Logger.WebLog("\UI\Customers\Support")

        MyBase.SetTemplate(11)
        Dim d As DateTime = CachedControls.getExpireDate()
        If HttpContext.Current.Cache.Item("Template11") Is Nothing Then
            HttpContext.Current.Cache.Insert("Template11", DateTime.Now, Nothing, d, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
        End If
        Response.AddCacheItemDependency("Template11")
        If Application(Request.Url.LocalPath) Is Nothing Then
            Application.Add(Request.Url.LocalPath, "Template11")
        End If
    End Sub

    Private Sub SetContentKeys()
        If Not (Request.QueryString(QueryStringName.SupportArticleID) Is Nothing) Then
            litLeftMainContent.Visible = False
            pnlSupportArticle.Visible = True
            GetSupportArticle(Request.QueryString(QueryStringName.SupportArticleID))
        ElseIf Not (Request.QueryString(QueryStringName.MenuItem) Is Nothing) Then
            Me.videoscript.ContentKey = ""

            Select Case Request.QueryString(QueryStringName.MenuItem)
                Case MenuItem.CableTV
                    Me.GetCMSContent("Support:CableHelp:TabContents")
                Case MenuItem.Internet
                    Me.GetCMSContent("Support:InternetHelp:TabContents")
                Case MenuItem.Telephone
                    Me.GetCMSContent("Support:TelephoneHelp:TabContents")
                Case MenuItem.MyAccount
                    Me.GetCMSContent("Support:MyAccountBilling:TabContents")
                    Me.flashMyAccountBilling.Visible = True
                Case MenuItem.ChangingServicesAndMoving
                    Me.GetCMSContent("Support:ResourceHelpTools:ChangingServicesMoving")
                Case MenuItem.Troubleshooting
                    Me.GetCMSContent("Support:ResourceHelpTools:Troubleshooting")
                Case MenuItem.UserGuidesandDiagrams
                    Me.GetCMSContent("Support:ResourceHelpTools:UserGuidesandDiagrams")
                Case MenuItem.VideosandDemos
                    Me.GetCMSContent("Support:ResourceHelpTools:VideosandDemos")
                    Me.videoscript.Visible = True
                    Me.videoscript.ContentKey = "Support:ResourceHelpTools:VideosandDemos:Scripts"
                Case MenuItem.Email
                    Me.GetCMSContent("Support:EmailHelp")
                Case MenuItem.FAQ
                    Me.GetCMSContent("Support:FAQ")
                Case Else
                    '*************************************************************************************
                    ' All MenuItems 61 - 81 will be handled by this case.  It concatenates 
                    ' a prefix “Support:MenuItem" with the MenuItem number to determine the content zone.
                    '*************************************************************************************
                    Dim result As Int32
                    If (Int32.TryParse(Request.QueryString(QueryStringName.MenuItem), result)) Then
                        Me.GetCMSContent("Support:MenuItem" & result)
                    End If
            End Select
        ElseIf Not (Request.QueryString(QueryStringName.NonProductItem) Is Nothing) Then
            GetNonProductItem(Request.QueryString(QueryStringName.NonProductItem))
        ElseIf Not (Request.QueryString(QueryStringName.FolderID) Is Nothing) Then
            ' PUT FOLDER STUFF HERE...
            'getFolderItem(Request.QueryString(QueryStringName.FolderID))
        Else
            Server.Transfer("SupportOverview.aspx")
        End If

        Me.ucSupportHomeResourcesHelpTools.ContentKey = "Support:Home:ResourcesHelpTools:SYCH"
        'Me.ucSupportOverviewContactUs.ContentKey = "Support:Overview:ContactUs"
    End Sub

    Private Sub GetCMSContent(ByVal userControlName As String)
        Dim cmsContent As String = String.Empty
        cmsContent = ContentManager.Instance.GetContent(userControlName, "1", OwnerType.Other)
        If Not (cmsContent Is Nothing) Then
            If Not (cmsContent = "") Then
                Me.litLeftMainContent.Text = cmsContent
            Else
                Me.litLeftMainContent.Text = "Content Not found for: " & userControlName
            End If
        Else
            Me.litLeftMainContent.Text = "Content not found for: " & userControlName
        End If
    End Sub

    Private Sub GetFolderItem(ByVal folderId As String)

        'lblTitle.Text = "Support"
        'ucLocalNavigation.Item = MenuItem.Support
        'ucFrequentQuestions.Visible = False
        'ucSupportHelpIntroduction.Visible = False
        'ucSupportArticle.Visible = False

        'sbBreadCrumb = New StringBuilder()
        'sbTreeView = New StringBuilder()

        '_folderID = CType(Request.QueryString(QueryStringName.FolderID), Integer)

        '_folder = SiteManager.Instance.GetFolder(_folderID)

        'sbBreadCrumb.AppendFormat("<span style='font-weight:bold'>{0}</span>", _folder.Name)

        'While _folder.ParentFolderID > 0
        '    _folder = SiteManager.Instance.GetFolder(_folder.ParentFolderID)

        '    sbBreadCrumb.Insert(0, String.Format("<a href='../customers/support.aspx?FolderID={0}'>{1}</a> &gt; ", _folder.ID, _folder.Name))
        'End While

        'ltrBreadCrumb.Text = String.Format("<p>{0}<p>", sbBreadCrumb.ToString())
        'ltrBreadCrumb.Visible = True

        '_folder = SiteManager.Instance.GetDocumentFolders(_folderID)

        'If _folder.ChildFolders IsNot Nothing Then
        '    For Each _childFolder In _folder.ChildFolders
        '        sbTreeView.AppendFormat("<li style='font-style:italic'><a href='../customers/support.aspx?FolderID={0}'>{1}</a></li>", _childFolder.Value.ID, _childFolder.Value.Name)
        '    Next
        'End If

        '_folder = SiteManager.Instance.GetFolderDocuments(_folderID)

        'If _folder.ChildDocuments IsNot Nothing Then
        '    For Each _childDocument In _folder.ChildDocuments
        '        sbTreeView.AppendFormat("<li><a href='../customers/support.aspx?SupportArticleID={0}'>{1}</a></li>", _childDocument.Value.ID, _childDocument.Value.Title)
        '    Next
        'End If

        'ltrTreeView.Text = String.Format("<ul>{0}</ul>", sbTreeView.ToString())
        'ltrTreeView.Visible = True
        '        Else
        'lblTitle.Text = "Support"
        '_folderID = CType(ConfigurationManager.AppSettings(AppSettingKey.SupprtFAQHomePage), Integer)
        '_folder = SiteManager.Instance.GetFolderDocuments(_folderID)
        'SupportHelpcontentKey = "Support:Home"
        'ucFrequentQuestions.ContentKey = SupportHelpcontentKey
        'ucLocalNavigation.Item = MenuItem.Support
        'ucFrequentQuestions.Visible = True
        'ucSupportHelpIntroduction.Visible = False
        'ucSupportArticle.Visible = False
    End Sub

    Private Sub GetNonProductItem(ByVal userNonProductItem As String)
        Dim cmsContent As String
        litLeftMainContent.Visible = False
        pnlSupportArticle.Visible = True
        divSupportArticle.Visible = False
        divNonProductItem.Visible = True

        Select Case CType(userNonProductItem, NonProductItem)
            Case NonProductItem.SupportSecurity
                litNonProductItem.Visible = True
                Me.litTitle.Text = "Online Security"
                If Request.QueryString(QueryStringName.Section) Is Nothing Then
                    cmsContent = ContentManager.Instance.GetContent("Support:OnlineSecurity", "1", OwnerType.Other)
                    litNonProductItem.Text = cmsContent
                Else
                    cmsContent = ContentManager.Instance.GetContent(String.Format("Support:OnlineSecurity:{0}", Request.QueryString(QueryStringName.Section)), "1", OwnerType.Other)
                    litNonProductItem.Text = cmsContent
                End If
            Case NonProductItem.SupportDownloads
                Me.litTitle.Text = "Downloads"
                Me.ucDownloads.Visible = True
        End Select

    End Sub

    Private Sub GetSupportArticle(ByVal artId As String)

        Dim lMenuItems As String = Application("SUPPORT_ARTICLE_MENU_ITEM")
        If Not lMenuItems Is Nothing Then
            ' Get starting and ending positions of the support article parameter in the querystring
            Dim lStartPos As Int32 = Request.Url.ToString().ToLower().IndexOf("supportarticleid=")
            Dim lEndPos As Int32
            If Request.Url.ToString().IndexOf("&", lStartPos) <> -1 Then
                lEndPos = Request.Url.ToString().IndexOf("&", lStartPos)
            Else
                lEndPos = Request.Url.ToString().Length
            End If

            Dim lArticlePos As Int32 = lMenuItems.IndexOf(Request.Url.ToString().ToLower().Substring(lStartPos, lEndPos - lStartPos))

            ' If the support article ID in the URL is contained in the config string...
            If lArticlePos <> -1 Then

                ' Split the string starting at the position where the support article ID is found; this should ensure that
                ' the first array element is the one we want and limit looping to just one time
                Dim lSupportArticles As String() = lMenuItems.Substring(lArticlePos).Split(CType("|", Char))

                For Each supportArticle As String In lSupportArticles
                    If supportArticle <> String.Empty Then
                        Dim lSupportArticleElements As String() = supportArticle.Split(CType(";", Char))

                        If lSupportArticleElements.Length > 0 Then
                            ' If the url contains this support article ID...
                            If Request.Url.ToString().ToLower().Contains(lSupportArticleElements(0).ToLower) Then
                                Try
                                    ' Attempt to set the product category
                                    Me.ucBrowseSupport.Productategory = CType(lSupportArticleElements(1), MenuItem)
                                Catch ex As InvalidCastException
                                    Me.ucBrowseSupport.Productategory = MenuItem.Internet
                                End Try

                                Exit For
                            End If

                        End If

                    End If
                Next
            End If  'If lArticlePos <> -1
        End If  'If Not lMenuItems Is Nothing

        Me.litTitle.Text = "Support"

        Dim articleID As Integer = CType(artId, Integer)
        ucSupportArticle.ArticleID = articleID
        Dim document As IHTMLDocument = SiteManager.Instance.GetDocument(articleID)




        '############################################################################################################
        'ROD COPELAND   ISSUE ID 7819   7/28/2010
        'REDIRECT USER TO THE MAIN PAGE AS SOMEONE IS ASKING FOR A ARTICLE ID THAT DOES NOT EXIST IN THE DB ANYMORE.
        '############################################################################################################
        If document Is Nothing Then
            '-----------------------------------------------------------------------------------------------------
            ' ISSUE #11705  12-07-2010  JLN
            '-----------------------------------------------------------------------------------------------------
            ' Description:  SupportOverview.aspx page not displaying properly when article not found.
            '      Change:  Redirect to Support.aspx with no article-id, instead.
            '-----------------------------------------------------------------------------------------------------
            Response.Redirect("Support.aspx")
        End If



        ucSupportArticle.Document = document
        ucSupportArticle.Visible = True
        If (ucSupportArticle.Document.Title.Length > 0) Then
            Me.litTitle.Text = ucSupportArticle.Document.Title
        End If

        'if inactive article then don't display the rating control
        If ucSupportArticle.Document.Title.IndexOf("Inactive Support Article") = 0 Then
            ucSupportArticleRanking.Visible = False
        Else
            ucSupportArticleRanking.Visible = True
        End If

        litEmailPrintArticle.Text = "<a class=""modalLink"" href=""EmailArticle.aspx?SupportArticleID=" & CType(Request.QueryString(QueryStringName.SupportArticleID), Integer) & "&title=" & Server.UrlEncode(Me.litTitle.Text) & """><img src=../images/email.gif /> E-mail </a>&nbsp;" + _
        ":: <a target=""_blank"" href=../customers/printarticle.aspx?SupportArticleID=" & CType(Request.QueryString(QueryStringName.SupportArticleID), Integer) & "><img src=../images/print.gif /> Print </a><br /><img src=../images/spacer.gif height=10 /><br />"
        litEmailPrintArticle.Visible = True

    End Sub
End Class






