$(document).ready(function () {
    $("body").on('focus', '.colrrow', changeColour);
    $("body").on("click", ".remove", remove);
    $("body").on("blur", ".remark", AddRows);
    

    
        function changeColour() {
        $('tr input').focus(function () {
            var $tr = $(this).closest('tr'); //get tr
            $tr.css('background-color', '#91e7ff'); //change background color 
            $tr.siblings().css('background-color', 'white'); //set sibling tr's background color to be old color
        }).blur(function () {
            var $tr = $(this).closest('tr');//get tr
            $tr.css('background-color', 'white');//set tr's background color to be old color
        });
    }
    
         function remove() {
        $(this).closest("tr").remove();
    }
    
    $("#addnew").click(function () {
        AddRows();
    });
    
    function AddRows() {
        var ctr = $("#items").val();
        var addflg = $(".addflg").val();
        var hide_check = "";
        if ($("#del_all").prop("checked")) {
            hide_check = 0;
        } else {
            hide_check = 1;
        }
        var focusFld = ".focusFld_" + ctr;
        $.post(
                "sub_add.php",
                {ctr: ctr, hide: hide_check, addflg: addflg},
                function (data) {
                    $(data).appendTo(".tbody");
                    ctr++;
                    $("#items").val(ctr);
                    $(focusFld).focus();
                }
        );
    }

});
