<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="role-mode" id="add-working-day" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content" >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel"><?php print CommonLanguage::getMessage('add_working_days'); ?></h4>
                <br>
            </div>
            <div class="modal-body">
                <div class="col-md-12" style="padding:0px;">
                    <div class="btn-group">
                        <?php foreach ($days as $day): ?>
                        <div class="col-md-4">
                            <input type="checkbox"   value="<?php echo $day['Working_Day_ID']; ?>" id="<?php echo $day['Working_Day_ID']; ?>" <?php echo $day['Is_Checked'] == 1 ? 'checked' : '' ?>>
                            <label for="<?php echo $day['Working_Day_ID']; ?>"><?php echo CommonLanguage::getMessage($day['Working_Day_Name']); ?></label>
                        </div>                           
                        <?php endforeach; ?>
                    </div>
                </div>
                <?php if ($permissions->hasPermission('viewWorkingDays')) { ?>
                <div class="col-md-12 m-t-10">
                    <a href="#" class="ViewExistingDays" data-toggle="modal" data-target="#view-working-days">+ <?php echo CommonLanguage::getMessage('view_working_days'); ?> </a><br>
                </div>
                <?php } ?>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" id="CloseaddWorkingDay" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button type="submit" class="btn btn-success " id="addWorkingDay"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('addworkingLoader'); ?>
        </div>
    </div>
</div>
<!-- End of Modal -->
<script>
    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
        Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            working_days_required = <?php echo json_encode(CommonLanguage::getMessage('working_days_required')); ?>;
            $(function () {
                $("#addWorkingDay").on("click", function () {
                    $("#addWorkingDayValidationAlert").remove();
                    var AlertBox = $('<div id="addWorkingDayValidationAlert" class="WizardValidationAlert alert"></div>'), IsValidated = true;
                    AlertBox.insertAfter($("#add-working-day").find(".modal-dialog .modal-header").find("h4"))
                    var days = [];
                    $('input[type="checkbox"]:checked').each(function () {
                        days.push($(this).attr("id"))
                    })
                    var Data = {
                        MyData: days
                    };
                    if (days.length == 0) {
                        $("#addWorkingDayValidationAlert").attr("class", "alert alert-danger").empty().html(shift_days_required);
                        return;
                    }
                    $("#addworkingLoader").removeClass('hidden')
                    $.ajax({
                        url: "HRMAjax/addWorkingDayRequest",
                        method: "POST",
                        data: Data,
                        complete: function (v1, v2) {
                            if (v2 == 'success') {
                                if (v1.responseText == 'ok') {
                                    $("#addWorkingDayValidationAlert").addClass("alert-success").empty().html(Submitted_Successfully);
                                    setTimeout(function () {
                                        $("#add-working-day").modal('hide')
                                        $("#addWorkingDayValidationAlert").hide()
                                    }, 1500);
                                } else {
                                    $("#addWorkingDayValidationAlert").addClass("alert-danger").empty().html(v1.responseText);
                                }
                            } else {
                                $("#addWorkingDayValidationAlert").addClass("alert-danger").empty().html(Failed_Submit);
                            }
                            $("#addworkingLoader").addClass('hidden')
                        }
                    })
                });
                $("#add-working-day .ViewExistingDays").on('click', function () {
                    $("#view-working-days div.workingDays").empty();
                    $("#viewworkingLoader").removeClass('hidden')
                    $.ajax({
                        url: "HRMAjax/addWorkingDayRequest?cmd=getdays",
                        dataType: "json",
                        complete: function (v1, v2) {
                            if (v2 == 'success') {
                                if ($.isArray(v1.responseJSON)) {
                                    var Response = v1.responseJSON;
                                    for (var i = 0; i < Response.length; i++) {
                                        $("#view-working-days div.workingDays").append('<div class="col-md-12" style="display: inline-flex;padding:5px"><label>' + Response[i]['Working_Day_Name'] + '</label></div>');
                                    }
                                } else {
                                    $("#addWorkingDayValidationAlert").addClass("alert-danger").empty().html(Failed_Submit);
                                }
                            } else {
                                $("#addWorkingDayValidationAlert").addClass("alert-danger").empty().html(Failed_Submit);
                            }
                            $("#viewworkingLoader").addClass('hidden')
                        }
                    })
                })
            });
</script>