<commit_before>$(document).ready(function() {



var ACTIONPATH=MyHOSTNAME+"actions.php";


    function get_lang_param(par) {
        var result="";
        var zcode="";
        var url = window.location.href;

if (url.search("inc") >= 0) {
    zcode="../";
} 


        $.ajax({
            type: "POST",
            url: ACTIONPATH,
            data: "mode=get_lang_param"+
                "&param="+par,
            async: false,
            success: function(html){

                result=html;
            }
        });
        return (result);

    };


    $('textarea').autosize({append: "\n"});



    $('#my-select').multiSelect({
    });

    $("#spinner").hide();
    $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});

    var settingsShow = function() {
        var showPanel = $(".chosen-select").find('option:selected').attr('id');

    }
    $(".chosen-select").chosen({
        no_results_text: "Не знайдено...",
        allow_single_deselect: true,
    });
    $(".chosen-select").chosen().change(settingsShow);
    $.fn.editable.defaults.mode = 'inline';
    $("#user_info").hide();
    $("#alert_add").hide();

    $("#refer_to").hide();

function ispath(p1) {
var url = window.location.href;
var zzz=false;
if (url.search(p1) >= 0) {
    zzz=true;
}	
return zzz;
};



function whatpath() {
var url = window.location.href;
var zzz="";
if (url.search("inc") >= 0) {
    zzz="../";
} 	
return zzz;
};

    $("#fio").autocomplete({
        max: 10,
        minLength: 2,
        source: MyHOSTNAME+"/inc/json.php?fio",
        focus: function(event, ui) {
            $("#fio").val(ui.item.label);
            return false;
        },
        select: function(event, ui) {
            $("#fio").val(ui.item.label);
            $("#client_id_param").val(ui.item.value);
            $('#fio').popover('hide');
            $('#for_fio').removeClass('has-error').addClass('has-success');
            $("#user_info").hide().fadeIn(500);
            $("#alert_add").hide();
            $.ajax({
                type: "POST",
                url: ACTIONPATH,
                data: "mode=get_client_from_new_t&get_client_info=" + ui.item.value,
                success: function(html) {
                    $("#user_info").hide().html(html).fadeIn(500);
                    $('#edit_login').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто'
                    });
                    $('#edit_posada').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто',
                        mode: 'popup',
                        showbuttons: false
                    });				$('#edit_unit').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто',
                        mode: 'popup',
                        showbuttons: false
                    });				$('#edit_tel').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто'
                    });				$('#edit_adr').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто'
                    });				$('#edit_mail').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто'
                    });
                    $('#for_fio').addClass('has-success');
                    $("#status_action").val('edit');

                }
            });
            return false;
        },
        change: function(event, ui) {
            console.log(this.value);

            if ($('input#fio').val().length != 0){


                if (ui.item == null) {
                    $("#user_info").hide();
                    $("#status_action").val('add');
                    $('#fio').popover('hide');
                    $('#for_fio').removeClass('has-error');
                    $('#for_fio').addClass('has-success');

                    $.ajax({
                        type: "POST",
                        url: ACTIONPATH,
                        data: "mode=get_client_from_new_t&new_client_info="+$("#fio").val(),
                        success: function(html) {
                            $("#alert_add").hide().html(html).fadeIn(500);
                            $('#username').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто'
                            });
                            $('#new_login').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто'
                            });$('#new_posada').editable({
                                inputclass: 'input-sm posada_class',
                                emptytext: 'пусто',
                                mode: 'popup',
                                showbuttons: false
                            });
                            $('#new_unit').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто',
                                mode: 'popup',
                                showbuttons: false
                            });
                            $('#new_tel').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто'
                            });
                            $('#new_adr').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто'
                            });
                            $('#new_mail').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто'
                            });
                        }
                    });
                } else {
                }

            }



        }









    });
    $("select#to").blur(function() {

        if ( $('select#to').val() != 0 ){

            $('#for_to').popover('hide');
            $('#for_to').removeClass('has-error');
            $('#for_to').addClass('has-success');
        }
        else {

            $('#for_to').popover('show');
            $('#for_to').addClass('has-error');

        }

    });

    function createuserslist(unit_id) {


        $.ajax({
            type: "POST",
            url: ACTIONPATH,
            data: "mode=get_users_list"+
                "&unit="+unit_id,
            dataType: "json",
            success: function(html){
                $('select#users_do').empty();
                if (html) {
                    $.each(html, function(i, item) {
                        $('select#users_do')
                            .append($("<option></option>")
                                .attr("value",item.co)
                                .text(item.name));

                    });
                }
                $('select#users_do').trigger('chosen:updated');
            }

        });




    }


    $("select#to").change(function() {
        var i=$('select#to').val();
        if ( $('select#to').val() != 0 ){

            $('#for_to').popover('hide');
            $('#for_to').removeClass('has-error');
            $('#for_to').addClass('has-success');

            createuserslist(i);

        }
        else {

            $('#for_to').popover('show');
            $('#for_to').addClass('has-error');

        }

    });

    $("select#subj").change(function() {

        if ( $('select#subj').val() != 0 ){

            $('#for_subj').popover('hide');
            $('#for_subj').removeClass('has-error');
            $('#for_subj').addClass('has-success');
        }
        else {

            $('#for_subj').popover('show');
            $('#for_subj').addClass('has-error');

        }

    });

    $("select#subj").blur(function() {

        if ( $('select#subj').val() != 0 ){

            $('#for_subj').popover('hide');
            $('#for_subj').removeClass('has-error');
            $('#for_subj').addClass('has-success');
        }
        else {

            $('#for_subj').popover('show');
            $('#for_subj').addClass('has-error');

        }

    });





    $('textarea#msg').keydown(function (e) {

        if (e.ctrlKey && e.keyCode == 13) {


            $("button#do_comment").click();


        }
    });



    $("textarea#msg").blur(function() {
        if($(this).val().length > 1) {
            $("textarea#msg").popover('hide');
            $("#for_msg").removeClass('has-error').addClass('has-success');

        } else {
            $("textarea#msg").popover('show');
            $("#for_msg").addClass('has-error');
        }
    });

    $("textarea#msg").keypress(function() {
        if($(this).val().length > 1) {
            $("textarea#msg").popover('hide');
            $("#for_msg").removeClass('has-error').addClass('has-success');

        } else {
            $("textarea#msg").popover('show');
            $("#for_msg").addClass('has-error');
        }
    });


    var options_workers = {
        currentPage: $("#cur_page").val(),
        totalPages: $("#total_pages").val(),
        bootstrapMajorVersion: 3,
        size: "small",
        itemContainerClass: function (type, page, current) {
            return (page === current) ? "active" : "pointer-cursor";
        },
        onPageClicked: function(e,originalEvent,type,page){
            var current=$("#curent_page").attr('value');

            if (page != current) {

                $("#curent_page").attr('value', page);

                $.ajax({
                    type: "POST",
                    url: MyHOSTNAME+"inc/workers.inc.php",
                    data: "page="+page+
                        "&menu=list",
                    success: function(html){
                        $("#content_worker").hide().html(html).fadeIn(500);
                        $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                    }
                });
            }


        }

    }


    var options_in = {
        currentPage: $("#cur_page").val(),
        totalPages: $("#total_pages").val(),
        bootstrapMajorVersion: 3,
        size: "small",
        itemContainerClass: function (type, page, current) {
            return (page === current) ? "active" : "pointer-cursor";
        },
        onPageClicked: function(e,originalEvent,type,page){
            var current=$("#curent_page").attr('value');

            if (page != current) {

                $("#curent_page").attr('value', page);


                $("#spinner").fadeIn(300);

                $.ajax({
                    type: "POST",
                    url: MyHOSTNAME+"inc/list_content.inc.php",
                    data: "menu=in"+
                        "&page="+page,
                    success: function(html){
                        $("#content").hide().html(html).fadeIn(500);
                        $("#spinner").hide();
                        $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                    }
                });
            }


        }

    }
    var options_out = {
        currentPage: $("#cur_page").val(),
        totalPages: $("#total_pages").val(),
        bootstrapMajorVersion: 3,
        size: "small",
        itemContainerClass: function (type, page, current) {
            return (page === current) ? "active" : "pointer-cursor";
        },
        onPageClicked: function(e,originalEvent,type,page){
            var current=$("#curent_page").attr('value');

            if (page != current) {
                $("#spinner").fadeIn(300);
                $("#curent_page").attr('value', page);
                $.ajax({
                    type: "POST",
                    url: MyHOSTNAME+"inc/list_content.inc.php",
                    data: "menu=out"+
                        "&page="+page,
                    success: function(html){
                        $("#content").hide().html(html).fadeIn(500);
                        $("#spinner").hide();
                        $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                    }
                });
            }

        }

    }
    var options_arch = {
        currentPage: $("#cur_page").val(),
        totalPages: $("#total_pages").val(),
        bootstrapMajorVersion: 3,
        size: "small",
        itemContainerClass: function (type, page, current) {
            return (page === current) ? "active" : "pointer-cursor";
        },
        onPageClicked: function(e,originalEvent,type,page){
            var current=$("#curent_page").attr('value');

            if (page != current) {
                $("#curent_page").attr('value', page);
                $("#spinner").fadeIn(300);

                $.ajax({
                    type: "POST",
                    url: MyHOSTNAME+"inc/list_content.inc.php",
                    data: "menu=arch"+
                        "&page="+page,
                    success: function(html){
                        $("#content").hide().html(html).fadeIn(500);
                        $("#spinner").hide();
                        $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                    }
                });
            }


        }

    }

    $('#example_in').bootstrapPaginator(options_in);
    $('#example_out').bootstrapPaginator(options_out);
    $('#example_arch').bootstrapPaginator(options_arch);
    $('#example_workers').bootstrapPaginator(options_workers);



    $.ionSound({
        sounds: [
            "button_tiny"
        ]
    });


    var def_p = window.location.pathname.split("/");
    var def_filename = def_p[def_p.length-1];

    $.noty.defaults = {
        layout: 'top',
        theme: 'defaultTheme',
        type: 'information',
        text: '',
        dismissQueue: true,
        template: '<div class="noty_message"><button type="button" class="close" style="padding-left: 2px;margin-top: -5px;" aria-hidden="true">&times;</button><span class="noty_text"></span></div>',
        animation: {
            open: {height: 'toggle'},
            close: {height: 'toggle'},
            easing: 'swing',
            speed: 500
        },
        timeout: false,
        force: false,
        modal: false,
        maxVisible: 5,
        killer: false,
        closeWith: ['click'],
        callback: {
            onShow: function() {},
            afterShow: function() {},
            onClose: function() {},
            afterClose: function() {}
        },
        buttons: false
    };







    function check_update() {
        var ee=$("#main_last_new_ticket").val();
        var url = window.location.href;
		var zcode="";
if (url.search("inc") >= 0) {
    var zcode="../";
} 
        
        
        
        if (ee) {
            $.ajax({
                type: "POST",
                url: ACTIONPATH,
                data: "mode=check_update"+
                    "&type=all"+
                    "&last_update="+ee,
                success: function(html){
                    if (html == "no") {
                    }
                    else {
                        var new_lu=html;
                        $.ajax({
                            type: "POST",
                            url: ACTIONPATH,
                            data: "mode=list_ticket_update"+
                                "&last_update="+ee,
                            dataType: "json",
                            success: function(html){
                                if (html) {
                                    $.each(html, function(i, item) {
                                        var t='<div style=\'float: left;\'><a style=\'color: rgb(243, 235, 235); cursor: inherit;\' target=\'_blank\' href=\''+item.url+'/ticket?'+item.hash+'\'><strong>'+item.ticket+' #'+item.name+'</strong> </a></div><div style=\'float: right; padding-right: 10px;\'><small>'+item.time+'</small></div><br><hr style=\'margin-top: 5px; margin-bottom: 8px; border:0; border-top:0px solid #E4E4E4\'><a style=\'color: rgb(252, 252, 252); cursor: inherit;\' target=\'_blank\' href=\''+item.url+'/ticket?'+item.hash+'\'>'+item.at+'</a>';
                                        noty({
                                            text: t,
                                            layout: 'bottomRight',
                                            timeout: false
                                        });
                                        $.ionSound.play("button_tiny");
                                        $.titleAlert(item.up);
                                    });
                                }
                                $("#main_last_new_ticket").attr('value', new_lu);
                            }
                        });
                    }
                }});
        }
    };



    function check_update_index() {
        var ee=$("#main_last_new_ticket").val();
        if (ee) {
            $.ajax({
                type: "POST",
                url: ACTIONPATH,
                data: "mode=check_update"+
                    "&type=all"+
                    "&last_update="+ee,
                success: function(html){
                    if (html == "no") {
                    }
                    else {
                        var new_lu=html;
                        $.ajax({
                            type: "POST",
                            url: ACTIONPATH,
                            data: "mode=list_ticket_update"+
                                "&last_update="+ee,
                            dataType: "json",
                            success: function(html){
                                if (html) {
                                    $.each(html, function(i, item) {
                                        var t='<div style=\'float: left;\'><a style=\'color: rgb(243, 235, 235); cursor: inherit;\' target=\'_blank\' href=\''+item.url+'/ticket?'+item.hash+'\'><strong>'+item.ticket+' #'+item.name+'</strong> </a></div><div style=\'float: right; padding-right: 10px;\'><small>'+item.time+'</small></div><br><hr style=\'margin-top: 5px; margin-bottom: 8px; border:0; border-top:0px solid #E4E4E4\'><a style=\'color: rgb(252, 252, 252); cursor: inherit;\' target=\'_blank\' href=\''+item.url+'/ticket?'+item.hash+'\'>'+item.at+'</a>';
                                        noty({
                                            text: t,
                                            layout: 'bottomRight',
                                            timeout: false
                                        });
                                        $.ionSound.play("button_tiny");

                                        $.ajax({
                                            type: "POST",
                                            url: ACTIONPATH,
                                            data: "mode=last_news",
                                            success: function(html){
                                                $('#last_news').html(html);
                                                $('[data-toggle="tooltip"]').tooltip('hide');
                                                $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                                            }
                                        });
                                        $('#spinner').show();
                                        $.ajax({
                                            type: "POST",
                                            url: ACTIONPATH,
                                            data: "mode=dashboard_t",
                                            success: function(html){

                                                $('#dashboard_t').html(html);
                                                $('#spinner').hide();
                                                $('[data-toggle="tooltip"]').tooltip('hide');
                                                $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                                            }
                                        });

                                        $.ajax({
                                            type: "POST",
                                            url: ACTIONPATH,
                                            dataType: "json",
                                            data: "mode=update_dashboard_labels",
                                            success: function(html){
                                                $.each(html, function(i, item) {
                                                    $('#d_label_1').html(item.a);
                                                    $('#d_label_2').html(item.b);
                                                    $('#d_label_3').html(item.c);
                                                });
                                            }
                                        });


                                    });
                                }
                                $("#main_last_new_ticket").attr('value', new_lu);
                            }
                        });
                    }
                }});
        }
    };


if (ispath('notes') ) {
    //if (def_filename == "notes.php") {

        $.ajax({
            type: "POST",
            url: ACTIONPATH,
            data: "mode=get_list_notes",
            success: function(html){
                $('#table_list').html(html);

                $.ajax({
                    type: "POST",
                    url: ACTIONPATH,
                    data: "mode=get_first_note",
                    success: function(html){
                    }
                });


            }
        });






    }
if (ispath('ticket')) {
    //if (def_filename == "ticket.php") {
        setInterval(function(){
            var lu=$("#last_update").attr('value');
            var tid=$("#ticket_id").attr('value');
            check_update();
            $.ajax({
                type: "POST",
                url: ACTIONPATH,
                dataType: "json",
                data: "mode=check_update_one"+
                    "&id="+tid+
                    "&last_update="+lu,
                success: function(html){


                    if (html) {
                        $.each(html, function(i, item) {


                            if (item.type == "update") {window.location = MyHOSTNAME+"ticket?"+item.hash+"&refresh"; }
                            else if (item.type == "comment") {
                                $.ajax({
                                    type: "POST",
                                    url: ACTIONPATH,
                                    data: "mode=view_comment"+
                                        "&tid="+tid,
                                    success: function(r) {

                                        $("#comment_content").html(r);

                                        $("#last_update").attr('value',item.time);
                                    }
                                });

                            }
                            else if (item.type == "no") {

                            }



                        });

                    }

                }
            });




        },5000);


    }
    if (ispath('clients') ) {
    //if (def_filename == "clients.php") {
        setInterval(function(){
            check_update();
        },5000);
    }
if (ispath('profile') ) {
    //if (def_filename == "profile.php") {
        setInterval(function(){
            check_update();
        },5000);
    }
    if (ispath('create') ) {
    //if (def_filename == "new.php") {
        setInterval(function(){
            check_update();
        },5000);
    }
if (ispath('notes') ) {
    //if (def_filename == "notes.php") {
        $('#buttons').hide();
        setInterval(function(){
            check_update();
        },5000);
        
    }

    if ((def_filename == "index.php") || (def_filename == "")) {
    //alert(ACTIONPATH);
        $.ajax({
            type: "POST",
            url: ACTIONPATH,
            data: "mode=last_news",
            success: function(html){
                $('#last_news').html(html);

            }
        });
        $('#spinner').show();
        $.ajax({
            type: "POST",
            url: ACTIONPATH,
            data: "mode=dashboard_t",<commit_msg>FIX sound noty issue #82 part2.<commit_after>$(document).ready(function() {



var ACTIONPATH=MyHOSTNAME+"actions.php";


    function get_lang_param(par) {
        var result="";
        var zcode="";
        var url = window.location.href;

if (url.search("inc") >= 0) {
    zcode="../";
} 


        $.ajax({
            type: "POST",
            url: ACTIONPATH,
            data: "mode=get_lang_param"+
                "&param="+par,
            async: false,
            success: function(html){

                result=html;
            }
        });
        return (result);

    };


    $('textarea').autosize({append: "\n"});



    $('#my-select').multiSelect({
    });

    $("#spinner").hide();
    $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});

    var settingsShow = function() {
        var showPanel = $(".chosen-select").find('option:selected').attr('id');

    }
    $(".chosen-select").chosen({
        no_results_text: "Не знайдено...",
        allow_single_deselect: true,
    });
    $(".chosen-select").chosen().change(settingsShow);
    $.fn.editable.defaults.mode = 'inline';
    $("#user_info").hide();
    $("#alert_add").hide();

    $("#refer_to").hide();

function ispath(p1) {
var url = window.location.href;
var zzz=false;
if (url.search(p1) >= 0) {
    zzz=true;
}	
return zzz;
};



function whatpath() {
var url = window.location.href;
var zzz="";
if (url.search("inc") >= 0) {
    zzz="../";
} 	
return zzz;
};

    $("#fio").autocomplete({
        max: 10,
        minLength: 2,
        source: MyHOSTNAME+"/inc/json.php?fio",
        focus: function(event, ui) {
            $("#fio").val(ui.item.label);
            return false;
        },
        select: function(event, ui) {
            $("#fio").val(ui.item.label);
            $("#client_id_param").val(ui.item.value);
            $('#fio').popover('hide');
            $('#for_fio').removeClass('has-error').addClass('has-success');
            $("#user_info").hide().fadeIn(500);
            $("#alert_add").hide();
            $.ajax({
                type: "POST",
                url: ACTIONPATH,
                data: "mode=get_client_from_new_t&get_client_info=" + ui.item.value,
                success: function(html) {
                    $("#user_info").hide().html(html).fadeIn(500);
                    $('#edit_login').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто'
                    });
                    $('#edit_posada').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто',
                        mode: 'popup',
                        showbuttons: false
                    });				$('#edit_unit').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто',
                        mode: 'popup',
                        showbuttons: false
                    });				$('#edit_tel').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто'
                    });				$('#edit_adr').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто'
                    });				$('#edit_mail').editable({
                        inputclass: 'input-sm',
                        emptytext: 'пусто'
                    });
                    $('#for_fio').addClass('has-success');
                    $("#status_action").val('edit');

                }
            });
            return false;
        },
        change: function(event, ui) {
            console.log(this.value);

            if ($('input#fio').val().length != 0){


                if (ui.item == null) {
                    $("#user_info").hide();
                    $("#status_action").val('add');
                    $('#fio').popover('hide');
                    $('#for_fio').removeClass('has-error');
                    $('#for_fio').addClass('has-success');

                    $.ajax({
                        type: "POST",
                        url: ACTIONPATH,
                        data: "mode=get_client_from_new_t&new_client_info="+$("#fio").val(),
                        success: function(html) {
                            $("#alert_add").hide().html(html).fadeIn(500);
                            $('#username').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто'
                            });
                            $('#new_login').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто'
                            });$('#new_posada').editable({
                                inputclass: 'input-sm posada_class',
                                emptytext: 'пусто',
                                mode: 'popup',
                                showbuttons: false
                            });
                            $('#new_unit').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто',
                                mode: 'popup',
                                showbuttons: false
                            });
                            $('#new_tel').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто'
                            });
                            $('#new_adr').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто'
                            });
                            $('#new_mail').editable({
                                inputclass: 'input-sm',
                                emptytext: 'пусто'
                            });
                        }
                    });
                } else {
                }

            }



        }









    });
    $("select#to").blur(function() {

        if ( $('select#to').val() != 0 ){

            $('#for_to').popover('hide');
            $('#for_to').removeClass('has-error');
            $('#for_to').addClass('has-success');
        }
        else {

            $('#for_to').popover('show');
            $('#for_to').addClass('has-error');

        }

    });

    function createuserslist(unit_id) {


        $.ajax({
            type: "POST",
            url: ACTIONPATH,
            data: "mode=get_users_list"+
                "&unit="+unit_id,
            dataType: "json",
            success: function(html){
                $('select#users_do').empty();
                if (html) {
                    $.each(html, function(i, item) {
                        $('select#users_do')
                            .append($("<option></option>")
                                .attr("value",item.co)
                                .text(item.name));

                    });
                }
                $('select#users_do').trigger('chosen:updated');
            }

        });




    }


    $("select#to").change(function() {
        var i=$('select#to').val();
        if ( $('select#to').val() != 0 ){

            $('#for_to').popover('hide');
            $('#for_to').removeClass('has-error');
            $('#for_to').addClass('has-success');

            createuserslist(i);

        }
        else {

            $('#for_to').popover('show');
            $('#for_to').addClass('has-error');

        }

    });

    $("select#subj").change(function() {

        if ( $('select#subj').val() != 0 ){

            $('#for_subj').popover('hide');
            $('#for_subj').removeClass('has-error');
            $('#for_subj').addClass('has-success');
        }
        else {

            $('#for_subj').popover('show');
            $('#for_subj').addClass('has-error');

        }

    });

    $("select#subj").blur(function() {

        if ( $('select#subj').val() != 0 ){

            $('#for_subj').popover('hide');
            $('#for_subj').removeClass('has-error');
            $('#for_subj').addClass('has-success');
        }
        else {

            $('#for_subj').popover('show');
            $('#for_subj').addClass('has-error');

        }

    });





    $('textarea#msg').keydown(function (e) {

        if (e.ctrlKey && e.keyCode == 13) {


            $("button#do_comment").click();


        }
    });



    $("textarea#msg").blur(function() {
        if($(this).val().length > 1) {
            $("textarea#msg").popover('hide');
            $("#for_msg").removeClass('has-error').addClass('has-success');

        } else {
            $("textarea#msg").popover('show');
            $("#for_msg").addClass('has-error');
        }
    });

    $("textarea#msg").keypress(function() {
        if($(this).val().length > 1) {
            $("textarea#msg").popover('hide');
            $("#for_msg").removeClass('has-error').addClass('has-success');

        } else {
            $("textarea#msg").popover('show');
            $("#for_msg").addClass('has-error');
        }
    });


    var options_workers = {
        currentPage: $("#cur_page").val(),
        totalPages: $("#total_pages").val(),
        bootstrapMajorVersion: 3,
        size: "small",
        itemContainerClass: function (type, page, current) {
            return (page === current) ? "active" : "pointer-cursor";
        },
        onPageClicked: function(e,originalEvent,type,page){
            var current=$("#curent_page").attr('value');

            if (page != current) {

                $("#curent_page").attr('value', page);

                $.ajax({
                    type: "POST",
                    url: MyHOSTNAME+"inc/workers.inc.php",
                    data: "page="+page+
                        "&menu=list",
                    success: function(html){
                        $("#content_worker").hide().html(html).fadeIn(500);
                        $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                    }
                });
            }


        }

    }


    var options_in = {
        currentPage: $("#cur_page").val(),
        totalPages: $("#total_pages").val(),
        bootstrapMajorVersion: 3,
        size: "small",
        itemContainerClass: function (type, page, current) {
            return (page === current) ? "active" : "pointer-cursor";
        },
        onPageClicked: function(e,originalEvent,type,page){
            var current=$("#curent_page").attr('value');

            if (page != current) {

                $("#curent_page").attr('value', page);


                $("#spinner").fadeIn(300);

                $.ajax({
                    type: "POST",
                    url: MyHOSTNAME+"inc/list_content.inc.php",
                    data: "menu=in"+
                        "&page="+page,
                    success: function(html){
                        $("#content").hide().html(html).fadeIn(500);
                        $("#spinner").hide();
                        $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                    }
                });
            }


        }

    }
    var options_out = {
        currentPage: $("#cur_page").val(),
        totalPages: $("#total_pages").val(),
        bootstrapMajorVersion: 3,
        size: "small",
        itemContainerClass: function (type, page, current) {
            return (page === current) ? "active" : "pointer-cursor";
        },
        onPageClicked: function(e,originalEvent,type,page){
            var current=$("#curent_page").attr('value');

            if (page != current) {
                $("#spinner").fadeIn(300);
                $("#curent_page").attr('value', page);
                $.ajax({
                    type: "POST",
                    url: MyHOSTNAME+"inc/list_content.inc.php",
                    data: "menu=out"+
                        "&page="+page,
                    success: function(html){
                        $("#content").hide().html(html).fadeIn(500);
                        $("#spinner").hide();
                        $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                    }
                });
            }

        }

    }
    var options_arch = {
        currentPage: $("#cur_page").val(),
        totalPages: $("#total_pages").val(),
        bootstrapMajorVersion: 3,
        size: "small",
        itemContainerClass: function (type, page, current) {
            return (page === current) ? "active" : "pointer-cursor";
        },
        onPageClicked: function(e,originalEvent,type,page){
            var current=$("#curent_page").attr('value');

            if (page != current) {
                $("#curent_page").attr('value', page);
                $("#spinner").fadeIn(300);

                $.ajax({
                    type: "POST",
                    url: MyHOSTNAME+"inc/list_content.inc.php",
                    data: "menu=arch"+
                        "&page="+page,
                    success: function(html){
                        $("#content").hide().html(html).fadeIn(500);
                        $("#spinner").hide();
                        $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                    }
                });
            }


        }

    }

    $('#example_in').bootstrapPaginator(options_in);
    $('#example_out').bootstrapPaginator(options_out);
    $('#example_arch').bootstrapPaginator(options_arch);
    $('#example_workers').bootstrapPaginator(options_workers);



    $.ionSound({
        sounds: [
            "button_tiny"
        ]
    });


    var def_p = window.location.pathname.split("/");
    var def_filename = def_p[def_p.length-1];
    
    


//alert(window.location);


    $.noty.defaults = {
        layout: 'top',
        theme: 'defaultTheme',
        type: 'information',
        text: '',
        dismissQueue: true,
        template: '<div class="noty_message"><button type="button" class="close" style="padding-left: 2px;margin-top: -5px;" aria-hidden="true">&times;</button><span class="noty_text"></span></div>',
        animation: {
            open: {height: 'toggle'},
            close: {height: 'toggle'},
            easing: 'swing',
            speed: 500
        },
        timeout: false,
        force: false,
        modal: false,
        maxVisible: 5,
        killer: false,
        closeWith: ['click'],
        callback: {
            onShow: function() {},
            afterShow: function() {},
            onClose: function() {},
            afterClose: function() {}
        },
        buttons: false
    };







    function check_update() {
        var ee=$("#main_last_new_ticket").val();
        var url = window.location.href;
		var zcode="";
if (url.search("inc") >= 0) {
    var zcode="../";
} 
        
        
        
        if (ee) {
            $.ajax({
                type: "POST",
                url: ACTIONPATH,
                data: "mode=check_update"+
                    "&type=all"+
                    "&last_update="+ee,
                success: function(html){
                    if (html == "no") {
                    }
                    else {
                        var new_lu=html;
                        $.ajax({
                            type: "POST",
                            url: ACTIONPATH,
                            data: "mode=list_ticket_update"+
                                "&last_update="+ee,
                            dataType: "json",
                            success: function(html){
                                if (html) {
                                    $.each(html, function(i, item) {
                                        var t='<div style=\'float: left;\'><a style=\'color: rgb(243, 235, 235); cursor: inherit;\' target=\'_blank\' href=\''+item.url+'/ticket?'+item.hash+'\'><strong>'+item.ticket+' #'+item.name+'</strong> </a></div><div style=\'float: right; padding-right: 10px;\'><small>'+item.time+'</small></div><br><hr style=\'margin-top: 5px; margin-bottom: 8px; border:0; border-top:0px solid #E4E4E4\'><a style=\'color: rgb(252, 252, 252); cursor: inherit;\' target=\'_blank\' href=\''+item.url+'/ticket?'+item.hash+'\'>'+item.at+'</a>';
                                        noty({
                                            text: t,
                                            layout: 'bottomRight',
                                            timeout: false
                                        });
                                        $.ionSound.play("button_tiny");
                                        $.titleAlert(item.up);
                                    });
                                }
                                $("#main_last_new_ticket").attr('value', new_lu);
                            }
                        });
                    }
                }});
        }
    };



    function check_update_index() {
        var ee=$("#main_last_new_ticket").val();
        if (ee) {
            $.ajax({
                type: "POST",
                url: ACTIONPATH,
                data: "mode=check_update"+
                    "&type=all"+
                    "&last_update="+ee,
                success: function(html){
                    if (html == "no") {
                    }
                    else {
                        var new_lu=html;
                        $.ajax({
                            type: "POST",
                            url: ACTIONPATH,
                            data: "mode=list_ticket_update"+
                                "&last_update="+ee,
                            dataType: "json",
                            success: function(html){
                                if (html) {
                                    $.each(html, function(i, item) {
                                        var t='<div style=\'float: left;\'><a style=\'color: rgb(243, 235, 235); cursor: inherit;\' target=\'_blank\' href=\''+item.url+'/ticket?'+item.hash+'\'><strong>'+item.ticket+' #'+item.name+'</strong> </a></div><div style=\'float: right; padding-right: 10px;\'><small>'+item.time+'</small></div><br><hr style=\'margin-top: 5px; margin-bottom: 8px; border:0; border-top:0px solid #E4E4E4\'><a style=\'color: rgb(252, 252, 252); cursor: inherit;\' target=\'_blank\' href=\''+item.url+'/ticket?'+item.hash+'\'>'+item.at+'</a>';
                                        noty({
                                            text: t,
                                            layout: 'bottomRight',
                                            timeout: false
                                        });
                                        $.ionSound.play("button_tiny");

                                        $.ajax({
                                            type: "POST",
                                            url: ACTIONPATH,
                                            data: "mode=last_news",
                                            success: function(html){
                                                $('#last_news').html(html);
                                                $('[data-toggle="tooltip"]').tooltip('hide');
                                                $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                                            }
                                        });
                                        $('#spinner').show();
                                        $.ajax({
                                            type: "POST",
                                            url: ACTIONPATH,
                                            data: "mode=dashboard_t",
                                            success: function(html){

                                                $('#dashboard_t').html(html);
                                                $('#spinner').hide();
                                                $('[data-toggle="tooltip"]').tooltip('hide');
                                                $('[data-toggle="tooltip"]').tooltip({container: 'body', html:true});
                                            }
                                        });

                                        $.ajax({
                                            type: "POST",
                                            url: ACTIONPATH,
                                            dataType: "json",
                                            data: "mode=update_dashboard_labels",
                                            success: function(html){
                                                $.each(html, function(i, item) {
                                                    $('#d_label_1').html(item.a);
                                                    $('#d_label_2').html(item.b);
                                                    $('#d_label_3').html(item.c);
                                                });
                                            }
                                        });


                                    });
                                }
                                $("#main_last_new_ticket").attr('value', new_lu);
                            }
                        });
                    }
                }});
        }
    };


if (ispath('notes') ) {
    //if (def_filename == "notes.php") {

        $.ajax({
            type: "POST",
            url: ACTIONPATH,
            data: "mode=get_list_notes",
            success: function(html){
                $('#table_list').html(html);

                $.ajax({
                    type: "POST",
                    url: ACTIONPATH,
                    data: "mode=get_first_note",
                    success: function(html){
                    }
                });


            }
        });






    }
if (ispath('ticket')) {
    //if (def_filename == "ticket.php") {
        setInterval(function(){
            var lu=$("#last_update").attr('value');
            var tid=$("#ticket_id").attr('value');
            check_update();
            $.ajax({
                type: "POST",
                url: ACTIONPATH,
                dataType: "json",
                data: "mode=check_update_one"+
                    "&id="+tid+
                    "&last_update="+lu,
                success: function(html){


                    if (html) {
                        $.each(html, function(i, item) {


                            if (item.type == "update") {window.location = MyHOSTNAME+"ticket?"+item.hash+"&refresh"; }
                            else if (item.type == "comment") {
                                $.ajax({
                                    type: "POST",
                                    url: ACTIONPATH,
                                    data: "mode=view_comment"+
                                        "&tid="+tid,
                                    success: function(r) {

                                        $("#comment_content").html(r);

                                        $("#last_update").attr('value',item.time);
                                    }
                                });

                            }
                            else if (item.type == "no") {

                            }



                        });

                    }

                }
            });




        },5000);


    }
    if (ispath('clients') ) {
    //if (def_filename == "clients.php") {
        setInterval(function(){
            check_update();
        },5000);
    }
if (ispath('profile') ) {
    //if (def_filename == "profile.php") {
        setInterval(function(){
            check_update();
        },5000);
    }
    if (ispath('create') ) {
    //if (def_filename == "new.php") {
        setInterval(function(){
            check_update();
        },5000);
    }
if (ispath('notes') ) {
    //if (def_filename == "notes.php") {
        $('#buttons').hide();
        setInterval(function(){
            check_update();
        },5000);
        
    }


    if ((def_filename == "index.php") || (window.location == MyHOSTNAME)) {
    //alert(ACTIONPATH);
        $.ajax({
            type: "POST",
            url: ACTIONPATH,
            data: "mode=last_news",
            success: function(html){
                $('#last_news').html(html);

            }
        });
        $('#spinner').show();
        $.ajax({
            type: "POST",
            url: ACTIONPATH,
            data: "mode=dashboard_t",
{'fraction_non_alphanumeric': 0.15937151545869235, 'fraction_numerical': 0.005575266092245312, 'mean_word_length': 1.0514889369489269, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 202, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4636489', 'n_tokens_mistral': 12686, 'n_tokens_neox': 11943, 'n_words': 1854}