Imports System.Collections.Generic
Imports System.Xml
Imports CharterDotCom.CommonEntities.Library
Imports CharterDotCom.CommonEntities.Library.Enumerations
Imports CharterDotCom.CommonEntities.Library.EntityMemberServices
Imports CharterDotCom.CommonEntities.Library.EntityEBSServices
Imports CharterDotCom.CommonEntities.Library.EntitySupport
Imports CharterDotCom.CommonEntities.Library.EntitySearch
Imports CharterDotCom.CommonEntities.Library.EntityWebConfig
Imports CharterDotCom.CommonEntities.Library.EntityG2BServices
Imports CharterDotCom.CommonEntities.Library.Common
Imports CharterDotCom.WebSite.Library

Partial Class Controls_Localize
    Inherits System.Web.UI.UserControl

    Public Event Localized()

    Private _AffiliateID As Integer
    Private _panelToDisplay As String = ""
    Public _address1 As String
    Public _address2 As String
    Public _zip As String

    Public Property PanelToDisplay() As String
        Get
            '###########################
            'CURRENT OPTIONS AVAILABLE
            '###########################
            'pnlEnterInfo
            'pnlNotFound
            'pnlTryAnother
            'pnlLeadSharing 
            'pnlSmallEnterInfo
            Return _panelToDisplay
        End Get
        Set(ByVal value As String)
            _panelToDisplay = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim _address As IAddress


        Dim affiliateID As String = HttpContext.Current.Request.QueryString.Get("affid")




        '#########################################################################
        'MODIFICATION   ROD COPELAND    APR 3, 2009 ISSUE ID 5768
        '#########################################################################
        'REDIRECT THE AFFILLIATE USER IN THE EVENT THAT THEY COME HERE BY ASKING 
        'FOR THE URL DIRECTLY RATHER THAN USING THE AFFILIATE DOMAIN NAME, WHICH 
        'IS NOW POINTING TO A KNOTICE SERVER IP RATHER THAN CHARTER.COM NOW.
        '#########################################################################
        If Not (Application("AFFILIATE_SITE_LOCALIZEPAGE_REDIRECT_ENABLED") Is Nothing) Then
            If Application("AFFILIATE_SITE_LOCALIZEPAGE_REDIRECT_ENABLED").ToString().ToUpper() = "T" Then
                If Not (Application("AFFILIATE_SITE_LOCALIZEPAGE_REDIRECT_URL") Is Nothing) Then
                    If Not (affiliateID Is Nothing) Then
                        If affiliateID.Trim() <> "" Then
                            '#######################################
                            'SEND TO AFFILIATE BUNDLE BUILDER SITE.
                            '#######################################
                            Response.Redirect(Server.HtmlEncode(Application("AFFILIATE_SITE_LOCALIZEPAGE_REDIRECT_URL").ToString() & affiliateID.ToString()))
                        End If
                    End If
                End If
            End If
        End If
        '#########################################################################






        If HttpContext.Current.Session("affid") IsNot Nothing AndAlso HttpContext.Current.Request.QueryString.Get("affid") Is Nothing Then
            affiliateID = HttpContext.Current.Session("affid")
        End If

        If affiliateID = String.Empty Then
            _AffiliateID = 0
        ElseIf Not IsNumeric(affiliateID) Then
            _AffiliateID = 0
        Else
            _AffiliateID = CInt(affiliateID)
        End If

        HttpContext.Current.Session.Add("affid", _AffiliateID)

        If Not IsPostBack Then

            If Not HttpContext.Current.Request.Cookies("chkBoxStatus") Is Nothing Then

                If (HttpContext.Current.Request.Cookies("chkBoxStatus").Value.ToString()) = "True" Then
                    chkRememberMe.Checked = True
                    If Not HttpContext.Current.Request.Cookies("Street1") Is Nothing Then
                        _address1 = HttpContext.Current.Request.Cookies("Street1").Value.ToString()
                    End If
                    If Not HttpContext.Current.Request.Cookies("Street2") Is Nothing Then
                        _address2 = HttpContext.Current.Request.Cookies("Street2").Value.ToString()
                    End If
                    If Not HttpContext.Current.Request.Cookies("ZipCode") Is Nothing Then
                        _zip = HttpContext.Current.Request.Cookies("ZipCode").Value.ToString()
                    End If
                End If

                '#######################################################################
                '9/18/2007 - Brad Miller
                'City and State removed due to redundancy, as users can just enter Zip.
                '#######################################################################
                'vldStreet1Required.ValidationGroup = Me.ID
                'vldZipCodeRequired.ValidationGroup = Me.ID
                'vldZipCodeRegExp.ValidationGroup = Me.ID
                'vldPhone1.ValidationGroup = Me.ID
                'vldPhone2.ValidationGroup = Me.ID
                'vldPhone3.ValidationGroup = Me.ID
                'vldSummaryLocalize.ValidationGroup = Me.ID
                'btnContinue.ValidationGroup = Me.ID



                '########################################################################
                'MODIFICATION   ROD COPELAND    ISSUE ID 3998
                'COMMENTED TWO LINES AS PART OF MAKING THE ADDRESS NOT FOUND SECTION CMS 
                'MANAGED, THE LINKS WILL BE HARD CODED IN THE CMS RECORD.
                '########################################################################
                'aTryAnother.HRef = Request.Url.ToString()
                'aChatLive.HRef = Request.Url.ToString()
                '########################################################################




                'ddlState.DataSource = CType(Application(ApplicationKey.StateList), System.Data.DataTable)
                'ddlState.DataTextField = "Name"
                'ddlState.DataValueField = "Abbv"
                'ddlState.DataBind()

                'ddlState.Items.Insert(0, New ListItem(String.Empty, String.Empty))

                txtStreet1.Text = _address1
                txtStreet2.Text = _address2
                txtZipCode.Text = _zip

                pnlEnterInfo.Visible = True
                pnlNotFound.Visible = False
                pnlTryAnother.Visible = False


                ' AccountManager.Instance.Localize(_address1, _address2, _zip, _AffiliateID)
            Else
                chkRememberMe.Checked = False
                vldStreet1Required.ValidationGroup = Me.ID
                vldZipCodeRequired.ValidationGroup = Me.ID
                vldZipCodeRegExp.ValidationGroup = Me.ID
                btnContinue.ValidationGroup = Me.ID



                '########################################################################
                'MODIFICATION   ROD COPELAND    ISSUE ID 3998
                'COMMENTED TWO LINES AS PART OF MAKING THE ADDRESS NOT FOUND SECTION CMS 
                'MANAGED, THE LINKS WILL BE HARD CODED IN THE CMS RECORD.
                '########################################################################
                'aTryAnother.HRef = Request.Url.ToString()
                'aChatLive.HRef = Request.Url.ToString()
                '########################################################################



                'ddlState.DataSource = CType(Application(ApplicationKey.StateList), System.Data.DataTable)
                'ddlState.DataTextField = "Name"
                'ddlState.DataValueField = "Abbv"
                'ddlState.DataBind()

                'ddlState.Items.Insert(0, New ListItem(String.Empty, String.Empty))

                _address = AccountManager.Instance.GetAccount().Address

                If _address IsNot Nothing Then
                    txtStreet1.Text = _address.Street1
                    txtStreet2.Text = _address.Street2
                    'txtCity.Text = _address.City
                    txtZipCode.Text = _address.Zip
                End If


                pnlEnterInfo.Visible = True
                pnlNotFound.Visible = False
                pnlTryAnother.Visible = False
            End If

        ElseIf Not (Request.QueryString(QueryStringName.AddressID) Is Nothing) Then
            _address = AccountManager.Instance.GetAddresses(Request.QueryString(QueryStringName.AddressID))

            Dim localized As Boolean
            If _AffiliateID = 0 Then
                localized = AccountManager.Instance.Localize(_address.Street1, _address.Street2, _address.Zip, txtPromotionCode.Text)
            Else
                localized = AccountManager.Instance.Localize(_address.Street1, _address.Street2, _address.Zip, txtPromotionCode.Text, _AffiliateID)
            End If
            If localized Then
                RaiseEvent Localized()
            Else
                txtStreet1.Text = _address.Street1
                txtStreet2.Text = _address.Street2
                'txtCity.Text = _address.City

                'If Not String.IsNullOrEmpty(_address.State) Then
                '    ddlState.Text = _address.State
                'End If

                txtZipCode.Text = _address.Zip

                pnlEnterInfo.Visible = True
                pnlNotFound.Visible = False
                pnlTryAnother.Visible = False
            End If
        End If





        If Not IsPostBack Then
            If Request.Url.ToString.ToLower().Contains("order/localize.aspx") Then
                If Not (Session("SmallAddress1") Is Nothing) Then
                    If Not (Session("SmallZip") Is Nothing) Then
                        txtPhone1.Text = Session("SmallPhone1")
                        txtPhone2.Text = Session("SmallPhone2")
                        txtPhone3.Text = Session("SmallPhone3")
                        txtStreet1.Text = Session("SmallAddress1")
                        txtStreet2.Text = Session("SmallAddress2")
                        txtZipCode.Text = Session("SmallZip")

                        Call Localize_And_Continue()

                    End If
                End If
            End If





            If Request.Url.ToString.ToLower().Contains("visitors/home.aspx") Then
                Dim account As IAccount = AccountManager.Instance.GetAccount()
                If Not (account Is Nothing) Then
                    If Not (account.UserStatus = UserStatus.Localized) Then

                        If Not (Me.PanelToDisplay Is Nothing) Then
                            If Me.PanelToDisplay.ToLower().Contains("pnlsmallenterinfo") Then
                                pnlEnterInfo.Visible = False
                                pnlNotFound.Visible = False
                                pnlTryAnother.Visible = False
                                pnlLeadSharing.Visible = False
                                pnlSmallEnterInfo.Visible = True

                                'this.value='';
                                If Not (_address1 Is Nothing) Then
                                    If _address1.Trim() <> "" Then
                                        txtSmallAddress1.Text = _address1
                                    Else
                                        txtSmallAddress1.Text = "Enter Address"
                                    End If
                                Else
                                    txtSmallAddress1.Text = "Enter Address"
                                End If


                                If Not (_address2 Is Nothing) Then
                                    If _address2.Trim() <> "" Then
                                        txtSmallAddress2.Text = _address2
                                    Else
                                        txtSmallAddress2.Text = "Apt #"
                                    End If
                                Else
                                    txtSmallAddress2.Text = "Apt #"
                                End If

                                If Not (_zip Is Nothing) Then
                                    If _zip.Trim() <> "" Then
                                        txtSmallZip.Text = _zip
                                    Else
                                        txtSmallZip.Text = "Zip"
                                    End If
                                Else
                                    txtSmallZip.Text = "Zip"
                                End If
                            End If
                        End If
                    Else
                        '##################################################################
                        'IF THE USER IS ALREADY LOCALIZED THEN DONT SHOW THE LOCALIZE 
                        'CONTROL FOR THE HOME PAGE.  JUST FOR NOW. MARKETING MAY WANT 
                        'TO SHOW SOME UPSELL DETAILS HERE SINCE THE USER IS LOCALIZED HERE.
                        '##################################################################
                        pnlEnterInfo.Visible = False
                        pnlNotFound.Visible = False
                        pnlTryAnother.Visible = False
                        pnlLeadSharing.Visible = False
                        pnlSmallEnterInfo.Visible = False
                    End If
                End If

            End If
        End If



        lblErrorMessage.Text = ""
        lblErrorMessage.Visible = False

    End Sub

    Private Sub Localize_And_Continue()
        '#############################
        'RESET UPON SUCCESS
        '#############################
        Session("SmallPhone1") = Nothing
        Session("SmallPhone2") = Nothing
        Session("SmallPhone3") = Nothing
        Session("SmallAddress1") = Nothing
        Session("SmallAddress2") = Nothing
        Session("SmallZip") = Nothing

        Dim blnUseAddressSearch As Boolean = False
        Dim blnUsePhoneSearch As Boolean = False

        If (txtStreet1.Text.Trim.Length > 0 OrElse txtZipCode.Text.Trim.Length > 0) Then
            blnUseAddressSearch = True
        End If
        If (txtPhone1.Text.Trim.Length > 0 OrElse txtPhone2.Text.Trim.Length > 0 OrElse txtPhone3.Text.Trim.Length > 0) Then
            blnUsePhoneSearch = True
        End If

        If Not (blnUseAddressSearch) AndAlso Not (blnUsePhoneSearch) Then
            lblErrorMessage.Text = "<div class=""ValidationSummary"">" & "<img src='../Images/error-icon_small.ccom' /> " & "An address or phone number must be entered." & "</div>"
            lblErrorMessage.Visible = True
        ElseIf blnUseAddressSearch AndAlso Not (blnUsePhoneSearch) Then
            If PageIsValidForAddress() Then
                LocalizeByAddress(True)
            Else
                DisplayValidationMessagesForAddress()
            End If
        ElseIf Not (blnUseAddressSearch) AndAlso blnUsePhoneSearch Then
            If PageIsValidForPhone() Then
                LocalizeByPhone(True)
            Else
                DisplayValidationMessagesForPhone()
            End If
        Else
            Dim blnAddress As Boolean = PageIsValidForAddress()
            Dim blnPhone As Boolean = PageIsValidForPhone()

            If Not (blnAddress) AndAlso Not (blnPhone) Then
                DisplayValidationMessagesForAddress()
                DisplayValidationMessagesForPhone()
            ElseIf blnAddress AndAlso Not (blnPhone) Then
                LocalizeByAddress(True)
            ElseIf Not (blnAddress) AndAlso blnPhone Then
                LocalizeByPhone(True)
            Else
                LocalizeByAddress(False)
                LocalizeByPhone(True)
            End If
        End If

    End Sub

    Protected Sub btnContinue_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnContinue.Click
        If Not (Session("SmallPhone1") Is Nothing) Then
            If Session("SmallPhone1").ToString().Trim() <> "" Then
                txtPhone1.Text = Session("SmallPhone1").ToString()
            End If
        End If
        If Not (Session("SmallPhone2") Is Nothing) Then
            If Session("SmallPhone2").ToString().Trim() <> "" Then
                txtPhone2.Text = Session("SmallPhone2").ToString()
            End If
        End If
        If Not (Session("SmallPhone3") Is Nothing) Then
            If Session("SmallPhone3").ToString().Trim() <> "" Then
                txtPhone3.Text = Session("SmallPhone3").ToString()
            End If
        End If
        If Not (Session("SmallAddress1") Is Nothing) Then
            If Session("SmallAddress1").ToString().Trim() <> "" Then
                txtStreet1.Text = Session("SmallAddress1").ToString()
            End If
        End If
        If Not (Session("SmallAddress2") Is Nothing) Then
            If Session("SmallAddress2").ToString().Trim() <> "" Then
                txtStreet2.Text = Session("SmallAddress2").ToString()
            End If
        End If
        If Not (Session("SmallZip") Is Nothing) Then
            If Session("SmallZip").ToString().Trim() <> "" Then
                txtZipCode.Text = Session("SmallZip").ToString()
            End If
        End If


        Call Localize_And_Continue()
    End Sub

    Private Function PageIsValidForAddress() As Boolean
        Dim chkBoxStatusCookie As HttpCookie
        Dim blnValid = False

        EnableValidators(phAddressValidators)

        Page.Validate()

        If Page.IsValid Then

            chkBoxStatusCookie = New HttpCookie("ChkBoxStatus")
            chkBoxStatusCookie.Value = chkRememberMe.Checked
            chkBoxStatusCookie.Expires = Date.Today.AddDays(40)
            HttpContext.Current.Response.Cookies.Add(chkBoxStatusCookie)

            If chkRememberMe.Checked = True Then
                Dim address1 As String = txtStreet1.Text.ToString()
                Dim address1Cookie As HttpCookie = New HttpCookie("Street1")
                address1Cookie.Value = address1
                address1Cookie.Expires = Date.Today.AddDays(40)
                HttpContext.Current.Response.Cookies.Add(address1Cookie)

                Dim address2 As String = txtStreet2.Text.ToString()
                Dim address2Cookie As HttpCookie = New HttpCookie("Street2")
                address2Cookie.Value = address2
                address2Cookie.Expires = Date.Today.AddDays(40)
                HttpContext.Current.Response.Cookies.Add(address2Cookie)

                Dim zipc As String = txtZipCode.Text.ToString()
                Dim zipCookie As HttpCookie = New HttpCookie("ZipCode")
                zipCookie.Value = zipc
                zipCookie.Expires = Date.Today.AddDays(40)
                HttpContext.Current.Response.Cookies.Add(zipCookie)
            End If

            blnValid = True
        Else
            blnValid = False
        End If

        DisableValidators(phAddressValidators)

        Return blnValid

    End Function

    Private Sub DisplayValidationMessagesForAddress()
        EnableValidators(phAddressValidators)
        DisplayErrors(Page)
        DisableValidators(phAddressValidators)
    End Sub

    Private Sub LocalizeByAddress(ByVal blnShowTryAnotherPanel As Boolean)
        Dim addresses As Dictionary(Of String, IAddress)
        Dim localizedByAddress As Boolean = False

        If _AffiliateID = 0 Then
            localizedByAddress = AccountManager.Instance.Localize(txtStreet1.Text, txtStreet2.Text, txtZipCode.Text.Substring(0, 5).ToString, txtPromotionCode.Text)
        Else
            localizedByAddress = AccountManager.Instance.Localize(txtStreet1.Text, txtStreet2.Text, txtZipCode.Text.Substring(0, 5).ToString, txtPromotionCode.Text, _AffiliateID)
        End If

        If localizedByAddress Then
            HttpContext.Current.Response.Cookies.Add(New HttpCookie(CookieKey.LocalAddress1, txtStreet1.Text))
            HttpContext.Current.Response.Cookies.Add(New HttpCookie(CookieKey.LocalAddress2, txtStreet2.Text))
            HttpContext.Current.Response.Cookies.Add(New HttpCookie(CookieKey.LocalZip, txtZipCode.Text))
            RaiseEvent Localized()
        Else
            If blnShowTryAnotherPanel Then

                addresses = AccountManager.Instance.GetAddresses()

                If addresses IsNot Nothing Then
                    rprAddress.DataSource = addresses
                    rprAddress.DataBind()

                    pnlEnterInfo.Visible = False
                    pnlNotFound.Visible = True
                    pnlTryAnother.Visible = True
                    pnlLeadSharing.Visible = False
                    Page.ClientScript.RegisterStartupScript(Me.GetType(), "HBXScript", GenerateHBXPageScript())
                Else
                    ' do Zip code lookup (issue #2130)
                    ' the purpose of this was to send potential leads to leapfrog if their zip code is in
                    ' the zip code footprint provided by CCIA data.  Zip data with City and State is held in 
                    ' an Application variable
                    Dim xmlDoc As New XmlDocument
                    Dim nav As XPath.XPathNavigator
                    Dim iterator As XPath.XPathNodeIterator

                    xmlDoc.LoadXml(CType(Application(ApplicationKey.ZipcodeLocalization), String))
                    'xmlDoc = New XPath.XPathDocument(CType(Application(ApplicationKey.ZipcodeLocalization), String))
                    nav = xmlDoc.CreateNavigator
                    iterator = nav.Select("/Zip_footprint/Location/Zip[.='" & txtZipCode.Text & "']")

                    If (iterator Is Nothing) OrElse (iterator.Count = 0) Then
                        Page.ClientScript.RegisterStartupScript(Me.GetType(), "HBXScript", GenerateHBXPageScript("ccom_leapfrog", "/landing"))
                        pnlEnterInfo.Visible = False
                        pnlNotFound.Visible = False
                        pnlTryAnother.Visible = False
                        pnlLeadSharing.Visible = True
                    Else
                        Page.ClientScript.RegisterStartupScript(Me.GetType(), "HBXScript", GenerateHBXPageScript())
                        pnlEnterInfo.Visible = False
                        pnlNotFound.Visible = False
                        pnlTryAnother.Visible = True
                        pnlLeadSharing.Visible = False

                    End If
                End If
            End If
        End If
    End Sub

    Private Function PageIsValidForPhone() As Boolean
        Dim blnValid = False

        EnableValidators(phPhoneValidators)

        Page.Validate()

        If Page.IsValid Then
            blnValid = True
        Else
            blnValid = False
        End If

        DisableValidators(phPhoneValidators)

        Return blnValid
    End Function

    Private Sub DisplayValidationMessagesForPhone()
        EnableValidators(phPhoneValidators)
        DisplayErrors(Page)
        DisableValidators(phPhoneValidators)
    End Sub

    Private Sub LocalizeByPhone(ByVal blnShowTryAnotherPanel As Boolean)
        Dim localizedByPhone As Boolean = False

        If _AffiliateID = 0 Then
            localizedByPhone = AccountManager.Instance.LocalizeByPhone(txtPhone1.Text & txtPhone2.Text & txtPhone3.Text)
        Else
            localizedByPhone = AccountManager.Instance.LocalizeByPhone(txtPhone1.Text & txtPhone2.Text & txtPhone3.Text, _AffiliateID)
        End If


        If localizedByPhone Then
            RaiseEvent Localized()
        Else
            If blnShowTryAnotherPanel Then
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "HBXScript", GenerateHBXPageScript())
                pnlEnterInfo.Visible = False
                pnlNotFound.Visible = False
                pnlTryAnother.Visible = True
                pnlLeadSharing.Visible = False
            End If
        End If
    End Sub

    Private Sub EnableValidators(ByVal container As Control)
        For Each c As Control In container.Controls
            If TypeOf c Is IValidator Then
                CType(c, BaseValidator).Enabled = True
            End If
        Next
    End Sub

    Private Sub DisableValidators(ByVal container As Control)
        For Each c As Control In container.Controls
            If TypeOf c Is IValidator Then
                CType(c, BaseValidator).Enabled = False
            End If
        Next
    End Sub

    Private Sub DisplayErrors(ByVal pg As Page)
        Dim iValidator As IValidator
        Dim arlValidators As New ArrayList()

        Page.Validate()

        lblErrorMessage.Visible = True

        For Each iValidator In pg.Validators
            If Not iValidator.IsValid Then
                lblErrorMessage.Text += "<div class=""ValidationSummary"">" & "<img src='../Images/error-icon_small.ccom' /> " & iValidator.ErrorMessage & "</div><br>"
            End If
        Next
    End Sub

    Protected Sub rprAddress_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rprAddress.ItemCommand
        Dim addressID As String
        Dim addresses As Dictionary(Of String, IAddress)

        addressID = e.CommandArgument

        If AccountManager.Instance.SelectAddress(addressID, txtPromotionCode.Text) Then
            RaiseEvent Localized()
        Else
            addresses = AccountManager.Instance.GetAddresses()

            If addresses IsNot Nothing Then
                rprAddress.DataSource = addresses
                rprAddress.DataBind()

                pnlEnterInfo.Visible = False
                pnlNotFound.Visible = True
                pnlTryAnother.Visible = True
            Else
                pnlEnterInfo.Visible = False
                pnlNotFound.Visible = False
                pnlTryAnother.Visible = True
            End If
        End If
    End Sub

    Private Overloads Function GenerateHBXPageScript() As String
        Try
            Dim strTemp As New StringBuilder()
            ' issue 15850
            strTemp.AppendLine("<script type=""text/javascript"">")
            strTemp.AppendLine("var utag_data = {")
            strTemp.AppendLine("page_level2:         'address not found',")
            strTemp.AppendLine("page_level1:        '/error'")
            strTemp.AppendLine("}")
            strTemp.AppendLine("</script>")
            strTemp.AppendLine("<script type=""text/javascript"" src=""//tealium.hs.llnwd.net/o43/utag/charter/main/prod/utag.js""></script>")

            'strTemp.Append("<SCRIPT>")
            'strTemp.Append("var hbxObj = new Object();")
            'strTemp.Append("hbxObj.pn = ""address not found"";")
            'strTemp.Append("hbxObj.mlc = ""/error"";")
            'strTemp.Append("hbxObj.pr = """";")
            'strTemp.Append("hbxObj.ca = """";")
            'strTemp.Append("hbxObj.pc = """";")
            'strTemp.Append("hbxObj.qn = """";")
            'strTemp.Append("hbxObj.st = 1;")
            'strTemp.Append("hbxObj.sp = 0;")
            'strTemp.Append("hbxObj.sr = 1;")
            'strTemp.Append("hbxObj.oi = """";")
            'strTemp.Append("hbxObj.sk = """";")
            'strTemp.Append("hbxObj.po = """";")
            'strTemp.Append("hbxObj.ds = 0;")
            'strTemp.Append("hbxObj.ci = """";")
            'strTemp.Append("</script>")
            'strTemp.Append("<script language=""javascript"" type=""text/javascript"" src=""../Scripts/hbx_pagecode.js""></script>")
            'strTemp.Append("<script language=""javascript"" type=""text/javascript"" src=""../Scripts/hbx.js""></script>")
            Return strTemp.ToString
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Overloads Function GenerateHBXPageScript(ByVal iPn As String, ByVal iMlc As String) As String
        ' DB - creating this for the lead sharing panel, eventually we might want to look at eliminating the first
        ' function that accepts no argument, and use this for both instances of calling the HBX script
        ' nice to have, but no time to mess with now...
        Try
            Dim strTemp As New StringBuilder
            strTemp.AppendLine("<script type=""text/javascript"">")
            strTemp.AppendLine("var utag_data = {")
            strTemp.AppendLine("page_level2:         '" & iPn & "',")
            strTemp.AppendLine("page_level1:        '" & iMlc & "'")
            strTemp.AppendLine("}")
            strTemp.AppendLine("</script>")
            strTemp.AppendLine("<script type=""text/javascript"" src=""//tealium.hs.llnwd.net/o43/utag/charter/main/prod/utag.js""></script>")

            'strTemp.Append("<SCRIPT>")
            'strTemp.Append("var hbxObj = new Object();")
            'strTemp.Append("hbxObj.pn = """ & iPn & """;")
            'strTemp.Append("hbxObj.mlc = """ & iMlc & """;")
            'strTemp.Append("hbxObj.pr = """";")
            'strTemp.Append("hbxObj.ca = """";")
            'strTemp.Append("hbxObj.pc = """";")
            'strTemp.Append("hbxObj.qn = """";")
            'strTemp.Append("hbxObj.st = 1;")
            'strTemp.Append("hbxObj.sp = 0;")
            'strTemp.Append("hbxObj.sr = 1;")
            'strTemp.Append("hbxObj.oi = """";")
            'strTemp.Append("hbxObj.sk = """";")
            'strTemp.Append("hbxObj.po = """";")
            'strTemp.Append("hbxObj.ds = 0;")
            'strTemp.Append("hbxObj.ci = """";")
            'strTemp.Append("</script>")
            'strTemp.Append("<script language=""javascript"" type=""text/javascript"" src=""../Scripts/hbx_pagecode.js""></script>")
            'strTemp.Append("<script language=""javascript"" type=""text/javascript"" src=""../Scripts/hbx.js""></script>")
            Return strTemp.ToString
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function FormatUrl() As String

        Dim sb As New StringBuilder
        Dim addr1 As String = Trim(txtStreet1.Text).Replace(" ", "+")
        Dim addr2 As String = Trim(txtStreet2.Text).Replace(" ", "+")
        Dim zip As String = Trim(txtZipCode.Text)

        Try
            '###############################################################
            'MODIFICATION   ROD COPELAND    ISSUE 7134  9/29/2009
            'UPDATED THE DOMAIN THE USER IS REDIRECTED TO
            '###############################################################
            sb.Append("http://www.bestcabledeals.net/Redirect.aspx?sender=bb")
            sb.AppendFormat("&add={0}", addr1)
            sb.AppendFormat("&add2={0}", addr2)
            sb.AppendFormat("&zip={0}", zip)

            Return sb.ToString

        Catch ex As Exception
            Throw ex
        End Try
    End Function


    Protected Sub btnLocalizeContinue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLocalizeContinue.Click
        Session("SmallPhone1") = txtSmallPhone1.Text.Trim()
        Session("SmallPhone2") = txtSmallPhone2.Text.Trim()
        Session("SmallPhone3") = txtSmallPhone3.Text.Trim()
        Session("SmallAddress1") = txtSmallAddress1.Text.Trim().ToLower().Replace("enter address", "")
        Session("SmallAddress2") = txtSmallAddress2.Text.Trim().ToLower().Replace("apt #", "")
        Session("SmallZip") = txtSmallZip.Text.Trim().ToLower().Replace("zip", "")



        'txtPhone1.Text = txtSmallPhone1.Text.Trim()
        'txtPhone2.Text = txtSmallPhone2.Text.Trim()
        'txtPhone3.Text = txtSmallPhone3.Text.Trim()
        'txtStreet1.Text = txtSmallAddress1.Text.Trim().ToLower().Replace("enter address", "")
        'txtStreet2.Text = txtSmallAddress2.Text.Trim().ToLower().Replace("apt #", "")
        'txtZipCode.Text = txtSmallZip.Text.Trim().ToLower().Replace("zip", "")

        'Call Localize_And_Continue()

        'If Not pnlTryAnother.Visible Then
        '    Response.Redirect("../visitors/localize.aspx")
        'End If


        Response.Redirect("../visitors/localize.aspx")

    End Sub

End Class
