Imports System.Collections.Generic
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.WebSite.Library
Imports System.Net

Partial Class Controls_AffiliateOffer
  Inherits System.Web.UI.UserControl

  Public Const ContentControlID As String = "Offer"

    Private _chatcategory As String

    Public Property Chatcategory() As String
        Get
            Return _chatcategory
        End Get
        Set(ByVal value As String)
            _chatcategory = value
        End Set
    End Property

  Public Property OfferID() As Integer
    Get
      If ViewState(Me.ID & "_OfferID") Is Nothing Then
        Return 0
      Else
        Return CType(ViewState(Me.ID & "_OfferID"), Integer)
      End If
    End Get

    Set(ByVal value As Integer)
      ViewState(Me.ID & "_OfferID") = value
    End Set
  End Property

  Public Property OfferType() As OwnerType
    Get
      If ViewState(Me.ID & "_OfferType") Is Nothing Then
        Return OwnerType.Bundle
      Else
        Return CType(ViewState(Me.ID & "_OfferType"), OwnerType)
      End If
    End Get

    Set(ByVal value As OwnerType)
      ViewState(Me.ID & "_OfferType") = value
    End Set
  End Property

  Public Property OfferName() As String
    Get
      Return ltrName.Text
    End Get

    Set(ByVal value As String)
      ltrName.Text = value
    End Set
  End Property

  Public Property OfferPrice() As String
    Get
      If ViewState(Me.ID & "_OfferPrice") Is Nothing Then
        Return "$0.00"
      Else
        Return CType(ViewState(Me.ID & "_OfferPrice"), String)
      End If
    End Get

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

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

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

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

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

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

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

  Public Property OfferContent() As String
    Get
      Return ltrContent.Text
    End Get

    Set(ByVal value As String)
      ltrContent.Text = value
    End Set
  End Property

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    'ltrContent.Text = String.Format("ControlID:{0};OwnerID:{1};OwnerType:{2}", ContentControlID, OfferID, OfferType)	'ContentManager.Instance.GetContent(ContentControlID, OfferID, OfferType)
    'ltrContent.Text = ContentManager.Instance.GetContent(ContentControlID, OfferID, OfferType)
    lnkLearnMore.NavigateUrl = String.Format("../Order/AffiliateOfferDetail.aspx?{0}={1}", QueryStringName.OfferID, OfferID)
    aAddToCart.HRef = String.Format("javascript:addItem({0});", OfferID)

  End Sub

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


        aAddToCart.Visible = False
    aChat.Visible = False
    spanAlreadyIn.Visible = False


        If IsAvailable Then
            If IsExistingCustomer Then
                If OfferType = OwnerType.Bundle Then
                    aChat.Visible = True
                Else
                    If Existing Then
                        aChat.Visible = True
                    Else
                        aAddToCart.Visible = True
                    End If
                End If
            Else
                aAddToCart.Visible = True
            End If
        Else
            spanAlreadyIn.Visible = True
        End If

    ltrPrice.Text = FormatPrice(OfferPrice)

    lblOfferID.Text = OfferID
  End Sub

  Private Function FormatPrice(ByVal s As String) As String
    Return String.Format("{0}<sup>{1}</sup>", s.Substring(0, s.Length - 3), s.Substring(s.Length - 2))
  End Function

End Class

