<div class="modal fade " id="add_vehicle_mecanique" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label bold"><?php echo CommonLanguage::getMessage($is_syndicate ? 'syndicate' :'mecanique');?></h5>
                <div id="addchecupAlert"></div>
            </div>
            <div class="modal-body">
                <form id="add_vehicle_checkupForm" method="POST" onsubmit="return false">
                    <input type="hidden" class="Is_Edit" id="IS_Edit" value="0"/> 
                    <div class="row " >
                        <div class="col-md-12 form-group">
                            <label><?php echo CommonLanguage::getMessage('vehicle') ?></label><span class="red-star">*</span>
                            <input type="hidden" value="<?php  echo !empty($vehicle_id) ? $vehicle_id : '';?>" data-select-name="<?php  echo !empty($vehicle_name) ? $vehicle_name : '';?>" class="full-width vehicle_id" id="vehicle_id" required/>
                        </div>
                    </div>
                    <div class="row ">
                        <div class="col-md-12 form-group">
                            <label><?php echo CommonLanguage::getMessage('Date') ?></label><span class="red-star">*</span>
                            <input type="text" class="form-control mecanique_date" id="mecanique_date" value="" />
                        </div>
                    </div>
                    <div class="row " >
                        <div class="col-md-12 form-group">
                            <label><?php echo CommonLanguage::getMessage($is_syndicate ? 'start_insurance_date' : 'year') ?></label><span class="red-star">*</span>
                            <input type="text" class="form-control mecanique_year" id="mecanique_year" value="" />
                        </div>
                    </div>
                    <div class="row ">
                        <div class="col-md-12 form-group">
                            <label><?php echo CommonLanguage::getMessage('note') ?></label>
                            <textarea class="form-control mecanique_note" id="mecanique_note" style="resize:none"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <div class="pull-right">
                    <button class="btn btn-default" id="CloseCheckup" data-dismiss="modal"   > <?php print CommonLanguage::getMessage('Close'); ?> </button>
                    <button class="btn btn-bg-success-darker" id="SubmitCheckup"  > <?php print CommonLanguage::getMessage('Save'); ?>   </button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
        Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
                is_syndicate = <?php echo json_encode($is_syndicate); ?>,vehicle_mecanique_id;
    $(function () {
        build_select2($('#vehicle_id'), 'xhr/truckSearch');
        $('#mecanique_date').datepicker({autoclose: true});
        $('.new_vehicle_syndicate').on('click',function(){
            $('#mecanique_date').datepicker().datepicker("setDate", new Date());
        });
        if(is_syndicate == 0)
            $('#mecanique_year').attr("data-date-format","yyyy").datepicker({autoclose: true,minViewMode:'years',viewMode:'years'});
        else
            $('#mecanique_year').datepicker({autoclose: true});
        $('#SubmitCheckup').on('click', function () {
            var Data = {
                vehicle_id: $('#vehicle_id').val(),
                mecanique_year: $('#mecanique_year').val(),
                mecanique_date: $('#mecanique_date').val(),
                mecanique_note: $('#mecanique_note').val(),
                is_syndicate:$('#is_syndicate').val()
            };
            console.log("$('#mecanique_year').val(): "+$('#mecanique_year').val());
            console.log("$('#mecanique_date').val(): "+$('#mecanique_date').val());
            if (!$("#add_vehicle_checkupForm").valid() ||$('#mecanique_year').val()=='' || $('#mecanique_date').val()==''){
                $('#addchecupAlert').attr('class', 'alert alert-danger').empty().html(Required_Fields);
                return;}
            if ($('#IS_Edit').val() == 1) {
                Data.vehicle_mecanique_id = vehicle_mecanique_id;
            }
            $.ajax({
                url: "GarageAjax/addVehicleMecaniqueRequest",
                data: Data,
                dataType: 'JSON',
                type: 'post',
                complete: function (v, v2) {
                    if (v2 == 'success') {
                        if (v.responseJSON[0] == 'ok') {
                            $('#addchecupAlert').attr('class', 'alert alert-success').empty().html(Submitted_Successfully);
                            RebuildDataTable($('.panel-heading .panel-title').html(), [0, 1, 2, 3], 'GarageAjax/vehiclemecaniqueListRequest',{is_syndicate:$('#is_syndicate').val()});
                            setTimeout(function () {
                                $('#addchecupAlert').addClass('hidden');
                                $('#add_vehicle_mecanique').modal('hide');
                                $('#IS_Edit').val('0');
                            }, 800);
                        } else {
                            $('#addchecupAlert').attr('class', 'alert alert-danger').empty().html(v.responseJSON[1]);
                        }
                    } else {
                        $('#addchecupAlert').attr('class', 'alert alert-danger').empty().html(Failed_Submit);
                    }
                }
            });
        });
        $('#CloseCheckup').on('click', function () {
            $('#IS_Edit').val('0');
        });
    });
</script>  