Imports System.Collections.Generic
Partial Class CBSite
    Inherits System.Web.UI.MasterPage
    Private _canregisterscript As Boolean = True
    Private _hbxpagename As String
    Private _hbxmlc As String
    Public _metaTags As String = ""
    Public _cbMyAcctColBorderColor As Boolean
    Public showSupportPageSearch As Boolean = False


    '###########################################################################################
    '                               MODIFICATION   SIVA DOLA  04-07-2008
    '###########################################################################################
    ' BELOW STYLE IS LINKED TO CB.COM STYLE SHEET ( A COPY OF CHARTER STYLE SHEET)
    '###########################################################################################
    Public _stylesheetURL As String = "<link type=""text/css"" rel=""stylesheet"" href=""../CBMS/CBdotCom.css"" />"
    '###########################################################################################
    '                               MODIFICATION   SIVA DOLA  04-07-2008
    '###########################################################################################
    ' BELOW PROPERTY IS ADDED TO ENABLE COLUMN BORDER COLOR(BLUE), ONLY FOR CB MYACCOUNT PAGE
    '###########################################################################################
    Public Property cbMyAcctColBorderColor() As Boolean
        Get
            If ViewState("cbMyAcctColBorderColor") Is Nothing Then
                Return False
            Else
                Return CType(ViewState("cbMyAcctColBorderColor"), Boolean)
            End If
        End Get
        Set(ByVal value As Boolean)
            ViewState("cbMyAcctColBorderColor") = value
        End Set
    End Property


    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 ReadOnly Property LiveZoneManager() As ASP.controls_livezone_ascx
        Get
            Return Me.ucLiveZone
        End Get
    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
       
        '##################################################################################
        'MODIFICATION   FEB 11, 2008    ROD COPELAND
        'GOOGLE SEARCH INTEGRATION
        '##################################################################################
        'FOR RIGHT NOW JUST FOR THE SUPPORT PAGE WE HAVE A SECONDARY SEARCH BOX TO SEARCH 
        'SUPPORT ONLY WHILE LEAVING THE SEARCH SITE  TEXT BOX UP TOP.
        '##################################################################################
        If Request.Url.ToString().ToLower().Trim().Contains("customer/support.aspx") Then
            showSupportPageSearch = True
        Else
            showSupportPageSearch = False
        End If
        '##################################################################################




        Try
            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

            If Not Request.QueryString("livezone") Is Nothing Then
                LiveZoneManager.URL = "http://www.google.com"
                LiveZoneManager.SetDimentions(350, 300)
                LiveZoneManager.SetLocation(350, 200)
                LiveZoneManager.Visible = True
            End If

            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
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If Not Page.IsPostBack Then

            If OrphanPage Then
                ltrCol1.Text = "<td class='col1' id='greenTop'>"
                ltrCol2.Text = "<td class='col2d' id='greenTop'>"
                ltrCol3.Text = "<td class='col3' id='greenTop'>"
            Else
                ltrCol1.Text = "<td class='col1'>"
                ltrCol2.Text = "<td class='col2'>"
                ltrCol3.Text = "<td class='col3'>"
            End If
            '###########################################################################################
            '                               MODIFICATION   SIVA DOLA  04-07-2008
            '###########################################################################################
            '   BELOW CONDITION IS USED TO ENABLE COLUMN BORDER COLORS. USED IN CBMYACCOUNT PAGE.
            '###########################################################################################
            If cbMyAcctColBorderColor Then
                ltrCol1.Text = "<td class='cbCol1'>"
                ltrCol2.Text = "<td class='cbCol2'>"
                ltrCol3.Text = "<td class='cbCol3'>"
            End If
            If CanRegisterHBXScript Then
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "HBXScript", HBXSupport.GenerateHBXPageScript(HBXPageName, HBXMLC))
            End If
        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

