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_AffiliateShoppingCart
  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
      ' vldHSDTermsRequired.ValidationGroup = "SubmitOrderGroup"
    End If
    lstSHowPrice = Context.Application(ApplicationKey.ShowPrice)
    notifying = False

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

    If SelectedSubitemID > 0 Then
      notifying = True
      AffliateCatalogManager.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 = AffliateCatalogManager.Instance.GetCatalog()

    If Cart IsNot Nothing Then
      '  Throw New MissingCatalogException()
      'End If

      ' cart = catalog.Cart

      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
    Else
      btnUndoRemove.Visible = False
      pnlEmpty.Visible = True
      pnlFilled.Visible = False
    End If
    Page.ClientScript.RegisterStartupScript(Me.GetType, "CARTSCRIPT", GenerateHBXPageScript())

  End Sub

  Protected Sub btnUndoRemove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUndoRemove.Click
    notifying = True
    AffliateCatalogManager.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

    If _existingServices Is Nothing Then
      Response.Redirect("AffiliateUpsell.aspx")
    Else
      Response.Redirect("AffiliateChooseOptions.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>")
    If Not Me.IsFixed Then
      description.AppendFormat("<td class='item'>{1}<br /><a href='javascript:removeItem({0});'>remove</a></td>", bundle.ID, bundle.Name)
    Else
      description.AppendFormat("<td class='item'>{0}</td>", bundle.Name)
    End If

    description.AppendFormat("<td class='price'>{0:C}</td>", bundle.Price)
    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 Sub RenderFeatures(ByVal _servicePlan As ISubCartItem, ByVal customizations As StringBuilder)
    Dim feature As KeyValuePair(Of String, ISubCartItem)
    Dim choice As KeyValuePair(Of String, ISubCartItem)

    For Each feature In _servicePlan.Children
      If feature.Value.IsSelected Then
        If feature.Value.InputType = InputType.Selection Then
          For Each choice In feature.Value.Children
            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.AppendFormat("</td><td class='price'>{0:C}", choice.Value.Price)
                                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.AppendFormat("</td><td class='price'>{0:C}", choice.Value.Price)
                Else
                  customizations.Append("</td><td class='price'>&nbsp;</td></tr>")
                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.AppendFormat("</td><td class='price'>{0:C}", choice.Value.Price)
                End If
                customizations.Append("</td></tr>")
              End If
            End If
          Next
        ElseIf feature.Value.InputType = InputType.Number 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()
            ' issue 15850
            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.Append("<SCRIPT>")
            'strTemp.Append("var hbxObj = new Object();")
            'strTemp.Append("hbxObj.pn = '" & HBXInfo_PageName & "';")
            'strTemp.Append("hbxObj.mlc = '" & HBXInfo_MLC & "';")
            'strTemp.Append("hbxObj.pr = '" & _HBXInfo_pr & "';")
            'strTemp.Append("hbxObj.ca = '" & _HBXInfo_ca & "';")
            'strTemp.Append("hbxObj.pc = '" & _HBXInfo_pc & "';")
            'strTemp.Append("hbxObj.qn = '" & _HBXInfo_qn & "';")
            'strTemp.Append("hbxObj.st = '" & _HBXInfo_st & "';")
            'strTemp.Append("hbxObj.sp = " & _HBXInfo_sp & ";")
            'strTemp.Append("hbxObj.sr = 1;")
            'strTemp.Append("hbxObj.oi = '" & _HBXInfo_oi & "';")
            'strTemp.Append("hbxObj.sk = '" & _HBXInfo_sk & "';")
            'strTemp.Append("hbxObj.po = '" & _HBXInfo_po & "';")
            'strTemp.Append("hbxObj.ds = " & _HBXInfo_ds & ";")
            'strTemp.Append("hbxObj.ci = '';")
            'strTemp.Append("</script>")
            'strTemp.Append("<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.Append("<script language=""javascript"" type=""text/javascript"" src=""../Scripts/hbx_order.js""></script>")
            'Else
            '  strTemp.Append("<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
