var formatResult;
$(document).ready(function (e) {

    $('.dataTableClass22').dataTable(
            {"lengthMenu"
                        : [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
                "order"
                        : [
                            [4, "desc"]       // order by drug cat
                        ]
            }
    );

    //	alert(document.getElementById("searchvalue").value);
    formatResult = function (data) {
        return  data.text;
    }


    $(".select2parcode").select2({
        placeholder: "الباركود",
        // minimumInputLength: document.getElementById("searchpar").value,
        // minimumInputLength: false,
        // multiple: false,
        // quietMillis: 100,
        minimumInputLength: 1,
        ajax: {
            url: "sellbillAjaxController.php?do=loadProductWithByParcode",
            dataType: 'json',
            data: function (term, page) {
                return {
                    term: term, //search term
                    page_limit: 10 // page size
                };
            },
            results: function (data) {
                console.log(data)
                return {results: data};
            }
        },
        formatResult: formatResult,
        initSelection: function (element, callback) {
            var item = element.val().split(':');
            var data = {id: item[0], text: item[1]};
            callback(data);
        }
    });

    //assign select2 properties
    $(".select2product").select2({
        placeholder: "إسم المنتج",
        minimumInputLength: document.getElementById("searchvalue").value,
        //minimumInputLength: 3,
        multiple: false,
        quietMillis: 100,
        ajax: {
            url: "sellbillAjaxController.php?do=getProducts2",
            dataType: 'json',
            data: function (term, page) {
                return {
                    term: term, //search term
                    page_limit: 5 // page size
                };
            },
            results: function (data) {
                return {results: data};
            }
        },
        formatResult: formatResult,
        initSelection: function (element, callback) {
            var item = element.val().split(':');
            var data = {id: item[0], text: item[1]};
            callback(data);
        }
    });

    // $(".select2productdeleted").select2({
    //     placeholder: "إسم المنتج",
    //     minimumInputLength: document.getElementById("searchvalue").value,
    //     //minimumInputLength: 3,
    //     multiple: false,
    //     quietMillis: 100,
    //     ajax: {
    //         url: "sellbillAjaxController.php?do=loadProductWithByName2deleted",
    //         dataType: 'json',
    //         data: function (term, page) {
    //             return {
    //                 term: term, //search term
    //                 page_limit: 10 // page size
    //             };
    //         },
    //         results: function (data) {
    //             return {results: data};
    //         }
    //     },
    //     formatResult: formatResult,
    //     initSelection: function (element, callback) {
    //         var item = element.val().split(':');
    //         var data = {id: item[0], text: item[1]};
    //         callback(data);
    //     }
    // });

    $('.productCat').live('change', function () {
        var id = $(this).val();
        var level = Number($(this).attr('data-level'));
        level = level + 1;
        $('#level').val(level);
        $.post('salesreportajax.php?do=getsubcat', {id: id, level: level}, function (data) {
            $('.productCat').each(function () {
                var thisLevel = Number($(this).attr('data-level'));
                if (thisLevel >= level) {
                    $(this).parent('div').remove();
                }
            });
            $('#productIdDiv').remove();
            if (data != "-1") {
                $('#manyParents').append(data);
            }
            else
            {
                $('#level').val((level - 1));
                $.post('salesreportajax.php?do=getproducts', {id: id}, function (data) {
                    $('#manyParents').append(data);
                });
            }
        });

    });
});
$(document).ready(function (e) {
    //Row details is from https://datatables.net/examples/server_side/row_details.html
    function formatit(d) {
        //d is product id
        var html;
        if ($('#sizecolordetails' + d).length > 0 && $('#sizecolordetails' + d).val() != "" && d.includes("SAC")) {//size and color
            var sizecolordetails = JSON.parse($('#sizecolordetails' + d).val());
            var html = '<table class="table table-black datatableClass' + d + '">' +
                    '    <thead>' +
                    '        <tr>' +
                    '            <th>اللون</th>' +
                    '            <th>المقاس</th>' +
                    '            <th>الباركود</th>' +
                    '            <th>الكمية</th>' +
                    '        </tr>' +
                    '    </thead>' +
                    '    <tbody>';
            if (sizecolordetails.length > 0) {
                sizecolordetails.forEach(function (arrayItem) {
                    html += '        <tr>' +
                            '            <td>' +
                            '                <input type="text" class="form-control" disabled="disabled" style="width:99%" value="' + arrayItem.colorName + '">' +
                            '            </td>' +
                            '            <td>' +
                            '                <input type="text" class="form-control" disabled="disabled" style="width:99%" value="' + arrayItem.sizeName + '">' +
                            '            </td>' +
                            '            <td>' +
                            '                <input type="text" class="form-control" style="width:99%" value="' + arrayItem.parcode + '">' +
                            '            </td>' +
                            '            <td>' +
                            '                <input type="text" class="form-control" disabled="disabled" style="width:99%" value="' + arrayItem.quantity + '">' +
                            '            </td>' +
                            '        </tr>';
                });
            } else {
                html += '        <tr>' +
                        '            <td colspan="3"> لا يوجد بيانات</td>' +
                        '        </tr>';
            }
            html += '    </tbody>' +
                    '</table>';
            return html;
        }
        else if ($('#sizecolordetails' + d).length > 0 && $('#sizecolordetails' + d).val() != "" && d.includes("SOC")) {//size or color
            var sizecolordetails = JSON.parse($('#sizecolordetails' + d).val());
            var html = '<table class="table table-black datatableClass' + d + '">' +
                    '    <thead>' +
                    '        <tr>' +
                    '            <th>اللون / المقاس</th>' +
                    '            <th>الباركود</th>' +
                    '            <th>الكمية</th>' +
                    '        </tr>' +
                    '    </thead>' +
                    '    <tbody>';
            if (sizecolordetails.length > 0) {
                sizecolordetails.forEach(function (arrayItem) {
                    html += '        <tr>' +
                            '            <td>' +
                            '                <input type="text" class="form-control" disabled="disabled" style="width:99%" value="' + arrayItem.productName + '">' +
                            '            </td>' +
                            '            <td>' +
                            '                <input type="text" class="form-control" disabled="disabled" style="width:99%" value="' + arrayItem.parcode + '">' +
                            '            </td>' +
                            '            <td>' +
                            '                <input type="text" class="form-control" disabled="disabled" style="width:99%" value="' + arrayItem.sumProductQuantity + '">' +
                            '            </td>' +
                            '        </tr>';
                });
            } else {
                html += '        <tr>' +
                        '            <td colspan="3"> لا يوجد بيانات</td>' +
                        '        </tr>';
            }
            html += '    </tbody>' +
                    '</table>';
            return html;
        }
        else if ($('#sizecolordetails' + d).length > 0 && $('#sizecolordetails' + d).val() != "" && d.includes("ING")) {//Ingridients  "collective product"
            var sizecolordetails = JSON.parse($('#sizecolordetails' + d).val());
            var html = '<table class="table table-black">' +
                    '    <thead>' +
                    '        <tr>' +
                    '            <th>المنتجات الخام</th>' +
                    '            <th>وحدة القياس</th>' +
                    '            <th>عدد الوحدات</th>' +
                    '        </tr>' +
                    '    </thead>' +
                    '    <tbody>';
            if (sizecolordetails.length > 0) {
                sizecolordetails.forEach(function (arrayItem) {
                    html += '        <tr>' +
                            '            <td>' +
                            '                <input type="text" class="form-control" disabled="disabled" style="width:99%" value="' + arrayItem.productName + '">' +
                            '            </td>' +
                            '            <td>' +
                            '                <input type="text" class="form-control" disabled="disabled" style="width:99%" value="' + arrayItem.unitName + '">' +
                            '            </td>' +
                            '            <td>' +
                            '                <input type="text" class="form-control" disabled="disabled" style="width:99%" value="' + arrayItem.quantity + '">' +
                            '            </td>' +
                            '        </tr>';
                });
            } else {
                html += '        <tr>' +
                        '            <td colspan="3"> لا يوجد بيانات</td>' +
                        '        </tr>';
            }
            html += '    </tbody>' +
                    '</table>';
            return html;
        }
        else {
            //html = 'منتج بلا مقاسات و الوان';
            return false;
            //var html = '<table class="table table-black"></table>';
            //return html;
        }




    }

    /*-- data table of products ----------------------------------------------*/

    var mydatatable = $('#productQuantityTable').dataTable({
        dom: 'Bfrtip',
        buttons: [//'csv', 'pdf'
//            {
//                extend: 'excelHtml5',
//                text: 'XLS', //<i class="fa fa-file-excel-o"></i>
//                titleAttr: 'Excel',
//                "oSelectorOpts": {filter: 'applied', order: 'current'},
//                "sFileName": "report.xls",
//                charset: 'UTF-8',
//                action: function (e, dt, button, config) {
//                    exportTableToCSV.apply(this, [$('#productQuantityTable'), 'export.xls']);
//
//                }
//
//            },
            {
                extend: 'csvHtml5',
                charset: 'UTF-8',
                bom: true,
                "visible": false,
                className: "btn dark btn-outline",
                text: 'اكسل بالمقاسات والالوان', //<i class="fa fa-file-text-o"></i>
                titleAttr: 'CSV',
                extension: '.csv',
                filename: 'export',
                fieldSeparator: ';',
                fieldBoundary: '',
                exportOptions: {
                    columns: ':visible'
                },
                action: function (e, dt, button, config) {
                    //exportTableToCSV.apply(this, [$('#productQuantityTable'), 'برنامج البسيط للمحاسبة.csv']);
                    createAndExport.apply(this, [$('#productQuantityTable'), 'برنامج البسيط للمحاسبة']);
                    //loadEXCEL('productQuantityTable', 'برنامج البسيط للمحاسبة');
                },
                customize: function (win) {
                    $(win.document.body).find('table')
                            //.addClass('compact')
                            .css('direction', 'rtl');
                }

            },
            {
                extend: 'print', //https://datatables.net/forums/discussion/43133/how-to-print-child-rows#latest
                "visible": false,
                className: "btn dark btn-outline",
                text: "طباعه بالمقاسات و الالوان<i class='fa fa-print'></i>",
                action: function (e, dt, button, config) {
                    dt_print(e, dt, button, config, true)
                }, /* true here means table has child rows */
                customize: function (win) {
                    $(win.document.body).find('table')
                            //.addClass('compact')
                            .css('direction', 'rtl');
                }
            }
            , {
                extend: "print",
                className: "btn dark btn-outline",
                text: "طباعه<i class='fa fa-print'></i>",
                exportOptions: {
                    //columns: '.show-print'
                    columns: ':visible'
                },
                customize: function (win) {
                    $(win.document.body).find('table')
                            //.addClass('compact')
                            .css('direction', 'rtl');
                }
            }
            , {
                extend: "copy",
                className: "btn red btn-outline",
                text: "نسخ",
                exportOptions: {
                    //columns: '.show-print'
                    columns: ':visible'
                }
            }, {
                extend: "excel",
                className: "btn yellow btn-outline ",
                text: "اكسل",
                exportOptions: {
                    //columns: '.show-print'
                    columns: ':visible'
                }
            },
            {
                extend: "colvis",
                className: "btn dark btn-outline",
                text: "المكونات"
            }
        ],
        "bStateSave": true,
        "language": {
            "aria": {
                "sortAscending": ": Used to order Ascending",
                "sortDescending": ": Used to order Descending"
            },
            "emptyTable": "لا يوجد بيانات",
            "info": "عرض _START_ من _END_ الى _TOTAL_ عناصر",
            "infoEmpty": "لا يوجد بيانات",
            "infoFiltered": "(تنقيه _MAX_ من الاجمالى)",
            "lengthMenu": " _MENU_ عنصر",
            "search": "البحث:",
            "zeroRecords": "لا يوجد بيانات تشابه البحث"
        },
        responsive: !0,
        "columnDefs": [
            {
                /*
                 * column exists for purpose of printing/exporting
                 * only required when using child rows
                 */
                "targets": [0]
                , title: 'index'
                , visible: false
                , render: function (row, type, full, meta) {
                    return meta.row;
                },
            },
            {"targets": [1], "className": "details-control"}, //"details-control show-print"
//            {"targets": [2], "className": "show-print"},
//            {"targets": [3], "className": "show-print"},
            {targets: '_all', "className": 'show-print'}
        ],
        order: [
            [0, "asc"]
        ],
        "paging": false,
        dom: "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>"
    });
    function dt_print(e, dt, button, config, has_child_rows) {
        var data = dt.buttons.exportData(config.exportOptions);
        openDetailsRow();
        var addRow = function (d, tag, child_row) {
            var str = '<tr>';

            for (var i = 0, ien = d.length; i < ien; i++) {
                if (has_child_rows && !child_row && i === 0)
                    continue;
                str += '<' + tag + '>' + d[i] + '</' + tag + '>';
            }

            return str + '</tr>';
        };

        var addSubTable = function (subtable, colspan) {
            var str = '<tr class="innertable-row">'
                    + '<td class="innertable-row" colspan="' + colspan + '">';

            // If there is no subtable, there must be other child row content, display that
            if (subtable.length == 0) {
                str += '<div style="text-align: left">'
                str += $(dt.row(row_idx).child()).children().children().html();
                return str + '<div></td></tr>';
            }

            // Add header row
            var headers = subtable.find('tr').first().find('th,td');

            str += '<table class="dataTable no-footer">'
                    + '<thead><tr>';

            for (var i = 0; i < headers.length; i++) {
                str += '<th>' + headers.eq(i).text() + '</th>';
            }

            str += '</tr></thead><tbody>';

            // Add body rows
            subtable.find('tbody').children('tr').each(function (index, tr) {
                var lines = $('td', tr).map(function (index, td) {
                    //this is how to read rows of details text
                    //this read text of td
                    //return $(td).text();
                    return $(td).children('input').first().val()//this read value of input inside td
                });
                str += addRow(lines, 'td', true);
            });

            return str + '</tbody></table></td></tr>';
        };

        // Construct a table for printing
        var html = '<table class="' + dt.table().node().className + '">';

        if (config.header) {
            html += '<thead>' + addRow(data.header, 'th') + '</thead>';
        }

        html += '<tbody>';
        for (var i = 0, ien = data.body.length; i < ien; i++) {
            html += addRow(data.body[i], 'td');

            if (has_child_rows) {
                var row_idx = data.body[i][0];
                if (dt.row(row_idx).child() && dt.row(row_idx).child.isShown()) {
                    html += addSubTable($(dt.row(row_idx).child()).find('table:visible'), data.body[0].length);
                }
            }
        }
        html += '</tbody>';

        if (config.footer && data.footer) {
            html += '<tfoot>' + addRow(data.footer, 'th') + '</tfoot>';
        }

        // Open a new window for the printable table
        var win = window.open();
        var title = config.title;

        if (typeof title === 'function') {
            title = title();
        }

        if (title.indexOf('*') !== -1) {
            title = title.replace('*', $('title').text());
        }

        win.document.close();

        // Inject the title and also a copy of the style and link tags from this
        // document so the table can retain its base styling. Note that we have
        // to use string manipulation as IE won't allow elements to be created
        // in the host document and then ك2appended to the new window.
        var head = '<title>' + title + '</title>';
        //this is to include styles ,note src of <link> shouldnot be realtive
        var link = window.location.href;
        var hosturl = link.split('controllers')[0];
        //var hosturl = $('#hosturl').val();
        head += '<link href="' + hosturl + '/views/default/assets/plugins/datatables/datatables.min.css" rel="stylesheet" type="text/css" />';
        head += '<link href="' + hosturl + '/views/default/assets/css/print.css" rel="stylesheet">';
//        //$('style, link').each(function () {
//        //head += _styleToAbs(this);//may be absolute path?
//            head += String($(this)[0]);
//        });

        try {
            win.document.head.innerHTML = head; // Work around for Edge
        }
        catch (e) {
            $(win.document.head).html(head); // Old IE
        }



        // Inject the table and other surrounding information
        win.document.body.innerHTML =
                '<h1>' + title + '</h1>'
                + '<div>'
                + (typeof config.message === 'function' ?
                        config.message(dt, button, config) :
                        config.message
                        )
                + '</div>'
                + html;


        $(win.document.body).addClass('dt-print-view');

        $('img', win.document.body).each(function (i, img) {
            img.setAttribute('src', _relToAbs(img.getAttribute('src')));
        });

        if (config.customize) {
            config.customize(win);
        }

        setTimeout(function () {
            if (config.autoPrint) {
                win.print();
                win.close();
            }
        }, 250);
    }
    function exportTableToCSV($table, filename) {//working but with arabic language issues
        //rescato los títulos y las filas
        var $Tabla_Nueva = $table.find('tr:has(td,th)');
        // elimino la tabla interior.
        var Tabla_Nueva2 = $Tabla_Nueva.filter(function () {
            return (this.childElementCount != 1);
        });

        var $rows = Tabla_Nueva2,
                // Temporary delimiter characters unlikely to be typed by keyboard
                // This is to avoid accidentally splitting the actual contents
                tmpColDelim = String.fromCharCode(11), // vertical tab character
                tmpRowDelim = String.fromCharCode(0), // null character

                // Solo Dios Sabe por que puse esta linea
                colDelim = (filename.indexOf("xls") != -1) ? '"\t"' : '","',
                rowDelim = '"\r\n"',
                // Grab text from table into CSV formatted string
                csv = '"' + $rows.map(function (i, row) {
                    var $row = $(row);
                    var $cols = $row.find('td:not(.hidden),th:not(.hidden)');

                    return $cols.map(function (j, col) {
                        var $col = $(col);
                        var text = $col.text().replace(/\./g, '');
                        if (!!$col.find('input[type="text"]').val()) {//!! means if not-undefined "like isset php"
                            text = $col.find('input[type="text"]').val().replace(/\./g, '');
                        }

                        return text.replace('"', '""'); // escape double quotes

                    }).get().join(tmpColDelim);
                    csv = csv + '"\r\n"' + 'fin ' + '"\r\n"';
                }).get().join(tmpRowDelim)
                .split(tmpRowDelim).join(rowDelim)
                .split(tmpColDelim).join(colDelim) + '"';
        //console.log(csv);

        download_csv(csv, filename);


    }
    var createAndExport = function ($table, filename) {//working but no spaces bettween words are kept in arabic nor english => so we use table = table.replace(/ /g, '%20');
        //https://jsfiddle.net/3fohpL9u/2/

        openDetailsRow();
        var table = "<head><meta charset='UTF-8'></head>";


        //rescato los títulos y las filas
        var $Tabla_Nueva = $table.find('tr:has(td,th)');
        // elimino la tabla interior.
        var Tabla_Nueva2 = $Tabla_Nueva.filter(function () {
            return (this.childElementCount != 1);
        });


        var headStyle = 'style="background-color:brown;font-size: 15px;"';
        var productRowStyle = 'style="background-color:cornflowerblue;"';
        var subHeadRowStyle = '';//'style="background-color:yellow;"';

        var $rows = Tabla_Nueva2;
        // Grab text from table into CSV formatted string
        table += "<table>";
        $rows.map(function (i, row) {
            var $row = $(row);
            var $cols = $row.find('td:not(.hidden),th:not(.hidden)');

            table += "<tr>";
            var productRowFlag = 0;
            var productDetailsFlag = 0;
            return $cols.map(function (j, col) {
                var $col = $(col);
                var text = $col.text();
                var originalText = $col.text();
                if (!!$col.find('input[type="text"]').val()) {//!! means if not-undefined "like isset php"
                    text = $col.find('input[type="text"]').val();
                }


                if (j == 0 && i > 0 && originalText == "") {
                    productRowFlag = 1;//now it is product row as it always start with empty cell due to (+) cell in table
                }
                if (j == 0 && i > 0 && originalText != "") {
                    productDetailsFlag = 1;//now it is product row as it always start with empty cell due to (+) cell in table
                }

                //this special condition can be removed
                if ((j == 0 && !!text && originalText != "") || j > 0) {
                    if (i == 0) { //i == 0 it is the head of biggest table
                        table += "<td " + headStyle + ">" + text + "</td>";//headStyle
                    } else if (productRowFlag == 1) {
                        table += "<td " + productRowStyle + ">" + text + "</td>";
                    } else if (productDetailsFlag == 1) {//
                        table += "<td " + subHeadRowStyle + ">" + text + "</td>";
                    } else {
                        table += "<td>" + text + "</td>";
                    }

                }

            })
            table += "</tr>";//
        });

        table += "</table>";
        table = table.replace(/ /g, '%20');
        var uri = 'data:application/vnd.ms-excel;charset=utf-8,' + table;

        var downloadLink = document.createElement("a");
        downloadLink.href = uri;
        downloadLink.download = filename + ".xls";

        document.body.appendChild(downloadLink);
        downloadLink.click();
        document.body.removeChild(downloadLink);
    }
    function loadEXCEL(tableID, thisFileName) {//https://codepen.io/konutis/pen/RwwmXwV?editors=1010
        openDetailsRow();
        //Gather Data
        var downloadLink;
        var dataType = 'application/vnd.ms-excel';
        var tableSelect = document.getElementById(tableID);

        var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
        //console.log(tableHTML);

        // Create download link element
        downloadLink = document.createElement("a");

        document.body.appendChild(downloadLink);

        if (navigator.msSaveOrOpenBlob) {
            var blob = new Blob(['\ufeff', tableHTML], {
                type: dataType
            });
            navigator.msSaveOrOpenBlob(blob, thisFileName);
        } else {
            // Create a link to the file
            downloadLink.href = 'data:' + dataType + ', ' + tableHTML;

            // Setting the file name
            downloadLink.download = thisFileName;

            //triggering the function
            downloadLink.click();
        }
    }



    function download_csv(csv, filename) {
        var csvFile;
        var downloadLink;

        // CSV FILE
        csvFile = new Blob([csv], {type: "text/csv" /*+ "UTF-8"*/});

        // Download link
        downloadLink = document.createElement("a");

        // File name
        downloadLink.download = filename;

        // We have to create a link to the file
        downloadLink.href = window.URL.createObjectURL(csvFile);

        // Make sure that the link is not displayed
        downloadLink.style.display = "none";

        // Add the link to your DOM
        document.body.appendChild(downloadLink);

        // Lanzamos
        downloadLink.click();
    }
    //$('#productQuantityTable td').css("height", "30px");
    // Array to track the ids of the details displayed rows
    var detailRows = [];
    $('#productQuantityTable tbody').on('click', 'tr td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = mydatatable.api().row(tr);
        var idx = $.inArray(tr.attr('id'), detailRows);
        if (row.child.isShown()) {
            //hide
            tr.removeClass('details');
            row.child.hide();
            // Remove from the 'open' array
            detailRows.splice(idx, 1);
        }
        else {
            //show
            tr.addClass('details');
            //row.child(formatit(row.data())).show();
            row.child(formatit(tr.attr('data-pro'))).show();
            // Add to the 'open' array
            if (idx === -1) {
                detailRows.push(tr.attr('id'));
            }
            //$('.datatableClass' + tr.attr('data-pro')).dataTable();
        }
    });
    $('#toggleAll').click(function () {
        var status = $(this).attr('data-status');
        $('#productQuantityTable tbody tr td.details-control').each(function () {
            var tr = $(this).closest('tr');
            var row = mydatatable.api().row(tr);
            var idx = $.inArray(tr.attr('id'), detailRows);
            if (status == "opend") {
                //hide
                tr.removeClass('details');
                row.child.hide();
                // Remove from the 'open' array
                detailRows.splice(idx, 1);
            } else if (status == "closed") {
                //show
                tr.addClass('details');
                //row.child(formatit(row.data())).show();
                row.child(formatit(tr.attr('data-pro'))).show();
                // Add to the 'open' array
                if (idx === -1) {
                    detailRows.push(tr.attr('id'));
                }
                //$('.datatableClass' + tr.attr('data-pro')).dataTable();
            }
        });
        if (status == "opend") {
            $('#toggleAll').attr('data-status', 'closed');
        } else if (status == "closed") {
            $('#toggleAll').attr('data-status', 'opend');
        }
    });
    function openDetailsRow() {
        $('#productQuantityTable tbody tr td.details-control').each(function () {
            var tr = $(this).closest('tr');
            var row = mydatatable.api().row(tr);
            var idx = $.inArray(tr.attr('id'), detailRows);
            //show
            tr.addClass('details');
            //row.child(formatit(row.data())).show();
            row.child(formatit(tr.attr('data-pro'))).show();
            // Add to the 'open' array
            if (idx === -1) {
                detailRows.push(tr.attr('id'));
            }
        });
        $('#toggleAll').attr('data-status', 'opend');
    }
    /*-----------------------------------------------------------*/
});


