$(document).ready(function () {

    getdataheader();
    getdata(0);

});

function getdataheader() {


    $("#MainContent_txt_linegroup").html("xxxxxxxxxxxxxxxxxxxxxxxxxx");
    $("#MainContent_txt_linename").html("xxxxxxxxxxxxxxxxxxx");
    $("#MainContent_txt_partnumber").html("xxxxxxxxxxxxx");
    $("#MainContent_txt_machine").html("xxxxxxxxxxxxx");




}



function newrows(ctl) {

    $('#tbldt tr').find('input').each(function () {


        if ($(this).attr('id').indexOf('Seq') != -1) {

            var ctlname = $(this).attr('id');
            var arrctl = ctlname.split('_');

            let irow = parseFloat(arrctl[3].toString());
            irow = irow + 1;
            addrow("Y");
            return false;



        }
    });

}

let inputrow = 0;
function addrow(news) {



    $('#tbldt tr').find('input').each(function () {


        if ($(this).attr('id').indexOf('Seq') != -1) {

            var ctlname = $(this).attr('id');
            var arrctl = ctlname.split('_');

            inputrow = parseFloat(arrctl[3].toString());



        }
    });

    var aClone = $('#tbldt tbody>tr:last').clone(true)
    var regex = new RegExp("_" + inputrow.toString(), "g");
    var newrow = aClone.html().replace(regex, "_" + (inputrow + 1).toString());
    inputrow++;
    $("#tbldt > tbody:last").append("<tr id='rowd_" + inputrow.toString() + "'>" + newrow + "</tr>");


    let iseq = 1;
    $('#tbldt tbody>tr input[type="text"]').each(function () {
        let ctl = $(this).attr('id');
        if (ctl.indexOf("Seq") != -1) {
            if ($(this).is(':hidden')) {

            } else {
                $(this).val(iseq.toString());
                iseq++;

            }
        }
    });


    $('#tbldt tbody>tr input[type="text"]').each(function () {

        $(this).addClass("fonttextcontent");
        $(this).css({ 'border-style': 'none' });
        $(this).prop('readonly', true);


    });







}

function getnext() {


    var elmnt = document.getElementById("g2");

    var y = elmnt.scrollTop;
    var x = elmnt.scrollHeight;
    var n = elmnt.clientHeight;
    //$("#MainContent_txt_linegroup").val(parseInt(y, 0).toString() + "," + (x - n).toString());
    if (parseInt(y, 0) == (x - n) - 1 || parseInt(y, 0) == (x - n)) {

        getdata(1);

        //pubcurrentpagestock = pubcurrentpagestock + 1;
        //try {

        //    setTimeout(
        //      function () {
        //          getdata(pubcurrentpagestock, pubirow, pubfilter, parseInt(y, 0));



        //      }, 500);



        //} catch (err) { };



    }

}
let iseqno = 1;
let ipub = 0;
function getdata(page) {

    if (page == 0) {
        for (let i = 0; i < 10; i++) {

            addrow("Y");

            $("#MainContent_txt_Tool_" + ipub.toString()).html("Tool_" + iseqno.toString());
            $("#MainContent_txt_Serial_" + ipub.toString()).html("Serial_" + iseqno.toString());
            $("#MainContent_txt_Expridate_" + ipub.toString()).html("dd/MM/yyyy");
            $("#MainContent_txt_Comment_" + ipub.toString()).html("comment_" + iseqno.toString());





            ipub++;
            iseqno++;



        }
    }
    else {

        for (var i = ipub; i < 20; i++) {

            addrow("Y");
            $("#MainContent_txt_Tool_" + ipub.toString()).html("Tool_" + iseqno.toString());
            $("#MainContent_txt_Serial_" + ipub.toString()).html("Serial_" + iseqno.toString());
            $("#MainContent_txt_Expridate_" + ipub.toString()).html("dd/MM/yyyy");
            $("#MainContent_txt_Comment_" + ipub.toString()).html("comment_" + iseqno.toString());

            ipub++;
            iseqno++;



        }



    }




}

