Imports CharterDotCom.CommonEntities.Library
Imports CharterDotCom.CommonEntities.Library.Common
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 CharterDotCom.WebSite.Library.BLCommon
Imports System.Web
Imports System.Net
' Imports CharterDotCom.Common.Logging

Partial Class Visitors_ContactUs
    Inherits CharterCMSPage

    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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Logger.WebLog("\UI\Customers\ContactUs")

        MyBase.SetTemplate(5)
        Dim _contactUs As ContactUsMode
        Dim _folderID As Integer
        Dim _folder As IDocumentFolder
        If Not Page.IsPostBack Then

            ddlState.DataSource = CType(Application(ApplicationKey.StateList), System.Data.DataTable)
            ddlState.DataTextField = "Name"
            ddlState.DataValueField = "Abbv"
            ddlState.DataBind()
            ddlState.Items.Insert(0, New ListItem(String.Empty, String.Empty))

            Dim flag1 As Boolean = False
            Dim flag2 As Boolean = False

            Dim startTime As DateTime = Context.Application("startTimeKey")
            Dim endTime As DateTime = Context.Application("endTimeKey")

            Dim presentTime As String = DateTime.Now.ToString("t")

            If DateTime.Compare(DateTime.Parse(endTime), DateTime.Parse(presentTime)) > 0 Then
                flag1 = True
                'Page.Response.Write("Current Time is greater <br>")
            Else
                flag1 = False
                'Page.Response.Write("Current Time is smaller")
            End If
            If DateTime.Compare(DateTime.Parse(startTime), DateTime.Parse(presentTime)) < 0 Then
                flag2 = True
            Else
                flag2 = False
            End If
            If (flag1 And flag2) Then
                pnlOption4.Visible = False
                'pnlOption3.Visible = False
            End If




            '###############################################################
            Dim d As DateTime = CachedControls.getExpireDate()

            If HttpContext.Current.Cache.Item("Template5") Is Nothing Then
                HttpContext.Current.Cache.Insert("Template5", DateTime.Now, Nothing, d, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
            End If

            Response.AddCacheItemDependency("Template5") 'CacheKey.OutputCacheDurationKey)

            If Application(Request.Url.LocalPath) Is Nothing Then
                Application.Add(Request.Url.LocalPath, "Template5")
            End If
            '###############################################################

            _folderID = CType(System.Configuration.ConfigurationManager.AppSettings(AppSettingKey.SupprtFAQHomePage), Integer)
            '_folder = SiteManager.Instance.GetFolderDocuments(_folderID)
            'ucFrequentQuestions.Folder = _folder
            'ucFrequentQuestions.Visible = True


            'ucHeader.SelectedItem = MenuItem.Unspecified

            vldSummaryContact.ValidationGroup = "Send"

            spanPrice.Visible = False
            'spanSupport.Visible = False
            spanQuestion.Visible = False
            spanSupportBilling.Visible = False
            spanSupportCableTV.Visible = False
            spanSupportHSI.Visible = False
            spanSupportTelephone.Visible = False
            spanASAPrice.Visible = False
            spanASASupportBilling.Visible = False
            spanASASupportCableTV.Visible = False
            spanASASupportHSI.Visible = False
            spanASASupportTelephone.Visible = False


            pnlBefore.Visible = True
            pnlAfter.Visible = False
            pnlAfter1.Visible = False
            pnlContact.Visible = False
            pnlContactAfter.Visible = False

            pnlASAOptions.Visible = False
            pnlNonASAOptions.Visible = False



            ucContactUs.ContentKey = "ContactUs"


            If Request.QueryString(QueryStringName.ContactUs) IsNot Nothing Then
                _contactUs = CType(Request.QueryString(QueryStringName.ContactUs), ContactUsMode)

                Select Case _contactUs
                    Case ContactUsMode.Price
                        ucContactUs.ContentKey = "ContactUs:Price"
                    Case ContactUsMode.Support
                        ucContactUs.ContentKey = "ContactUs:Support"
                    Case ContactUsMode.Question
                        ucContactUs.ContentKey = "ContactUs:Question"
                    Case ContactUsMode.Contact
                        ucContactUs.ContentKey = "ContactUs:Contact"
                    Case ContactUsMode.Billing
                        ucContactUs.ContentKey = "ContactUs:Billing"
                    Case ContactUsMode.SupportCableTV
                        ucContactUs.ContentKey = "ContactUs:Support:Cable"
                    Case ContactUsMode.SupportHSI
                        ucContactUs.ContentKey = "ContactUs:Support:HSI"
                    Case ContactUsMode.SupportTelephone
                        ucContactUs.ContentKey = "ContactUs:Support:Telephone"
                    Case Else
                        ucContactUs.ContentKey = "ContactUs"
                End Select
            End If




            'If Request.QueryString(QueryStringName.ContactUs) IsNot Nothing Then
            '    _contactUs = CType(Request.QueryString(QueryStringName.ContactUs), ContactUsMode)

            '    Select Case _contactUs
            '        Case ContactUsMode.Price

            '            lblTitle.Text = "For prices or to order services..."
            '            'freq.Visible = False
            '            spanPrice.Visible = True
            '            spanASAPrice.Visible = True
            '            trSubject.Visible = True
            '            pnlNonASAOptions.Visible = True

            '            ddlSubject.Items.Clear()
            '            ddlSubject.Items.Add("")
            '            ddlSubject.Items.Add("Bundled Services")
            '            ddlSubject.Items.Add("Cable TV")
            '            ddlSubject.Items.Add("High-Speed Internet")
            '            ddlSubject.Items.Add("Telephone")
            '            ddlSubject.Items.Add("High-Definition TV (HDTV)")
            '            ddlSubject.Items.Add("Digital Video Recorder (DVR)")
            '            ddlSubject.Items.Add("Pay-Per-View")
            '            ddlSubject.Items.Add("Video On Demand")

            '            pnlBefore.Visible = False
            '            pnlAfter.Visible = True

            '            '#####################################################################
            '            'MODIFICATION   ROD COPELAND    FEB 25, 2008    ISSUE ID 3373
            '            '#####################################################################
            '            'IT LOOKS LIKE THE BUSINESS HAS ADDED SOME NEW QUEUES THAT DIDNT 
            '            'EXIST AT THE TIME OF THE ASA CHAT ROLLOUT.  THE ISSUE ID HAS 
            '            'PROVIDED SPECIFIC URLS THAT SHOULD ROUTE TRAFFIC TO THE NEW QUEUES.
            '            '#####################################################################
            '            '_chatcategory = "SALES"
            '            _chatcategory = "Q_21853"

            '            ucBrowseSupport.Productategory = MenuItem.Home



            '            '#######################################################################
            '            'MODIFICATION   ROD COPELAND    6/24/2009   ISSUE ID 6496
            '            '#######################################################################
            '            'HIDE THE CONTACT US - EMAIL SUBMIT FORM OPTION FROM THE PAGE. 
            '            '#######################################################################
            '            If Not (Application("ContactUsEmailForm_ENABLED") Is Nothing) Then
            '                If Application("ContactUsEmailForm_ENABLED").ToString().Trim().ToLower() = "t" Then
            '                    pnlOption4.Visible = False
            '                    pnlOption4Description2.Visible = False
            '                Else
            '                    pnlOption4.Visible = True
            '                    pnlOption4Description2.Visible = True
            '                End If
            '            Else
            '                pnlOption4.Visible = True
            '                pnlOption4Description2.Visible = True
            '            End If
            '            '#######################################################################




            '        Case ContactUsMode.SupportCableTV

            '            lblTitle.Text = "For Cable TV product support & repairs"

            '            spanSupportCableTV.Visible = True
            '            spanASASupportCableTV.Visible = True
            '            pnlASAOptions.Visible = True

            '            trSubject.Visible = True
            '            ddlSubject.Items.Clear()
            '            ddlSubject.Items.Add("Cable")
            '            'ddlSubject.Items.Add("")
            '            'ddlSubject.Items.Add("Blank Screen With Sound")
            '            'ddlSubject.Items.Add("Connection Diagrams")
            '            'ddlSubject.Items.Add("DVR Troubleshooting")
            '            'ddlSubject.Items.Add("No Sound")
            '            'ddlSubject.Items.Add("Recent Cable Statement Changes")
            '            'ddlSubject.Items.Add("Remote Control User Guides")
            '            'ddlSubject.Items.Add("Snowy Picture")
            '            'ddlSubject.Items.Add("TV Not Working")
            '            'ddlSubject.Items.Add("TV Reception Problems")
            '            'ddlSubject.Items.Add("Other Cable Inquiries")

            '            pnlBefore.Visible = False
            '            pnlAfter.Visible = True


            '            '#####################################################################
            '            'MODIFICATION   ROD COPELAND    FEB 25, 2008    ISSUE ID 3373
            '            '#####################################################################
            '            'IT LOOKS LIKE THE BUSINESS HAS ADDED SOME NEW QUEUES THAT DIDNT 
            '            'EXIST AT THE TIME OF THE ASA CHAT ROLLOUT.  THE ISSUE ID HAS 
            '            'PROVIDED SPECIFIC URLS THAT SHOULD ROUTE TRAFFIC TO THE NEW QUEUES.
            '            '#####################################################################
            '            '_chatcategory = "DIGCABLE"
            '            _chatcategory = "Q_20957"

            '            ucBrowseSupport.Productategory = MenuItem.CableTV

            '            '#######################################################################
            '            'MODIFICATION   ROD COPELAND    10/30/2009   ISSUE ID 7515
            '            '#######################################################################
            '            'HIDE THE CONTACT US - EMAIL SUBMIT FORM OPTION FROM THE PAGE. 
            '            '#######################################################################
            '            If Not (Application("ContactUsEmailForm_ENABLED") Is Nothing) Then
            '                If Application("ContactUsEmailForm_ENABLED").ToString().Trim().ToLower() = "t" Then
            '                    pnlOption4.Visible = False
            '                    pnlOption4Description1.Visible = False
            '                Else
            '                    pnlOption4.Visible = True
            '                    pnlOption4Description1.Visible = True
            '                End If
            '            Else
            '                pnlOption4.Visible = True
            '                pnlOption4Description1.Visible = True
            '            End If
            '            '#######################################################################

            '        Case ContactUsMode.SupportHSI

            '            lblTitle.Text = "For Internet product support & repairs"

            '            spanSupportHSI.Visible = True
            '            spanASASupportHSI.Visible = True
            '            pnlASAOptions.Visible = True

            '            trSubject.Visible = True
            '            ddlSubject.Items.Clear()
            '            ddlSubject.Items.Add("")
            '            ddlSubject.Items.Add("Internet")
            '            ddlSubject.Items.Add("Email")
            '            ddlSubject.Items.Add("Charter Security Suite")
            '            'ddlSubject.Items.Add("Cannot Login")
            '            'ddlSubject.Items.Add("E-Mail Not Working")
            '            'ddlSubject.Items.Add("E-Mail Setup")
            '            'ddlSubject.Items.Add("Internet Not Working")
            '            'ddlSubject.Items.Add("Recent Internet Statement Changes")
            '            'ddlSubject.Items.Add("Security Suite Installation")
            '            'ddlSubject.Items.Add("Slow Internet Connection")
            '            'ddlSubject.Items.Add("Web Mail Quick Hits")
            '            'ddlSubject.Items.Add("Other Internet Inquiries")

            '            pnlBefore.Visible = False
            '            pnlAfter.Visible = True


            '            '#####################################################################
            '            'MODIFICATION   ROD COPELAND    FEB 25, 2008    ISSUE ID 3373
            '            '#####################################################################
            '            'IT LOOKS LIKE THE BUSINESS HAS ADDED SOME NEW QUEUES THAT DIDNT 
            '            'EXIST AT THE TIME OF THE ASA CHAT ROLLOUT.  THE ISSUE ID HAS 
            '            'PROVIDED SPECIFIC URLS THAT SHOULD ROUTE TRAFFIC TO THE NEW QUEUES.
            '            '#####################################################################
            '            '_chatcategory = "HSI"
            '            _chatcategory = "Q_20956"

            '            ucBrowseSupport.Productategory = MenuItem.Internet



            '            '#######################################################################
            '            'MODIFICATION   ROD COPELAND    6/24/2009   ISSUE ID 6496
            '            '#######################################################################
            '            'HIDE THE CONTACT US - EMAIL SUBMIT FORM OPTION FROM THE PAGE. 
            '            '#######################################################################
            '            If Not (Application("ContactUsEmailForm_ENABLED") Is Nothing) Then
            '                If Application("ContactUsEmailForm_ENABLED").ToString().Trim().ToLower() = "t" Then
            '                    pnlOption4.Visible = False
            '                    pnlOption4Description1.Visible = False
            '                Else
            '                    pnlOption4.Visible = True
            '                    pnlOption4Description1.Visible = True
            '                End If
            '            Else
            '                pnlOption4.Visible = True
            '                pnlOption4Description1.Visible = True
            '            End If
            '            '#######################################################################




            '        Case ContactUsMode.SupportTelephone

            '            lblTitle.Text = "For Telephone product support & repairs"
            '            spanSupportTelephone.Visible = True
            '            spanASASupportTelephone.Visible = True
            '            pnlASAOptions.Visible = True

            '            'spanCharter.Visible = False
            '            'spanTelephone.Visible = True
            '            trSubject.Visible = True
            '            ddlSubject.Items.Clear()
            '            ddlSubject.Items.Add("Repair and Support")
            '            'ddlSubject.Items.Add("")
            '            'ddlSubject.Items.Add("Call Features")
            '            'ddlSubject.Items.Add("Telephone Call Details")
            '            'ddlSubject.Items.Add("Recent Telephone Statement Changes")
            '            'ddlSubject.Items.Add("Telephone Not Working")
            '            'ddlSubject.Items.Add("Voicemail")
            '            'ddlSubject.Items.Add("Other Telephone Inquiries")

            '            pnlBefore.Visible = False
            '            pnlAfter.Visible = True


            '            '#####################################################################
            '            'MODIFICATION   ROD COPELAND    FEB 25, 2008    ISSUE ID 3373
            '            '#####################################################################
            '            'IT LOOKS LIKE THE BUSINESS HAS ADDED SOME NEW QUEUES THAT DIDNT 
            '            'EXIST AT THE TIME OF THE ASA CHAT ROLLOUT.  THE ISSUE ID HAS 
            '            'PROVIDED SPECIFIC URLS THAT SHOULD ROUTE TRAFFIC TO THE NEW QUEUES.
            '            '#####################################################################
            '            '_chatcategory = "TELEPHONE"
            '            _chatcategory = "Q_21175"

            '            ucBrowseSupport.Productategory = MenuItem.Telephone


            '            '#######################################################################
            '            'MODIFICATION   ROD COPELAND    10/30/2009   ISSUE ID 7515
            '            '#######################################################################
            '            'HIDE THE CONTACT US - EMAIL SUBMIT FORM OPTION FROM THE PAGE. 
            '            '#######################################################################
            '            If Not (Application("ContactUsEmailForm_ENABLED") Is Nothing) Then
            '                If Application("ContactUsEmailForm_ENABLED").ToString().Trim().ToLower() = "t" Then
            '                    pnlOption4.Visible = False
            '                    pnlOption4Description1.Visible = False
            '                Else
            '                    pnlOption4.Visible = True
            '                    pnlOption4Description1.Visible = True
            '                End If
            '            Else
            '                pnlOption4.Visible = True
            '                pnlOption4Description1.Visible = True
            '            End If
            '            '#######################################################################
            '        Case ContactUsMode.Question

            '            'pnlAfter1.Visible = True
            '            pnlAfter1.Visible = False

            '            'lblTitle.Text = "For other questions, comments, suggestions..."
            '            'freq.Visible = False
            '            trSubject.Visible = False

            '            ddlSubject.Items.Clear()
            '            ddlSubject.Items.Add("")
            '            ddlSubject.Items.Add("Call Center Comment")
            '            ddlSubject.Items.Add("Installation/Repair Comment")
            '            ddlSubject.Items.Add("Product Comment")
            '            ddlSubject.Items.Add("Policies Comment")
            '            ddlSubject.Items.Add("Website Comment")
            '            ddlSubject.Items.Add("Channel Addition Request")
            '            ddlSubject.Items.Add("Event Addition Request")

            '            pnlBefore.Visible = False
            '            pnlAfter.Visible = False
            '            _chatcategory = "CHATWINDOW"
            '            ucBrowseSupport.Productategory = MenuItem.Support






            '        Case ContactUsMode.Billing

            '            lblTitle.Text = "For Billing and My Account questions"
            '            'freq.Visible = False
            '            spanSupportBilling.Visible = True
            '            spanASASupportBilling.Visible = True
            '            pnlASAOptions.Visible = True

            '            'trSubject.Visible = True


            '            ddlSubject.Items.Clear()
            '            ddlSubject.Items.Add("")
            '            ddlSubject.Items.Add("Billing")
            '            'ddlSubject.Items.Add("Cable")
            '            'ddlSubject.Items.Add("Internet")
            '            'ddlSubject.Items.Add("Recent Statement Changes")
            '            'ddlSubject.Items.Add("Telephone Billing")
            '            ddlSubject.Items.Add("Telephone Billing Questions")
            '            ddlSubject.Items.Add("Other My Account Inquiries")


            '            pnlBefore.Visible = False
            '            pnlAfter.Visible = True



            '            '#######################################################################
            '            'MODIFICATION   ROD COPELAND    6/24/2009   ISSUE ID 6496
            '            '#######################################################################
            '            'HIDE THE CONTACT US - EMAIL SUBMIT FORM OPTION FROM THE PAGE. 
            '            '#######################################################################
            '            If Not (Application("ContactUsEmailForm_ENABLED") Is Nothing) Then
            '                If Application("ContactUsEmailForm_ENABLED").ToString().Trim().ToLower() = "t" Then
            '                    pnlOption4.Visible = False
            '                    pnlOption4Description1.Visible = False
            '                Else
            '                    pnlOption4.Visible = True
            '                    pnlOption4Description1.Visible = True
            '                End If
            '            Else
            '                pnlOption4.Visible = True
            '                pnlOption4Description1.Visible = True
            '            End If
            '            '#######################################################################




            '            '#####################################################################
            '            'MODIFICATION   ROD COPELAND    FEB 25, 2008    ISSUE ID 3373
            '            '#####################################################################
            '            'IT LOOKS LIKE THE BUSINESS HAS ADDED SOME NEW QUEUES THAT DIDNT 
            '            'EXIST AT THE TIME OF THE ASA CHAT ROLLOUT.  THE ISSUE ID HAS 
            '            'PROVIDED SPECIFIC URLS THAT SHOULD ROUTE TRAFFIC TO THE NEW QUEUES.
            '            '#####################################################################
            '            '_chatcategory = "CHATWINDOW"
            '            _chatcategory = "Q_20957"
            '            ucBrowseSupport.Productategory = MenuItem.MyAccount

            '        Case ContactUsMode.Contact
            '            'freq.Visible = False
            '            pnlBefore.Visible = False
            '            pnlContact.Visible = True

            '            '#####################################################################
            '            'MODIFICATION   ROD COPELAND    FEB 25, 2008    ISSUE ID 3373
            '            '#####################################################################
            '            'IT LOOKS LIKE THE BUSINESS HAS ADDED SOME NEW QUEUES THAT DIDNT 
            '            'EXIST AT THE TIME OF THE ASA CHAT ROLLOUT.  THE ISSUE ID HAS 
            '            'PROVIDED SPECIFIC URLS THAT SHOULD ROUTE TRAFFIC TO THE NEW QUEUES.
            '            '#####################################################################
            '            '_chatcategory = "CHATWINDOW"
            '            _chatcategory = "Q_21193"
            '            ucBrowseSupport.Productategory = MenuItem.Support
            '    End Select
            'End If
        End If
    End Sub


    Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSend.Click
        Dim _subject As String
        Dim _emailQueue As String


        '########################################################
        'MODIFICATION   ROD COPELAND    ISSUES ID 5679
        'Per Dan Clegg, Route ALL emails to Email Queue = 21327 
        '########################################################
        _emailQueue = "21327"
        '########################################################



        _subject = Server.UrlEncode(ddlSubject.SelectedItem.Text)

        Dim sb As New StringBuilder
        Dim encoding As New System.Text.ASCIIEncoding

        sb.Append("ai=6092&di=" & _emailQueue & "&fromaddr=" & Server.UrlEncode(txtEmail.Text) & "&subject=" & _subject & "&mailmessagetext=" & Server.UrlEncode(txtMessage.Text))
        sb.Append("&fname=" & Server.UrlEncode(txtFirstName.Text) & "&lname=" & Server.UrlEncode(txtLastName.Text) & "&email=" & Server.UrlEncode(txtEmail.Text))
        ' Jonathan Parks - Issue #4421
        ' added the following querystring parameters to pass to instantservice
        sb.Append("&phone=" & Server.UrlEncode(txtTelephone.Text) & "&optionaldata1=" & Server.UrlEncode(txtStreetAddress.Text) & "&optionaldata2=" & Server.UrlEncode(txtCity.Text))
        sb.Append("&optionaldata3=" & Server.UrlEncode(ddlState.SelectedItem.Value) & "&optionaldata4=" & Server.UrlEncode(txtZipcode.Text))

        Dim data As Byte() = encoding.GetBytes(sb.ToString)

        Dim MyRequest As System.Net.HttpWebRequest = HttpWebRequest.Create("https://admin.instantservice.com/servlet/MailMessagePost")

        MyRequest.Method = "POST"
        MyRequest.ContentType = "application/x-www-form-urlencoded"
        MyRequest.ContentLength = data.Length

        Dim newstream As System.IO.Stream = MyRequest.GetRequestStream
        newstream.Write(data, 0, data.Length)
        newstream.Close()

        Dim myResponse As WebResponse
        Dim strResponse As System.IO.Stream
        Dim strResult As String
        myResponse = MyRequest.GetResponse

        With myResponse
            '-- read the response into byte array 
            Dim strArr(100) As Byte
            strResponse = myResponse.GetResponseStream
            strResponse.Read(strArr, 0, strArr.Length)
            strResponse.Close()

            '-- convert response to string 
            strResult = encoding.GetString(strArr).Trim
            '-- parse response 

        End With

        'If SiteManager.Instance.ContactUsByEmail(txtFirstName.Text, txtLastName.Text, txtStreetAddress.Text, txtCity.Text, ddlState.SelectedItem.ToString(), txtZipcode.Text, txtTelephone.Text, txtEmail.Text, _subject, txtMessage.Text) Then
        If InStr(strResult, "100") > 0 Then ' success!
            pnlAfter.Visible = False
            pnlContactAfter.Visible = True
        Else ' fail!
            Throw New CharterBLException("ContactUsByEmail failed - Instant Service return code: " & strResult)
        End If
    End Sub

    Protected Sub ucSearch_SearchSiteAgain() Handles ucSearch.SearchSite
        Response.Redirect(String.Format("../Visitors/SearchSite.aspx?{0}={1}", QueryStringName.Criteria, ucSearch.Criteria))
    End Sub

    Protected Sub btnSend1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSend1.Click

        If Page.IsValid Then

            If SiteManager.Instance.ContactUsByEmail(txtFirstName1.Text, txtLastName1.Text, "", "", "", "", txtTelephone1.Text, txtEmail1.Text, "Comments", txtMessage1.Text) Then
                pnlAfter1.Visible = False
                pnlContactAfter.Visible = True
            Else
                Throw New CharterBLException("ContactUsByEmail failed")
            End If
        End If
    End Sub

End Class
