Imports System
Imports System.Net
Imports System.Data

Partial Class Visitors_Chat
    Inherits CharterCMSPage

    Dim chatmapping As String
    Dim orderID As String
    Dim userfname As String = ""
    Dim phone As String = ""
    Dim mailaddress As String = ""
    Dim userlname As String = ""
    Dim reformatPhone As String = ""
    ' issue 25578
    Private Const cPricingOrderServices As String = "20955"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        '#####################################################################
        ' MODIFICATION   Jonathan Parks    July 3, 2008
        '#####################################################################
        ' The Chat.aspx page should now just redirect to the new ChatLive.aspx
        ' page and pass any and all querystring parameters
        '#####################################################################

        Dim qs As String = ""

        For Each qsItem As String In Request.QueryString
            If qs.Length > 0 Then
                qs &= "&" & qsItem & "=" & Request.QueryString(qsItem)
            Else
                qs = qsItem & "=" & Request.QueryString(qsItem)
            End If
        Next

        Response.Redirect("../Visitors/ChatLive.aspx?" & qs, False)

        'SetPageTitle("Chat")
        'Dim _item As MenuItem

        'If Not Page.IsPostBack Then
        '    chatmapping = Request.QueryString("Chattype")
        '    orderID = Request.QueryString("orderID")
        '    If (chatmapping IsNot Nothing) Then
        '        If chatmapping.ToUpper() <> "CHATWINDOW" Then
        '            If orderID IsNot Nothing Then
        '                userfname = Request.QueryString("user")
        '                phone = Request.QueryString("phone")
        '                reformatPhone = Left(phone, 3) & "-" & Mid(phone, 4, 3) & "-" & Right(phone, 4)
        '                phone = reformatPhone
        '                mailaddress = Request.QueryString("mail")
        '                mailaddress = mailaddress.Replace(" ", "")
        '                userlname = Request.QueryString("lname")
        '                fnChatOrder()
        '            Else
        '                fnChat()
        '            End If
        '        Else
        '            If Request.QueryString(QueryStringName.MenuItem) IsNot Nothing Then
        '                _item = CType(Request.QueryString(QueryStringName.MenuItem), MenuItem)
        '            End If
        '        End If
        '    End If

        'End If
    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        Dim client As WebClient = New WebClient()
        'Dim category As String
        Dim chatType As String
        'Dim strBSN As String = "0"
        Dim strDepartmentNumber As String = ""

        chatType = rblChatAbout.SelectedItem.ToString()
        If Not chatType Is Nothing Then
            If (chatType = "Cable TV") Then
                chatmapping = "DIGCABLE"
                strDepartmentNumber = "20957"
            ElseIf (chatType = "High-Speed Internet") Then
                chatmapping = "HSI"
                strDepartmentNumber = "20956"
            ElseIf (chatType = "Telephone") Then
                chatmapping = "TELEPHONE"
                strDepartmentNumber = "21175"
            ElseIf (chatType = "Sales") Then
                chatmapping = "SALES"
                strDepartmentNumber = cPricingOrderServices 'CHANGE REQUEST MADE BY DCLEGG 2-25-2008 ISSUE ID 3373
            ElseIf (chatType = "Account & Billing") Then
                strDepartmentNumber = "20957" 'CHANGE REQUEST MADE BY DCLEGG 2-25-2008 ISSUE ID 3373
                chatmapping = "BILLING"
            End If

            'BuildInstantServicePlaceHolder(strDepartmentNumber)
            'BuildInstantServiceScript()

            Response.Redirect("../Visitors/ChatForm.aspx?d=" & strDepartmentNumber, False)

            'Dim _actualCategory = _catgr.ToString()
            'If Not category Is Nothing Then
            'If category.Contains("<NONE>") Then
            '    Dim sb As New StringBuilder("<script type=""text/javascript"" language=""javascript"">")
            '    sb.Append("alert('We are sorry, but chat is not available at this time. Please call 1-888-GET CHARTER  (1-888-438-2427) for assistance.');")
            '    sb.Append("window.close();")
            '    sb.Append("</script>")
            '    Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "CHATSCRIPT", sb.ToString())
            'Else
            '    'Response.Redirect("https://charterlive.chartercom.com/wcscgi/CDM.exe/default/english?SS_COMMAND=CUST_SUP&Category=" & _actualCategory & "&mode=FullWindow")
            'End If
            'End If
        End If
    End Sub

    Private Sub fnChat()
        Dim client As WebClient = New WebClient()
        'Dim category As String
        'Dim strBSN As String = "0"
        Dim pDepartmentNumber As String = ""

        Try

            Select Case chatmapping.ToUpper()
                Case Is = "Q_21175"
                    '#####################################################################
                    '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.
                    '#####################################################################
                    pDepartmentNumber = "21175"
                Case Is = "Q_20956"
                    '#####################################################################
                    '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.
                    '#####################################################################
                    pDepartmentNumber = "20956"
                Case Is = "Q_21193"
                    '#####################################################################
                    '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.
                    '#####################################################################
                    pDepartmentNumber = "21193"
                Case Is = "Q_21853"
                    '#####################################################################
                    '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.
                    '#####################################################################
                    pDepartmentNumber = cPricingOrderServices
                Case Is = "Q_20957"
                    '#####################################################################
                    '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.
                    '#####################################################################
                    pDepartmentNumber = "20957"
                Case Is = "SALES_Q_21790"
                    '#####################################################################
                    'MODIFICATION   ROD COPELAND    FEB 13, 2008    ISSUE ID 3301
                    '#####################################################################
                    '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.
                    '#####################################################################
                    pDepartmentNumber = "21790"
                Case Is = "SALES_Q_21791"
                    pDepartmentNumber = "21791"
                Case Is = "SALES_Q_21792"
                    pDepartmentNumber = "21792"
                    '#####################################################################

                Case Is = "SALES"
                    pDepartmentNumber = cPricingOrderServices
                Case Is = "DIGCABLE"
                    pDepartmentNumber = "20957"
                Case Is = "HSI"
                    pDepartmentNumber = "20956"
                Case Is = "TELEPHONE"
                    pDepartmentNumber = "21175"
                Case Is = "BILLING"
                    pDepartmentNumber = "20956"
                Case Else
                    pDepartmentNumber = "20957"
            End Select

            Response.Redirect("../Visitors/ChatForm.aspx?d=" & pDepartmentNumber, False)

        Catch ex As Exception
        Finally
            client = Nothing
        End Try

    End Sub

    Private Sub fnChatOrder()
        Dim client As WebClient = New WebClient()
        'Dim strBSN As String = "0"
        Dim pDepartmentNumber As String = ""

        Try
            'It was decided that chat type needs to be "ORDER" for Order complete page alone to bring up a different UI
            chatmapping = "ORDER"
            pDepartmentNumber = cPricingOrderServices

            Response.Redirect("../Visitors/ChatForm.aspx?d=" & pDepartmentNumber & "&u=" & userfname & "&ln=" & userlname & "&p=" & phone & "&m=" & mailaddress & "&o=" & Left(orderID, 15), False)


        Catch ex As Exception
        Finally
            client = Nothing
        End Try

    End Sub

    Private Sub BuildInstantServiceScript()
        Dim sb As New StringBuilder

        sb.Append("<script language=""JavaScript"">")
        sb.Append("<!--")
        sb.Append("" & vbCrLf)
        sb.Append("function agents_available() {")
        'sb.Append("document.getElementById('smartbutton').innerHTML = '<A HREF=""#"" onClick=""window.navigate(\'https://www.yourserver.com/advanced_customer_form.html\',\'custclient\',\'width=500,height=320,scrollbars=0\');return false;"">Dave was Here</A>';")
        sb.Append("document.getElementById('smartbutton').innerHTML = 'Chat is available" & vbCrLf)
        sb.Append("window.location.href=""../Visitors/ChatForm.aspx?id=1234"" " & vbCrLf)
        sb.Append("return true;} ")

        sb.Append("" & vbCrLf)
        sb.Append("function agents_not_available() { ")
        sb.Append("document.getElementById('smartbutton').innerHTML = 'Chat Queue Not available';")
        sb.Append("alert('We are sorry, but chat is not available at this time. Please call 1-888-GET CHARTER  (1-888-438-2427) for assistance.');")
        sb.Append("return true; }")
        sb.Append("//-->")
        sb.Append("</script>")

        Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "InstantServiceScript", sb.ToString())


    End Sub

    Private Sub BuildInstantServicePlaceHolder(ByVal iDepartmentNumber As String)
        Dim sb As New StringBuilder

        sb.Append("<script language=""JavaScript"">document.write('<img src=""https://admin.instantservice.com/resources/smartbutton/6092/" & iDepartmentNumber & "/available.gif?'+Math.floor(Math.random()*10001)+'"" style=""width:0;height:0;visibility:hidden;position:absolute;"" onLoad=""agents_available()"" onError=""agents_not_available()"">');</script><div id=""smartbutton""></div>")
        Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "InstantServicePlaceholder", sb.ToString())

    End Sub
End Class
