Imports System
Imports System.Net
Imports System.Data

Partial Class Visitors_ChatForm
    Inherits CharterCMSPage

    Dim chatmapping As String
    Dim orderID As String
    Dim phone As String
    Dim mailaddress As String

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

        '#####################################################################
        ' Jonathan Parks    July 3, 2008
        '#####################################################################
        ' The ChatForm.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")

        ''###############################
        '' show two different 'intro' panels based on whether 
        '' an ORDER ID came across....
        ''###############################

        'If Request.QueryString("o") Is Nothing Then
        '    pnlORderVerbiage.Visible = False
        '    pnlRegularVerbiage.Visible = True
        'Else
        '    pnlORderVerbiage.Visible = True
        '    pnlRegularVerbiage.Visible = False
        '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 = "20955"
    '       '          End If

    '       BuildInstantServicePlaceHolder(strDepartmentNumber)
    '       BuildInstantServiceScript()


    '       '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
            'check availability of the queue
            Select Case chatmapping.ToUpper()
                '#####################################################################
                '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.
                '#####################################################################
                Case Is = "SALES_Q_21790"
                    pDepartmentNumber = "21790"
                Case Is = "SALES_Q_21791"
                    pDepartmentNumber = "21791"
                Case Is = "SALES_Q_21792"
                    pDepartmentNumber = "21792"
                    '#####################################################################

                Case Is = "SALES"
                    pDepartmentNumber = "20955"
                Case Is = "DIGCABLE"
                    pDepartmentNumber = "20957"
                Case Is = "HSI"
                    pDepartmentNumber = "20956"
                Case Is = "TELEPHONE"
                    pDepartmentNumber = "21175"
                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 category As String
    '    Dim strBSN As String = "0"

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

    '        category = client.DownloadString("https://charterlive.chartercom.com/wcsapp/weblib/charter/ProbQueueMapping.jsp?site=default&site=default&chat_type=" & chatmapping & "&bsn=" & strBSN & " &Format=CSV")
    '        Dim i As Integer
    '        Dim c As Char
    '        Dim _catgr As StringBuilder = New StringBuilder
    '        For i = 0 To category.Length - 1
    '            c = CType(category(i), Char)
    '            If Asc(c) >= 65 And Asc(c) <= 90 Or Asc(c) = 60 Or Asc(c) = 62 Then
    '                _catgr.Append(c)
    '            End If
    '        Next
    '        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 & "&orderID=" & orderID & "&user=" & user & "&phone=" & phone & "&mail=" & mailaddress & "&Prompt=Yes&AutoLogin=1&mode=FullWindow")
    '            End If
    '        End If
    '    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
