<script type='text/javascript'>
    $(function() {
        $("a.vote_up").click(function() {
            //get the id
            the_id = $(this).attr('id');

            // show the spinner
            $(this).parent().html("<img src='images/spinner.gif'/>");

            //fadeout the vote-count 
            $("span#votes_count" + the_id).fadeOut("fast");

            //the main ajax request
            $.ajax({
                type: "POST",
                data: "action=vote_up&id=" + $(this).attr("id"),
                url: "/main/vote/",
                success: function(msg) {
                    $("span#votes_count" + the_id).html(msg);
                    //fadein the vote count
                    $("span#votes_count" + the_id).fadeIn();
                    //remove the spinner
                    $("span#vote_buttons" + the_id).remove();
                }
            });
        });

        $("a.vote_down").click(function() {
            //get the id
            the_id = $(this).attr('id');

            // show the spinner
            $(this).parent().html("<img src='/img/spinner.gif'/>");

            //the main ajax request
            $.ajax({
                type: "POST",
                data: "action=vote_down&id=" + $(this).attr("id"),
                url: "/main/vote/",
                success: function(msg) {
                    //	alert(the_id);
                    $("span#votes_count" + the_id).fadeOut();
                    $("span#votes_count" + the_id).html(msg);
                    $("span#votes_count" + the_id).fadeIn();
                    $("span#vote_buttons" + the_id).remove();

                }
            });
        });
    });

    $(function() {
        $("a.savecena").click(function() {
            //get the id
            quser = $(this).attr('id');
            //alert(the_id);
            // show the spinner
            //	$(this).parent().html("<img src='images/spinner.gif'/>");
            //fadeout the vote-count 
            //$("span#votes_count"+the_id).fadeOut("fast");
            //the main ajax request
            var qmoney = encodeURI(document.getElementById('cenaplus').value);


            $.ajax({
                type: "POST",
                data: "qid=<?=intval($this->uri->segment(2));?>&userid=" + quser + "&money=" + qmoney,
                url: "/main/moneychange/",
                success: function(msg) {
                    location.reload();
                }
            });


        });


    });
</script>

      
    $(document).ready(function() {
    
      $("#damb").click(function() {
            //document.getElementById('inputQuestionTextArea').value='';
            //document.getElementById('inputQuestionTextArea').value();
            //document.getElementById('inputQuestionTextArea').val='';
            var qdes = encodeURI(document.getElementById('deswysiwyg').value);

            $("#cena").show();
        });

        //deleteans
        $("a.deleteans").click(function() {
            //get the id
            qid = $(this).attr('id');
            //alert(quser);
            // show the spinner
            //	$(this).parent().html("<img src='images/spinner.gif'/>");
            //fadeout the vote-count 
            //$("span#votes_count"+the_id).fadeOut("fast");
            //the main ajax request
            //var qmoney = encodeURI(document.getElementById('cenaplus').value);

            $.ajax({
                type: "POST",
                data: "idans=" + qid,
                url: "/main/deleteans/",
                success: function(msg) {
                    location.reload();
                }
            });


        });


        $("#inputQuestionButton").click(function() {
            var qtext = encodeURI(document.getElementById('inputQuestionTextArea').value);
            var qdes = encodeURI(document.getElementById('deswysiwyg').value);

            document.getElementById('inputQuestionTextArea').value = '';
            $('#deswysiwyg').wysiwyg('clear');
            document.getElementById('mavn').innerHTML = "<b>Ваш вопрос добавлен!</b>";

            $.post("/main/add/", {
                name: qtext,
                des: qdes
            },

            function(data) {
                // alert("Data Loaded: " + data);
                // document.getElementById('inputQuestionTextArea').value)='';
                document.getElementById('mavn').innerHTML = data;
                //   location.href=data;
            });

        });

        $(".button").click(function() {
            var idString = $(this).attr("id");
            $('div#formasn' + idString).show();
            $('span#zl' + idString).click(function() {
                // $('textarea#wysiwyg').text;
                var texar = $('textarea#wysiwyg').val();


                //alert(texar);
                document.getElementById('mavn').innerHTML = "<b>Ваш вопрос добавляется!</b> ";
                $.post("/main/otvet/", {
                    answere: texar,
                    idq: idString
                },

                function(data) {
                    // alert("Data Loaded: " + data);
                    document.getElementById('mavn').innerHTML = 'Вопрос добавлен!';
                    $('#wysiwyg').wysiwyg('clear');
                    location.reload();
                });

            });


        });


        $(".xbutton").click(function() {
            var idString = $(this).attr("id");
            $.post("/main/uprating/", {
                id: idString
            },

            function(data) {
                //alert("Data Loaded: " + data);
            });
        });



        $(".bestotvet").click(function() {
            var id = $(this).attr("id");
            //alert(id);
            $.post("/main/bestotvet/", {
                best: id
            },

            function(data) {
                // document.getElementById('mavn').innerHTML =data;
            });
        })



    });
</script>