
function printContent(el) {
    var restorepage = document.body.innerHTML;
    var printcontent = document.getElementById(el).innerHTML;
    document.body.innerHTML = printcontent;
    print_Custom('mycustomheader');
    document.body.innerHTML = restorepage;
}

$(document).ready(function (e) {
    //sync kitchen printNewBill
    var interval = Number($('#printTimeOut').val());//20000;  // 1000 = 1 second, 20000 = 20 seconds
    if (interval == 0)
    {
        interval = 1;
    }
    interval = interval * 1000;
    function synckitchenPrint() {
        //console.log(interval);
        var togetherArrJSON = '';
        $.ajax({
            type: 'POST',
            url: 'restaurantKitchenPrinterAjax.php?do=printNewBill&printer=' + $('#printer').val(),
            async: false,
            success: function (data) {
                $('#printThisDiv').html(data);
                if (Number($('#togetherArrCount').val()) > 0)
                {
                    printContent('printThisDiv');
                }

            },
            complete: function (data) {
                if (Number($('#togetherArrCount').val()) > 0)
                {
                    $.ajax({
                        type: "POST",
                        url: 'restaurantKitchenPrinterAjax.php?do=markTogetherValAsPrinted&printer=' + $('#printer').val(),
                        data: {togetherArrJSON: $('#togetherArrJSON').val()},
                        async: false,
                        success: function (data) {
                            $('#printThisDiv').html("");
                        }});
                }
                // Schedule the next********************************
                setTimeout(synckitchenPrint, interval);
            }
        });


    }

    setTimeout(synckitchenPrint, interval);


});