$(document).ready(function () {
    $('body').on('change', '.karigar', getAcNo);
    $('body').on('change', '.karigar', getLogDate);
    $('body').on('blur', '.vouchdt', getLogDate);

    $("#hprint").hide();
    function getLogDate() {
        var party = $(".karigar").val(),
                vouchdt = $(".vouchdt").val();
        if (party != '' && vouchdt != '') {
            $.get('chk_LogDate.php', {party: party}, function (data) {
                if (data != '0000-00-00') {
                    $(".logdate").val(data);
                    if (vouchdt < data) {
                        alert('Voucher Date is Less than Log Date');
//                        $(".party").select2("val", "");

                        $(".karigar").select2("open");

                    }
                }
            });
        }

    }

    $("form").submit(function () {
        var party = $(".karigar").val(),
                vouchdt = $(".vouchdt").val(),
                valid = true;

        if (party != '' && vouchdt != '') {
            $.get('chk_LogDate.php', {party: party}, function (data) {
                if (data != '0000-00-00') {
                    $(".logdate").val(data);
                }
            });
        }
        var logdate = $(".logdate").val();
        if (vouchdt < logdate) {
            alert('VOUCHER DATE IS LESS THAN Log Date');
            return false;
            valid = false;
        }
    });

    function getAcNo() {
        var karigar = $(".karigar").val();
        if (karigar != '') {
            $.post('getAcNo.php', {karigar: karigar}, function (data) {
                $(".acnum").val(data);
            });
        }
    }


});