<?php include('techsyn_header.php');
mysqli_query($conn, 'SET character_set_results=utf8');
error_log($_REQUEST['patient_id']);
error_log('abcde');
// print_r($_SESSION);
// print_r("PATIENT".$_REQUEST['patient_id']);

$patient_id = $_REQUEST['patient_id'];
error_log("forUpdate".$_REQUEST["forUpdate"]);
?>
<!-- Main Content Container for side bar and body-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">

<div class="main-container ace-save-state" id="main-container">
    <script type="text/javascript">
    try {
        ace.settings.loadState('main-container')
    } catch (e) {}
    </script>
    <?php include('techsyn_sidebar.php');
$user = $_SESSION['user_id'];
?>

    <!--breadcrumb-->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="breadcrumbs ace-save-state" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="ace-icon fa fa-home home-icon"></i>
                        <a href="#">Home</a>
                    </li>
                    <li class="#">Driving License Form Medical Examination</li>
                </ul>

            </div>
            <!-- End of breadcrumb -->



            <div class="page-content">
                <div class="box box-primary" style="padding: 10px; margin: 2px 0px 50px 5px; width: 99.5%; ">
                    <form enctype="multipart/form-data" id="question_form" method="post">
                        <?php
$sql1 = "select a.*,b.question_id,b.question_remarks,
b.question_answer,date_format(a.screen_date,'%d-%m-%Y %H:%i') as screening_date,c.id from questionaire_master_response a 
left join questionaire_master_response_details b on a.response_id = b.response_id left join patient_master c on a.patient_id = c.id where a.form_type='dlf' and a.patient_id='" . $_REQUEST['patient_id'] . "' and response_no='" . $_REQUEST['forUpdate'] . "'";
$result1 = @mysqli_query($conn, $sql1);
$num_rows1 = @mysqli_num_rows($result1);
$row2 = @mysqli_fetch_assoc($result1);
@extract($row2);
error_log("if data exists already " . $sql1);
error_log("date" . $row1['screening_date']);
?>

                        <div class="row">
                            <input type="hidden" name="response_id" id="response_id"
                                value="<?= $row2['response_id'] ?>">
                            <?php
if ($_SESSION['RoleCode'] == 'DOC') {
?>
                            <input type="hidden" id="approval_status" name="approval_status" value="Y">
                            <?php
} else {
?>
                            <input type="hidden" id="approval_status" name="approval_status" value="N">
                            <?php
}
?>

                            <div class="col-sm-3">
                                <label class="control-label" for="appointment_id"><strong
                                        style="font-size: 11px">Examination
                                        No:</strong></label>
                                <?php
if (empty($row2['medical_examination_no'])) {
$dlf_no = creatingDLFNo();
} else {
$dlf_no = $row2['medical_examination_no'];
}

?>
                                <input id="dlf_no" type="hidden" name="dlf_no" value="<?php echo $dlf_no; ?>" />

                                <div class="input-group">
                                    <b style="font-weight: 800"><?php echo $dlf_no; ?></b>

                                </div>
                            </div>
                        </div>
                        <hr>
                        <div class="row" style="margin-top: 5px;">
                            <div class="col-sm-3">
                                <label for="comm_date">Screening Date</label>
                                <input id="comm_date" type="text" class="form-control datetimepicker" name="comm_date"
                                    value="<?php echo $row2['screening_date'] ?>" />
                            </div>

                            <div class="col-sm-3">
                                <label for="height">Height</label>
                                <input type="number" id="height" name="height" class="form-control"
                                    onchange="calculateBMI();" value="<?php echo $row2['height'] ?>" />
                            </div>
                            <div class="col-sm-3">
                                <label for="weight">Weight</label>
                                <input type="number" id="weight" name="weight" class="form-control"
                                    onchange="calculateBMI();" value="<?php echo $row2['weight'] ?>" />
                            </div>
                            <div class="col-sm-3">
                                <label for="BMI">BMI</label>
                                <input type="number" readonly id="BMI" placeholder="BMI" name="BMI" class="form-control"
                                    value="<?php echo $row2['bmi'] ?>" />
                            </div>
                        </div>

                        <div class="row" style="margin-top: 5px;">
                            <div class="col-sm-3">
                                <label for="temp">Temprature</label>
                                <input type="number" id="temp" name="temp" class="form-control"
                                    value="<?php echo $row2['temp'] ?>" />
                            </div>
                            <div class="col-sm-3">
                                <label for="spo2">Spo2</label>
                                <input type="number" id="spo2" name="spo2" class="form-control"
                                    value="<?php echo $row2['spo2'] ?>" />
                            </div>
                            <div class="col-sm-3">
                                <label for="pulse">Pulse</label>
                                <input type="number" id="pulse" placeholder="" name="pulse" class="form-control"
                                    value="<?php echo $row2['pulse'] ?>" />
                            </div>
                            <div class="col-sm-3">
                                <label for="bp">BP</label>
                                <input type="text" id="bp" placeholder="" name="bp" class="form-control"
                                    value="<?php echo $row2['bp'] ?>" />
                            </div>
                        </div>


                        <div class="row" style="margin-top: 5px;">
                            <div class="col-sm-3">
                                <label for="distance_vis_rt">Distance Vision Right</label>
                                <input type="text" id="distance_vis_rt" placeholder="yes or no" name="distance_vis_rt"
                                    class="form-control" value="<?php echo $row2['distance_vis_rt'] ?>" />
                            </div>
                            <div class="col-sm-3">
                                <label for="distance_vis_lt">Distance Vision left</label>
                                <input type="text" id="distance_vis_lt" placeholder="yes or no" name="distance_vis_lt"
                                    class="form-control" value="<?php echo $row2['distance_vis_lt'] ?>" />
                            </div>
                            <div class="col-sm-3">
                                <label for="near_vis_rt">Near Vision Right</label>
                                <input type="text" id="near_vis_rt" name="near_vis_rt" placeholder="yes or no"
                                    class="form-control" value="<?php echo $row2['near_vis_rt'] ?>" />
                            </div>
                            <div class="col-sm-3">
                                <label for="near_vis_lt">Near Vision Left</label>
                                <input type="text" id="near_vis_lt" name="near_vis_lt" placeholder="yes or no"
                                    class="form-control" value="<?php echo $row2['near_vis_lt'] ?>" />
                            </div>
                        </div>
                        <div class="row" style="margin-top: 5px;">

                            <div class="col-sm-3">
                                <label for="color_vis">Color Vision</label>

                                <select name="color_vis" id="color_vis" placeholder="yes or no" class="form-control"
                                    value="<?php echo $row2['color_vis'] ?>">
                                    <option value="Normal"
                                        <?php if ($row2['color_vis'] == "Normal") echo 'selected="selected"'; ?>>Normal
                                    </option>
                                    <option value="Total CV Defect"
                                        <?php if ($row2['color_vis'] == "Total CV Defect") echo 'selected="selected"'; ?>>
                                        Total CV Defect
                                    </option>
                                    <option value="Partial CV Defect"
                                        <?php if ($row2['color_vis'] == "Partial CV Defect") echo 'selected="selected"'; ?>>
                                        Partial CV Defect
                                    </option>

                                </select>
                            </div>

                            <div class=" col-sm-3">
                                <label for="id_mark1">Identification Mark 1</label>

                                <textarea name="id_mark1" placeholder="Identification mark 1" class="form-control"
                                    id="id_mark1" cols="10"><?php echo $row2['id_mark1'] ?></textarea>
                            </div>
                            <div class="col-sm-3">
                                <label for="id_mark1">Identification Mark 2</label>

                                <textarea name="id_mark2" class="form-control" id="id_mark2"
                                    placeholder="Identification mark 2"
                                    cols="10"><?php echo $row2['id_mark2'] ?></textarea>
                            </div>


                        </div>

                </div>


            </div>



            <!-- box-body-->
            <div class="box-body">
                <div class="row">
                    <div class="col-sm-12">
                        <table id="myTable" class="table table-bordered order-list"
                            style="width: 100%; font-size: 11px">

                            <?php
$sql_sub_section = "select sub_section_order,section_name from questionaire_master where question_type='dlf' and sub_section_available='Y' group by sub_section_order";
$result_sub_section = mysqli_query($conn, $sql_sub_section);

$i = 0;
if (mysqli_num_rows($result_sub_section) > 0) {
while ($row_sub_section = mysqli_fetch_assoc($result_sub_section)) {
$section_name = $row_sub_section['section_name'];
?>
                            <thead>
                                <tr>

                                    <?php
$sql_config = "select value from config where key_name = 'QUESTIONNAIRE_LANGUAGE'";
$result_config = @mysqli_query($conn, $sql_config);

$row_config = @mysqli_fetch_array($result_config);



if ($row_config['value'] == 'LOCAL_LANGUAGE') { ?>

                                    <th></th>
                                    <th><?= $section_name ?></th>

                                    <th></th>

                                    <?php } elseif ($row_config['value'] == 'ENGLISH') { ?>


                                    <th>Sr.No</th>
                                    <th><?= $section_name ?></th>

                                    <th>Yes/No</th>
                                    <th>Observation and remark</th>

                                    <?php } else { ?>

                                    <th>Sr.No</th>
                                    <th><?= $section_name ?></th>

                                    <th>Yes/No</th>
                                    <th>Observation and remark</th>
                                    <?php } ?>


                                </tr>
                            </thead>
                            <tbody>

                                <?php

$sql = "select patient_name from patient_master WHERE id ='" . $_REQUEST['patient_id'] . "' ";

// echo $_REQUEST ['flex_patient_id'] ;
if (!$result = @mysqli_query($conn, $sql)) {
die(mysqli_error($conn));
}
if (mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_array($result)) {
//echo $row ['patient_name'];
}
}
error_log($sql);
?>
                                <?php

$row = null;
$sql = "select * from questionaire_master where question_type='dlf'  and sub_section_order='" . $row_sub_section['sub_section_order'] . "'  ";
$result = @mysqli_query($conn, $sql);
$num_rows = @mysqli_num_rows($result);
$row = @mysqli_fetch_array($result);

do {

?>


                                <tr>

                                    <td style="width:5%"><b> <?php echo $i + 1; ?><b></td>

                                    <td style="width: 60%">

                                        <input type="hidden" name="question_id<?php echo $i ?>"
                                            id="question_id<?php echo $i ?>"
                                            value="<?php echo $row['question_id'] ?>" />

                                        <input type="hidden" name="ftype" id="ftype"
                                            value="<?php echo $row['question_type'] ?>" />

                                        <input type="hidden" name="patient_id" id="patient_id"
                                            value="<?php echo $_REQUEST['patient_id']; ?>">

                                        <?php

if ($row_config['value'] == 'LOCAL_LANGUAGE') { ?>

                                        <b>
                                            <?php echo $row['question_hindi'] ?><b>

                                                <?php } elseif ($row_config['value'] == 'ENGLISH') { ?>

                                                <b>
                                                    <?php echo $row['question'] ?><b>

                                                        <?php } else { ?>

                                                        <b><?php echo $row['question'] ?> /
                                                            <?php echo $row['question_local_lang'] ?></b>

                                                        <?php } ?>
                                    </td>
                                    <?php
$sql_r = "SELECT question_remarks,question_answer from questionaire_master_response_details a left join questionaire_master_response b on a.response_id = b.response_id where b.patient_id='" . $_REQUEST['patient_id'] . "' and a.question_id='" . $row['question_id'] . "' and b.medical_examination_no='" . $dlf_no . "'";
error_log("remarks sql " . $sql_r);
$result_r = mysqli_query($conn, $sql_r);
$row_r = mysqli_fetch_assoc($result_r);
?>

                                    <td style="width: 20%">
                                        <select name="question_ans<?= $i ?>" id="question_ans<?= $i ?>"
                                            class="form-control">
                                            <option value="">select answer</option>
                                            <?php
    if ($row_r['question_answer'] == 'Y') {
    ?>
                                            <option value="Y" selected>Yes</option>
                                            <option value="N">No</option>
                                            <?php
    } else if ($row_r['question_answer'] == 'N') {
    ?>
                                            <option value="N" selected>No</option>
                                            <option value="Y">Yes</option>
                                            <?php
    } else {
    ?>
                                            <option value="Y">Yes</option>
                                            <option value="N">No</option>
                                            <?php
    }
    ?>
                                        </select>

                                    </td>

                                    <td style="width: 30%;">
                                        <textarea name="remarks<?= $i ?>" id="remarks<?= $i ?>" cols="30"
                                            rows="3"><?php echo $row_r['question_remarks'] ?></textarea>
                                    </td>
                                </tr>
                                <?php
$i++;
} while ($row = @mysqli_fetch_array($result));
}
} else {
?>
                                <thead>
                                    <tr>

                                        <?php
$sql_config = "select value from config where key_name = 'QUESTIONNAIRE_LANGUAGE'";
$result_config = @mysqli_query($conn, $sql_config);

$row_config = @mysqli_fetch_array($result_config);



if ($row_config['value'] == 'LOCAL_LANGUAGE') { ?>

                                        <th></th>
                                        <th> </th>

                                        <th></th>

                                        <?php } elseif ($row_config['value'] == 'ENGLISH') { ?>


                                        <th>Sr.No</th>
                                        <th>Please answer the questions in Yes or No</th>

                                        <th>Yes/No</th>
                                        <th>Observation and remark</th>

                                        <?php } else { ?>

                                        <th>Sr.No</th>
                                        <th> Please
                                            answer the questions in Yes or No</th>

                                        <th>Yes/No</th>
                                        <th>Observation and remark</th>
                                        <?php } ?>


                                    </tr>
                                </thead>
                            <tbody>

                                <?php

$sql = "select patient_name from patient_master WHERE id ='" . $_REQUEST['flex_patient_id'] . "' ";

// echo $_REQUEST ['flex_patient_id'] ;
if (!$result = @mysqli_query($conn, $sql)) {
die(mysqli_error($conn));
}
if (mysqli_num_rows($result) > 0) {
while ($row = @mysqli_fetch_array($result)) {
//echo $row ['patient_name'];
}
}
error_log($sql);
?>
                                <?php $i = 0;
$row = null;
$sql = "select * from questionaire_master where question_type='dlf'";
$result = @mysqli_query($conn, $sql);
$num_rows = @mysqli_num_rows($result);
$row = @mysqli_fetch_array($result);

do {
$count = 0;
?>


                                <tr>

                                    <td style="width:5%"><b> <?php echo $i + 1; ?><b></td>

                                    <td style="width: 60%">

                                        <input type="hidden" name="question_id<?php echo $i ?>"
                                            id="question_id<?php echo $i ?>"
                                            value="<?php echo $row['question_id'] ?>" />
                                        <input type="hidden" name="ftype" id="ftype"
                                            value="<?php echo $row['question_type'] ?>" />
                                        <input type="hidden" name="patient_id" id="patient_id"
                                            value="<?php echo $_REQUEST['patient_id']; ?>">

                                        <?php

if ($row_config['value'] == 'LOCAL_LANGUAGE') { ?>

                                        <b><?php echo $row['question_hindi'] ?><b>

                                                <?php } elseif ($row_config['value'] == 'ENGLISH') { ?>

                                                <b><?php echo $row['question'] ?><b>

                                                        <?php } else { ?>

                                                        <b><?php echo $row['question'] ?>
                                                            <?php echo $row['question_hindi'] ?></b>

                                                        <?php } ?>




                                    </td>



                                    <td style="width: 20%">
                                        <select name="question_ans<?= $i ?>" id="question_ans<?= $i ?>"
                                            class="form-control">
                                            <option value="">select answer</option>
                                            <?php
    if ($row2['question_answer'] == 'Y') {
    ?>
                                            <option value="Y" selected>Yes</option>
                                            <option value="N">No</option>
                                            <?php
    } else if ($row2['question_answer'] == 'N') {
    ?>
                                            <option value="N" selected>No</option>
                                            <option value="Y">Yes</option>
                                            <?php
    } else {
    ?>
                                            <option value="Y">Yes</option>
                                            <option value="N">No</option>
                                            <?php
    }
    ?>
                                        </select>

                                    </td>
                                    <?php $qremarks =  getTableFieldValue('questionaire_master_response_details', 'question_remarks', 'patient_id', $_REQUEST['patient_id'], 'question_id', $i,) ?>
                                    <td style="width: 30%;">
                                        <textarea name="remarks<?= $i ?>" id="remarks<?= $i ?>" cols="30"
                                            rows="3"><?= $qremarks ?></textarea>
                                    </td>
                                </tr>
                                <?php
$i++;
} while ($row = @mysqli_fetch_array($result));
//end of while
}
?>
                            </tbody>
                        </table>

                        <input type="hidden" name="count_items" id="count_items" value="<?php echo $i ?>" />

                    </div>

                </div>

            </div>
            <!-- End box-body-->
            <!--box-footer-->
            <br><br>

            <div class="box-footer" style="text-align: center;">

                <!-- <button class="btn btn-info save_button" id="save_button" type="button"
onclick="validate();">
<i class="ace-icon fa fa-floppy-o bigger-110"></i>
Save
</button> -->
                <input type="hidden" name="attendedStatus" id="attendedStatus" value="" />
                <a class="btn btn-primary btn-bold" id="forwardButton" tabindex="0" aria-controls="dynamic-table"
                    data-original-title="Send To chief medical officer" title="Save"><span> <span
                            class="hidden">Forword</span></span> Forword</a>
                <script>
                <?php
if ($_SESSION['RoleCode'] == 'LAB') {    ?>

                $("#forwardButton").on("click", function() {

                    BootstrapDialog.show({
                        // type: BootstrapDialog.TYPE_DEFAULT,
                        title: 'Save & Forward',

                        message: '<select class="form-control"  id="forward_status" >' +
                            '<option value="<?php echo $__STATUS_DOCTOR_PENDING ?>">Forward To Doctor</option>' +
                            '</select>',

                        buttons: [{
                            label: 'Save & Submit',
                            icon: 'fa fa-save',
                            cssClass: 'btn-info',
                            action: function() {
                                $("#attendedStatus").val($("#forward_status")
                                    .val());
                                validate($("#forward_status").val())
                                $(".close").click();
                            }
                        }]
                    });
                });
                <?php  } else { ?>
                validate($("#forward_status").val())
                <?php  } ?>
                </script>

                &nbsp; &nbsp; &nbsp;
                <button class="btn btn-warning" type="reset">
                    <i class="ace-icon fa fa-undo bigger-110"></i>
                    Reset
                </button>
                &nbsp; &nbsp; &nbsp;
                <button class="btn btn-success" id="generate_pdf" onclick='printpdf()'>

                    <i class="ace-icon fa fa-print"></i> Print Pdf

                </button>

            </div>

            <!--End box-footer-->
            <input type="hidden" name="forUpdate" id="forUpdate" value=<?php echo $_REQUEST['forUpdate'] ?> />

            </form>
        </div>


        <!-- Main Content Container for side bar and body-->
        <div class="main-container ace-save-state" id="main-container">
            <script type="text/javascript">
            try {
                ace.settings.loadState('main-container')
            } catch (e) {}
            </script>





            <!--breadcrumb-->
            <div class="main-content">
                <div class="main-content-inner">

                    <!-- End of breadcrumb -->


                    <form name="export_form" method="post" id="export_form" action="">

                        <input type="hidden" name="pdf_actions" id="pdf_actions"
                            value="bio_medical_waste_generation_pdf.php" />
                        <input type="hidden" name="excel_actions" id="excel_actions"
                            value="bio_medical_waste_generation_excel.php" />
                        <input type="hidden" name="pdf_action" id="pdf_action" value="biowaste_pdf.php" />
                        <input type="hidden" name="excel_action" id="excel_action" value="excel_ambulance.php" />
                    </form>


                </div>
            </div>



        </div><!-- /.page-content -->
    </div>
</div><!-- /.main-content -->


<script type="text/javascript">
function calculateBMI() {
    var height = $("#height").val();
    var weight = $("#weight").val();
    if (height != null && height != '' && weight != null && weight != '') {
        height = parseFloat(height);
        weight = parseFloat(weight);
        if (height != 0.0)
            var bmi = (weight / (height * height)) * 100 * 100;
        $("#BMI").val(bmi.toFixed(1));
    }
}



function show_save_button() {
    $("#save_button").show()
}


function printpdf() {

    $("#question_form").attr('method', 'POST');
    $("#question_form").attr('action', 'driving_licence_form_pdf_dlf.php');
    $("#question_form").attr('target', "_blank");
    $("#question_form").submit();
}


function myDateFormat(date) {

    var d = new Date(date);
    var day = d.getDate();
    var m = d.getMonth() + 1;
    var y = d.getFullYear();


    return day + "-" + m + "-" + y;


}
</script>

<?php include('techsyn_footer.php'); ?>




</div>


<!-- End of page-content -->
</div>
</div>
</div>

<script>
function validate() {
    save();
}
</script>

<style>
#modal-add-ailment {
    overflow-y: scroll;
}
</style>



<?php include('techsyn_footer.php'); ?>
<script type="text/javascript">
$('.select2').select2()
jQuery(function($) {

    var myTable =
        $('#dynamic-table')

        .DataTable({
            bAutoWidth: false,
            "aoColumns": [{
                    "bSortable": false
                },
                null, null, null, null, null,
                {
                    "bSortable": false
                }
            ],
            "aaSorting": [],





            select: {
                style: 'multi'
            }
        });




    var defaultCopyAction = myTable.button(1).action();
    myTable.button(1).action(function(e, dt, button, config) {
        defaultCopyAction(e, dt, button, config);
        $('.dt-button-info').addClass('gritter-item-wrapper gritter-info gritter-center white');
    });


    var defaultColvisAction = myTable.button(0).action();
    myTable.button(0).action(function(e, dt, button, config) {

        defaultColvisAction(e, dt, button, config);


        if ($('.dt-button-collection > .dropdown-menu').length == 0) {
            $('.dt-button-collection')
                .wrapInner('<ul class="dropdown-menu dropdown-light dropdown-caret dropdown-caret" />')
                .find('a').attr('href', '#').wrap("<li />")
        }
        $('.dt-button-collection').appendTo('.tableTools-container .dt-buttons')
    });



    setTimeout(function() {
        $($('.tableTools-container')).find('a.dt-button').each(function() {
            var div = $(this).find(' > div').first();
            if (div.length == 1) div.tooltip({
                container: 'body',
                title: div.parent().text()
            });
            else $(this).tooltip({
                container: 'body',
                title: $(this).text()
            });
        });
    }, 500);





    myTable.on('select', function(e, dt, type, index) {
        if (type === 'row') {
            $(myTable.row(index).node()).find('input:checkbox').prop('checked', true);
        }
    });
    myTable.on('deselect', function(e, dt, type, index) {
        if (type === 'row') {
            $(myTable.row(index).node()).find('input:checkbox').prop('checked', false);
        }
    });




    $('th input[type=checkbox], td input[type=checkbox]').prop('checked', false);


    $('#dynamic-table > thead > tr > th input[type=checkbox], #dynamic-table_wrapper input[type=checkbox]').eq(
        0).on('click', function() {
        var th_checked = this.checked;

        $('#dynamic-table').find('tbody > tr').each(function() {
            var row = this;
            if (th_checked) myTable.row(row).select();
            else myTable.row(row).deselect();
        });
    });


    $('#dynamic-table').on('click', 'td input[type=checkbox]', function() {
        var row = $(this).closest('tr').get(0);
        if (this.checked) myTable.row(row).deselect();
        else myTable.row(row).select();
    });



    $(document).on('click', '#dynamic-table .dropdown-toggle', function(e) {
        e.stopImmediatePropagation();
        e.stopPropagation();
        e.preventDefault();
    });




    var active_class = 'active';
    $('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function() {
        var th_checked = this.checked;

        $(this).closest('table').find('tbody > tr').each(function() {
            var row = this;
            if (th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0)
                .prop('checked', true);
            else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop(
                'checked', false);
        });
    });

    $('#simple-table').on('click', 'td input[type=checkbox]', function() {
        var $row = $(this).closest('tr');
        if ($row.is('.detail-row ')) return;
        if (this.checked) $row.addClass(active_class);
        else $row.removeClass(active_class);
    });




    $('[data-rel="tooltip"]').tooltip({
        placement: tooltip_placement
    });


    function tooltip_placement(context, source) {
        var $source = $(source);
        var $parent = $source.closest('table')
        var off1 = $parent.offset();
        var w1 = $parent.width();

        var off2 = $source.offset();


        if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
        return 'left';
    }




    /***************/
    $('.show-details-btn').on('click', function(e) {
        e.preventDefault();
        $(this).closest('tr').next().toggleClass('open');
        $(this).find(ace.vars['.icon']).toggleClass('fa-angle-double-down').toggleClass(
            'fa-angle-double-up');
    });
    /***************/






})

function save() {
    $.ajax({
        url: 'save_dlf_question.php',
        type: "POST",
        data: $("#question_form").serialize(),
        success: function(data) {
            // alert(data);
            BootstrapDialog.alert('Saved Successfully.');
            // location.reload();
            setTimeout(() => {
                window.location.replace("home_medical.php");
            }, 2000);

            return;
        },
        error: function(data) {
            BootstrapDialog.alert('Error Saving Covid Questions');
            return;
        }
    });
    $('.close').click();
    // location.href="procurement_list.php";
}
$('.date-picker').datepicker({
    autoclose: true,
    format: 'dd/mm/yyyy'
}).next().on(ace.click_event, function() {
    $(this).prev().focus();
});
</script>
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="assets/font-awesome/4.5.0/css/font-awesome.min.css" />

<!-- page specific plugin styles -->
<link rel="stylesheet" href="assets/css/jquery-ui.custom.min.css" />
<link rel="stylesheet" href="assets/css/chosen.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-datepicker3.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-timepicker.min.css" />
<link rel="stylesheet" href="assets/css/daterangepicker.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-datetimepicker.min.css" />
<link rel="stylesheet" href="assets/css/bootstrap-colorpicker.min.css" />
<script type="text/javascript" src="js/typeahead.bundle.js"></script>
<script src="assets/js/jquery-ui.custom.min.js"></script>
<script src="assets/js/jquery.ui.touch-punch.min.js"></script>
<script src="assets/js/chosen.jquery.min.js"></script>
<script src="assets/js/spinbox.min.js"></script>
<script src="assets/js/bootstrap-datepicker.min.js"></script>
<script src="assets/js/bootstrap-timepicker.min.js"></script>
<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/jquery.dataTables.bootstrap.min.js"></script>
<script src="assets/js/dataTables.buttons.min.js"></script>
<script src="assets/js/buttons.flash.min.js"></script>
<script src="assets/js/buttons.html5.min.js"></script>
<script src="assets/js/buttons.print.min.js"></script>
<script src="assets/js/buttons.colVis.min.js"></script>
<script src="assets/js/dataTables.select.min.js"></script>


<script src="assets/js/moment.min.js"></script>
<script src="assets/js/daterangepicker.min.js"></script>
<script src="assets/js/bootstrap-datetimepicker.min.js"></script>
<script src="assets/js/bootstrap-colorpicker.min.js"></script>
<script src="assets/js/jquery.knob.min.js"></script>
<script src="assets/js/autosize.min.js"></script>
<script src="assets/js/jquery.inputlimiter.min.js"></script>
<script src="assets/js/jquery.maskedinput.min.js"></script>
<script src="assets/js/bootstrap-tag.min.js"></script>
<script src="assets/js/ace-elements.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
    var counter = $("#count_items").val();
    //alert (counter);
    $("#addrow").on("click", function() {
        var newRow = $("<tr>");
        var task_frequency_option = $("#task_frequency0").html();
        var ohc_type_option = $("#ohc_type0").html();
        console.log("task_frequency_option" + task_frequency_option);
        var cols = "";


        cols += '<td><input type="text" class="form-control" id="frequency_name' + counter +
            '" name="frequency_name' + counter + '"/></td>';
        cols += '<td><input type="text" class="form-control" id="frequency_code' + counter +
            '" name="frequency_code' + counter + '"/></td>';
        cols +=
            '<td align="center"><a href="#" class="btn-lg" data-toggle="tooltip" id="deletebtn" title="Delete"><span class="glyphicon glyphicon-trash"></span></a></td>';

        newRow.append(cols);
        $("#myTable").append(newRow);
        /*$('#item_id'+counter).chosen({allow_single_deselect:true}); 
        $('#item_id'+counter).next().css({'width': $('#item_id'+counter).parent().width()});*/
        counter++;
        $('.select2').select2()
        $("#count_items").val(counter);
        $('.date-picker').datepicker({
            autoclose: true,
            todayHighlight: true
        })
    });




    $("#myTable").on("click", "#deletebtn", function(event) {
        $(this).closest("tr").remove();
        counter -= 1
        $("#count_items").val(counter);
    });


});
</script>

<script type="text/javascript">
jQuery(function($) {
    $('#id-disable-check').on('click', function() {
        var inp = $('#form-input-readonly').get(0);
        if (inp.hasAttribute('disabled')) {
            inp.setAttribute('readonly', 'true');
            inp.removeAttribute('disabled');
            inp.value = "This text field is readonly!";
        } else {
            inp.setAttribute('disabled', 'disabled');
            inp.removeAttribute('readonly');
            inp.value = "This text field is disabled!";
        }
    });


    if (!ace.vars['touch']) {
        $('.chosen-select').chosen({
            allow_single_deselect: true
        });


        $(window)
            .off('resize.chosen')
            .on('resize.chosen', function() {
                $('.chosen-select').each(function() {
                    var $this = $(this);
                    $this.next().css({
                        'width': $this.parent().width()
                    });
                })
            }).trigger('resize.chosen');
        //resize chosen on sidebar collapse/expand
        $(document).on('settings.ace.chosen', function(e, event_name, event_val) {
            if (event_name != 'sidebar_collapsed') return;
            $('.chosen-select').each(function() {
                var $this = $(this);
                $this.next().css({
                    'width': $this.parent().width()
                });
            })
        });


        $('#chosen-multiple-style .btn').on('click', function(e) {
            var target = $(this).find('input[type=radio]');
            var which = parseInt(target.val());
            if (which == 2) $('#form-field-select-4').addClass('tag-input-style');
            else $('#form-field-select-4').removeClass('tag-input-style');
        });
    }


    $('[data-rel=tooltip]').tooltip({
        container: 'body'
    });
    $('[data-rel=popover]').popover({
        container: 'body'
    });

    autosize($('textarea[class*=autosize]'));

    $('textarea.limited').inputlimiter({
        remText: '%n character%s remaining...',
        limitText: 'max allowed : %n.'
    });




    //"jQuery UI Slider"
    //range slider tooltip example
    $("#slider-range").css('height', '200px').slider({
        orientation: "vertical",
        range: true,
        min: 0,
        max: 100,
        values: [17, 67],
        slide: function(event, ui) {
            var val = ui.values[$(ui.handle).index() - 1] + "";

            if (!ui.handle.firstChild) {
                $("<div class='tooltip right in' style='display:none;left:16px;top:-6px;'><div class='tooltip-arrow'></div><div class='tooltip-inner'></div></div>")
                    .prependTo(ui.handle);
            }
            $(ui.handle.firstChild).show().children().eq(1).text(val);
        }
    }).find('span.ui-slider-handle').on('blur', function() {
        $(this.firstChild).hide();
    });


    $("#slider-range-max").slider({
        range: "max",
        min: 1,
        max: 10,
        value: 2
    });

    $("#slider-eq > span").css({
        width: '90%',
        'float': 'left',
        margin: '15px'
    }).each(function() {
        // read initial values from markup and remove that
        var value = parseInt($(this).text(), 10);
        $(this).empty().slider({
            value: value,
            range: "min",
            animate: true

        });
    });

    $("#slider-eq > span.ui-slider-purple").slider('disable'); //disable third item


    $('#id-input-file-1 , #id-input-file-2').ace_file_input({
        no_file: 'No File ...',
        btn_choose: 'Choose',
        btn_change: 'Change',
        droppable: false,
        onchange: null,
        thumbnail: false //| true | large
        //whitelist:'gif|png|jpg|jpeg'
        //blacklist:'exe|php'
        //onchange:''
        //
    });
    //pre-show a file name, for example a previously selected file
    //$('#id-input-file-1').ace_file_input('show_file_list', ['myfile.txt'])






    //datepicker plugin
    //link
    $('.date-picker').datepicker({
            autoclose: true,
            todayHighlight: true
        })
        //show datepicker when clicking on the icon
        .next().on(ace.click_event, function() {
            $(this).prev().focus();
        });



    //chosen plugin inside a modal will have a zero width because the select element is originally hidden
    //and its width cannot be determined.
    //so we set the width after modal is show
    $('#modal-form').on('shown.bs.modal', function() {
        if (!ace.vars['touch']) {
            $(this).find('.chosen-container').each(function() {
                $(this).find('a:first-child').css('width', '210px');
                $(this).find('.chosen-drop').css('width', '210px');
                $(this).find('.chosen-search input').css('width', '200px');
            });
        }
    })
    /**
    //or you can activate the chosen plugin after modal is shown
    //this way select element becomes visible with dimensions and chosen works as expected
    $('#modal-form').on('shown', function () {
    $(this).find('.modal-chosen').chosen();
    })
    */



    $(document).one('ajaxloadstart.page', function(e) {
        autosize.destroy('textarea[class*=autosize]')

        $('.limiterBox,.autosizejs').remove();
        $('.daterangepicker.dropdown-menu,.colorpicker.dropdown-menu,.bootstrap-datetimepicker-widget.dropdown-menu')
            .remove();
    });

});


jQuery(function($) {


    $('.date-picker').datepicker({
            autoclose: true,
            todayHighlight: true
        })
        //show datepicker when clicking on the icon
        .next().on(ace.click_event, function() {
            $(this).prev().focus();
        });



    $('#timepicker1').timepicker({
        minuteStep: 1,
        showSeconds: true,
        showMeridian: false,
        disableFocus: true,
        icons: {
            up: 'fa fa-chevron-up',
            down: 'fa fa-chevron-down'
        }
    }).on('focus', function() {
        $('#timepicker1').timepicker('showWidget');
    }).next().on(ace.click_event, function() {
        $(this).prev().focus();
    });



    /*
    if(!ace.vars['old_ie']) $('#appointment_date').datetimepicker({
    format: 'DD/MM/YYYY h:mm A',//use this option to display seconds
    defaultDate: new Date(<?php echo $row['appointment_date'] ?>),
    maxDate:  new Date(),
    icons: {
    time: 'fa fa-clock-o',
    date: 'fa fa-calendar',
    up: 'fa fa-chevron-up',
    down: 'fa fa-chevron-down',
    previous: 'fa fa-chevron-left',
    next: 'fa fa-chevron-right',
    today: 'fa fa-arrows ',
    clear: 'fa fa-trash',
    close: 'fa fa-times'
    }
    }).next().on(ace.click_event, function(){
    $(this).prev().focus();
    });



    */
    if (!ace.vars['old_ie']) $('.datetimepicker').datetimepicker({
        format: 'DD/MM/YYYY h:mm A', //use this option to display seconds
        defaultDate: new Date(),
        maxDate: new Date(),
        icons: {
            time: 'fa fa-clock-o',
            date: 'fa fa-calendar',
            up: 'fa fa-chevron-up',
            down: 'fa fa-chevron-down',
            previous: 'fa fa-chevron-left',
            next: 'fa fa-chevron-right',
            today: 'fa fa-arrows',
            clear: 'fa fa-trash',
            close: 'fa fa-times'
        }
    }).next().on(ace.click_event, function() {
        $(this).prev().focus();
    });

    // if(!ace.vars['old_ie']) $('#intake_time<?php echo $i ?>').datetimepicker({
    //  format: 'DD/MM/YYYY h:mm A',//use this option to display seconds
    //  defaultDate: new Date(),
    //  maxDate:  new Date(),
    //  icons: {
    // 	time: 'fa fa-clock-o',
    // 	date: 'fa fa-calendar',
    // 	up: 'fa fa-chevron-up',
    // 	down: 'fa fa-chevron-down',
    // 	previous: 'fa fa-chevron-left',
    // 	next: 'fa fa-chevron-right',
    // 	today: 'fa fa-arrows',
    // 	clear: 'fa fa-trash',
    // 	close: 'fa fa-times'
    //  }
    // }).next().on(ace.click_event, function(){
    // 	$(this).prev().focus();
    // });


    // if(!ace.vars['old_ie']) $('#output_time<?php echo $i ?>').datetimepicker({
    //  format: 'DD/MM/YYYY h:mm A',//use this option to display seconds
    //  defaultDate: new Date(),
    //  maxDate:  new Date(),
    //  icons: {
    // 	time: 'fa fa-clock-o',
    // 	date: 'fa fa-calendar',
    // 	up: 'fa fa-chevron-up',
    // 	down: 'fa fa-chevron-down',
    // 	previous: 'fa fa-chevron-left',
    // 	next: 'fa fa-chevron-right',
    // 	today: 'fa fa-arrows',
    // 	clear: 'fa fa-trash',
    // 	close: 'fa fa-times'
    //  }
    // }).next().on(ace.click_event, function(){
    // 	$(this).prev().focus();
    // });

})
</script>