<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
 <% if (CLASS.MvcApplication.Eng)
                   { %>      
    On-fly text classification
                    <% }
                   else
                   { %>
        Классификация текста "на лету"
<%} %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

                <% if (CLASS.MvcApplication.Eng)
                   { %>      
    <h2>Enter text for on-fly classification:</h2>
    <div />
    <textarea id='ta1' style='width:100%; height:120px;'></textarea>
    <h2>Current classification:</h2>
                    <% }
                   else
                   { %>
    <h2>Вводите текст для динамической классификации:</h2>
    <div />
    <textarea id='Textarea1' style='width:100%; height:120px;'></textarea>
    <h2>Текущая классификация:</h2>

   <% } %>

    <div />
    <div id='res' style='border:1px solid #ddd; width:100%; height:420px; overflow:scroll;'></div>
    <script type="text/javascript">
        myload();
    </script>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MetaContent" runat="server">
    <script type="text/javascript">
        /*function aaa() {
        var ta1 = $("#ta1").val();
        $("#res").text(ta1);
        }

        jQuery(document).ready(function() {
        $("#res").click(aaa);
        });*/
        var xmlhttp = null;
        var content = " ";
        var t;
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else {
            alert("Your browser does not support XMLHTTP!");
        }

        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var obj = document.getElementById("res");
                obj.innerHTML = xmlhttp.responseText;
            }
        }

        function mychange() {
            var ta1 = document.getElementById("ta1");

            var txt = ta1.value;
            console.log(txt);
            if (txt != content) {
                content = txt;
                //if (txt.length % 30 == 29) {//alert(txt);
           //     if (txt[txt.length - 1] == ' ') {
                    xmlhttp.open("POST", "/Home/AnalyzeMin", true);
                    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    xmlhttp.send("text=" + txt);
            //    }
            }
            
        }
        function myload() {
            obj = document.getElementById("ta1");
            if (obj != null && obj.focus != null) obj.focus();

            if (obj != null) {
            //    obj.onkeyup = mychange;
            /*    if (obj.addEventListener) {
                    obj.addEventListener('input', mychange, false);
                } else if (obj.attachEvent) {
                    obj.attachEvent('onpropertychange', mychange);
                }
                obj.addEventListener('paste', function () { alert("paste"); }, false);
            */
                t = setInterval(mychange, 1000);
            } 
            //alert('my' + obj + "," + obj.onkeyup + "," + obj.value);
        }

        //myload();
    </script>
</asp:Content>
