Imports System.Collections.Generic
Imports System.Threading
Imports System.Text
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_ShoppingCart
    Inherits System.Web.UI.UserControl

    Private notifying As Boolean
    Private isHSDinCart As Boolean = False
    Private _HBXInfo_page As String
    Private _HBXInfo_mlc As String
    Private _HBXInfo_pr As String
    Private _HBXInfo_ca As String
    Private _HBXInfo_pc As String
    Private _HBXInfo_qn As String
    Private _HBXInfo_st As String
    Private _HBXInfo_sp As Decimal = 0
    Private _HBXInfo_sr As Integer = 1
    Private _HBXInfo_oi As String
    Private _HBXInfo_sk As String
    Private _HBXInfo_po As String
    Private _HBXInfo_ds As Decimal = 0
    Private _HBXInfo_ci As String
    Private lstSHowPrice As List(Of String)
    Private _cart As ICart

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

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

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

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

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

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

    Public Property NavigateFrom() As String
        Get
            If ViewState(Me.ID & "_NavigateFrom") Is Nothing Then
                Return String.Empty
            Else
                Return CType(ViewState(Me.ID & "_NavigateFrom"), String)
            End If
        End Get

        Set(ByVal value As String)
            ViewState(Me.ID & "_NavigateFrom") = value
        End Set
    End Property

    Public ReadOnly Property SelectedItemID() As Integer
        Get
            If Request.Form("txtRemoveItem") Is Nothing Or Request.Form("txtRemoveItem") = String.Empty Then
                Return 0
            Else
                Return CType(Request.Form("txtRemoveItem"), Integer)
            End If
        End Get
    End Property

    Public ReadOnly Property SelectedSubitemID() As Integer
        Get
            If Request.Form("txtRemoveSubitem") Is Nothing Or Request.Form("txtRemoveSubitem") = String.Empty Then
                Return 0
            Else
                Return CType(Request.Form("txtRemoveSubitem"), Integer)
            End If
        End Get
    End Property

    Public Property HBXInfo_PageName() As String
        Get
            Return _HBXInfo_page
        End Get
        Set(ByVal value As String)
            _HBXInfo_page = value
        End Set
    End Property

    Public Property HBXInfo_MLC() As String
        Get
            Return _HBXInfo_mlc
        End Get
        Set(ByVal value As String)
            _HBXInfo_mlc = value
        End Set
    End Property

    Public Property Cart() As ICart
        Get
            Return _cart
        End Get
        Set(ByVal value As ICart)
            _cart = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            pnlCheckoutButton.Visible = Not HideCheckout
            'vldSummaryAgreement.ValidationGroup = Me.ID
            ' vldHSDTermsRequired.ValidationGroup = "SubmitOrderGroup"
        End If
        lstSHowPrice = Context.Application(ApplicationKey.ShowPrice)
        notifying = False

        If SelectedItemID > 0 Then
            notifying = True
            CatalogManager.Instance.RemoveCartItem(SelectedItemID, New Notify(AddressOf OnNotification))
        End If

        If SelectedSubitemID > 0 Then
            notifying = True
            CatalogManager.Instance.RemoveSubCartItem(SelectedSubitemID, Nothing, New Notify(AddressOf OnNotification))
        End If
    End Sub

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

        ' Dim catalog As ICatalog
        'Dim cart As ICart

        While notifying
            Thread.Sleep(100)
        End While

        'catalog = CatalogManager.Instance.GetCatalog()

        'If catalog Is Nothing Then
        '  Throw New MissingCatalogException()
        'End If

        ' cart = catalog.Cart
        If Not Cart Is Nothing Then


            If Not Me.IsFixed And Cart.CanUndo Then
                btnUndoRemove.Visible = True
            Else
                btnUndoRemove.Visible = False
            End If

            pnlEmptyLinks.Visible = Not EmptyNoLinks

            If Cart.CartItems.Count = 0 Or Cart.Submitted Then
                pnlEmpty.Visible = True
                pnlFilled.Visible = False
            Else
                pnlEmpty.Visible = False
                pnlFilled.Visible = True

                Const BUNDLE_PACKAGE_BUNDLE = 0
                Const BUNDLE_PACKAGE_CABLE = 1
                Const BUNDLE_PACKAGE_HSD = 2
                Const BUNDLE_PACKAGE_TELEPHONE = 3

                Dim bundlePackageDescription(4) As StringBuilder
                Dim bundlePackageCustomization(4) As StringBuilder
                Dim oneTimeCharges As New StringBuilder()

                Dim item As KeyValuePair(Of String, ICartItem)

                Dim i As Integer

                For i = 0 To bundlePackageDescription.Length - 1
                    bundlePackageDescription(i) = New StringBuilder()
                Next

                For i = 0 To bundlePackageCustomization.Length - 1
                    bundlePackageCustomization(i) = New StringBuilder()
                Next

                For Each item In Cart.CartItems
                    If item.Value.Type = ItemType.Bundle Then
                        RenderBundle(item.Value, bundlePackageDescription(BUNDLE_PACKAGE_BUNDLE), _
                          bundlePackageCustomization(BUNDLE_PACKAGE_BUNDLE))
                    Else
                        Select Case item.Value.Category
                            Case Category.Cable
                                RenderServicePlan(item.Value, bundlePackageDescription(BUNDLE_PACKAGE_CABLE), _
                                  bundlePackageCustomization(BUNDLE_PACKAGE_CABLE), True)
                            Case Category.HSD
                                RenderServicePlan(item.Value, bundlePackageDescription(BUNDLE_PACKAGE_HSD), _
                                  bundlePackageCustomization(BUNDLE_PACKAGE_HSD), True)
                                isHSDinCart = True
                            Case Category.Telephoney
                                RenderServicePlan(item.Value, bundlePackageDescription(BUNDLE_PACKAGE_TELEPHONE), _
                                  bundlePackageCustomization(BUNDLE_PACKAGE_TELEPHONE), True)
                        End Select
                    End If
                Next

                RenderOneTimeCharges(Cart.OneTimeTotal, Cart.OneTimeChargeItems, oneTimeCharges)

                ltrBundle.Text = bundlePackageDescription(BUNDLE_PACKAGE_BUNDLE).ToString()
                ltrBundleCustomizations.Text = bundlePackageCustomization(BUNDLE_PACKAGE_BUNDLE).ToString()
                ltrCableTV.Text = bundlePackageDescription(BUNDLE_PACKAGE_CABLE).ToString()
                ltrCableCustomizations.Text = bundlePackageCustomization(BUNDLE_PACKAGE_CABLE).ToString()
                ltrInternet.Text = bundlePackageDescription(BUNDLE_PACKAGE_HSD).ToString()
                ltrInternetCustomizations.Text = bundlePackageCustomization(BUNDLE_PACKAGE_HSD).ToString()
                ltrTelephone.Text = bundlePackageDescription(BUNDLE_PACKAGE_TELEPHONE).ToString()
                ltrTelephoneCustomizations.Text = bundlePackageCustomization(BUNDLE_PACKAGE_TELEPHONE).ToString()
                lblMonthlyCharge.Text = Cart.MonthlyTotal.ToString("C")
                ltrOneTimeCharges.Text = oneTimeCharges.ToString()
                lblTotalCharge.Text = Cart.GrandTotal.ToString("C")

                If Me.Page.Request.Url.ToString.ToLower.Contains(PageName.SubmitOrder.ToLower) Then
                    ' this is submit order page , show HSD residensial terms if HSD is selected
                    If isHSDinCart Then
                        chkHSDTerms.Text = ContentManager.Instance.GetContent("HSIResidentialTerms", "1", OwnerType.Other)
                        pnlHSDTerms.Visible = True
                        vldHSDTermsRequired.Enabled = True
                    Else
                        pnlHSDTerms.Visible = False
                        vldHSDTermsRequired.Enabled = False
                    End If
                Else
                    pnlHSDTerms.Visible = False
                    vldHSDTermsRequired.Enabled = False
                End If
            End If

            Page.ClientScript.RegisterStartupScript(Me.GetType, "CARTSCRIPT", GenerateHBXPageScript())
        Else
            btnUndoRemove.Visible = False
            pnlEmpty.Visible = True
            pnlFilled.Visible = False
        End If

    End Sub

    Protected Sub btnUndoRemove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUndoRemove.Click
        notifying = True
        CatalogManager.Instance.UndoRemove(New Notify(AddressOf OnNotification))
    End Sub

    Protected Sub btnCheckout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCheckout.Click
        Dim _existingServices As List(Of Category)

        _existingServices = AccountManager.Instance.GetAccount().ExistingService

        '##################################################################################
        'MODIFICATION   ROD COPELAND    FEB 01 2008
        'THIS CHANGE WAS REQUESTED BY SHARON RENAUD, JOE KESSLER, LINDA LAMBERT.
        '##################################################################################
        'COUNT FLAG IS RESET IN THE CONTROLS/SHOPPINGCART.ASCX.VB AT THIS TIME.
        'IN THE EVENT THE USER ENDS UP ON THIS PAGE BY HITTING F5 WHILE ITS LOADING 
        'OR NAVIGATING DIRECTLY TO IT, THE INTENT IS TO NOT SUBMIT THE WEB SERVICE CALL 
        'TWICE BY USING THIS FLAG.
        'TO CLEAR THESE FLAGS, THE USER WILL NEED TO CHECKOUT AGAIN.
        '##################################################################################
        Session("SUBMIT_ORDER_COUNT") = Nothing
        Session("SUBMIT_SCHEDULE_COUNT") = Nothing
        Session("AUTHENTICATE_CALL_FOR_SUBMIT_ORDER_COUNT") = Nothing
        Session("SUBMIT_ORDER_NEXT_URL") = Nothing

        If _existingServices Is Nothing Then
            Response.Redirect("../Order/Upsell.aspx")
        Else
            Response.Redirect("../Order/ChooseOptions.aspx")
        End If
    End Sub

    Public Sub OnNotification(ByVal message As INotification)
        Dim sb As StringBuilder

        sb = New StringBuilder()

        Select Case message.ResultCode
            Case NotificationCode.CannotAddCustomization
                sb.AppendFormat("Feature '{0}' cannot be added to the cart.", message.Source)
            Case NotificationCode.ChangeBundle
                sb.AppendFormat("Bundle '{0}' in your cart has been changed to {1}.", message.FromTarget, message.ToTarget)
            Case NotificationCode.ChangeServicePlan
                sb.AppendFormat("Service Plan '{0}' in your cart has been changed to {1}.", message.FromTarget, message.ToTarget)
            Case NotificationCode.LocalizationChanged
                sb.Append("Your cart has been emptied because the address is changed.")
            Case NotificationCode.NewBundle
                sb.AppendFormat("Bundle '{0}' has been added to your cart.", message.ToTarget)
            Case NotificationCode.NewServicePlan
                sb.AppendFormat("Service Plan '{0}' has been added to your cart.", message.ToTarget)
            Case NotificationCode.RemoveBundle
                sb.AppendFormat("Bundle '{0}' has been removed from your cart.", message.FromTarget)
            Case NotificationCode.RemoveCustomizationByServicePlan
                sb.AppendFormat("Features associated with Service Plan '{0}' are removed", message.Source)
        End Select

        If message.ResultCode = NotificationCode.Success Then
            lblMessage.Text = String.Empty
            pnlMessage.Visible = False
        Else
            lblMessage.Text = sb.ToString()
            pnlMessage.Visible = True
        End If
        notifying = False
    End Sub

    Private Sub RenderBundle(ByVal bundle As ICartItem, ByVal description As StringBuilder, ByVal customizations As StringBuilder)
        Dim servicePlan As KeyValuePair(Of String, ISubCartItem)

        description.Append("<div class='solidRoundedLtGreen'>")
        description.Append("  <div class='solidRoundedTop'>")
        description.Append("    <div></div>")
        description.Append("  </div>")
        description.Append("  <div id='solidRoundedContent' class='ltGreen'>")
        description.Append("    <table id='cartGroup' cellpadding='0' cellspacing='0'>")
        description.Append("      <tr>")
        description.AppendFormat("  <td class='item'>{0}</td>", bundle.Name)
        description.Append("      </tr>")
        description.Append("    </table>")
        description.Append("    <table>")
        description.Append("        <tr>")
        description.Append("            <td>")
        description.AppendFormat("          <a href='javascript:removeItem({0});' style='color:#ff6600'>remove</a>", bundle.ID)
        description.Append("            </td>")
        description.Append("            <td width='90'> </td>")
        description.AppendFormat("      <td class='price'>{0:C}</td>", bundle.Price)
        description.Append("        <tr>")
        description.Append("      </tr>")
        description.Append("    </table>")
        description.Append("  </div>")
        description.Append("  <div class='solidRoundedBot' id='flat'>")
        description.Append("    <div></div>")
        description.Append("  </div>")
        description.Append("</div>")

        _HBXInfo_pr = _HBXInfo_pr & bundle.Name & ","
        _HBXInfo_ca = _HBXInfo_ca & "service,"
        _HBXInfo_pc = _HBXInfo_pc & bundle.ListPrice & ","
        _HBXInfo_qn = _HBXInfo_qn & "1,"
        _HBXInfo_st = _HBXInfo_st & bundle.InstallDescription
        _HBXInfo_sp = _HBXInfo_sp + bundle.InstallPrice
        _HBXInfo_sk = _HBXInfo_sk & CStr(bundle.ID).Substring(1) & ","
        _HBXInfo_po = _HBXInfo_po & bundle.PromotionName & ","
        _HBXInfo_ds = _HBXInfo_ds + (bundle.ListPrice - bundle.Price)

        For Each servicePlan In bundle.Children
            If servicePlan.Value.Children.Count > 0 Then
                RenderFeatures(servicePlan.Value, customizations)

            End If
            If servicePlan.Value.Category = Category.HSD Then isHSDinCart = True
        Next
    End Sub

    Private Sub RenderServicePlan(ByVal _servicePlan As ISubCartItem, ByVal description As StringBuilder, ByVal customizations As StringBuilder, ByVal showPrice As Boolean)

        description.Append("<div class='solidRoundedLtGreen'>")
        description.Append("  <div class='solidRoundedTop'>")
        description.Append("    <div></div>")
        description.Append("  </div>")
        description.Append("  <div id='solidRoundedContent' class='ltGreen'>")
        description.Append("    <table id='cartGroup' cellpadding='0' cellspacing='0'>")

        If showPrice Then
            description.AppendFormat("<tr><td class='item'>{0}</td>", _servicePlan.Name)
            description.AppendFormat("<td class='price'>{0:C}</td></tr>", _servicePlan.Price)

            _HBXInfo_pr = _HBXInfo_pr & _servicePlan.Name & ","
            _HBXInfo_ca = _HBXInfo_ca & "service,"
            _HBXInfo_pc = _HBXInfo_pc & _servicePlan.ListPrice & ","
            _HBXInfo_qn = _HBXInfo_qn & "1,"
            _HBXInfo_st = _HBXInfo_st & _servicePlan.InstallDescription
            _HBXInfo_sp = _HBXInfo_sp + _servicePlan.InstallPrice
            _HBXInfo_sk = _HBXInfo_sk & CStr(_servicePlan.ID).Substring(1) & ","
            _HBXInfo_po = _HBXInfo_po & CType(_servicePlan, ICartItem).PromotionName & ","
            _HBXInfo_ds = _HBXInfo_ds + (_servicePlan.ListPrice - _servicePlan.Price)

            If Not Me.IsFixed Then
                description.AppendFormat("<tr><td colspan='2'><a href='javascript:removeItem({0});'>remove</a></td></tr>", _servicePlan.ID)
            End If
        Else
            description.AppendFormat("<tr><td class='item' colspan='2'>{0}</td>", _servicePlan.Name)

            _HBXInfo_pr = _HBXInfo_pr & _servicePlan.Name & ","
            _HBXInfo_ca = _HBXInfo_ca & "service,"
            _HBXInfo_pc = _HBXInfo_pc & _servicePlan.ListPrice & ","
            _HBXInfo_qn = _HBXInfo_qn & "1,"
            _HBXInfo_st = _HBXInfo_st & _servicePlan.InstallDescription
            _HBXInfo_sp = _HBXInfo_sp + _servicePlan.InstallPrice
            _HBXInfo_sk = _HBXInfo_sk & CStr(_servicePlan.ID).Substring(1) & ","
            _HBXInfo_po = _HBXInfo_po & CType(_servicePlan, ICartItem).PromotionName & ","
            _HBXInfo_ds = _HBXInfo_ds + (_servicePlan.ListPrice - _servicePlan.Price)

            If Not Me.IsFixed Then
                description.AppendFormat("<tr><td colspan='2'><a href='javascript:removeItem({0});'>remove</a>>", _servicePlan.ID)
            End If

            description.Append("</td></tr>")
        End If
        description.Append("    </table>")
        description.Append("  </div>")
        description.Append("  <div class='solidRoundedBot' id='flat'>")
        description.Append("    <div></div>")
        description.Append("  </div>")
        description.Append("</div>")

        If _servicePlan.Children.Count > 0 Then
            RenderFeatures(_servicePlan, customizations)
        End If

    End Sub

    Private Function getChoiceCount(ByVal feature As KeyValuePair(Of String, ISubCartItem)) As Integer
        '############################################################################
        'GET A COUNT OF HOW MANY ARE SELECTED ON THE MIDDLE OF THE PAGE OPTIONS SO 
        'WE CAN DETERMINE THE DISCOUNT AMOUNT TO THE REMAINING UNSELECTED AMOUNTS.
        '############################################################################
        Dim intChoicesSelected As Integer = 0
        Dim choice As KeyValuePair(Of String, ISubCartItem)
        For Each choice In feature.Value.Children
            '#################################################################
            'INITIALIZE THE CART PRICES PRIOR TO APPLYING THE DISCOUNTS BELOW
            '#################################################################
            choice.Value.Price = choice.Value.ListPrice
            If choice.Value.IsSelected Then
                '#####################################################
                'GO UPDATE THE XML FOR THIS FEATURE WITH THE NEW PRICE
                '#####################################################
                intChoicesSelected += 1
            End If
        Next
        '###################################################################

        Return intChoicesSelected
    End Function

    Private Sub ApplyMultiSelectionDiscountPriceToFeature(ByVal _servicePlan As ISubCartItem, ByVal intChoicesSelected As Integer)
        '########################################################################
        'MODIFICATION   ROD COPELAND    DIGITAL REPACKAGING     SEPT 18, 2008
        '########################################################################
        Dim feature As KeyValuePair(Of String, ISubCartItem)
        Dim choice As KeyValuePair(Of String, ISubCartItem)
        Dim blnUpdateNonSelectedChoice As Boolean = False
        Dim intLoopCnt As Integer = 1


        For Each feature In _servicePlan.Children
            intLoopCnt = 1
            Select Case feature.Key()
                Case "413410"

                Case "413407"
                    If intChoicesSelected > 1 Then
                        For Each choice In feature.Value.Children
                            blnUpdateNonSelectedChoice = False

                            If choice.Value.IsSelected Then
                                '################################################################################
                                'THIS WILL BE ITEMS THAT HAVE BEEN SELECTED AND WE NEED TO FIND THE PRICE AS 
                                'EXPECTED IN ADDITION TO MAINTAINING THE DISCOUNTED PRICE FOR SUBSEQUENT ITEMS 
                                'THAT HAVE BEEN SELECTED AS WELL.
                                '################################################################################
                                Select Case intLoopCnt
                                    Case 2
                                        choice.Value.Price = choice.Value.ListPrice - 2
                                    Case 3
                                        choice.Value.Price = choice.Value.ListPrice - 4
                                    Case Else
                                        choice.Value.Price = choice.Value.ListPrice
                                End Select

                                intLoopCnt += 1
                            Else
                                '##########################################################
                                'THIS SHOULD BE THE ITEMS THAT HAVE NOT BEEN SELECTED YET.
                                'BE SURE TO REVERT ANY MODIFICATIONS WE MAY HAVE MADE AS 
                                'PART OF PREVIOUS DISCOUNTS WE'VE APPLIED 
                                '##########################################################
                                choice.Value.Price = choice.Value.ListPrice
                            End If
                        Next
                    End If
                Case "414331" ' 1 free Premium channel
                    If intChoicesSelected > 1 Then
                        For Each choice In feature.Value.Children
                            blnUpdateNonSelectedChoice = False

                            If choice.Value.IsSelected Then
                                '################################################################################
                                'THIS WILL BE ITEMS THAT HAVE BEEN SELECTED AND WE NEED TO FIND THE PRICE AS 
                                'EXPECTED IN ADDITION TO MAINTAINING THE DISCOUNTED PRICE FOR SUBSEQUENT ITEMS 
                                'THAT HAVE BEEN SELECTED AS WELL.
                                '################################################################################
                                Select Case intChoicesSelected
                                    Case 1
                                        choice.Value.Price = choice.Value.ListPrice
                                    Case 2
                                        Select Case intLoopCnt
                                            'Case 1
                                            'choice.Value.Price = 0
                                            Case 2
                                                choice.Value.Price = choice.Value.ListPrice
                                            Case 3
                                                choice.Value.Price = choice.Value.ListPrice - 2
                                            Case Else
                                                choice.Value.Price = choice.Value.ListPrice
                                        End Select
                                    Case 3
                                        Select Case intLoopCnt
                                            'Case 1
                                            '    choice.Value.Price = 0
                                            Case 2
                                                choice.Value.Price = choice.Value.ListPrice
                                            Case 3
                                                choice.Value.Price = choice.Value.ListPrice - 2
                                            Case Else
                                                choice.Value.Price = choice.Value.ListPrice
                                        End Select
                                    Case Else

                                End Select



                                intLoopCnt += 1
                            Else
                                '##########################################################
                                'THIS SHOULD BE THE ITEMS THAT HAVE NOT BEEN SELECTED YET.
                                'BE SURE TO REVERT ANY MODIFICATIONS WE MAY HAVE MADE AS 
                                'PART OF PREVIOUS DISCOUNTS WE'VE APPLIED 
                                '##########################################################
                                choice.Value.Price = choice.Value.ListPrice
                            End If
                        Next
                    End If
            End Select
        Next

    End Sub

    Private Function getPriceValueToDisplay(ByVal strFeatureKey As String, ByVal decChoicePrice As Decimal, ByVal intChoicesSelected As Integer, ByRef blnShowPriceForChoice As Boolean) As String

        If blnShowPriceForChoice Then
            '###########################################
            'SHOW PRICE FOR REMAINING SELECTION OPTIONS
            '###########################################
            Return String.Format("</td><td class='price'>{0:C}", decChoicePrice)
        Else
            '##################################################################
            'ATTEMPT TO HIDE THE PRICE ON THE FIRST SELECTED ITEM IN THE GROUP.
            '##################################################################
            Return "</td><td class='price'>&nbsp;</td></tr>"
        End If

    End Function


    Private Sub RenderFeatures(ByVal _servicePlan As ISubCartItem, ByVal customizations As StringBuilder)
        Dim feature As KeyValuePair(Of String, ISubCartItem)
        Dim choice As KeyValuePair(Of String, ISubCartItem)
        Dim intChoicesSelected As Integer = 0


        For Each feature In _servicePlan.Children
            '########################################################################
            'MODIFICATION   ROD COPELAND    DIGITAL REPACKAGING     SEPT 18, 2008
            '########################################################################
            'UPDATE THE CART OBJECT WITH ANY DISCOUNTED PRICES
            '########################################################################
            If Request.Url.ToString.ToLower().Contains("chooseoptions.aspx") Then
                If Not (feature.Key Is Nothing) Then
                    Select Case feature.Key.Trim().ToLower()
                        Case "414331", "413407", "413410"
                            intChoicesSelected = getChoiceCount(feature)

                            '################################################################################
                            'ACTUALLY APPLY THE CHANGES TO THE CART VALUES ON THE CHOOSE OPTIONS PAGE ONLY.  
                            'THE OTHER PAGES WHEN DISPLAYING ON THE PAGE CAN JUST USE THE ALREADY MODIFYIED 
                            'CART VALUES RATHER THAN RE-EVALUTING THE DISCOUNT PRICE ON EVERY PAGE THAT USES 
                            'THE CART CONTROL.
                            '################################################################################
                            Call ApplyMultiSelectionDiscountPriceToFeature(_servicePlan, intChoicesSelected)
                    End Select
                End If


            End If
            '########################################################################




            If feature.Value.IsSelected Then
                If feature.Value.InputType = InputType.Selection Then
                    Dim blnShowPriceForChoice As Boolean = False
                    Dim intPricesDisplayedLoopCnt As Integer = 1

                    For Each choice In feature.Value.Children

                        Select Case feature.Key.Trim().ToLower()
                            Case "414331" 'Digital Cable + 1 Free Premiums + Internet - JUST AN EXAMPLE
                                If choice.Value.IsSelected Then
                                    Select Case intChoicesSelected
                                        Case 1 'THE USER HAS CHECKED 1 CHECKBOXES ON THE GROUP
                                            Select Case intPricesDisplayedLoopCnt
                                                Case 1                              'IF ITS THE 1ST ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case 2                              'IF ITS THE 2ND ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case 3                              'IF ITS THE 3RD ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case Else
                                                    blnShowPriceForChoice = True
                                            End Select
                                            intPricesDisplayedLoopCnt += 1
                                        Case 2 'THE USER HAS CHECKED 2 CHECKBOXES ON THE GROUP
                                            Select Case intPricesDisplayedLoopCnt
                                                Case 1                              'IF ITS THE 1ST ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case 2                              'IF ITS THE 2ND ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = True
                                                Case 3                              'IF ITS THE 3RD ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = True
                                                Case Else
                                                    blnShowPriceForChoice = True
                                            End Select
                                            intPricesDisplayedLoopCnt += 1
                                        Case 3 'THE USER HAS CHECKED 3 CHECKBOXES ON THE GROUP
                                            Select Case intPricesDisplayedLoopCnt
                                                Case 1                              'IF ITS THE 1ST ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case 2                              'IF ITS THE 2ND ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = True
                                                Case 3                              'IF ITS THE 3RD ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = True
                                                Case Else
                                                    blnShowPriceForChoice = True
                                            End Select
                                            intPricesDisplayedLoopCnt += 1
                                        Case Else
                                            blnShowPriceForChoice = True
                                    End Select
                                Else
                                    '##################################
                                    'JUST TO DEFAULT IT TO SOMETHING 
                                    '##################################
                                    blnShowPriceForChoice = True
                                End If


                            Case "413410"  'Digital Cable + 2 Free Premiums+Internet+Phone - JUST AN EXAMPLE
                                If choice.Value.IsSelected Then
                                    Select Case intChoicesSelected
                                        Case 1 'THE USER HAS CHECKED 1 CHECKBOXES ON THE GROUP
                                            Select Case intPricesDisplayedLoopCnt
                                                Case 1                              'IF ITS THE 1ST ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case 2                              'IF ITS THE 2ND ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case 3                              'IF ITS THE 3RD ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case Else
                                                    blnShowPriceForChoice = True
                                            End Select
                                            intPricesDisplayedLoopCnt += 1
                                        Case 2 'THE USER HAS CHECKED 2 CHECKBOXES ON THE GROUP
                                            Select Case intPricesDisplayedLoopCnt
                                                Case 1                              'IF ITS THE 1ST ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case 2                              'IF ITS THE 2ND ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case 3                              'IF ITS THE 3RD ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = True
                                                Case Else
                                                    blnShowPriceForChoice = True
                                            End Select
                                            intPricesDisplayedLoopCnt += 1
                                        Case 3 'THE USER HAS CHECKED 3 CHECKBOXES ON THE GROUP
                                            Select Case intPricesDisplayedLoopCnt
                                                Case 1                              'IF ITS THE 1ST ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case 2                              'IF ITS THE 2ND ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = False
                                                Case 3                              'IF ITS THE 3RD ITEM IN THE GROUP THAT IS SELECTED
                                                    blnShowPriceForChoice = True
                                                Case Else
                                                    blnShowPriceForChoice = True
                                            End Select
                                            intPricesDisplayedLoopCnt += 1
                                        Case Else
                                            blnShowPriceForChoice = True
                                    End Select
                                Else
                                    '##################################
                                    'JUST TO DEFAULT IT TO SOMETHING 
                                    '##################################
                                    blnShowPriceForChoice = True
                                End If
                            Case Else
                                blnShowPriceForChoice = True
                        End Select







                        If choice.Value.IsSelected And choice.Value.PriceFrequency = BLPriceFrequency.Monthly Then
                            If choice.Value.FeatureType = FeatureType.IsPlaceholder Then
                                customizations.AppendFormat("<tr><td class='item'>{0}", choice.Value.Name)

                                _HBXInfo_pr = _HBXInfo_pr & choice.Value.Name & ","
                                _HBXInfo_sk = _HBXInfo_sk & CStr(choice.Value.ID).Substring(3) & ","

                                If choice.Value.PriceFrequency = BLPriceFrequency.Monthly Then
                                    _HBXInfo_ca = _HBXInfo_ca & "service,"
                                Else
                                    _HBXInfo_ca = _HBXInfo_ca & "installation,"
                                End If
                                _HBXInfo_pc = _HBXInfo_pc & choice.Value.ListPrice & ","
                                _HBXInfo_qn = _HBXInfo_qn & "1,"
                                _HBXInfo_ds = _HBXInfo_ds + (choice.Value.ListPrice - choice.Value.Price)

                                If Not Me.IsFixed And choice.Value.IsRemovable Then
                                    customizations.AppendFormat("<br /><a href='javascript:removeSubitem({0});'>remove</a>", choice.Value.ID)
                                End If
                                If lstSHowPrice IsNot Nothing AndAlso lstSHowPrice.Contains(feature.Value.ID) Then
                                    customizations.Append(getPriceValueToDisplay(feature.Key, choice.Value.Price, intChoicesSelected, blnShowPriceForChoice))
                                ElseIf choice.Value.ID = CStr(HttpContext.Current.Application(CharterDotCom.CommonEntities.Library.Common.m_TOTALVIEWID)) Or choice.Value.ID = CStr(HttpContext.Current.Application(CharterDotCom.CommonEntities.Library.Common.m_DIGITALVIEWID)) Then
                                    customizations.Append(getPriceValueToDisplay(feature.Key, choice.Value.Price, intChoicesSelected, blnShowPriceForChoice))
                                Else
                                    customizations.Append(getPriceValueToDisplay(feature.Key, choice.Value.Price, intChoicesSelected, blnShowPriceForChoice))
                                End If

                            ElseIf choice.Value.FeatureType = FeatureType.IsCustomization Then
                                customizations.AppendFormat("<tr><td class='item'>{0}", choice.Value.Name)

                                _HBXInfo_pr = _HBXInfo_pr & choice.Value.Name & ","
                                _HBXInfo_sk = _HBXInfo_sk & CStr(choice.Value.ID).Substring(3) & ","

                                If choice.Value.PriceFrequency = BLPriceFrequency.Monthly Then
                                    _HBXInfo_ca = _HBXInfo_ca & "service,"
                                Else
                                    _HBXInfo_ca = _HBXInfo_ca & "installation,"
                                End If
                                _HBXInfo_pc = _HBXInfo_pc & choice.Value.ListPrice & ","
                                _HBXInfo_qn = _HBXInfo_qn & "1,"
                                _HBXInfo_ds = _HBXInfo_ds + (choice.Value.ListPrice - choice.Value.Price)

                                If Not Me.IsFixed And choice.Value.IsRemovable Then
                                    'If lstSHowPrice IsNot Nothing AndAlso lstSHowPrice.Contains(feature.Value.ID) Then
                                    customizations.AppendFormat("<br /><a href='javascript:removeSubitem({0});'>remove</a></td><td class='price'>{1:C}", choice.Value.ID, choice.Value.Price)
                                    'Else
                                    'customizations.AppendFormat("<br /><a href='javascript:removeSubitem({0});'>remove</a></td><td>&nbsp;", choice.Value.ID)
                                    'End If
                                Else
                                    customizations.Append(getPriceValueToDisplay(feature.Key, choice.Value.Price, intChoicesSelected, blnShowPriceForChoice))
                                End If
                                customizations.Append("</td></tr>")
                            End If
                        End If

                    Next
                ElseIf feature.Value.InputType = InputType.Number AndAlso feature.Value.PriceFrequency = BLPriceFrequency.Monthly Then
                    If feature.Value.Price > 0 Then
                        customizations.AppendFormat("<tr><td class='item'>{0}", feature.Value.Name)

                        _HBXInfo_pr = _HBXInfo_pr & feature.Value.Name & ","
                        _HBXInfo_sk = _HBXInfo_sk & CStr(feature.Value.ID).Substring(1) & ","

                        If feature.Value.PriceFrequency = BLPriceFrequency.Monthly Then
                            _HBXInfo_ca = _HBXInfo_ca & "service,"
                        Else
                            _HBXInfo_ca = _HBXInfo_ca & "installation,"
                        End If
                        _HBXInfo_pc = _HBXInfo_pc & (feature.Value.ListPrice * feature.Value.Quantity) & ","
                        _HBXInfo_qn = _HBXInfo_qn & "1,"
                        _HBXInfo_ds = _HBXInfo_ds + ((feature.Value.ListPrice * feature.Value.Quantity) - (feature.Value.Price * feature.Value.Quantity))

                        If Not Me.IsFixed And feature.Value.IsRemovable Then
                            customizations.AppendFormat("<br /><a href='javascript:removeSubitem({0});'>remove</a>", feature.Value.ID)
                        End If

                        customizations.AppendFormat("</td><td class='price'>{0:C}", (feature.Value.Price * feature.Value.Quantity))

                    End If
                End If
            End If
        Next

    End Sub

    Private Sub RenderOneTimeCharges(ByVal total As Decimal, ByVal charges As Dictionary(Of String, Decimal), ByVal description As StringBuilder)
        Dim charge As KeyValuePair(Of String, Decimal)

        If charges.Count > 0 Then
            description.Append("<tr class='subHead'><td colspan='2'>Installation &amp; One Time Fees:</td></tr>")
            For Each charge In charges
                If charge.Value <> 0 Then
                    description.AppendFormat("<tr><td class='item'>{0}</td>", charge.Key)
                    description.AppendFormat("<td class='price'>{0:C}&nbsp;&nbsp;</td></tr>", charge.Value)
                End If
            Next
            description.Append("<tr><td class='item'>Total</td>")
            description.AppendFormat("<td class='price'>{0:C}&nbsp;&nbsp;</td></tr>", total)
        End If

    End Sub

    Protected Sub ValidateHSDTerms(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ServerValidateEventArgs)
        vldHSDTermsRequired.IsValid = True
        If pnlHSDTerms.Visible Then
            If Not chkHSDTerms.Checked Then
                vldHSDTermsRequired.IsValid = False
                e.IsValid = False

            End If
        End If
    End Sub

    Private Function GenerateHBXPageScript() As String
        Try
            If Len(_HBXInfo_pr) > 0 Then
                _HBXInfo_pr = Left(_HBXInfo_pr, Len(_HBXInfo_pr) - 1)
            End If
            If Len(_HBXInfo_ca) > 0 Then
                _HBXInfo_ca = Left(_HBXInfo_ca, Len(_HBXInfo_ca) - 1)
            End If
            If Len(_HBXInfo_pc) > 0 Then
                _HBXInfo_pc = Left(_HBXInfo_pc, Len(_HBXInfo_pc) - 1)
            End If
            If Len(_HBXInfo_qn) > 0 Then
                _HBXInfo_qn = Left(_HBXInfo_qn, Len(_HBXInfo_qn) - 1)
            End If
            If Len(_HBXInfo_st) > 0 Then
                _HBXInfo_st = Left(_HBXInfo_st, Len(_HBXInfo_st) - 1)
                _HBXInfo_st = Replace(_HBXInfo_st, vbCrLf.Chars(1), "")
                _HBXInfo_st = Replace(Replace(Replace(_HBXInfo_st, "@", ""), "$", ""), "'", "''")
            End If
            If Len(_HBXInfo_sk) > 0 Then
                _HBXInfo_sk = Left(_HBXInfo_sk, Len(_HBXInfo_sk) - 1)
            End If
            If Len(_HBXInfo_po) > 0 Then
                _HBXInfo_po = Left(_HBXInfo_po, Len(_HBXInfo_po) - 1)
                _HBXInfo_po = Replace(Replace(Replace(_HBXInfo_po, "@", ""), "$", ""), "'", "''")
            End If
            Dim strTemp As New StringBuilder()
            strTemp.AppendLine("<script type=""text/javascript"">")
            strTemp.AppendLine("var utag_data = {")
            strTemp.AppendLine("page_level2:         '" & HBXInfo_PageName & "',")
            strTemp.AppendLine("page_level1:        '" & HBXInfo_MLC & "'")
            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.AppendLine("<SCRIPT>")
            'strTemp.AppendLine("var hbxObj = new Object();")
            'strTemp.AppendLine("hbxObj.pn = '" & HBXInfo_PageName & "';")
            'strTemp.AppendLine("hbxObj.mlc = '" & HBXInfo_MLC & "';")
            'strTemp.AppendLine("hbxObj.pr = '" & Trim(_HBXInfo_pr) & "';")
            'strTemp.AppendLine("hbxObj.ca = '" & Trim(_HBXInfo_ca) & "';")
            'strTemp.AppendLine("hbxObj.pc = '" & Trim(_HBXInfo_pc) & "';")
            'strTemp.AppendLine("hbxObj.qn = '" & Trim(_HBXInfo_qn) & "';")
            'strTemp.AppendLine("hbxObj.st = '" & Trim(_HBXInfo_st) & "';")
            'strTemp.AppendLine("hbxObj.sp = " & _HBXInfo_sp & ";")
            'strTemp.AppendLine("hbxObj.sr = 1;")
            'strTemp.AppendLine("hbxObj.oi = '" & Trim(_HBXInfo_oi) & "';")
            'strTemp.AppendLine("hbxObj.sk = '" & Trim(_HBXInfo_sk) & "';")
            'strTemp.AppendLine("hbxObj.po = '" & Trim(_HBXInfo_po) & "';")
            'strTemp.AppendLine("hbxObj.ds = " & _HBXInfo_ds & ";")
            'strTemp.AppendLine("hbxObj.ci = '';")
            'strTemp.AppendLine("</script>")
            'strTemp.AppendLine("<script language=""javascript"" type=""text/javascript"" src=""../Scripts/hbx_pagecode.js""></script>")
            'If HBXInfo_PageName = "step 6 - finish and receipt" And HBXInfo_MLC = "/orderflow" Then
            '    strTemp.AppendLine("<script language=""javascript"" type=""text/javascript"" src=""../Scripts/hbx_order.js""></script>")
            'Else
            '    strTemp.AppendLine("<script language=""javascript"" type=""text/javascript"" src=""../Scripts/hbx.js""></script>")
            'End If
            Return strTemp.ToString
        Catch ex As Exception
            Throw ex
        End Try
    End Function

End Class
