Imports CharterDotCom.CommonEntities.Library.Enumerations
Imports CharterDotCom.WebSite.Library
Imports CharterDotCom.CommonEntities.Library
Imports CharterDotCom.CommonEntities.Library.EntityMemberServices
Imports CharterDotCom.CommonEntities.Library.EntityWebConfig
Imports System.Collections.Generic

Partial Class Home_Latino
    Inherits System.Web.UI.MasterPage

    Private _canregisterscript As Boolean = True
    Private _hbxpagename As String
    Private _hbxmlc As String
    Public _metaTags As String = ""
    Public _stylesheetURL As String = "<link type=""text/css"" rel=""stylesheet"" href=""../Styles/Charter.css"" />"
    Public showSupportPageSearch As Boolean = False

    Public Property OrphanPage() As Boolean
        Get
            If ViewState("OrphanPage") Is Nothing Then
                Return False
            Else
                Return CType(ViewState("OrphanPage"), Boolean)
            End If
        End Get

        Set(ByVal value As Boolean)
            ViewState("OrphanPage") = value
        End Set
    End Property

    Public Property CanRegisterHBXScript() As Boolean
        Get
            Return _canregisterscript
        End Get

        Set(ByVal value As Boolean)
            _canregisterscript = value
        End Set
    End Property

    Public Property HBXPageName() As String
        Get
            Return _hbxpagename
        End Get
        Set(ByVal value As String)
            _hbxpagename = value
        End Set
    End Property

    Public Property HBXMLC() As String
        Get
            Return _hbxmlc
        End Get
        Set(ByVal value As String)
            _hbxmlc = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim WebCrawledPageCollection As Dictionary(Of String, WebCrawledPage) = Application("WEB_CRAWLED_PAGE_COLLECTION")
            Dim url As String = Request.RawUrl.Trim().ToLower()
            If url.Substring(0, 4).Contains("/ui/") Then
                url = url.Replace("/ui/", "") '/UI/ value will exist if running on local machine, non PROD, UAT, Or DEV stuff
            Else
                url = url.Substring(1) ' THIS IS AN ATTEMPT TO REMOVE THE FORWARD SLASH FROM THE URL
            End If



            If Not (WebCrawledPageCollection Is Nothing) Then
                If WebCrawledPageCollection.ContainsKey(url) Then
                    If Not (WebCrawledPageCollection(url) Is Nothing) Then
                        Dim lRecord As WebCrawledPage = WebCrawledPageCollection(url)

                        If Not (lRecord.StyleSheetURL Is Nothing) Then
                            If lRecord.StyleSheetURL.Trim() <> "" Then
                                _stylesheetURL = vbNewLine & vbNewLine & "<link type=""text/css"" rel=""stylesheet"" href=""" & lRecord.StyleSheetURL & """ />" & vbNewLine & vbNewLine & vbNewLine
                            End If
                        End If


                        If Not (lRecord.PageDescription Is Nothing) Then
                            If lRecord.PageDescription.Trim() <> "" Then
                                Dim x As String = "<meta name=""description"" content=""" & lRecord.PageDescription & """ />" & vbNewLine & vbNewLine
                                _metaTags = vbNewLine & vbNewLine & _metaTags & x
                            End If
                        End If

                        If Not (lRecord.PageKeywords Is Nothing) Then
                            If lRecord.PageKeywords.Trim() <> "" Then
                                Dim x As String = "<meta name=""keywords"" content=""" & lRecord.PageKeywords & """ />" & vbNewLine & vbNewLine
                                _metaTags = vbNewLine & vbNewLine & _metaTags & x
                            End If
                        End If
                    End If
                End If
            End If
        Catch ex As Exception
            '###############################################################################
            'ROD COPELAND July 07 2007, I WOULD IMAGE WE WOULDN'T WANT TO SHOW THE
            'REQUEST FOR FOLLOW UP PAGE JUST BECAUSE WE CANT LOAD THE KEYWORDS AND  
            'DESCRIPTION TO LOAD CORRECTLY. SO FOR NOW, IF AN EXCEPTION OCCURS, JUST RETURN
            ' NOTHING AND CONTINUE ON TO LOAD THE REST OF THE PAGE.
            '###############################################################################
        End Try

        SetHBXInfo()
        Dim strTemp As String = Page.Request.Url.LocalPath.ToString().ToUpper()
        Dim strChar(1) As Char
        Dim strSplit() As String
        strChar(0) = CChar("/")
        strSplit = strTemp.Split(strChar, StringSplitOptions.RemoveEmptyEntries)
        Select Case strSplit(UBound(strSplit))
            Case PageName.AllOffers.ToUpper(), PageName.BuildYourOwn.ToUpper(), PageName.ChooseOptions.ToUpper(), PageName.EnterInformation.ToUpper(), PageName.FinishOrder.ToUpper(), PageName.Offers.ToUpper(), PageName.ShoppingCart.ToUpper(), PageName.Upsell.ToUpper(), PageName.OfferDetail.ToUpper(), PageName.AffiliateFinishOrder.ToUpper(), PageName.QuickPay.ToUpper(), PageName.PayYourBill.ToUpper(), PageName.MyAccount.ToUpper()
                CanRegisterHBXScript = False
            Case Else
                CanRegisterHBXScript = True
        End Select

    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If CanRegisterHBXScript Then
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "HBXScript", HBXSupport.GenerateHBXPageScript(HBXPageName, HBXMLC))
        End If
    End Sub

    Protected Sub SearchSite(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgSiteSearch.Click
        Dim SearchSiteURL As String

        If (Application("SearchSiteURL") Is Nothing) Then
            SearchSiteURL = ContentManager.Instance.GetContent("Support:Home:SearchSiteURL", "1", OwnerType.Other)
            If Not (SearchSiteURL Is Nothing) Then
                Application.Lock()
                Application("SearchSiteURL") = SearchSiteURL
                Application.UnLock()
            End If
        Else
            SearchSiteURL = Application("SearchSiteURL")
        End If

        If (SearchSiteURL <> Nothing) Then
            SearchSiteURL = SearchSiteURL + Server.UrlEncode(Me.txtSearchSite.Value)
            Response.Redirect(SearchSiteURL)
        End If
    End Sub


    Private Sub SetHBXInfo()
        Try
            Dim _defaultSiteTitle As String = ConfigurationManager.AppSettings("SiteTitle")

            Dim WebCrawledPageCollection As Dictionary(Of String, WebCrawledPage) = Application("WEB_CRAWLED_PAGE_COLLECTION")
            Dim url As String = Request.RawUrl.Trim().ToLower()
            If url.Substring(0, 4).Contains("/ui/") Then
                url = url.Replace("/ui/", "") '/UI/ value will exist if running on local machine, non PROD, UAT, Or DEV stuff
            Else
                url = url.Substring(1) ' THIS IS AN ATTEMPT TO REMOVE THE FORWARD SLASH FROM THE URL
            End If



            If Not (WebCrawledPageCollection Is Nothing) Then
                If WebCrawledPageCollection.ContainsKey(url) Then
                    If Not (WebCrawledPageCollection(url) Is Nothing) Then
                        Dim lRecord As WebCrawledPage = WebCrawledPageCollection(url)


                        If Not (lRecord.HBXPageCategory Is Nothing) Then
                            HBXMLC = lRecord.HBXPageCategory
                        Else
                            HBXMLC = Request.RawUrl.ToUpper()
                            HBXMLC = HBXMLC.Replace("/UI/", "")
                        End If

                        If Not (lRecord.HBXPageName Is Nothing) Then
                            HBXPageName = lRecord.HBXPageName
                        Else
                            HBXPageName = "***NEW PAGE TO ADD TO HBX ***"
                        End If



                    Else
                        '###############################
                        'DO THE NORMAL ASSIGNMENT
                        '###############################
                        HBXMLC = Request.RawUrl.ToUpper()
                        HBXMLC = HBXMLC.Replace("/UI/", "")
                        HBXPageName = "***NEW PAGE TO ADD TO HBX XML***"
                    End If
                Else
                    '###############################
                    'DO THE NORMAL ASSIGNMENT
                    '###############################
                    HBXMLC = Request.RawUrl.ToUpper()
                    HBXMLC = HBXMLC.Replace("/UI/", "")
                    HBXPageName = "***NEW PAGE TO ADD TO HBX XML***"
                End If
            Else
                '###############################
                'DO THE NORMAL ASSIGNMENT
                '###############################
                HBXMLC = Request.RawUrl.ToUpper()
                HBXMLC = HBXMLC.Replace("/UI/", "")
                HBXPageName = "***NEW PAGE TO ADD TO HBX XML***"
            End If
        Catch ex As Exception

            '###############################################################################
            'ROD COPELAND JAN 31 2007, ALTHOUGH NO ONE HAS CONFIRMED THIS THOUGHT YET. 
            'I WOULD IMAGE WE WOULDN'T WANT TO SHOW THE REQUEST FOR FOLLOW UP PAGE 
            'JUST BECAUSE WE CANT LOAD THE PAGE TITLE CORRECTLY. SO FOR NOW, IF AN 
            'EXCEPTION OCCURS, JUST RETURN NOTHING AND CONTINUE ON TO LOAD THE REST 
            'OF THE PAGE.
            '###############################################################################

        End Try

    End Sub
End Class

