$(function(){    //預かり金行を追加する    $(document).on("click", ".rowAddDeposit", function() {        $ ("#depositTable").append(                $("<tr class=\"inner\"></tr>")                .append($("<td><input type=\"button\" name=\"\" class=\"btn btn-inverse rowDel\" value=\"削除\"></td>"))                .append($("<td><input type=\"text\" name=\"depositName[]\" class=\"form-control\"></td>"))                .append($("<td><input type=\"text\" id=\"deposit\" name=\"deposit[]\" class=\"deposit form-control hankaku\"></td>"))                );        $(".hankaku").on("change",function(){            var value = $(this).val();            var hankaku = halfNum(value);            $(this).val(hankaku);        });    });    //諸経費行を追加する    $(document).on("click", ".rowAddexpense", function() {        $ ("#expenseTable").append(                $("<tr class=\"inner\"></tr>")                .append($("<td><input type=\"button\" name=\"\" class=\"btn btn-inverse rowDel\" value=\"削除\"></td>"))                .append($("<td><input type=\"text\" name=\"expenseName[]\" class=\"form-control\"></td>"))                .append($("<td><input type=\"text\" id=\"expense\" name=\"expense[]\" class=\"expense form-control hankaku\"></td>"))                );        $(".hankaku").on("change",function(){            var value = $(this).val();            var hankaku = halfNum(value);            $(this).val(hankaku);        });    });    $(document).on("click", ".rowAddownerExpense", function() {        $ ("#ownerExpenseTable").append(                $("<tr class=\"inner\"></tr>")                .append($("<td><input type=\"button\" name=\"\" class=\"btn btn-inverse rowDel\" value=\"削除\"></td>"))                .append($("<td><input type=\"text\" name=\"ownerExpenseName[]\" class=\"form-control\"></td>"))                .append($("<td><input type=\"text\" name=\"ownerExpense[]\" class=\"expense form-control hankaku\"></td>"))                );        $(".hankaku").on("change",function(){            var value = $(this).val();            var hankaku = halfNum(value);            $(this).val(hankaku);        });    });    $(document).on("click", ".rowAddvendor", function() {        $ ("#vendorTable").append(                $("<tr class=\"inner\"></tr>")                .append($("<td><input type=\"button\" name=\"\" class=\"btn btn-inverse rowDel\" value=\"削除\"></td>"))                .append($("<td><input type=\"text\" name=\"vendorExpenseName[]\" class=\"form-control\"></td>"))                .append($("<td><input type=\"text\" name=\"vendorExpense[]\" class=\"expense form-control hankaku\"></td>"))                );        $(".hankaku").on("change",function(){            var value = $(this).val();            var hankaku = halfNum(value);            $(this).val(hankaku);        });    });    //金額を計算    function depositSum(){        var depositSum = 0;        $("#depositTable tr:gt(0):lt(99)").each(function(){            if(isNaN(parseInt($(this).children("td:eq(2)").children("#deposit").val()))){                depositSum += 0;            }else{                depositSum += parseInt($(this).children("td:eq(2)").children("#deposit").val());            }        });        $("#depositHidden").val(depositSum);        num = depositSum.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');        $("#depositSum").html(num);    }    function rentSum(){        var rentSum = 0;        $("#rentTable tr:gt(0):lt(99)").each(function(){            if($(this).children("td:eq(0)").children(".rent:checked").val()){                rentSum += parseInt($(this).children("td:eq(3)").children("#rent").val());            }else if($(this).children("td:eq(0)").children('.done').val()){                rentSum += parseInt($(this).children("td:eq(3)").children("#rent").val());            }        });        $("#rentHidden").val(rentSum);        num = rentSum.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');        $("#rentSum").html(num);    }    function otherCostSum(){        var otherCostSum = 0;        $("#otherCostTable tr:gt(0):lt(99)").each(function(){            if($(this).children("td:eq(0)").children(".otherCost:checked").val()){                otherCostSum += parseInt($(this).children("td:eq(3)").children("#otherCost").val());            }else if($(this).children("td:eq(0)").children('.done').val()){                otherCostSum += parseInt($(this).children("td:eq(3)").children("#otherCost").val());            }        });        $("#otherHidden").val(otherCostSum);        num = otherCostSum.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');        $("#otherCostSum").html(num);    }    function expenseSum(){        var expenseSum = 0;        $("#expenseTable tr:gt(0):lt(99)").each(function(){            if(isNaN(parseInt($(this).children("td:eq(2)").children("#expense").val()))){                expenseSum += 0            }else{                expenseSum += parseInt($(this).children("td:eq(2)").children("#expense").val());            }        });        $("#expenseHidden").val(expenseSum);        num = expenseSum.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');        $("#expenseSum").html(num);    }    function allSum(){        var depositSum = $("#depositHidden").val();        var rentSum = $("#rentHidden").val();        var otherCostSum = $("#otherHidden").val();        var expenseSum = $("#expenseHidden").val();        var allSum = 0;        allSum = eval(depositSum)-eval(rentSum)-eval(otherCostSum)-eval(expenseSum);        num = allSum.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');        $("#allSum").html(num);    }    //実行    $(document).ready(function(){        depositSum();        rentSum();        otherCostSum();        expenseSum();        allSum();    });    $(document).on("change", ".deposit", function() {        depositSum();        rentSum();        otherCostSum();        expenseSum();        allSum();    });    $(document).on("change", ".rent", function() {        depositSum();        rentSum();        otherCostSum();        expenseSum();        allSum();    });    $(document).on("change", "#rent", function() {        depositSum();        rentSum();        otherCostSum();        expenseSum();        allSum();    });    $(document).on("change", ".otherCost", function() {        depositSum();        rentSum();        otherCostSum();        expenseSum();        allSum();    });    $(document).on("change", "#otherCost", function() {        depositSum();        rentSum();        otherCostSum();        expenseSum();        allSum();    });    $(document).on("change", ".expense", function() {        expenseSum();        rentSum();        otherCostSum();        allSum();    });    //行を削除する    $(document).on("click", ".rowDel", function() {        $(this).parent().parent().remove();        depositSum();        rentSum();        expenseSum();        allSum();    });});