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

Partial Class Controls_QuickPay
    Inherits System.Web.UI.UserControl

    Dim _account As IAccount
    Dim _address1 As String = ""
    Dim _address2 As String = ""
    Dim _city As String = ""
    Dim _state As String = ""
    Dim _zip As String = ""

    Private _MyAccountUse As Boolean = False
    Private __HBXPageName As String = ""
    Private __HBXCategory As String = ""
    Public _latestBill As String = ""
    Public _payBillOptions As String = ""
    Public _cellColorBillSummary As String = ""
    Public _altCellColorBillSummary As String = ""
    Public _footerColorBillSummary As String = ""
    Public _bgColor As String = ""

    Public Property MyAccountUse() As Boolean
        Get
            Return _MyAccountUse
        End Get
        Set(ByVal value As Boolean)
            _MyAccountUse = value
        End Set
    End Property

    Public Property ShowIdentification() As Boolean
        Get
            If ViewState(Me.ID & "_ShowIdentification") Is Nothing Then
                Return False
            Else
                Return CType(ViewState(Me.ID & "_ShowIdentification"), Boolean)
            End If
        End Get

        Set(ByVal value As Boolean)
            ViewState(Me.ID & "_ShowIdentification") = value
        End Set
    End Property

    Public Property Account() As IAccount    'added
        Get
            Return _account
        End Get
        Set(ByVal value As IAccount)
            _account = value
        End Set
    End Property

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        V3PreRender()
    End Sub

    Public Function getIcomsStatementCode(ByVal inBillSummary As Object) As String
        Dim oStatementCode As String = ""

        If Len(inBillSummary.AccountNumber) > 18 Then
            oStatementCode = Right(inBillSummary.AccountNumber, 3)
        End If

        Return oStatementCode
    End Function

    Public Function getAccountNumberIndex(ByVal inBillSummary As Object) As String
        '#################################################################
        'MODIFICATION   ROD COPELAND    ISSUE ID 6782   AUG 13, 2009
        '#################################################################
        'SUPPORT CSG MULTI-STATEMENT LINKS NOT DIRECTING TO SPECIFIC ACCTS 
        'ON THE BILL VENDOR DOMAIN
        '#################################################################

        If Application("MULTISTATEMENT_ACCT_SPECIFIC_LINKING_ENABLED") IsNot Nothing Then
            Dim strFlag As String = Application("MULTISTATEMENT_ACCT_SPECIFIC_LINKING_ENABLED").ToString().Trim()
            If String.Compare(strFlag, "T", True) = 0 Then


                Dim lAccount As IAccount = AccountManager.Instance.GetAccount()
                If lAccount IsNot Nothing Then
                    If lAccount.Bill IsNot Nothing Then
                        If lAccount.Bill.Count > 0 Then
                            For i As Integer = 0 To lAccount.Bill.Count
                                If lAccount.Bill(i).AccountNumber = inBillSummary.AccountNumber Then
                                    Return i
                                End If
                            Next
                        End If
                    End If
                End If
            End If
        End If
        Return Nothing

    End Function

    Public Function trimIcomsAccountNumber(ByVal inBillSummary As Object) As String
        ' This function was put in to parse the ICOMS account number for the QuickPay portion
        ' of My Account.  Basically we want to strip out "character 19" from the actual Account number 
        ' coming back from the OSS Web services.

        Dim oAccountNumber As String
        If Len(inBillSummary.AccountNumber) > 18 Then
            oAccountNumber = inBillSummary.AccountNumber.Substring(0, 16) & "00" & Right(inBillSummary.AccountNumber, 1)
        Else
            Return inBillSummary.AccountNumber
        End If
        Return oAccountNumber

    End Function

    Public Function formatIcomsDueDate(ByVal inBillSummary As Object) As String
        ' This function was put in to parse the ICOMS due date for the QuickPay portion
        ' of My Account.  If the DueUponReceipt flag is set, return "Due Upon Receipt" otherwise
        ' format the date.

        Dim oDueDate As String = ""
        If inBillSummary.DueUponReceipt = True Then
            Return "Due Upon Receipt"
        Else
            If IsDate(inBillSummary.StatementDueDate_ICOMS_ONLY) Then
                If inBillSummary.StatementDueDate_ICOMS_ONLY.ToString() = "1/1/0001 12:00:00 AM" Then
                    oDueDate = "Invalid Date"
                Else
                    oDueDate = DatePart("M", inBillSummary.StatementDueDate_ICOMS_ONLY).ToString
                    oDueDate &= "/" & DatePart("d", inBillSummary.StatementDueDate_ICOMS_ONLY).ToString
                    oDueDate &= "/" & DatePart("yyyy", inBillSummary.StatementDueDate_ICOMS_ONLY).ToString
                End If
            Else
                oDueDate = "Invalid Date"
            End If
        End If
        Return oDueDate

    End Function

    Public Function formatCSGDueDate(ByVal inBillSummary As Object) As String
        Dim oDueDate As String = ""

        '#######################################################################################################
        'MODIFICATION   ROD COPELAND    ISSUE ID:8153   FEB 02, 2010
        'PER TIM W - EAI: CSG WILL RETURN A DATE OR A DESCRIPTION BUT NOT BOTH AND IN SOME RARE CASES, NOTHING.
        '#######################################################################################################
        If String.IsNullOrEmpty(inBillSummary.DueDateDescription) Then
            If IsDate(inBillSummary.PaymentDueDate_CSG_ONLY) Then
                If inBillSummary.PaymentDueDate_CSG_ONLY.ToString() = "1/1/0001 12:00:00 AM" Then
                    '######################################################################
                    'NOT GOOD, EAI IS SENDING BACK A DATE FIELD THAT IS NOT SET BASICALLY.
                    '######################################################################
                    oDueDate = ""
                Else
                    '################
                    'THIS IS GOOD
                    '################
                    oDueDate = DatePart("M", inBillSummary.PaymentDueDate_CSG_ONLY).ToString
                    oDueDate &= "/" & DatePart("d", inBillSummary.PaymentDueDate_CSG_ONLY).ToString
                    oDueDate &= "/" & DatePart("yyyy", inBillSummary.PaymentDueDate_CSG_ONLY).ToString
                End If
            Else
                '###############################################################################
                'THIS IS BAD DATE ALONG WITH A DUEDATEDESCRIPTION FIELD WITH NO DESCRIPTION SO 
                'THIS IS PRETTY BAD TOO.  JUST DISPLAY AN EMPTY STRING IN THIS ERROR CONDITION.
                '###############################################################################
                oDueDate = ""
            End If
        Else
            Select Case inBillSummary.DueDateDescription.ToString().Trim().ToUpper()
                Case "ON RECEIPT"
                    '###################################################################
                    'THIS IS THE NORMAL PATH FOR THE DESCRIPTION FIELD HAVING A VALUE.
                    '###################################################################
                    oDueDate = "Due Upon Receipt"
                Case Else
                    '#####################################
                    'COULD BE AN ERROR OR UNKNOWN STATUS.
                    '#####################################
                    oDueDate = ""
            End Select

        End If

        Return oDueDate

    End Function

    Public Function formatCSGStatementAmount(ByVal inBillSummary As Object) As String
        Try
            If (_account Is Nothing) OrElse _
               (_account.BillingVendorType <> BillingVendorType.CSG) OrElse _
               (inBillSummary.StatementBalance_CSG_ONLY Is Nothing) Then
                '##########################################
                'DONT DISPLAY THE CALC BALANCE ON THE PAGE.
                '##########################################
                Return ""
            End If

            If inBillSummary.StatementBalance_CSG_ONLY >= 0 Then
                Return String.Format("$ {0:N2}", inBillSummary.StatementBalance_CSG_ONLY)
            End If

            Return FormatNegative(inBillSummary.StatementBalance_CSG_ONLY)
        Catch ex As Exception
            Return ""
        End Try
    End Function

    ' issue 27033
    ' use the current balance from the GetAccounts call instead of the calculated balance
    Public Function formatCSGDueAmount2013(ByVal inBillSummary As Object) As String
        Dim oGetAcctsReq As EntityEBSServices.GetAccountsRequestCSG
        Dim oGetAcctsResp As EntityEBSServices.GetAccountsResponseCSG
        Dim oGetAcctsCriteria As New EntityEBSServices.AccountCriteriaCSG
        Dim sReturnValue As String = ""
        Dim oEBSProv As IEBSServicesProvider
        Dim sEBSProvLoc As String
        Dim oAccount As EntityEBSServices.AccountCSG

        Try

            'oGetAcctsCriteria.Item = _account.OSSProvidedAccountNumber
            oGetAcctsCriteria.Item = inBillSummary.AccountNumber
            oGetAcctsCriteria.ItemElementName = EntityEBSServices.ItemChoiceTypeCSG.AccountNumber
            oGetAcctsReq = New EntityEBSServices.GetAccountsRequestCSG(Nothing, oGetAcctsCriteria)

            '##################################
            'MAKE THE PROVIDER CALL TO THE WS 
            ' - get the provider location 
            ' - instantiate a provider object
            ' - make the call
            '##################################
            sEBSProvLoc = CStr(System.Web.HttpContext.Current.Application("RemoteURL_EBSServicesProvider"))
            oEBSProv = CType(Activator.GetObject(GetType(IEBSServicesProvider), _
                                                  sEBSProvLoc),  _
                              IEBSServicesProvider)

            oGetAcctsResp = CType(oEBSProv.GetAccountsFromCSG(oGetAcctsReq),  _
                                           EntityEBSServices.GetAccountsResponseCSG)

            ' evaluate response from WS call
            If (oGetAcctsResp Is Nothing) Then
                sReturnValue = String.Empty
            Else
                If oGetAcctsResp.Exception Then
                    sReturnValue = String.Empty
                Else
                    If Not (oGetAcctsResp.Accounts Is Nothing) Then
                        If oGetAcctsResp.Accounts.Length() > 0 Then
                            oAccount = oGetAcctsResp.Accounts(0)  ' apparently the first acct is the default to use if multiples returned
                            sReturnValue = oAccount.CurrentAccountBalance
                        Else
                            sReturnValue = String.Empty
                        End If
                    Else
                        sReturnValue = String.Empty
                    End If
                End If
            End If

            '############################################################################################
            'PULL THE CURRENT BALANCE AND DISPLAY ON THE MYACCOUNT.ASPX PAGE IN THE BILL SUMMARY SECTION.
            '############################################################################################
            If String.IsNullOrEmpty(sReturnValue) OrElse sReturnValue = 0 Then
                Return "$ 0.00"
            End If

            If sReturnValue >= 0 Then
                Return String.Format("$ {0:N2}", sReturnValue)
            End If

            Return FormatNegative(sReturnValue)

        Catch ex As Exception
            Return String.Empty
        Finally

        End Try

    End Function

    Private Function FormatNegative(psAmount As String) As String
        '################################################################
        'MODIFICATION   ROD COPELAND    APRIL 21, 2009  ISSUE ID 5798
        '################################################################
        'THE NEXT CONDITION BLOCK IS MEANT TO FORMAT NEGATIVE NUMBERS TO 
        'LOOK LIKE -$1.00 RATHER THAN $-1.00 TYPICALLY FOUND, 
        'PER DIANA IN CUSTOMER CARE.
        '################################################################
        Dim tempOutAmount As String = String.Format("{0:N2}", psAmount)
        If tempOutAmount.IndexOf("-") < 0 Then
            '###########################################
            'NEGATIVE SYMBOL TO REMOVE IS NOT THERE. 
            'DISPLAY A DEFAULT VALUE WITHOUT SPECIAL 
            'FORMATTING.
            '###########################################
            Return "$ " & tempOutAmount
        End If
        '##########################################################
        'THIS IS NORMAL NEGATIVE NUMBER FORMATTING. ALL GOOD HERE, 
        'NOT AN EXCEPTION CASE.
        '##########################################################
        Return "-$ " & tempOutAmount.Substring(1)
    End Function

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.pnlBillSummary.Visible = True
        V3PageLoad()
    End Sub

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

            Return strTemp.ToString
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    ''' <summary>
    ''' NEW Page Load
    ''' </summary>
    ''' <remarks></remarks>
    Protected Sub V3PageLoad()
        'ASSIGN DEFAULT VALUES
        '#######################
        Select Case True
            Case Request.RawUrl.ToUpper().Contains("MYACCOUNT.ASPX")
                __HBXPageName = "MyAccountLandingAndBillSummaryPage"
                __HBXCategory = Request.RawUrl.ToUpper().Replace("/UI", "").ToUpper()
            Case Else
                __HBXPageName = "PayYourBillSummaryPage"
                __HBXCategory = Request.RawUrl.ToUpper().Replace("/UI", "").ToUpper()
        End Select

        '################################################
        'CLEAR THE CC PAYMENT MESSAGE FIELD USED TO 
        'DISPLAY ANY PROBLEMS WITH PAYMENT APPLICATION
        '################################################
        lblEFTPaymentMessage.Text = "By clicking Pay Now you agree to have the amount shown charged to your bank account."
        lblEFTPaymentMessage.ForeColor = Drawing.Color.Black

        lblCCPaymentMessage.Text = "By clicking Pay Now you agree to have the amount shown charged to your credit card."
        lblCCPaymentMessage.ForeColor = Drawing.Color.Black

        'Dim _account As IAccount 'commntd
        Dim _bill As New List(Of IAccount.IBill)
        Dim y As Integer
        Dim i As Integer

        If Not Page.IsPostBack Then
            txtPaymentAmountCC.Enabled = True
            txtPaymentAmountBA.Enabled = True

            If ShowIdentification Then
                pnlIdentification.Visible = True
                pnlBillSummary.Visible = False
            Else
                pnlIdentification.Visible = False
                pnlBillSummary.Visible = True
            End If

            pnlPaymentInfo.Visible = False
            pnlCreditCardInfo.Visible = False
            pnlBankAccountInfo.Visible = False
            pnlConfirmation.Visible = False

            y = Date.Now.Year

            For i = y To y + 12
                ddlExpirationYear.Items.Add(New ListItem(i, i))
            Next

            vldTelephoneRequired.ValidationGroup = "Continue"
            vldTelephoneRegEx.ValidationGroup = "Continue"
            vldZipCodeRequired.ValidationGroup = "Continue"
            vldZipCodeRegEx.ValidationGroup = "Continue"
            vldEmailRegEx.ValidationGroup = "Continue"
            btnContinue.ValidationGroup = "Continue"

            vldPaymentAmountCCRequired.ValidationGroup = "CC"
            vldNameOnCardRequired.ValidationGroup = "CC"
            vldNameOnCardRegExNumbersOnly.ValidationGroup = "CC"
            vldCardIssuerRequired.ValidationGroup = "CC"
            vldCardNumberRequired.ValidationGroup = "CC"
            vldExpirationMonthRequired.ValidationGroup = "CC"
            vldExpirationYearRequired.ValidationGroup = "CC"
            btnPayNowCC.ValidationGroup = "CC"

            vldPaymentAmountBARequired.ValidationGroup = "BA"
            vldInstitutionRequired.ValidationGroup = "BA"
            vldRoutingNumberRequired.ValidationGroup = "BA"
            vldAccountNumberRequired.ValidationGroup = "BA"
            vldAccountTypeRequired.ValidationGroup = "BA"
            txtInstitution.ValidationGroup = "BA"
            txtRoutingNumber.ValidationGroup = "BA"
            txtAccountNumber.ValidationGroup = "BA"
            ddlAccountType.ValidationGroup = "BA"
            btnPayNowBA.ValidationGroup = "BA"
        End If

        ' Jonathan Parks - Issue # 4352 / #4084
        ' need this value to set the successPage parms on the hyperlinks based on BillingVendor
        If _account.BillingVendorType = BillingVendorType.CSG Then
            _latestBill = "viewcurrentbill"
            _payBillOptions = "paymentmethod"
        Else
            _latestBill = "currentstatement"
            _payBillOptions = "paybilloptions"
        End If

        If (Request.IsAuthenticated) Then
            '################################################################################
            'AT THIS POINT, THIS IS FOR THE MEMBER SERVICES FLOW TO GET BILL SUMMARY INFO.
            'THATS IF IT DOESNT ALREADY EXIST.
            '################################################################################
            If Not (Account Is Nothing) Then
                If Not (Account.Bill Is Nothing) Then
                    _bill = Account.Bill
                Else
                    '###################################################################################
                    'GO AND GET THE BILL, SINCE THE BILL IN THE ACCOUNT OBJECT DOESNT HAVE A VALUE YET.
                    '###################################################################################
                    If Not (Account.Address Is Nothing) Then
                        If Not (Account.Address.Zip Is Nothing) Then
                            txtZipCode.Text = Account.Address.Zip
                            If Not (Account.Person Is Nothing) Then
                                If Not (Account.Person.ContactEmailAddress Is Nothing) Then
                                    Dim lEmail As String = Account.Person.ContactEmailAddress
                                    txtEmail.Text = lEmail
                                    If Not (Account.Phone Is Nothing) Then
                                        txtTelephone.Text = Account.Phone
                                        _bill = AccountManager.Instance.GetBillSummary(Account.Phone, Account.Address.Zip, lEmail)
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If

            End If
        Else
            '##################################
            'THIS IS FOR THE ORDER FLOW MOSTLY
            '##################################
            If Not (Request.Form("ctl00$cphCenter$ucPayYourBill$txtTelephone") Is Nothing) And _
             Not (Request.Form("ctl00$cphCenter$ucPayYourBill$txtZipCode") Is Nothing) And _
             Not (Request.Form("ctl00$cphCenter$ucPayYourBill$txtEmail") Is Nothing) Then
                txtTelephone.Text = Request.Form("ctl00$cphCenter$ucPayYourBill$txtTelephone")
                txtZipCode.Text = Request.Form("ctl00$cphCenter$ucPayYourBill$txtZipCode")
                txtEmail.Text = Request.Form("ctl00$cphCenter$ucPayYourBill$txtEmail")

                Dim _phone As String = Request.Form("ctl00$cphCenter$ucPayYourBill$txtTelephone")
                '###################################################################
                'M O D I F  I C A T I O N    BY ROD COPELAND 5/09/07
                '###################################################################
                'PER GREG KOCK AND THE EBS TEAM, WE NEED TO STRIP OUT THE DASHES 
                'IN THE PHONE NUMBER SINCE THE SERVICEABILITY CALL WONT FAIL OUT
                '###################################################################
                _phone = _phone.Replace("-", "")
                _phone = _phone.Replace(".", "")
                _phone = _phone.Replace("/", "")
                '###################################################################
                Try
                    _bill = AccountManager.Instance.GetBillSummary(_phone, Request.Form("ctl00$cphCenter$ucPayYourBill$txtZipCode"), Request.Form("ctl00$cphCenter$ucPayYourBill$txtEmail"))
                Catch ex As Exception
                    _bill = Nothing
                End Try
            End If
        End If

        '############################################################################
        'ROD COPELAND   MODIFICATION  6/16/2008     Issue ID:  5736
        '############################################################################
        'ICOMS BUSINES RULE:ONLY DISPLAY BILLS THAT HAVE A VALID STATEMENT DUE DATE PER CUST CARE.
        '############################################################################
        Dim billCollectionToBeDisplayedOnUI As New List(Of IAccount.IBill)
        Dim validBillForDisplay As IAccount.IBill
        For Each validBillForDisplay In _bill
            If Not (validBillForDisplay Is Nothing) Then
                If Not (Me.Account Is Nothing) Then
                    Select Case Me.Account.BillingVendorType
                        Case BillingVendorType.CSG
                            If validBillForDisplay.DisplayBillSummary Then
                                billCollectionToBeDisplayedOnUI.Add(validBillForDisplay)
                                '##################################################################################
                                'SET A DEFAULT FOR THIS ZONE IN THE EVENT THERE IS A PROBLEM LATER IN THE SEQUENCE.
                                'DOESNT REALLY THERE IS A PROBLEM RIGHT NOW WITH THE BILLING INFO FROM EAI.
                                '##################################################################################
                                CustomContent1.ContentKey = "myaccount:billingsummary:unavailable"
                            Else
                                '##################################################################################
                                'MODIFICATION   ROD COPELAND    Issue ID:  7125
                                '##################################################################################
                                'THERE IS A PROBLEM WITH THIS BILL FROM THE BILLING SYSTEM.  RIGHT NOW THE ONLY 
                                'CONDITION THAT FALLS IN THIS CATEGORY IS A NEW CUSTOMER THAT HASNT HAD A BILLING 
                                'CYCLE YET.
                                '##################################################################################
                                CustomContent1.ContentKey = "myaccount:billingsummary:unavailable:nostatementavailableyet"
                            End If

                        Case BillingVendorType.ICOM
                            '#########################################################
                            'IF DUE UPON RECEIPT, ITS HANDLED IN formatIcomsDueDate()
                            'AFTER DATA BIND
                            '#########################################################
                            If validBillForDisplay.DueUponReceipt Or validBillForDisplay.StatementDueDate_ICOMS_ONLY.Year > 1900 Then
                                '#######################################
                                'SHOULD BE A VALID DATE AT THIS POINT.
                                '#######################################
                                billCollectionToBeDisplayedOnUI.Add(validBillForDisplay)
                            Else
                                '##################################################################################
                                'MODIFICATION   ROD COPELAND    Issue ID:  7125
                                '##################################################################################
                                CustomContent1.ContentKey = "myaccount:billingsummary:unavailable"
                            End If

                    End Select
                End If
            End If
        Next
        '############################################################################

        If Not Page.IsPostBack Then
            If billCollectionToBeDisplayedOnUI Is Nothing Then
                '##############################################
                'HIDE BILLING SUMMARY INFO ON PAGE.
                '##############################################
                pnlPaymentInfo.Visible = False
                pnlBillSummary.Visible = False
                pnlCreditCardInfo.Visible = False
                pnlBankAccountInfo.Visible = False
                pnlConfirmation.Visible = False
                pnlNoBillingSummaryAvailable.Visible = True
                '##############################################

                vldCustom.ErrorMessage = "No bills can be found for the info you entered."
                vldCustom.IsValid = False
            ElseIf billCollectionToBeDisplayedOnUI.Count = 0 Then
                '##############################################
                'HIDE BILLING SUMMARY INFO ON PAGE.
                '##############################################
                pnlPaymentInfo.Visible = False
                pnlBillSummary.Visible = False
                pnlCreditCardInfo.Visible = False
                pnlBankAccountInfo.Visible = False
                pnlConfirmation.Visible = False
                pnlNoBillingSummaryAvailable.Visible = True
                '##############################################

                vldCustom.ErrorMessage = "No bills can be found for the info you entered."
                vldCustom.IsValid = False
            Else
                If Not (Me.Account Is Nothing) Then
                    Select Case Me.Account.BillingVendorType
                        Case BillingVendorType.CSG
                            rprCSGBillingSummary.DataSource = billCollectionToBeDisplayedOnUI
                            rprCSGBillingSummary.DataBind()
                        Case BillingVendorType.ICOM
                            rprICOMSBillingSummary.DataSource = billCollectionToBeDisplayedOnUI
                            rprICOMSBillingSummary.DataBind()
                    End Select
                End If
                pnlNoBillingSummaryAvailable.Visible = False
                pnlIdentification.Visible = False
                pnlBillSummary.Visible = True
            End If
        End If

        If Not (Session("QP_LockDownStartTime") Is Nothing) Then
            If Session("QP_LockDownStartTime") < Now Then
                '################################
                'ALLOW ACCESS TO MAKE A PAYMENT
                '################################
                Session.Remove("QP_LockDownStartTime")
                Session.Remove("QP_TotalAttemptCount")
                pnlQuickPayAttemptLimitReached.Visible = False
            Else
                '#########################################
                'CONTINUE TO LOCK THEM OUT FROM PAYMENTS
                '#########################################
                pnlQuickPayAttemptLimitReached.Visible = True

                '#####################
                'HIDE ALL THE OTHERS
                '#####################
                pnlPaymentInfo.Visible = False
                pnlBillSummary.Visible = False
                pnlCreditCardInfo.Visible = False
                pnlBankAccountInfo.Visible = False
                pnlConfirmation.Visible = False
                pnlNoBillingSummaryAvailable.Visible = False
            End If
        End If
    End Sub

    ''' <summary>
    ''' NEW Prerender
    ''' </summary>
    ''' <remarks></remarks>
    Protected Sub V3PreRender()
        '######################################################################################################
        'ROD COPELAND 8/2/2007  M O D I F I C A T I O N
        '######################################################################################################
        'BECAUSE THIS CONTROL IS USED FROM THE PAYYOURBILL.ASPX TRANSFER, MY ACCOUNT LANDING PAGE, OR 
        'QUICKPAY PAGE, DO A CHECK TO DETERMINE HOW TO LOAD THE HBX SCRIPT IN THE PAGE.  THERE CURRENTLY 
        'IS A BUG ON THE SITE.MASTER.VB FILE THAT DOESNT RENDER HBX SCRIPT IN THE PAGE WHEN A POST BACK 
        'HAPPENS, THIS WORKS FOR THE MOST PART UP UNTIL WE NEED TO DISPLAY DIFFERENT HBX VALUES DEPENDING 
        'UPON WHAT PANEL IS SHOWING ON THE SAME PAGE.  WHEN THIS HAPPENED, THE OLD HBX MODEL WENT OUT THE 
        'WINDOW.  WE CURRENTLY DONT HAVE TIME TO EVALUATE THE IMPACTS ON THE ENTIRE SITE, THE NOT 
        'GENERATING THE HBX SCRIPT ON POST BACK.  THERE IS A CHANCE THIS WILL BE AN ISSUE OF NOT TRACKING 
        'ANYTHING FOR PAGES THAT USE PANELS AND POST BACKS.  IN THE CASE OF QUICKPAY, THIS BUG WAS 
        'ACTUALLY KEEPING THE SCRIPT FROM EVER HITTING THE PAGE AT ALL.  ONE CAVEAT TO THIS IS THAT 
        'QUICK PAY RECEIVES A SERVER.TRANSFER FROM THE PAY YOUR BILL.ASPX PAGE.  TIME WILL TELL.
        '######################################################################################################
        If Request.Path.ToLower().Contains("quickpay.aspx") Or Request.Path.ToLower().Contains("myaccount.aspx") Or Request.Path.ToLower().Contains("payyourbill.aspx") Then
            Page.ClientScript.RegisterStartupScript(Me.GetType, "HBXQuickPayScript", GenerateHBXPageScript())
        End If

        If Me.MyAccountUse Then
            If rblPaymentMethod.Items.Count() > 0 Then
                If rblPaymentMethod.Items(0).Attributes.Count() < 1 Then
                    rblPaymentMethod.Items(0).Attributes.Add("Style", "background-color: #D9E4EE")
                Else
                    '####################
                    'LEAVE STYLING AS IS
                    '####################
                End If
            End If
            If rblPaymentMethod.Items.Count() > 1 Then
                If rblPaymentMethod.Items(1).Attributes.Count() < 1 Then
                    rblPaymentMethod.Items(1).Attributes.Add("Style", "background-color: #D9E4EE")
                Else
                    '####################
                    'LEAVE STYLING AS IS
                    '####################
                End If
            End If

            '10/9/2007 Brad Miller - set ImageUrl dynamically depending on intended row bgcolor
            Dim rpiItem As RepeaterItem
            Dim ctlOuter As Control
            Dim ctlInner As Control
            Dim btnRprButton As ImageButton

            If Not (Me.Account Is Nothing) Then
                Select Case Me.Account.BillingVendorType
                    Case BillingVendorType.CSG
                        For Each ctlOuter In rprCSGBillingSummary.Controls
                            If ctlOuter.GetType().ToString() = "System.Web.UI.WebControls.RepeaterItem" Then
                                rpiItem = CType(ctlOuter, RepeaterItem)
                                If rpiItem.ItemType = ListItemType.AlternatingItem Then
                                    For Each ctlInner In rpiItem.Controls
                                        If ctlInner.GetType().ToString() = "System.Web.UI.WebControls.ImageButton" Then
                                            btnRprButton = New ImageButton
                                            btnRprButton = CType(ctlInner, ImageButton)
                                            If btnRprButton.ImageUrl = "../Images/paynow_but.jpg" Then
                                                btnRprButton.ImageUrl = "../Images/paynow_gray_but.jpg"
                                            End If
                                        End If
                                    Next
                                ElseIf rpiItem.ItemType = ListItemType.Footer Then
                                    For Each ctlInner In rpiItem.Controls
                                        If ctlInner.GetType().ToString() = "System.Web.UI.WebControls.ImageButton" Then
                                            btnRprButton = New ImageButton
                                            btnRprButton = CType(ctlInner, ImageButton)
                                            If btnRprButton.ImageUrl = "../Images/payall_but.jpg" Then
                                                btnRprButton.ImageUrl = "../Images/payall_but_blue.jpg"
                                            End If
                                        End If
                                    Next
                                End If
                            End If
                        Next
                    Case BillingVendorType.ICOM
                        For Each ctlOuter In rprICOMSBillingSummary.Controls
                            If ctlOuter.GetType().ToString() = "System.Web.UI.WebControls.RepeaterItem" Then
                                rpiItem = CType(ctlOuter, RepeaterItem)
                                If rpiItem.ItemType = ListItemType.AlternatingItem Then
                                    For Each ctlInner In rpiItem.Controls
                                        If ctlInner.GetType().ToString() = "System.Web.UI.WebControls.ImageButton" Then
                                            btnRprButton = New ImageButton
                                            btnRprButton = CType(ctlInner, ImageButton)
                                            If btnRprButton.ImageUrl = "../Images/paynow_but.jpg" Then
                                                btnRprButton.ImageUrl = "../Images/paynow_gray_but.jpg"
                                            End If
                                        End If
                                    Next
                                ElseIf rpiItem.ItemType = ListItemType.Footer Then
                                    For Each ctlInner In rpiItem.Controls
                                        If ctlInner.GetType().ToString() = "System.Web.UI.WebControls.ImageButton" Then
                                            btnRprButton = New ImageButton
                                            btnRprButton = CType(ctlInner, ImageButton)
                                            If btnRprButton.ImageUrl = "../Images/payall_but.jpg" Then
                                                btnRprButton.ImageUrl = "../Images/payall_but_blue.jpg"
                                            End If
                                        End If
                                    Next
                                End If
                            End If
                        Next
                End Select
            End If
        End If
    End Sub

    ''' <summary>
    ''' NEW V3 Repeater Control
    ''' </summary>
    ''' <param name="source"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub rprBillSummary_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rprCSGBillingSummary.ItemCommand, rprICOMSBillingSummary.ItemCommand
        'Dim _account As IAccount 'commntd
        Dim _vendorType As BillingVendorType
        Dim _bill As IAccount.IBill
        Dim _amountDue As Decimal

        txtBillAccountNumber.Value = e.CommandArgument

        '	_account = AccountManager.Instance.GetAccount()  'commntd
        _vendorType = _account.BillingVendorType

        If e.CommandArgument.ToString().ToLower() = "payall" Then
            '############################################################################
            'MODIFICATION  6/5/2007 BY ROD COPELAND
            '############################################################################
            'THE USER HAS SELECTED THE PAY ALL BUTTON.  PER JOE KESSLER (BA FOR IT), 
            'WE SHOULD ADD THE TOTAL FOR ALL STATEMENTS AND DISPLAY THIS AMOUNT AS 
            'WHAT THE USER IS TO PAY, THEY CAN'T EDIT THIS VALUE.  WE WILL LOOP 
            'THROUGH MAKING ONE PAYMENT AT A TIME UNTIL ALL ARE APPLIED.
            '############################################################################
            For Each _bill In _account.Bill
                _amountDue = _amountDue + _bill.Amount
            Next
            txtPaymentAmountCC.Text = _amountDue.ToString()
            txtPaymentAmountCC.Enabled = False
            txtPaymentAmountBA.Text = _amountDue.ToString()
            txtPaymentAmountBA.Enabled = False

        Else
            For Each _bill In _account.Bill
                If _bill.AccountNumber = e.CommandArgument Then
                    _amountDue = _bill.Amount
                    Exit For
                End If
            Next
        End If

        lblAmountDueBA.Text = String.Format("{0:C}", _amountDue)
        lblAmountDueCC.Text = String.Format("{0:C}", _amountDue)

        If _vendorType = BillingVendorType.CSG Then
            'ddlCardIssuer.Items.Add(New ListItem("American Exptess", CreditCardType.AmericanExpress))
            ddlCardIssuer.Items.Add(New ListItem("Discover", CreditCardType.Discover))
            ddlCardIssuer.Items.Add(New ListItem("MasterCard", CreditCardType.Master))
            ddlCardIssuer.Items.Add(New ListItem("Visa", CreditCardType.Visa))
        ElseIf _vendorType = BillingVendorType.ICOM Then
            ddlCardIssuer.Items.Add(New ListItem("Debit", CreditCardType.Debit))
            ddlCardIssuer.Items.Add(New ListItem("Discover", CreditCardType.Discover))
            ddlCardIssuer.Items.Add(New ListItem("MasterCard", CreditCardType.Master))
            ddlCardIssuer.Items.Add(New ListItem("Visa", CreditCardType.Visa))
        Else
            ddlCardIssuer.Items.Add(New ListItem("Visa", CreditCardType.Visa))
        End If
        pnlBillSummary.Visible = False
        pnlPaymentInfo.Visible = True

        Select Case True
            Case Request.RawUrl.ToUpper().Contains("MYACCOUNT.ASPX")
                __HBXPageName = "MyAccountPaymentMethod/Unselected"
            Case Else
                __HBXPageName = "PayYourBillPaymentMethod/Unselected"
        End Select

    End Sub

    Protected Function GetVisibility() As String
        If Not (Me.Account Is Nothing) Then
            Select Case Me.Account.BillingVendorType
                Case BillingVendorType.CSG
                    If CType(rprCSGBillingSummary.DataSource, ICollection).Count > 1 Then
                        Return "visible"
                    Else
                        Return "hidden"
                    End If
                Case BillingVendorType.ICOM
                    If CType(rprICOMSBillingSummary.DataSource, ICollection).Count > 1 Then
                        Return "visible"
                    Else
                        Return "hidden"
                    End If
            End Select
        End If
    End Function

    Protected Sub rblPaymentMethod_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rblPaymentMethod.SelectedIndexChanged
        If rblPaymentMethod.SelectedValue = 0 Then
            pnlCreditCardInfo.Visible = True
            pnlBankAccountInfo.Visible = False

            Select Case True
                Case Request.RawUrl.ToUpper().Contains("MYACCOUNT.ASPX")
                    __HBXPageName = "MyAccountPaymentMethod/SelectedCC"
                Case Else
                    __HBXPageName = "PayYourBillPaymentMethod/SelectedCC"
            End Select

        Else
            pnlCreditCardInfo.Visible = False
            pnlBankAccountInfo.Visible = True

            Select Case True
                Case Request.RawUrl.ToUpper().Contains("MYACCOUNT.ASPX")
                    __HBXPageName = "MyAccountPaymentMethod/SelectedBA"
                Case Else
                    __HBXPageName = "PayYourBillPaymentMethod/SelectedBA"
            End Select
        End If
    End Sub

    Private Sub EvaluateQuickPayFailedAttempts_Display_Panel()
        Try
            '#################################################################
            '6/21/2007  ROD COPELAND
            'SHOW THE PLEASE CONTACT CUST SERVICE PANEL, THEY MAY HAVE EXCEEDED THE
            'MAX ERRORS FOR QUICK PAY ATTEMPTS AS DEFINED BY CUST CARE 
            'DEPARTMENT AND DIANA
            '#################################################################

            '#############################################################################
            'IF DATE IS STILL ACTIVE, SHOW CALL BACK PANEL IF MAX COUNT HAS BEEN EXCEEDED
            '#############################################################################
            If Not (Session("QP_TotalAttemptCount") Is Nothing) Then
                If Session("QP_TotalAttemptCount") >= Application("QP_TOTAL_PAYMENT_ATTEMPT_MAX_COUNT") Then

                    'we continue to lock them out until the time limit runs out then we give option to make payments again.
                    If (Session("QP_LockDownStartTime") Is Nothing) Then
                        'Session("QP_LockDownStartTime") = Now.AddMinutes(2)
                        Session("QP_LockDownStartTime") = New Date(Now.AddMinutes(CType(Application("QP_LOCKOUT_WAIT_MINUTES"), Integer)).Ticks())
                    End If

                    If Session("QP_LockDownStartTime") < Now Then
                        '################################
                        'ALLOW ACCESS TO MAKE A PAYMENT
                        '################################
                        pnlQuickPayAttemptLimitReached.Visible = False
                        Session.Remove("QP_LockDownStartTime")
                        Session.Remove("QP_TotalAttemptCount")
                    Else
                        '#########################################
                        'CONTINUE TO LOCK THEM OUT FROM PAYMENTS
                        '#########################################
                        pnlQuickPayAttemptLimitReached.Visible = True

                        '#####################
                        'HIDE ALL THE OTHERS
                        '#####################
                        pnlPaymentInfo.Visible = False
                        pnlBillSummary.Visible = False
                        pnlCreditCardInfo.Visible = False
                        pnlBankAccountInfo.Visible = False
                        pnlConfirmation.Visible = False
                    End If
                Else
                    '####################################
                    'UPDATE COUNT AND LET THEM CONTINUE
                    '####################################
                    Session("QP_TotalAttemptCount") = (CType(Session("QP_TotalAttemptCount"), Integer) + 1).ToString()
                    pnlQuickPayAttemptLimitReached.Visible = False
                End If
            End If

        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnPayNowCC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPayNowCC.Click

        '#################################################################
        '6/21/2007  ROD COPELAND
        'SHOW THE PLEASE CONTACT CUST SERVICE PANEL, THEY MAY HAVE EXCEEDED THE
        'MAX ERRORS FOR QUICK PAY ATTEMPTS AS DEFINED BY CUST CARE 
        'DEPARTMENT AND DIANA
        '#################################################################
        Call EvaluateQuickPayFailedAttempts_Display_Panel()

        '##################################################################
        '6/25/2007 ROD COPELAND
        'ADD THE TEXT IMAGE SOLUTION TO FURTHER VALIDATE THE USER IS A 
        'PERSON RATHER THAN A SCRIPT RUNNING AGAINST SITE.
        '##################################################################
        If Not CC_CaptchaControl.UserValidated Then
            lblCCPaymentMessage.Text = CC_CaptchaControl.ErrorMessage & "</br>"
            lblCCPaymentMessage.ForeColor = Drawing.Color.Red
        End If

        '####################################################
        'DOUBLE CHECK IF THE CONTROLS ARE ACTUALLY VALIDE 
        'JUST INCASE THE CLIENT-SIDE VALIDATION ISN'T DOING 
        'ITS JOB.
        '####################################################
        valPaymentAmountCCRegEx.Validate()
        RangeValidator22.Validate()
        vldPaymentAmountCCRequired.Validate()
        vldNameOnCardRequired.Validate()
        vldNameOnCardRegExNumbersOnly.Validate()
        vldCardIssuerRequired.Validate()
        vldCardNumberRequired.Validate()
        vldCardNumberRegEx.Validate()
        vldExpirationMonthRequired.Validate()
        vldExpirationYearRequired.Validate()

        Try
            If Page.IsValid Then
                If txtBillAccountNumber.Value.ToLower() = "payall" Then
                    '############################################################################
                    'MODIFICATION  6/5/2007 BY ROD COPELAND
                    '############################################################################
                    'THE USER HAS SELECTED THE PAY ALL BUTTON.  PER JOE KESSLER (BA FOR IT), 
                    'WE SHOULD ADD THE TOTAL FOR ALL STATEMENTS AND DISPLAY THIS AMOUNT AS 
                    'WHAT THE USER IS TO PAY, THEY CAN'T EDIT THIS VALUE.  WE WILL LOOP 
                    'THROUGH MAKING ONE PAYMENT AT A TIME UNTIL ALL ARE APPLIED.
                    '############################################################################
                    Dim _bill As IAccount.IBill
                    Dim PayAllConfirmationList As New Dictionary(Of String, String)
                    For Each _bill In _account.Bill
                        Dim _confirmation As IConfirmation
                        _confirmation = AccountManager.Instance.PayByCreditCard(_bill.AccountNumber, _
                         _bill.Amount, txtNameOnCard.Text, CType(ddlCardIssuer.SelectedValue, CreditCardType), _
                        txtCardNumber.Text, New DateTime(ddlExpirationYear.SelectedValue, ddlExpirationMonth.SelectedValue, 1), txtEmail.Text)

                        PayAllConfirmationList.Add(_confirmation.Number, _bill.Amount.ToString())
                    Next

                    RenderPayAllConfirmation(PayAllConfirmationList)

                Else
                    '##################################
                    'DO THE NORMAL ONE TIME PAYMENT
                    '##################################
                    Dim _confirmation As IConfirmation
                    _confirmation = AccountManager.Instance.PayByCreditCard(txtBillAccountNumber.Value, _
                    CType(txtPaymentAmountCC.Text, Decimal), txtNameOnCard.Text, CType(ddlCardIssuer.SelectedValue, CreditCardType), _
                    txtCardNumber.Text, New DateTime(ddlExpirationYear.SelectedValue, ddlExpirationMonth.SelectedValue, 1), txtEmail.Text)
                    RenderConfirmation(_confirmation, txtPaymentAmountCC.Text)
                End If

            End If
        Catch ex As Exception
            Select Case True
                Case Request.RawUrl.ToUpper().Contains("MYACCOUNT.ASPX")
                    __HBXPageName = "MyAccountCCPaymentException:" & ex.Message.ToString()
                Case Else
                    __HBXPageName = "PayYourBillCCPaymentException:" & ex.Message.ToString()
            End Select

            'lblCCPaymentMessage.Text = "Card number appears to be incorrect.  Please check the number and try again."
            lblCCPaymentMessage.Text = ex.Message & "<BR>"
            lblCCPaymentMessage.ForeColor = Drawing.Color.Red
        End Try
    End Sub

    Protected Sub btnPayNowBA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPayNowBA.Click

        Dim sb As New StringBuilder

        '#################################################################
        '6/21/2007  ROD COPELAND
        'SHOW THE PLEASE CONTACT CUST SERVICE PANEL, THEY MAY HAVE EXCEEDED THE
        'MAX ERRORS FOR QUICK PAY ATTEMPTS AS DEFINED BY CUST CARE 
        'DEPARTMENT AND DIANA
        '#################################################################
        Call EvaluateQuickPayFailedAttempts_Display_Panel()

        '##################################################################
        '6/25/2007 ROD COPELAND
        'ADD THE TEXT IMAGE SOLUTION TO FURTHER VALIDATE THE USER IS A 
        'PERSON RATHER THAN A SCRIPT RUNNING AGAINST SITE.
        '##################################################################
        If Not EFT_CaptchaControl.UserValidated Then
            lblEFTPaymentMessage.Text = EFT_CaptchaControl.ErrorMessage & "</br>"
            lblEFTPaymentMessage.ForeColor = Drawing.Color.Red
        End If

        '####################################################
        'DOUBLE CHECK IF THE CONTROLS ARE ACTUALLY VALIDE 
        'JUST INCASE THE CLIENT-SIDE VALIDATION ISN'T DOING 
        'ITS JOB.
        '####################################################
        vldPaymentAmountBARequired.Validate()
        vldPaymentAmountBARegEx.Validate()
        vldPaymentAmountBA.Validate()
        vldInstitutionRequired.Validate()
        vldRoutingNumberRequired.Validate()
        vldRoutingNumberRegEx.Validate()
        vldAccountNumberRequired.Validate()
        vldAccountNumberRegEx.Validate()
        vldAccountTypeRequired.Validate()
        vldAccountNumberLimitFieldLengthRegEx.Validate()
        vldRoutingNumberLimitFieldLengthRegEx.Validate()

        Try
            If Page.IsValid Then
                If txtBillAccountNumber.Value.ToLower() = "payall" Then
                    '############################################################################
                    'MODIFICATION  6/5/2007 BY ROD COPELAND
                    '############################################################################
                    'THE USER HAS SELECTED THE PAY ALL BUTTON.  PER JOE KESSLER (BA FOR IT), 
                    'WE SHOULD ADD THE TOTAL FOR ALL STATEMENTS AND DISPLAY THIS AMOUNT AS 
                    'WHAT THE USER IS TO PAY, THEY CAN'T EDIT THIS VALUE.  WE WILL LOOP 
                    'THROUGH MAKING ONE PAYMENT AT A TIME UNTIL ALL ARE APPLIED.
                    '############################################################################
                    Dim _bill As IAccount.IBill
                    'Dim PayAllConfirmationList As New Dictionary(Of String, String)
                    For Each _bill In _account.Bill
                        Dim _confirmation As IConfirmation
                        _confirmation = AccountManager.Instance.PayByBankAccount(_bill.AccountNumber, _
                           _bill.Amount, txtInstitution.Text, txtRoutingNumber.Text, txtAccountNumber.Text, _
                        CType(ddlAccountType.SelectedValue, BankAccountType), txtEmail.Text)

                        'PayAllConfirmationList.Add(_confirmation.Number, _bill.Amount.ToString())
                    Next

                    lblConfirmation.Text = "Your payment was completed successfully."

                    RenderEFTConfirmation()

                    pnlPaymentInfo.Visible = False
                    pnlConfirmation.Visible = True

                Else
                    '##################################
                    'DO THE NORMAL ONE TIME PAYMENT
                    '##################################
                    Dim _confirmation As IConfirmation
                    _confirmation = AccountManager.Instance.PayByBankAccount(txtBillAccountNumber.Value, _
                       CType(txtPaymentAmountBA.Text, Decimal), txtInstitution.Text, txtRoutingNumber.Text, txtAccountNumber.Text, _
                    CType(ddlAccountType.SelectedValue, BankAccountType), txtEmail.Text)

                    sb.Append("<div id=""supportsectionheader""><h1>Quick Pay - Confirmation</h1></div>")
                    sb.Append("<table cellpadding=""0"" cellspacing=""0"" border=""0"" width=""100%""><tr><td style=""background-color:#E9EEF4;"" rowspan=""2"" width=""33%""><img src=""../Images/gncheckmark.jpg""/></td><td width=""67%"" style=""background-color:#E9EEF4;""><br/>Your payment was completed successfully.</td></tr>")
                    sb.Append("<tr><td style=""background-color:#E9EEF4;"">&nbsp;</tr></td></table>")
                    sb.Append("<div align=""left"">")
                    sb.Append("<a href='../Order/PaymentReceipt.aspx' target='_charter_receipt'>Print this page</a> for your records. ")
                    sb.Append("This is your only payment confirmation.  You will be contacted if this payment is rejected for any reason.<br/><br/>")
                    sb.Append("This is how your payment is recorded on your account online:<br/>")
                    sb.Append("This payment is not reflected on your Account Statement Balance online.<br/>")
                    sb.Append("<a href=""../Account/CharterEpay.aspx"" target=""_blank"">Click Here</a> for Charter ePay to view your payment:<br/>")
                    sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;Account Summary - Amount paid to verify your payment<br/>")
                    sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;Recent Activity may take up to 48 hours to reflect this payment<br/><br/>")
                    sb.Append("<a href=""../Visitors/chatlive.aspx?d=20957"" target=""_blank"">Click Here</a> if you would like to chat live with a Customer Care agent regarding this payment.<br/><br/>")
                    sb.Append("<a href=""../Account/MyAccount.aspx"">Go Back to the My Account Home Page</a></div>")
                    lblConfirmation.ForeColor = Drawing.Color.Black
                    lblConfirmation.Text = sb.ToString

                    RenderEFTConfirmation()

                    pnlPaymentInfo.Visible = False
                    pnlConfirmation.Visible = True

                End If

            End If
        Catch ex As Exception
            Select Case True
                Case Request.RawUrl.ToUpper().Contains("MYACCOUNT.ASPX")
                    __HBXPageName = "MyAccountBAPaymentException:" & ex.Message.ToString()
                Case Else
                    __HBXPageName = "PayYourBillBAPaymentException:" & ex.Message.ToString()
            End Select

            'lblEFTPaymentMessage.Text = "Sorry, we're unable to apply your payment at this time"
            lblEFTPaymentMessage.Text = ex.Message & "<BR>"
            lblEFTPaymentMessage.ForeColor = Drawing.Color.Red
        End Try

    End Sub

    Private Sub RenderPayAllConfirmation(ByVal PayAllConfirmationList As Dictionary(Of String, String))
        Dim sb As New StringBuilder

        lblConfirmation.Text = ""

        For Each lConfirmation As KeyValuePair(Of String, String) In PayAllConfirmationList
            If lblConfirmation.Text.Trim() = "" Then
                '####################
                'FIRST TIME THROUGH
                '####################
                sb.Append("Your Payment was completed successfully.<br/><br/>")
                sb.Append("Your Confirmation Number is " & lConfirmation.Key & "<br/><br/>")
                sb.Append("If you have any questions, please reference this number")

                'lblConfirmation.Text = "Your confirmation number is:<BR />" & lblConfirmation.Text & lConfirmation.Key
                lblConfirmation.Text = sb.ToString
                hdnConfNumber.Value = hdnConfNumber.Value & lConfirmation.Key
                hdnPaymentAmount.Value = Val(lConfirmation.Value)
            Else
                lblConfirmation.Text = lblConfirmation.Text & "<BR>" & lConfirmation.Key
                hdnConfNumber.Value = hdnConfNumber.Value & "," & lConfirmation.Key
                hdnPaymentAmount.Value = Val(hdnPaymentAmount.Value) + Val(lConfirmation.Value)
            End If
        Next
        lblConfirmation.Text = lblConfirmation.Text & "<BR /><BR />If you have any questions, please use this information as reference. <br> <a href='../Order/PaymentReceipt.aspx' target='_charter_receipt'>Print a receipt</a> for your records."

        If Not (Application("QUICKPAY_EMAIL_MESSAGE") Is Nothing) And (Application("QUICKPAY_EMAIL_MESSAGE").ToString().Trim() <> "") Then
            If txtEmail.Text.Trim() = "" Then
                lblEmail.Text = ""
            Else
                lblEmail.Text = "A confirmation e-mail has been sent to <b>" & txtEmail.Text & "</b>."
            End If
        Else
            lblEmail.Text = ""
        End If

        pnlPaymentInfo.Visible = False
        pnlConfirmation.Visible = True

        Select Case True
            Case Request.RawUrl.ToUpper().Contains("MYACCOUNT.ASPX")
                __HBXPageName = "MyAccountPayAllCCPaymentConfirmation"
            Case Else
                __HBXPageName = "PayYourBillPayAllCCPaymentConfirmation"
        End Select

    End Sub

    Private Sub RenderEFTConfirmation()
        If Not (Application("QUICKPAY_EMAIL_MESSAGE") Is Nothing) And (Application("QUICKPAY_EMAIL_MESSAGE").ToString().Trim() <> "") Then
            If txtEmail.Text.Trim() = "" Then
                lblEmail.Text = ""
            Else
                lblEmail.Text = "A confirmation e-mail has been sent to <b>" & txtEmail.Text & "</b>."
            End If
        Else
            lblEmail.Text = ""
        End If

        pnlPaymentInfo.Visible = False
        pnlConfirmation.Visible = True

        Select Case True
            Case Request.RawUrl.ToUpper().Contains("MYACCOUNT.ASPX")
                __HBXPageName = "MyAccountBAPaymentConfirmation"
            Case Else
                __HBXPageName = "PayYourBillBAPaymentConfirmation"
        End Select

    End Sub

    Private Sub RenderConfirmation(ByVal _confirmation As IConfirmation, ByVal amount As String)
        Dim _person As IAccount.IMember
        Dim _emails As List(Of IAccount.IMember.IEmail)
        Dim _email As IAccount.IMember.IEmail
        Dim sb As New StringBuilder

        If _confirmation IsNot Nothing Then
            sb.Append("<div id=""supportsectionheader""><h1>Quick Pay - Confirmation</h1></div>")
            sb.Append("<table cellpadding=""0"" cellspacing=""0"" border=""0"" width=""100%""><tr><td style=""background-color:#E9EEF4;"" rowspan=""2"" width=""33%""><img src=""../Images/gncheckmark.jpg""/></td><td width=""67%"" style=""background-color:#E9EEF4;""><br/>Your payment was completed successfully.</td></tr>")
            sb.Append("<tr><td style=""background-color:#E9EEF4;"">Your confirmation number: <big>" & _confirmation.Number & "</big><br/>If you have any questions, please reference this number. </tr></td></table>")
            sb.Append("<div align=""left"">")
            sb.Append("<a href='../Order/PaymentReceipt.aspx' target='_charter_receipt'>Print this page</a> for your records. ")
            sb.Append("This is your only payment confirmation.  You will be contacted if this payment is rejected for any reason.<br/><br/>")
            sb.Append("This is how your payment is recorded on your account online:<br/>")
            sb.Append("This payment is not reflected on your Account Statement Balance online.<br/>")
            sb.Append("<a href=""../Account/CharterEpay.aspx"" target=""_blank"">Click Here</a> for Charter ePay to view your payment:<br/>")
            sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;Account Summary - Amount paid to verify your payment<br/>")
            sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;Recent Activity may take up to 48 hours to reflect this payment<br/><br/>")
            sb.Append("<a href=""../Visitors/chatlive.aspx?d=20957"" target=""_blank"">Click Here</a> if you would like to chat live with a Customer Care agent regarding this payment.<br/><br/>")
            sb.Append("<a href=""../Account/MyAccount.aspx"">Go Back to the My Account Home Page</a></div>")
            lblConfirmation.Text = sb.ToString
            'lblConfirmation.Text = "Your confirmation number(s):<BR />" & _confirmation.Number & "<BR /><BR />If you have any questions, please use this information as reference. <br> <a href='../Order/PaymentReceipt.aspx' target='_charter_receipt'>Print a receipt</a> for your records."
            lblConfirmation.ForeColor = Drawing.Color.Black
            'Changed to account for Payment receipt
            hdnConfNumber.Value = _confirmation.Number
            hdnPaymentAmount.Value = amount

            If Not (Application("QUICKPAY_EMAIL_MESSAGE") Is Nothing) And (Application("QUICKPAY_EMAIL_MESSAGE").ToString().Trim() <> "") Then
                If txtEmail.Text.Trim() = "" Then
                    lblEmail.Text = ""
                Else
                    lblEmail.Text = "A confirmation e-mail has been sent to <b>" & txtEmail.Text & "</b>."
                End If
            Else
                lblEmail.Text = ""
            End If

            pnlPaymentInfo.Visible = False
            pnlConfirmation.Visible = True


            Select Case True
                Case Request.RawUrl.ToUpper().Contains("MYACCOUNT.ASPX")
                    __HBXPageName = "MyAccountCCPaymentConfirmation"
                Case Else
                    __HBXPageName = "PayYourBillCCPaymentConfirmation"
            End Select
        Else
            'TODO
        End If
    End Sub

    Protected Sub btnContinue_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnContinue.Click
        Dim _bill As List(Of IAccount.IBill)
        Dim _phone As StringBuilder
        Dim c As Char
        Dim i As Integer

        If Page.IsValid Then
            _phone = New StringBuilder()

            For i = 0 To txtTelephone.Text.Length - 1
                c = CType(txtTelephone.Text(i), Char)

                If Asc(c) >= 48 And Asc(c) <= 57 Then
                    _phone.Append(c)
                End If
            Next

            _bill = AccountManager.Instance.GetBillSummary(_phone.ToString(), txtZipCode.Text, txtEmail.Text)

            If _bill Is Nothing Then
                vldCustom.ErrorMessage = "No bills can be found for the info you entered."
                vldCustom.IsValid = False
            ElseIf _bill.Count = 0 Then
                vldCustom.ErrorMessage = "No bills can be found for the info you entered."
                vldCustom.IsValid = False
            Else

                If Not (Me.Account Is Nothing) Then
                    Select Case Me.Account.BillingVendorType
                        Case BillingVendorType.CSG
                            rprCSGBillingSummary.DataSource = _bill
                            rprCSGBillingSummary.DataBind()
                        Case BillingVendorType.ICOM
                            rprICOMSBillingSummary.DataSource = _bill
                            rprICOMSBillingSummary.DataBind()
                    End Select
                End If

                pnlIdentification.Visible = False
                pnlBillSummary.Visible = True
            End If

            '############################################################################
            'ROD COPELAND   MODIFICATION  6/16/2008     ISSUE ID 3882
            '####################################################
            'ADD FULLY LEGIT BILLS TO THE VALID BILL COLLECTION, 
            'THEN BIND TO THE VALID BILL COLLECTION
            '####################################################
            Dim lBill As IAccount.IBill
            Dim ShowBillingSummary As Boolean = True
            For Each lBill In _bill

                If Not (Me.Account Is Nothing) Then
                    Select Case Me.Account.BillingVendorType
                        Case BillingVendorType.CSG
                            '######################################################
                            '1/1/0001 12:00:00 AM MEANS THE DATE VALUE IS NOT SET
                            'AND THIS IS A NOT A VALID BILL DATE.
                            '######################################################
                            If lBill.PaymentDueDate_CSG_ONLY.ToString() = "1/1/0001 12:00:00 AM" AndAlso lBill.DueUponReceipt = False Then
                                ShowBillingSummary = False
                            End If
                        Case BillingVendorType.ICOM
                            '######################################################
                            '1/1/0001 12:00:00 AM MEANS THE DATE VALUE IS NOT SET
                            'AND THIS IS A NOT A VALID BILL DATE.
                            '######################################################
                            If lBill.StatementDueDate_ICOMS_ONLY.ToString() = "1/1/0001 12:00:00 AM" AndAlso lBill.DueUponReceipt = False Then
                                ShowBillingSummary = False
                            End If
                    End Select
                End If
            Next
            If ShowBillingSummary Then
                '##################################
                'SHOW BILLING SUMMARY INFO ON PAGE
                '##################################
                pnlNoBillingSummaryAvailable.Visible = False
            Else
                '##################################
                'HIDE BILLING SUMMARY INFO ON PAGE.
                '##################################
                pnlPaymentInfo.Visible = False
                pnlBillSummary.Visible = False
                pnlCreditCardInfo.Visible = False
                pnlBankAccountInfo.Visible = False
                pnlConfirmation.Visible = False
                pnlNoBillingSummaryAvailable.Visible = True
            End If
            '############################################################################

            Select Case True
                Case Request.RawUrl.ToUpper().Contains("MYACCOUNT.ASPX")
                    __HBXPageName = "MyAccountBillSummary"
                Case Else
                    __HBXPageName = "PayYourBillBillSummary"
            End Select
        End If
    End Sub

End Class