
// hide,view Sub-Category And Sub-Department table and columns 
$(document).ready(function () {


    if ($('#HdMCDType').val() == 1) {
        $('#lblMName').html('Category Name');
        $('#lblSname').html('Sub Category Name *');
        $('.divHDeparmentColumn').hide();
    }
    else if($('#HdMCDType').val() == 2) {
        $('#lblMName').html('Department Name');
        $('#lblSname').html('Sub Department Name *');
        $('.divHDeparmentColumn').show();
    }
    else {
        $('#lblMName').html('Primary Cost Centre Name');
        $('#lblSname').html('Secondary Cost Centre Name *');
        $('.divHDeparmentColumn').hide();
    }
    $('#divNoCS').addClass('hidden');
    LoadSCDTable();
    display_order()
})

function LoadSCDTable() {
    debugger;
    $('#shade_slot').show();
    var SCDTbldata = {

        Dml_Indicator: 'SBCDS',
        Master_cd_id: $('#HdMCDID').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;
            $('#TblSubCategoryorDepartment tbody').empty();
            var data2 = JSON.parse(data);
            if (jQuery.isEmptyObject(data)) {

            }
            else {

                if (data2.msg == "Success") {
                    var data1 = data2.data;
                    debugger;
                    $('#txtMName').val(data1.Table[0].name);

                    if (data1.Table1.length > 0) {
                        tr = $('<table class="table table-bordered table-striped table-hover dt-responsive" id="SubCategoryandDepartmentTable"/>');

                        var TypeName = '';
                        if ($('#HdMCDType').val() == 1) {
                            TypeName = 'Add Sub Category';

                            tr.append("<thead><tr><th>S.No</th><th>Sub Category Code</th><th>Sub Category Name</th><th>Remarks</th><th>Report Display Order</th><th>Status</th><th>Actions</th></tr></thead><tbody>");

                        }
                        else if ($('#HdMCDType').val() == 2) {
                            TypeName = 'Add Sub Department';

                            tr.append("<thead><tr><th>S.No</th><th>Sub Department Code</th><th>Sub Department Name</th><th>Remarks</th><th>Department Level Booking</th><th>No of Concurrent Slots</th><th>Report Display Order</th><th>Status</th><th>Actions</th></tr></thead><tbody>");
                        }
                        else  {
                            TypeName = 'Add Secondary Cost Centre';

                            tr.append("<thead><tr><th>S.No</th><th>Secondary Cost Centre Code</th><th>Secondary Cost Centre Name</th><th>Remarks</th><th>Report Display Order</th><th>Status</th><th>Actions</th></tr></thead><tbody>");

                        }


                        $.each(data1.Table1, function (i, emp) {
                            var remarks = ''
                            if (emp.sub_cd_description != null && emp.sub_cd_description != '') {
                                remarks = emp.sub_cd_description
                            }
                            else {
                                remarks = '-'
                            }

                           // view = '<button type="button" class="btn btn-edit btn-xs" data-toggle="tooltip" data-placement="bottom" title="Edit" data-id="SCD_E1" data-type="role_rights_edit" data-nav="sp_div" data-name="edit_SubCategoryDepartment_form" onclick=SubCategoryorDepartmentTable(this,"' + emp.sub_category_department_id + '");><i class="fa fa-pencil-square-o" aria-hidden="true"></i></button>';
                            //Del = '<button type="button" class="btn btn-delete btn-xs" data-toggle="tooltip" data-placement="bottom" title="Delete" data-id="SCD_D1" data-type="role_rights_delete" data-nav="sp_div" data-name="delete_SubCategoryDepartment_form" onclick=DELSubCategoryorDepartment(this,"' + emp.sub_category_department_id + '","SCDEL");><i class="fa fa-trash" aria-hidden="true"></i></button>';

                            view = '<a class="edit_icon" title="Edit" data-id="SCD_E1" data-type="role_rights_edit" data-nav="sp_div" data-name="edit_SubCategoryDepartment_form" onclick=SubCategoryorDepartmentTable(this,"' + emp.sub_category_department_id + '");><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>';
                            Del = '<a class="delete_icon"title="Delete" data-id="SCD_D1" data-type="role_rights_delete" data-nav="sp_div" data-name="delete_SubCategoryDepartment_form" onclick=DELSubCategoryorDepartment(this,"' + emp.sub_category_department_id + '","SCDEL");><i class="fa fa-trash" aria-hidden="true"></i></a>';

                            if (emp.status == "2") {
                               // active_inactive = '<p><a type="button" class="btn btn-xs btn-blue" data-id="SCD_F1"  data-toggle="tooltip" data-placement="bottom" title="Make Active" data-type="role_rights_function" data-nav="sp_div" data-name="delete_CategoryDepartment_form" onclick=DELSubCategoryorDepartment(this,"' + emp.sub_category_department_id + '","subactive");><i class="fa fa-check-square-o mr-5" aria-hidden="true"></i>Active</a></p>';
                                active_inactive = '<a class="active_icon" data-id="SCD_F1"  title="Make Active" data-type="role_rights_function" data-nav="sp_div" data-name="delete_CategoryDepartment_form" onclick=DELSubCategoryorDepartment(this,"' + emp.sub_category_department_id + '","subactive");><i class="fa fa-check-square-o" aria-hidden="true"></i></a>';
                            }
                            else {
                               // active_inactive = '<p><a type="button" class="btn  btn-xs btn-blue" data-id="SCD_F1"  data-toggle="tooltip" data-placement="bottom" title="Make In Active" data-type="role_rights_function" data-nav="sp_div" data-name="delete_CategoryDepartment_form" onclick=DELSubCategoryorDepartment(this,"' + emp.sub_category_department_id + '","subinactive");><i class="fa fa-minus-square-o mr-5" aria-hidden="true"></i>In Active</a></p>';
                                active_inactive = '<a type="button" class="inactive_icon" data-id="SCD_F1"  title="Make In Active" data-type="role_rights_function" data-nav="sp_div" data-name="delete_CategoryDepartment_form" onclick=DELSubCategoryorDepartment(this,"' + emp.sub_category_department_id + '","subinactive");><i class="fa fa-minus-square-o" aria-hidden="true"></i></a>';
                            }

                            var status = '';
                            if (emp.status == '1') {
                                status = '<span class="label label-success">Active</span>';
                            }
                            else if (emp.status == '2') {
                                status = '<span class="label label-warning">Inactive</span>';
                            }
                            var dpt_level=''
                            if (emp.types_of_appointment_booking == 1) {
                                dpt_level = 'No'
                            }
                            else {
                                dpt_level = 'Yes'
                            }

                            if ($('#HdMCDType').val() == 1) {
                                if (emp.status == 2) {
                                    row_data = "<tr><td>" + emp.RowNo + "</td><td>" + emp.sub_code + "</td><td>" + emp.sub_cd_name + "</td><td>" + remarks + "</td><td>" + emp.Orderby + "</td><td>" + status + "</td><td><div class='dropdown'><i class='fa fa-ellipsis-h dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true'></i> <ul class='dropdown-menu info-dropdown-new'><div class='disp_if mb-10'><li>" + Del + "</li><li>" + active_inactive + "</li></div></ul></div></td></tr>";
                                }
                                else {
                                    row_data = "<tr><td>" + emp.RowNo + "</td><td>" + emp.sub_code + "</td><td>" + emp.sub_cd_name + "</td><td>" + remarks + "</td><td>" + emp.Orderby + "</td><td>" + status + "</td><td><div class='dropdown'><i class='fa fa-ellipsis-h dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true'></i> <ul class='dropdown-menu info-dropdown-new'><div class='disp_if mb-10'><li>" + view + "</li><li>" + Del + "</li><li>" + active_inactive + "</li></div></ul></div></td></tr>";
                                }
                            }
                            else if ($('#HdMCDType').val() == 2) {
                                if (emp.status == 2) {
                                    row_data = "<tr><td>" + emp.RowNo + "</td><td>" + emp.sub_code + "</td><td>" + emp.sub_cd_name + "</td><td>" + remarks + "</td><td>" + dpt_level + "</td><td>" + emp.number_of_concurrent_slots + "</td><td>" + emp.Orderby + "</td><td>" + status + "</td><td><div class='dropdown'><i class='fa fa-ellipsis-h dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true'></i> <ul class='dropdown-menu info-dropdown-new'><div class='disp_if mb-10'><li>" + Del + "</li><li>" + active_inactive + "</li></div></ul></div></td></tr>";
                                }
                                else {
                                    row_data = "<tr><td>" + emp.RowNo + "</td><td>" + emp.sub_code + "</td><td>" + emp.sub_cd_name + "</td><td>" + remarks + "</td><td>" + dpt_level + "</td><td>" + emp.number_of_concurrent_slots + "</td><td>" + emp.Orderby + "</td><td>" + status + "</td><td><div class='dropdown'><i class='fa fa-ellipsis-h dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true'></i> <ul class='dropdown-menu info-dropdown-new'><div class='disp_if mb-10'><li>" + view + "</li><li>" + Del + "</li><li>" + active_inactive + "</li></div></ul></div></td></tr>";
                                }
                            }
                            else {
                                if (emp.status == 2) {
                                    row_data = "<tr><td>" + emp.RowNo + "</td><td>" + emp.sub_code + "</td><td>" + emp.sub_cd_name + "</td><td>" + remarks + "</td><td>" + emp.Orderby + "</td><td>" + status + "</td><td><div class='dropdown'><i class='fa fa-ellipsis-h dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true'></i> <ul class='dropdown-menu info-dropdown-new'><div class='disp_if mb-10'><li>" + Del + "</li><li>" + active_inactive + "</li></div></ul></div></td></tr>";
                                }
                                else {
                                    row_data = "<tr><td>" + emp.RowNo + "</td><td>" + emp.sub_code + "</td><td>" + emp.sub_cd_name + "</td><td>" + remarks + "</td><td>" + emp.Orderby + "</td><td>" + status + "</td><td><div class='dropdown'><i class='fa fa-ellipsis-h dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true'></i> <ul class='dropdown-menu info-dropdown-new'><div class='disp_if mb-10'><li>" + view + "</li><li>" + Del + "</li><li>" + active_inactive + "</li></div></ul></div></td></tr>";
                                }
                            }
                            tr.append(row_data);
                        });
                        tr.append("</tbody></table>");
                        $('#TblSubCategoryorDepartment').html(tr);

                        $('#SubCategoryandDepartmentTable').DataTable();
                    }
                }
                else {
                    console.log(data);
                }
                $('#shade_slot').hide();
            }
        },
        error: function (data) {

        }
    });
}

// Master Sub Category And Department insert and update //
$('#BtnSubCDSubmit').click(function () {
    debugger;
    if ($.trim($('#txtSCDName').val()) == "") {
        $('#PtxtSCDName').show();
        $('#PtxtSCDName').fadeOut(8000);
        $('#PtxtSCDName').html('Enter ' + $('#lblSname').html());
        $('#txtSCDName').focus();
        $('#txtSCDName').val('');
        return false;
    }

    if ($('#AppointmentType').val() == 2) {
        if ($.trim($('#txtNoCD').val()) == "" || $.trim($('#txtNoCD').val()) == 0) {
            $('#PtxtNoCD').show();
            $('#PtxtNoCD').fadeOut(8000);
            $('#PtxtNoCD').html('Enter Number of Concurrent Slots');
            $('#txtNoCD').focus();
            $('#txtNoCD').val('');
            return false;
        }
    }

    if ($.trim($('#display_order').val()) == "" || $.trim($('#display_order').val()) == 0) {
        $('#Pdisplay_order').show();
        $('#Pdisplay_order').fadeOut(8000);
        $('#Pdisplay_order').html('Enter Display Order');
        $('#display_order').focus();
        $('#display_order').val('');
        return false;
    }

    if ($('#HdMCDType').val() == 2) {
        if ($.trim($('#AppointmentType').val()) == "") {
            $('#PAppointmentType').show();
            $('#PAppointmentType').fadeOut(8000);
            $('#PAppointmentType').html('Select Department Level Booking');
            $('#AppointmentType').focus();
            $('#AppointmentType').val('');
            return false;
        }
    }

    var NoCD = '';
    if ($('#AppointmentType').val() == 2) {
        NoCD = $("#txtNoCD").val();
    }
    else {
        NoCD = 1;
    }

    var MSCDdata = {
        Dml_Indicator: "MSBI",
        Master_cd_id: $('#HdMCDID').val(),
        MasterSub_cd_id: $('#HdnSubM_cd_id').val(),
        number_of_concurrent_slots: NoCD,
        appointment_booking_type: $('#AppointmentType').val(),
        name: $('#txtSCDName').val(),
        remarks: $('#txtSRemarks').val(),
        mobile_description: $('#txtSMobileDescription').val(),
        mobile_icon: $('#idpathvalue').val(),
        type: $('#HdMCDType').val(),
        branch_id: $('#HdBranchID').val(),
        display_order: $('#display_order').val()
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(MSCDdata),
        success: function (data) {
            debugger;
            var data2 = JSON.parse(data);
            if (jQuery.isEmptyObject((data2.data))) {

            }
            else {

                if (data2.msg == "Success") {
                    var data1 = data2.data;
                    if (data1.Table[0].msg == 'already') {
                        toastr.warning('Name alreay exist, kindly add different name');
                        $('#txtSCDName').val('')
                        return;
                    }
                    else if ($('#HdnSubM_cd_id').val() == '') {
                        if ($('#HdMCDType').val() == 1) {
                            toastr.success('Sub Category Added Successfully',
                          {
                              progressBar: true,
                              allowHtml: true,
                              timeOut: 0,
                          });
                        }
                        else {
                            toastr.success('Sub Department Added Successfully',
                                {
                                    progressBar: true,
                                    allowHtml: true,
                                    timeOut: 0,
                                });
                        }
                    }
                    else {
                        if ($('#HdMCDType').val() == 1) {
                            toastr.success('Sub Category Updated Successfully',
                          {

                              progressBar: true,
                              allowHtml: true,
                              timeOut: 0,
                          });
                        }
                        else {
                            toastr.success('Sub Department Updated Successfully',
                                {
                                    progressBar: true,
                                    allowHtml: true,
                                    timeOut: 0,
                                });
                        }
                    }
                    clearSCDdata();
                    LoadSCDTable();
                    display_order();
                }
                else {
                    console.log(data);
                }
            }
        }
    });

})


function clearSCDdata() {
    $('#txtNoCD').val('');
    $('#txtSCDName').val('');
    $('#txtSRemarks').val('');
    $('#txtSMobileDescription').val('');
    $('#idpathvalue').val('');
    $('#fileToUpload').val('');
    $('#photolog').val('');
    $('#photolog').hide();
    $('#photolog').empty();
    $('#HdnSubM_cd_id').val('');
    $('#AppointmentType').val('');
    $('#display_order').val('')

    $('a[data-toggle=AppointmentType][data-title="1"]').removeClass('active');
    $('a[data-toggle=AppointmentType][data-title="1"]').addClass('not-active');
    $('a[data-toggle=AppointmentType][data-title="2"]').removeClass('active');
    $('a[data-toggle=AppointmentType][data-title="2"]').addClass('not-active');
    $('#divNoCS').addClass('hidden');
}

//upload Mobile Icon
$('#fileToUpload').change(function () {
    debugger;
    packageimageupload();
});


function id_image_show(id) {
    window.open(id, '_blank');
}

function packageimageupload() {
    debugger;
    var uploadpath = $('#fileToUpload').val();
    var fileExtension = uploadpath.substring(uploadpath.lastIndexOf(".") + 1, uploadpath.length);
    if (window.FormData !== undefined) {
        var fileUpload = $("#fileToUpload").get(0);
        var files = fileUpload.files;
        var fileData = new FormData();
        for (var i = 0; i < files.length; i++) {
            fileData.append(files[i].name, files[i]);
        }
        fileData.append('username', 'Manas');
        $.ajax({
            //url: '/Hospitalsetup/UploadPhotoFiles?branch_id=' + $('#HdBranchID').val(), // one master concept
            url: '/Hospitalsetup/UploadPhotoFiles',
            type: "POST",
            contentType: false,
            processData: false,
            data: fileData,
            success: function (result) {
                $.each(result, function (i, emp) {
                    debugger;
                    $('#photolog').empty();
                    $('#photolog').show();
                    $('#idpathvalue').val(emp);
                    $('#photolog').append('<a href="' + $('#hdnSCDfilepath1').val() + "/" + $('#HospitalId').val() + "/" + $('#HdBranchID').val() + "/" + "CategoryAndDepartment/" + emp + '" target="_blank">Mobile Icon</a>');
                });
            }
        });
    }
}

function SubCategoryorDepartmentTable(event, id) {

    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;
                 var status = data1.Table[0].role_rights_add
                 if (status == 0) {

                     return;
                 }
                 else {
                     clearSCDdata();
                     $('#HdnSubM_cd_id').val(id);

                     var SCDTbldata = {

                         Dml_Indicator: 'SCDIDS',
                         MasterSub_cd_id: $('#HdnSubM_cd_id').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) {
                             var data2 = JSON.parse(data);
                             if (jQuery.isEmptyObject(data)) {

                             }
                             else {

                                 if (data2.msg == "Success") {
                                     var data1 = data2.data;
                                     debugger;

                                     $.each(data1.Table, function (i, emp) {
                                         debugger;
                                         $('#photolog').show();
                                         $('#txtNoCD').val(emp.number_of_concurrent_slots),
                                         $('#txtSCDName').val(emp.sub_cd_name),
                                         $('#txtSRemarks').val(emp.sub_cd_description),
                                         $('#txtSMobileDescription').val(emp.sub_mobile_description),
                                             $('#AppointmentType').val(emp.types_of_appointment_booking);

                                         if (emp.types_of_appointment_booking == 2) {
                                             $('a[data-toggle=AppointmentType][data-title="1"]').removeClass('active');
                                             $('a[data-toggle=AppointmentType][data-title="1"]').addClass('not-active');
                                             $('a[data-toggle=AppointmentType][data-title="2"]').removeClass('not-active');
                                             $('a[data-toggle=AppointmentType][data-title="2"]').addClass('active');
                                             $('#divNoCS').removeClass('hidden');
                                         }
                                         else {
                                             $('a[data-toggle=AppointmentType][data-title="1"]').removeClass('not-active');
                                             $('a[data-toggle=AppointmentType][data-title="1"]').addClass('active');
                                             $('a[data-toggle=AppointmentType][data-title="2"]').removeClass('active');
                                             $('a[data-toggle=AppointmentType][data-title="2"]').addClass('not-active');
                                         }

                                         $('#display_order').val(emp.Orderby)

                                         $('#photolog').empty();

                                         if (emp.mobile_icon != null && emp.mobile_icon != "") {
                                             $('#photolog').show();
                                             $('#photolog').append('<a href="' + $('#hdnSCDfilepath1').val() + "/" + $('#HospitalId').val() + "/" + $('#HdBranchID').val() + "/" + "CategoryAndDepartment/" + emp.mobile_icon + '" target="_blank">Mobile Icon</a>');
                                             $('#idpathvalue').val(emp.mobile_icon);
                                         }
                                     });

                                 }
                                 else {
                                     console.log(data);
                                 }
                             }
                         },
                         error: function (data) {

                         }
                     });
                 }
             }
         }
     });
}

function DELSubCategoryorDepartment(event, id, Dml_Indicator) {
    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;
                 var status = data1.Table[0].role_rights_add
                 if (status == 0) {

                     return;
                 }
                 else {
                     $('#HdnSubM_cd_id').val(id);

                     var status = "";
                     if (Dml_Indicator == 'subactive') {
                         status = "Are you sure you want to activate?";
                     }
                     else if (Dml_Indicator == 'subinactive') {
                         status = "Are you sure you want to In-activate?";
                     }
                     else if (id != '') {

                         status = "Are You Sure Do You want Delete?";
                     }

                     toastr.warning("<button type='button' id='confirmationRevertYes' class='btn btn-warning btn-xs mt20'>Yes</button><button type='button' id='confirmationRevertNo' class='btn btn-warning btn-xs mt20'>No</button>", status,
                         {
                             closeButton: true,
                             progressBar: true,
                             allowHtml: true,
                             timeOut: 20000000,

                             onShown: function (toast) {
                                 debugger;
                                 $("#confirmationRevertYes").click(function () {
                                     debugger;

                                     var SCDTbldata = {
                                         Dml_Indicator: Dml_Indicator,
                                         MasterSub_cd_id: $('#HdnSubM_cd_id').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;
                                                     if (Dml_Indicator == 'SCDEL') {
                                                         if (data1.Table[0].Message == 'Mapped') {
                                                             toastr.warning("Mapped with setup part. Unable to Delete.");
                                                             return;
                                                         }
                                                         else {
                                                             toastr.success("Deleted Successfully");
                                                             $('#HdnSubM_cd_id').val('');
                                                             LoadSCDTable();
                                                             display_order();
                                                         }
                                                     }
                                                     else if (Dml_Indicator == 'subinactive') {
                                                         if (data1.Table[0].Message == 'Mapped') {
                                                             var sub_cat_dept_id = data1.Table[0].sub_category_department_id
                                                             toastr.warning("<button type='button' id='confirmationRevertYes' class='btn btn-warning btn-xs mt20'>Yes</button><button type='button' id='confirmationRevertNo' class='btn btn-warning btn-xs mt20'>No</button>", 'Mapped with some setup part, Do you want to In-activate',
                                                           {
                                                               closeButton: true,
                                                               progressBar: true,
                                                               allowHtml: true,
                                                               timeOut: 20000000,

                                                               onShown: function (toast) {
                                                                   debugger;
                                                                   $("#confirmationRevertYes").click(function () {
                                                                       debugger;
                                                                       var inactive = {
                                                                           Dml_Indicator: 'inact',
                                                                           MasterSub_cd_id: sub_cat_dept_id,
                                                                       }
                                                                       $.ajax({
                                                                           async: true,
                                                                           type: 'POST',
                                                                           url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
                                                                           contentType: 'application/json; charset=UTF-8',
                                                                           data: JSON.stringify(inactive),
                                                                           success: function (data) {
                                                                               debugger;
                                                                               var data1 = JSON.parse(data)
                                                                               if (data1.msg == "Success") {
                                                                                   var data2 = data1.data;
                                                                                   toastr.success('In Activated successfully');
                                                                                   LoadSCDTable();
                                                                               }
                                                                               else {
                                                                                   console.log(data2)
                                                                               }
                                                                           }
                                                                       })
                                                                   })
                                                               }
                                                           })

                                                         }
                                                         else {
                                                             toastr.success("In Activated Successfully");
                                                             $('#HdnSubM_cd_id').val('');
                                                             LoadSCDTable();
                                                         }
                                                     }
                                                     else if (Dml_Indicator == 'subactive') {
                                                         toastr.success("Activated Successfully");
                                                         $('#HdnSubM_cd_id').val('');
                                                         LoadSCDTable();
                                                     }
                                                     else {
                                                         console.log(data);
                                                     }
                                                 }
                                                 else {
                                                     console.log(data);
                                                 }
                                             }
                                         },
                                         error: function (data) {

                                         }
                                     });
                                 });
                             }
                         })
                 }
             }
         }
     });
}

$('#AppointmentType').change(function () {

    if ($('#AppointmentType').val() == 2) {
        $('#txtNoCD').val('');
        $('#divNoCS').removeClass('hidden');
    }
    else {
        $('#divNoCS').addClass('hidden');
    }

});


// Load sub category & department display order
function display_order() {
    debugger;
    var data = {
        Dml_Indicator: "SCD_DO",
        Master_cd_id: $('#HdMCDID').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(data),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                debugger;
                var data1 = data1.data;
                console.log(data1);
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    debugger;
                    $('#display_order').val(data1.Table[0].S_Orderby_val)
                }
            }
            else {
                console.log(data1);
            }
        }
    });
}
