$(document).ready(function () {
    //CalendarConfigurationList();
    //if ($('#SelSchedule').val()==0) {
    //    $('#SelDoctor_div').hide();
    //    $('#SelDepartment_div').hide();
    //}
});

function LoadDoctor() {
    debugger;
    var roleId = $('#hiddenRole_id').val();

    var DoctorData = {
        Dml_Indicator: "HDL",
        hospital_id: $('#HospitalId').val(),
        branch_id: $('#SelBranch').val()
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/CalendarConfiguration/HosiptalSelect',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(DoctorData),
        success: function (data) {
            if (jQuery.isEmptyObject((data))) {
            }
            else {
                var data1 = JSON.parse(data)
                console.log(data1);
                if (data1.msg = "Success") {
                    var tr = '';
                    var SelRole = '';
                    $('#SelDoctor').empty();
                    var default_opt = '<option value="0">--Select--</option>';
                    var j = 0;
                    if (data1.data.length > 0) {
                        for (var i = 0; i < data1.data.length; i++) {
                            j++;
                            SelRole = SelRole + '<option value="' + data1.data[i].doctor_id + '">' + data1.data[i].first_name + '</option>';
                        }

                        if (data1.data.length == 1) {
                            $('#SelDoctor').append(SelRole);
                            $('#SelDoctor').change();
                        }
                        else {
                            $('#SelDoctor').append(default_opt + SelRole);
                        }

                        if ($('#hiddenRole_id').val() == 2 || $('#hiddenRole_id').val() == 6) {
                            $('#SelDoctor').attr('disabled', false);
                        }
                        else {
                            $('#SelDoctor').append(default_opt + SelRole);
                            //$('#SelDoctor').val($('#HiddenDoctorID').val());
                            //$('#SelDoctor').attr('disabled', true);
                            $('#SelDoctor').change();
                        }

                    }
                }
                else {
                    console.log(data1);
                }

            }

        }
    });
}

function LoadBranch() {
    $('#SelBranch').empty();

    //Only KinderSurge
    //var dml = ''
    //if (parseInt($('#hiddenRole_id').val()) == 1) {
    //    dml = 'DLBRAN'
    //}
    //else {
    //    dml = 'LBRAN'
    //}

    var subdepartment = {
        Dml_Indicator: "LBRAN",
        //Dml_Indicator: dml,
        name: $('#HiddenDoctorID').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(subdepartment),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                console.log(data1);
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    debugger;
                    var SubDepartment;
                    var default_opt = '<option value="0">All</option>';
                    $.each(data1.Table, function (i, emp) {
                        SubDepartment = SubDepartment + '<option value="' + emp.hospital_branch_id + '">' + emp.branch_name + '</option>';
                    });
                    if (data1.Table.length == 1) {
                        $('#SelBranch').append(SubDepartment);
                        $('#SelBranch').change();
                    }
                    else {
                        $('#SelBranch').append(default_opt + SubDepartment);
                    }
                    
                    //Only KinderSurge
                    //if ($('#hiddenRole_id').val() == 1) {
                    //    $('#SelBranch').val($('#HospitalBranchID').val());
                    //    LoadDoctor();
                    //    $('#SelDoctor_div').show();
                    //}
                    //else 
                    if ($('#hiddenRole_id').val() != 2) {
                        $('#SelBranch').val($('#HospitalBranchID').val());
                        $('#SelBranch').attr('disabled', true);
                        // LoadDoctor();
                        $('#Hdn_doctorid').val('');
                        $('#SelDoctor_div').show();
                        $('#SelDoctor').val(data1.Table1[0].doctorname);
                        $('#Hdn_doctorid').val($('#HiddenDoctorID').val());
                        $('#CalendarConfiguration').empty();
                        CalendarConfigurationList();

                    }
                }
            }
            else {
                console.log(data1);
            }

        }
    });
}
//Schedule Type change
$('#SelSchedule').change(function () {
    debugger;
    if ($('#SelSchedule').val() != 0) {
        debugger;
        $('#SelDoctor').empty();
        $('#CalendarConfiguration').empty();
        if ($('#SelSchedule').val() == 1) {
            $('#SelDoctor').attr('disabled', false);
            LoadDoctor();
            $('#SelDoctor_div').show();
            $('#SelDepartment_div').hide();
            $('#Selsubdept_div').hide();
            $('#Selservice_div').hide();
        }
        else {
            $('#SelDepartment').val(0);
            $('#SelSubDepartment').val(0);
            $('#SelService').val(0);
            $('#SelDoctor_div').hide();
            $('#SelDepartment_div').show();
            $('#Selsubdept_div').show();
            $('#Selservice_div').hide();
            load_departmentlist();
        }
    }
    else {
        $('#SelDoctor_div').hide();
        $('#SelDepartment_div').hide();
    }
});
//load department list based on hospital id
function load_departmentlist() {
    debugger;
    var MCDTbldata = {
        Dml_Indicator: 'CDSC',
        type: 2,
        branch_id: $('#SelBranch').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(MCDTbldata),
        success: function (data) {
            debugger;
            var data2 = JSON.parse(data);
            if (jQuery.isEmptyObject(data)) {
            }
            else {
                if (data2.msg == "Success") {
                    var data1 = data2.data;
                    var tr = '';
                    var SelRole = '';
                    var default_opt = '<option value="0">--Select--</option>';
                    var j = 0;
                    $('#SelDepartment').empty();
                    if (data1['Table'].length > 0) {
                        for (var i = 0; i < data1['Table'].length; i++) {
                            j++;
                            SelRole = SelRole + '<option value="' + data1['Table'][i].master_category_department_id + '">' + data1['Table'][i].name + '</option>';
                        }
                        $('#SelDepartment').append(default_opt + SelRole);
                    }
                }
                else {
                    console.log(data);
                }
            }
        }
    });
}

//on change function, call the load_sub_department function
$('#SelDepartment').change(function () {
    load_sub_department();
    $('#SelService').empty();
});


//load sub department list based on department id
function load_sub_department() {
    //SBCDS
    debugger;
    var SCDTbldata = {
        Dml_Indicator: 'SUDS',
        Master_cd_id: $('#SelDepartment').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(SCDTbldata),
        success: function (data) {
            debugger;
            var data2 = JSON.parse(data);
            if (jQuery.isEmptyObject(data)) {
            }
            else {
                if (data2.msg == "Success") {
                    var data1 = data2.data;
                    var tr = '';
                    var SelRole = '';
                    var default_opt = '<option value="0">--Select--</option>';
                    var j = 0;
                    $('#SelSubDepartment').empty();
                    //if (data1['Table1'].length > 0) {
                    //    for (var i = 0; i < data1['Table1'].length; i++) {
                    //        j++;
                    //        SelRole = SelRole + '<option value="' + data1['Table1'][i].sub_category_department_id + '">' + data1['Table1'][i].sub_cd_name + '</option>';
                    //    }
                    //    $('#SelSubDepartment').append(default_opt + SelRole);
                    //}
                    if (data1.Table.length > 0) {
                        for (var i = 0; i < data1.Table.length; i++) {
                            j++;
                            SelRole = SelRole + '<option value="' + data1.Table[i].sub_category_department_id + '">' + data1.Table[i].sub_cd_name + '</option>';
                        }
                        $('#SelSubDepartment').append(default_opt + SelRole);
                    }
                }
                else {
                    console.log(data);
                }
            }
        }
    });
}


//get no of concurrent slots based on sub department id
$('#SelSubDepartment').change(function () {

    DepartmentLevelList();
})
//Loading Service
function LoadService() {
    var service_data = {
        P_Dml_Indicator: "SL",
        branch_id: $('#SelBranch').val(),
        department_id: $('#SelDepartment').val(),
        sub_department_id: $('#SelSubDepartment').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Billing/Service_Master_Ins_upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(service_data),
        success: function (data) {
            debugger;
            if (jQuery.isEmptyObject((data))) {
                $('#SelService').empty();
            }
            else {
                var data1 = JSON.parse(data);
                $('#SelService').empty();
                if (data1.msg == "Success") {
                    var data1 = data1.data;
                    console.log(data1);

                    if (jQuery.isEmptyObject((data1))) {
                    }
                    else {
                        var Service;
                        var default_opt = '<option value="0">--Select--</option>';
                        $.each(data1, function (i, emp) {
                            Service = Service + '<option value="' + emp.master_service_id + '">' + emp.service_name + '</option>';
                        });
                        $('#SelService').append(default_opt + Service);
                    }
                }
                else {
                    console.log(data1);
                }
            }
        }
    })
}
$('#SelDoctor').change(function () {
    debugger;
    $('#CalendarConfiguration').empty();
    CalendarConfigurationList();
});
//service change         //commented by nandhini on 09/06/2022
//$('#SelService').change(function () {
//    DepartmentLevelList();
//})
//Department level schedule list
function DepartmentLevelList() {
    var Configuration = {
        department_id: $('#SelDepartment').val(),
        sub_department_id: $('#SelSubDepartment').val(),
        master_service_id: $('#SelService').val(),
        branch_id: $('#SelBranch').val(),
        hospital_id: $('#HospitalId').val(),
        Dml_Indicator: 'SD'
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/CalendarConfigurationList/GetCalendarConfiguration',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Configuration),
        success: function (data) {

            console.log(data);
            calendarconfiglist_binding(data)
        }
    })
}
//Table Binding
function calendarconfiglist_binding(data) {
    $('#shade_slot').show();
    debugger;
    var type = "", j = 0;
    if ($('#SelSchedule').val() == 1) {
        var appointment = '<div class=\"table-responsive\"><table id=\"example1\" class=\"ur-cal-conf-table table-responsive table table-bordered table-striped dataTable\" cellspacing=\"0\" width=\"100%\"><thead><tr><th>S No</th><th>Date</th><th>From Time</th><th>To Time</th><th>Per Patient handling time</th><th>Appointment Type</th><th class="tbl-status">Status</th><th class="tbl-action">View More</th></tr></thead><tbody>';
    }
    else {
        var appointment = '<div class=\"table-responsive\"><table id=\"example1\" class=\"ur-cal-conf-table table-responsive table table-bordered table-striped dataTable\" cellspacing=\"0\" width=\"100%\"><thead><tr><th>S No</th><th>Date</th><th>From Time</th><th>To Time</th><th class="tbl-status">Status</th><th class="tbl-action">View More</th></tr></thead><tbody>';
    }
    //var appointment = '<div class=\"table-responsive\"><table id=\"example1\" class=\"ur-cal-conf-table table-responsive table table-bordered table-striped dataTable\" cellspacing=\"0\" width=\"100%\"><thead><tr><th>S No</th><th>Date</th><th>From Time</th><th>To Time</th><th>Per Patient handling time</th><th>Appointment Type</th><th class="tbl-status">Status</th><th class="tbl-action">Action</th></tr></thead><tbody>';
    $.each(data, function (i, emp) {
        if (emp.appointment_type == "1") {
            type = "Walk In";
        }
        else if (emp.appointment_type == 2) {
            type = "Video";
        }
        else if (emp.appointment_type == 4) {
            type = "Walkin/Video";
        }
        else {
            type = "-";
        }
        if ($('#SelSchedule').val() == 1) {
            appointment = appointment + '<tr><td>' + (i + 1) + '</td><td>' + emp.sschedule_date + '</td><td>' + emp.fromtime + '</td><td>' + emp.totime + '</td><td>' + emp.per_patient_time + '</td><td>' + type + '</td>';
        }
        else {
            appointment = appointment + '<tr><td>' + (i + 1) + '</td><td>' + emp.sschedule_date + '</td><td>' + emp.fromtime + '</td><td>' + emp.totime + '</td>';
        }
        //appointment = appointment + '<tr><td>' + (i + 1) + '</td><td>' + emp.sschedule_date + '</td><td>' + emp.fromtime + '</td><td>' + emp.totime + '</td><td>' + emp.per_patient_time + '</td><td>' + type + '</td>';

        appointment = appointment + ' <td><div class="onoffswitch"><input type="checkbox" name="onoffswitch" data-id="CC_F1" data-type="role_rights_function" data-nav="" data-name="" onchange="StatusChange(this,' + '\'' + emp.doctor_schedule_id + '\',\'' + emp.doctor_schedule_id + '\');" class="onoffswitch-checkbox" id="myonoffswitch' + (i + 1) + '"';
        if (emp.schedule_status) {
            appointment = appointment + 'checked';
        }
        appointment = appointment + '><label class="onoffswitch-label" for="myonoffswitch' + (i + 1) + '"><span class="onoffswitch-inner"></span><span class="onoffswitch-switch"></span></label></div></td><td><button data-id="CC_V1" data-type="role_rights_view" data-nav="" data-name="" onclick="addSlot(\'slot_' + j + '\',\'' + emp.fromtime + '\',\'' + emp.totime + '\',\'' + emp.appointment_type + '\',\'' + emp.sschedule_date + '\',\'' + emp.doctor_schedule_id + '\',this);" data-toggle="tooltip" data-placement="bottom" title="View" class="part-payment btn btn-default btn-rounded btn-sm"><span class="glyphicon glyphicon-eye-open"></span></button></td></tr><tr class="hiddenRow accordian-body collapse" id="slot_' + j + '"></tr>';

        j = j + 1;

    })
    appointment = appointment + '</tbody></table></div>';
     $('#shade_slot').hide();
    //$('#CalendarConfiguration').html(appointment);

    $.when($('#CalendarConfiguration').html(appointment)).then($('#example1').DataTable({
        "columnDefs": [{
            "targets": 5,
            "orderable": false,
        }]
    }));
    //datatable('example1', 'Calendar_Confiuration', 'Legal');
}

function CalendarConfigurationList() {
     debugger;
    //var DoctorId = $('#HiddenDoctorID').val();

    var DoctorId = '';
    if ($('#hiddenRole_id').val() == 2 || $('#hiddenRole_id').val() == 3 || $('#hiddenRole_id').val() == 6) {
    //if ($('#hiddenRole_id').val() == 2 || $('#hiddenRole_id').val() == 4) {
        DoctorId = $('#Hdn_doctorid').val();
    }
    else {
        DoctorId = $('#HiddenDoctorID').val();
    }

    var Configuration = {
        doctor_id: DoctorId,
        Dml_Indicator: 'S',
        branch_id: $('#SelBranch').val()
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/CalendarConfigurationList/GetCalendarConfiguration',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Configuration),
        success: function (data) {
            //debugger;
            console.log(data);
            calendarconfiglist_binding(data);
            //var urcheck = $('#URight').val();
            ////if (urcheck == "1") {
            //    var appointment = '<div class=\"table-responsive\"><table id=\"example1\" class=\"ur-cal-conf-table table-responsive table table-bordered table-striped dataTable\" cellspacing=\"0\" width=\"100%\"><thead><tr><th>S No</th><th>Date</th><th>From Time</th><th>To Time</th><th>Per Patient handling time</th><th>Appointment Type</th><th>Action</th></tr></thead><tbody>';
            ////}
            //var type = "", j = 0;
            //if (urcheck == "2") {
            //    if (emp.appointment_type == "1") {
            //        type = "Walk In";
            //    }
            //    else if (emp.appointment_type == 2) {
            //        type = "Video";
            //    }
            //    else {
            //        type = "-";
            //    }
            //    appointment = appointment + '<tr data-toggle="collapse" data-target="#slot_' + j + '" class="accordion-toggle"><td>' + (i + 1) + '</td><td>' + emp.sschedule_date + '</td><td>' + emp.fromtime + '</td><td>' + emp.totime + '</td><td>' + emp.per_patient_time + '</td><td>' + type + '</td>';
            //}

            //$.each(data, function (i, emp) {
            //    appointment = appointment + '<tr><td>' + (i + 1) + '</td><td>' + emp.sschedule_date + '</td><td>' + emp.fromtime + '</td><td>' + emp.totime + '</td><td>' + emp.per_patient_time + '</td>';
            //    //if (urcheck == "1") {
            //        appointment = appointment + ' <td><div class="onoffswitch"><input type="checkbox" name="onoffswitch" onchange="StatusChange(this,' + '\'' + emp.doctor_schedule_id + '\',\'' + emp.doctor_schedule_id + '\');" class="onoffswitch-checkbox" id="myonoffswitch' + (i + 1) + '"';
            //        if (emp.schedule_status) {
            //            appointment = appointment + 'checked';
            //        }
            //        appointment = appointment + '><label class="onoffswitch-label" for="myonoffswitch' + (i + 1) + '"><span class="onoffswitch-inner"></span><span class="onoffswitch-switch"></span></label></div></td><td><button onclick="addSlot(\'slot_' + j + '\',\'' + emp.fromtime + '\',\'' + emp.totime + '\',\'' + emp.appointment_type + '\',\'' + emp.sschedule_date + '\',\'' + emp.doctor_schedule_id + '\');" class="part-payment btn btn-default btn-rounded btn-sm"><span class="glyphicon glyphicon-eye-open"></span></button></td></tr><tr class="hiddenRow accordian-body collapse" id="slot_' + j + '"></tr>';
            //    //}
            //    j = j + 1;
            //});
            //appointment = appointment + '</tbody></table></div>';
            ////$('#CalendarConfiguration').html(appointment);

            //$.when($('#CalendarConfiguration').html(appointment)).then($('#example1').DataTable({
            //    "columnDefs": [{
            //        "targets": 5,
            //        "orderable": false,
            //    }]
            //}));

            //$('#example').dataTable({
            //    "columnDefs": [{
            //        "targets": 'no-sort',
            //        "orderable": false,
            //    }]
            //});
        }
    });
}

//modifing for future release


function StatusChange(obj, schedule_id, Patient_ID) {
    var did = $(obj).attr("data-id");
    var navigation = $(obj).attr("data-nav");
    var name = $(obj).attr("data-name");
    var columntype = $(obj).attr("data-type");
    debugger;
    var chkprevilige = check_previlige(did, navigation, name, columntype);
    $.when(chkprevilige)
       .then(function (data) {
           var data1 = JSON.parse(data);
           if (data1.msg == "Success") {
               var data1 = data1.data;
               if (jQuery.isEmptyObject((data1))) {
               }
               else {
                   var j = 0;
                   debugger;
                   var status = data1.Table[0].role_rights_add

                   if (status == 0) {
                       var id = $(obj).prop("id");
                       if ($('#' + id).prop("checked") == true) {
                           $('#' + id).prop("checked", false);
                       }
                       else {
                           $('#' + id).prop("checked", true);
                       }

                       return;
                   }
                   else {
                       var Configuration = {
                           doctor_schedule_id: schedule_id,
                           //Patient_id: Patient_ID,
                           schedule_status: obj.checked,
                           Dml_Indicator: 'U'
                       }
                       console.log(Configuration);
                       $.ajax({
                           async: true,
                           type: 'POST',
                           url: '/CalendarConfigurationList/UpdateCalendarConfiguration',
                           contentType: 'application/json; charset=UTF-8',
                           data: JSON.stringify(Configuration),
                           success: function (data1) {
                               //alert(data1);
                               var data1 = JSON.parse(data);
                               if (data1.msg == "Success") {

                               }
                               else {
                                   console.log(data1);
                               }
                           }
                       });
                   }
               }
           }
       })

}

//Blocking Particular slot
function addSlot(val, fromTime, toTime, type, date, schedule_id, event) {
    debugger;
    var did = $(event).attr("data-id");
    var navigation = $(event).attr("data-nav");
    var name = $(event).attr("data-name");
    var columntype = $(event).attr("data-type");
    debugger;
    var chkprevilige = check_previlige(did, navigation, name, columntype);
    $.when(chkprevilige)
       .then(function (data) {
           var data1 = JSON.parse(data);
           if (data1.msg == "Success") {
               var data1 = data1.data;
               if (jQuery.isEmptyObject((data1))) {
               }
               else {
                   var j = 0;
                   debugger;
                   var status = data1.Table[0].role_rights_add

                   if (status == 0) {

                       return;
                   }
                   else {
                       var DoctorId = '', Dml_Indicator = '';
                       var htmlid = val;
                       if (($('#hiddenRole_id').val() == 2 || $('#hiddenRole_id').val() == 3) && $('#SelSchedule').val() == 1) {
                           DoctorId = $('#Hdn_doctorid').val();
                       }
                       else {
                           DoctorId = $('#HiddenDoctorID').val();
                       }
                       if ($('#SelSchedule').val() == 1) {
                           Dml_Indicator = "AS"
                       }
                       else {
                           Dml_Indicator = "ASD"
                       }
                       //var date1 = date.split('/');
                       //var schedule = date1[2] + "-" + date1[1] + "-" + date1[0];

                       var date1 = date.split('-');
                       var schedule = date1[2] + "-" + date1[1] + "-" + date1[0];

                       var Configuration = {
                           from_time: fromTime,
                           to_time: toTime,
                           doctor_schedule_type: type,
                           doctor_id: DoctorId,
                           schedule_date: schedule,
                           doctor_schedule_id: schedule_id,
                           Dml_Indicator: Dml_Indicator
                       }
                       console.log(Configuration);
                       $.ajax({
                           async: true,
                           type: 'POST',
                           url: '/CalendarConfigurationList/GetCalendarConfiguration',
                           contentType: 'application/json; charset=UTF-8',
                           data: JSON.stringify(Configuration),
                           success: function (data) {

                               //alert(data1);
                               debugger;
                               console.log(data);
                               var urcheck = $('#URight').val();
                               var tr = '', Action = '', type = "", j = 1;
                               var trhead = '<td colspan="12"><div><table class="table table-condensed body-borderless table_borderless"><thead><tr><th>S.No</th><th>Date</th><th>Slot Time</th><th>Appointment Type</th><th>Action</th></tr></thead><tbody>';

                               $.each(data, function (i, emp) {
                                   if (emp.doctor_schedule_type == "1") {
                                       type = "Walk In";
                                   }
                                   else if (emp.doctor_schedule_type == "2") {
                                       type = "Video";
                                   }
                                   else if (emp.doctor_schedule_type == 4) {
                                       type = "Walkin/Video";
                                   }
                                   else {
                                       type = "-";
                                   }
                                   tr = tr + '<tr><td>' + j + '</td><td>' + emp.sschedule_date + '</td><td>' + emp.fromtime + '</td><td>' + type + '</td>';
                                   //if (urcheck == "1") {
                                   tr = tr + ' <td><div class="onoffswitch"><input type="checkbox" name="onoffswitch" data-id="CC_F1" data-type="role_rights_function" data-nav="" data-name="" onchange="StatusChangeSlot(this,' + '\'' + emp.appointment_slot_id + '\');" class="onoffswitch-checkbox" id="' + htmlid + emp.appointment_slot_id + '"';
                                   if (emp.is_appointment_available == "1") {
                                       tr = tr + 'checked';
                                   }
                                   tr = tr + '><label class="onoffswitch-label" for="' + htmlid + emp.appointment_slot_id + '"><span class="onoffswitch-inner"></span><span class="onoffswitch-switch"></span></label></div></td></tr>';
                                   //}
                                   j = j + 1;
                               });
                               var trend = '</tbody></table></div></td>';
                               $('#' + htmlid).html(trhead + tr + trend);
                               if ($('#' + htmlid).hasClass('in') == true) {
                                   $('#' + htmlid).removeClass('in');
                               }
                               else {
                                   $('#' + htmlid).addClass('in');
                               }
                           }
                       });
                   }
               }
           }
       });

}

function StatusChangeSlot(obj, appointment_slot_id) {
    debugger
    var did = $(obj).attr("data-id");
    var navigation = $(obj).attr("data-nav");
    var name = $(obj).attr("data-name");
    var columntype = $(obj).attr("data-type");
    debugger;
    var chkprevilige = check_previlige(did, navigation, name, columntype);
    $.when(chkprevilige)
       .then(function (data) {
           var data1 = JSON.parse(data);
           if (data1.msg == "Success") {
               var data1 = data1.data;
               if (jQuery.isEmptyObject((data1))) {
               }
               else {
                   var j = 0;
                   debugger;
                   var status = data1.Table[0].role_rights_add

                   if (status == 0) {
                       var id = $(obj).prop("id");
                       if ($('#' + id).prop("checked") == true) {
                           $('#' + id).prop("checked", false);
                       }
                       else {
                           $('#' + id).prop("checked", true);
                       }
                       return;
                   }
                   else {
                       var Configuration = {
                           doctor_schedule_id: appointment_slot_id,
                           schedule_status: obj.checked,
                           Dml_Indicator: 'ASU'
                       }
                       console.log(Configuration);
                       $.ajax({
                           async: true,
                           type: 'POST',
                           url: '/CalendarConfigurationList/UpdateCalendarConfiguration',
                           contentType: 'application/json; charset=UTF-8',
                           data: JSON.stringify(Configuration),
                           success: function (data1) {
                               var data1 = JSON.parse(data);
                               if (data1.msg == "Success") {

                               }
                               else {
                                   console.log(data1);
                               }
                           }
                       });
                   }
               }
           }
       })

}

$('#SelBranch').change(function () {
    $('#CalendarConfiguration').empty();
    if ($('#SelSchedule').val() == 2) {
        load_departmentlist();
        $('#SelDepartment').val(0);
        $('#SelSubDepartment').val(0);
        $('#SelService').empty();
    }
    else {
        LoadDoctor();
    }
})


$('#SelDoctor').autocomplete({
    source: function (request, response) {
        $.ajax({
            async: true,
            url: "/Ipmanagement/DoctorNameAutoCompletelist",
            type: "POST",
            dataType: "json",
            data: { Prefix: request.term, Dml_Indicator: "HDL", branch_id: $('#SelBranch').val() },
            success: function (data) {
                debugger;
                  $('#Hdn_doctorid').val('');
                // var data2 = JSON.parse(data);
                var data2 = data;
                response($.map(data2, function (item) {
                    return { label: item.doctorname, value: item.doctorname, id: item.doctorid };
                }))
            }
        })
    },
    minLength: 1,
    select: function (event, ui) {
        debugger;
        $('#Hdn_doctorid').val(ui.item.id);
        $('#CalendarConfiguration').empty();
        CalendarConfigurationList();
    },
    html: true,
    open: function (event, ui) {
        $(".ui-autocomplete").css("z-index", 1000);

    }
});





