$(document).ready(function () {
    debugger;
    LoadBranch();
    loadConfigureData();
    LoadRole();
    LoadUser();
    loaddata_op();
    Formtype();
    Loadmoduletype();
    HeaderFormName();
    buildiframe();


})




//Load Branch
function LoadBranch(Branch_id) {
    debugger;
    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) {
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                console.log(data1);
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    debugger;
                    var SubDepartment = "";
                    $('.Access_branch').empty();
                    var default_opt = '<option value="0">--Select--</option>';
                    $.each(data1.Table, function (i, emp) {
                        SubDepartment = SubDepartment + '<option value="' + emp.hospital_branch_id + '">' + emp.branch_name + '</option>';
                    });
                    if (data1.Table.length == 1) {
                        $('.Access_branch').append(SubDepartment);
                        branch_change();

                    }
                    else {
                        $('.Access_branch').append(default_opt + SubDepartment);

                    }

                    //if ($('#hiddenRole_id').val() == 1) {
                    //    $('.Access_branch').val($('#HospitalBranchID').val());
                    //}
                    //else if (parseInt($('#hiddenRole_id').val()) != 2) {
                    //    $('.Access_branch').val($('#HospitalBranchID').val());
                    //    $('.Access_branch').attr('disabled', true);

                    //}
                    if ($('#hiddenRole_id').val() != 2) {
                        $('.Access_branch').val($('#HospitalBranchID').val());
                        $('.Access_branch').attr('disabled', true);
                    }
                    if (Branch_id != '' || Branch_id != null) {
                        $('.Access_branch').val(Branch_id)
                    }
                }
            }
            else {
                console.log(data1);
            }
        }
    });
}

//Load Form Type

function Formtype(Form_Type) {
    debugger;
    var department = {
        Dml_Indicator: "FT",
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(department),
        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 {
                    var Department;
                    $('#Form_Type').empty();

                    var default_opt = '<option value="0">--Select--</option>';
                    $.each(data1.Table, function (i, emp) {
                        Department = Department + '<option value="' + emp.Formtypeid + '">' + emp.Formtype + '</option>';
                    });
                    if (data1.Table.length == 1) {
                        $('#Form_Type').append(Department);
                        $("#Form_Type").change();

                    }
                    else {
                        $('#Form_Type').append(default_opt + Department);

                    }
                    if (Form_Type != '' || Form_Type != null) {
                        $('#Form_Type').val(Form_Type)
                    }

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

function Loadmoduletype(Module_Type, Module_Subtype) {
    debugger;
    var department = {
        Dml_Indicator: "MT",
        // branch_id: branch
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(department),
        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 {
                    var Department;
                    $('#Module_Type').empty();
                    $('#type_filter').empty();

                    var default_opt = '<option value="0">--Select--</option>';

                    $.each(data1.Table, function (i, emp) {
                        Department = Department + '<option value="' + emp.moduleid + '">' + emp.moduletype + '</option>';
                    });
                    if (data1.Table.length == 1) {
                        $('#Module_Type').append(Department);
                        $('#type_filter').append(Department);
                        $("#Module_Type").change();
                        $("#type_filter").change();
                    }
                    else {
                        $('#Module_Type').append(default_opt + Department);
                        $('#type_filter').append(default_opt + Department);

                    }
                    if (Module_Type != '' || Module_Type != null) {
                        $('#Module_Type').val(Module_Type)
                        Loadmodulesubtype(Module_Subtype)
                    }

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

$("#Module_Type").change(function () {
    if ($('#Module_Type').val() == "2") {
        $('#div_Type_of_Admission').show()
        $('#div_image').show()
    }
    else {
        $('#div_Type_of_Admission').hide()
        $('#div_image').show()

    }
    Loadmodulesubtype()
})

//load module subtype

function Loadmodulesubtype(Module_Subtype) {
    debugger;
    var department = ''
    if ($('#Module_Type').val() == 1) {
        debugger;
        department = {
            Dml_Indicator: "OP_ASS"
        }
    }
    else {
        department = {
            Dml_Indicator: "MST",
            display_order: $('#Module_Type').val()
        }
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(department),
        success: function (data) {
            debugger
            $('#Module_subtype').empty();
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                console.log(data1)
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    var Department;
                    $('#Module_subtype').empty();

                    var default_opt = '<option value="0">--Select--</option>';

                    $.each(data1.Table, function (i, emp) {
                        Department = Department + '<option value="' + emp.moduleid + '">' + emp.module_subtype + '</option>';
                    });

                    if (data1.Table.length == 1) {
                        $('#Module_subtype').append(Department);
                    }
                    else {
                        $('#Module_subtype').append(default_opt + Department);

                    }
                    if (Module_Subtype != '' || Module_Subtype != null) {
                        $('#Module_subtype').val(Module_Subtype)
                    }

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

//Get Dispaly Order
$("#Module_subtype").change(function () {
    debugger;

    var data = {
        Dml_Indicator: 'DSO',
        Moduletype: $("#Module_Type").val(),
        Module_subtype: $("#Module_subtype").val(),
        Hospitalid: $('#HospitalId').val()
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormMaster",
        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;
                    $('#displayorder').val(data1.Table[0].Display_Order_val)
                }
            }
            else {
                console.log(data1);
            }
        }
    });
})
$('#displayorder').change(function() {
    debugger
    check_displayOrder()
})

function check_displayOrder() {
    debugger;
    var data = {
        Dml_Indicator: 'CDSO',
        Moduletype: $("#Module_Type").val(),
        Module_subtype: $("#Module_subtype").val(),
        Hospitalid: $('#HospitalId').val(),
        display_order:$('#displayorder').val()
    }
    return $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormMaster",
        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 {
                    if (data1.Table[0].msg == 'already') {
                        toastr.warning('Display Order already exist');
                        $('#displayorder').val('');
                        return false;
                    }
                }
            }
            else {
                console.log(data1);
            }
        }
    });
}
//-----Form master starts--------
$('#Form_submit').click(function () {
    debugger;
    //one master concept
    //if ($("#Form_Branch").val() == 0 || $("#Form_Branch").val() == '') {
    //    $('#P_Form_Branch').show();
    //    $('#P_Form_Branch').fadeOut(8000);
    //    $('#P_Form_Branch').html('Select branch ');
    //    $('#Form_Branch').val(0);
    //    $('#Form_Branch').focus();
    //    return false;
    //}
    if ($("#Module_Type").val() == 0 || $("#Module_Type").val() == null) {
        $('#P_Module_Type').show();
        $('#P_Module_Type').fadeOut(8000);
        $('#P_Module_Type').html('Select Module Type');
        $('#Module_Type').val(0);
        $('#Module_Type').focus();
        return false;
    }
    var admission = $("#Type_of_Admission").val().toString()
    if ($('#Module_Type').val() == "2") {
        if (admission == '0' || admission == null) {
            $('#P_Type_of_Admission').show();
            $('#P_Type_of_Admission').fadeOut(8000);
            $('#P_Type_of_Admission').html('Select Admission Type');
            $('#P_Type_of_Admission').focus();
            $('#P_Type_of_Admission').val(0);

            return false;
        }
    }

    if ($("#Module_Type").val() == 1 || $("#Module_Type").val() == 2) {
        if ($("#Module_subtype").val() == 0 || $("#Module_subtype").val() == null) {
            $('#P_Module_subtype').show();
            $('#P_Module_subtype').fadeOut(8000);
            $('#P_Module_subtype').html('Select Module Sub Type');
            $('#Module_subtype').focus();
            $('#Module_subtype').val(0);
            return false;
        }
    }

    if ($("#Form_Type").val() == 0 || $("#Form_Type").val() == null) {
        $('#P_Form_Type').show();
        $('#P_Form_Type').fadeOut(8000);
        $('#P_Form_Type').html('Select Form Type');
        $('#Form_Type').val(0);
        $('#Form_Type').focus();
        return false;
    }
    if ($.trim($('#displayorder').val()) == "" || $.trim($('#displayorder').val()) == 0) {
        $('#P_displayorder').show();
        $('#P_displayorder').fadeOut(8000);
        $('#P_displayorder').html('Enter Display Order');
        $('#displayorder').focus();
        $('#displayorder').val('');
        return false;
    }
    if ($("#Form_Name").val() == '') {
        $('#P_Form_Name').show();
        $('#P_Form_Name').fadeOut(8000);
        $('#P_Form_Name').html('Select Form Name ');
        $('#Form_Name').val('');
        $('#Form_Name').focus();
        return false;
    }
   
    //var is_multiple = 0;
    //if ($('#ChkIS_mulitiple').prop("checked") == true) {
    //    is_multiple = 1;
    //}

    var is_multiple = $('#ChkIS_mulitiple').val() == '' ? 0 : $('#ChkIS_mulitiple').val();
    var Submit = ''
    var uploadfile = $('#hformimg').val()
    if ($('#Form_submit').html() == "Submit") {
        Submit = {
            //Branch_id: $('#Form_Branch').val(),            //one master concept
            Form_Type: $('#Form_Type').val(),
            //  Form_Structure: $('#Form_Structure').val(),
            Moduletype: $('#Module_Type').val(),
            Type_of_Admission: ($('#Type_of_Admission').val() == '' ? 0 : $('#Type_of_Admission').val()).toString(),
            Module_subtype: $('#Module_subtype').val(),
            Form_Name: $('#Form_Name').val(),
            Description: $('#Description').val(),
            Photo: uploadfile,
            is_multiple: is_multiple,
            Type_form: $('#Htype_form').val(),
            Hospitalid: $('#HospitalId').val(),
            display_order:$("#displayorder").val(),
            Dml_Indicator: 'FIN'
        }
    }
    else {
        Submit = {
            //Branch_id: $('#Form_Branch').val(),            //one master concept
            Form_Type: $('#Form_Type').val(),
            // Form_Structure: $('#Form_Structure').val(),
            Moduletype: $('#Module_Type').val(),
            Type_of_Admission: ($('#Type_of_Admission').val() == '' ? 0 : $('#Type_of_Admission').val()).toString(),
            Module_subtype: $('#Module_subtype').val(),
            Form_Name: $('#Form_Name').val(),
            Description: $('#Description').val(),
            Photo: uploadfile,
            is_multiple: is_multiple,
            Formid: $('#autodevice_Id').val(),
            // Type_form: $('#Htype_form').val(),
            Hospitalid: $('#HospitalId').val(),
            display_order: $("#displayorder").val(),
            Dml_Indicator: 'FUP'
        }
    }


    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormMaster",
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Submit),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            var data2 = data1.data.Table;

            if (data1.msg == 'Success') {
                if (data2[0].msg == 'inserted') {
                    toastr.success("Added Successfully");
                    clearform();
                    loaddata();
                    //loaddata1();
                    //loaddata2();
                    //loaddata3();
                }
                else if (data2[0].msg == 'already') {
                    toastr.warning("Device Model Name already exists");
                }
                else if (data2[0].msg == 'updated') {
                    toastr.success("Updated Successfully");
                    clearform();
                    loaddata();
                    HeaderFormName();
                    //loaddata1();
                    //loaddata2();
                    //loaddata3();
                }
                else {
                    console.log(data1)
                }
            }
            else {
                console.log(data1)

            }
        }

    })
});

$('#documents').change(function () {
    debugger;
    doctorimageupload();
});

function doctorimageupload() {
    debugger;
    var uploadpath = $('#documents').val();
    var fileExtension = uploadpath.substring(uploadpath.lastIndexOf(".") + 1, uploadpath.length);
    if (fileExtension == "png" || fileExtension == "PNG") {
    }
    else {
        $('#Pdocuments').show();
        $('#Pdocuments').fadeOut(8000);
        $('#Pdocuments').html('Please upload file having extensions .png only.');
        $('#documents').val('');
        $('#documents').focus();
        return false;
    }
    if (window.FormData !== undefined) {
        var fileUpload = $("#documents").get(0);
        var files = fileUpload.files;
        var fileData = new FormData();

        $.when(checkimagedimensionvalidation(fileUpload.files[0], 240, 256)).
        done(function (Results) {
            if (Results == 'Success') {
                for (var i = 0; i < files.length; i++) {
                    fileData.append(files[i].name, files[i]);

                }
                fileData.append('username', 'Manas');
                $.ajax({
                    url: '/Form_builder/UploadPhotoFiles',
                    type: "POST",
                    contentType: false,
                    processData: false,
                    data: fileData,
                    success: function (result) {
                        $.each(result, function (i, emp) {
                            $('#profile-photo').empty();
                            $('#profile-photo').show();
                            var d, n, drloimage;
                            d = new Date();
                            n = d.getTime();
                            drloimage = $('#hdnCDfilepath').val() + $('#HospitalId').val() + '/FormBuilderFileUpload/' + emp + '?' + n;
                            $('#profile-photo').append('<a href="' + drloimage + '" target="_blank" id="formimage">Image</a>');
                            //$('#documents').val(emp);
                            $('#hformimg').val(emp);
                            //var drphotoSrc = $('#hdnfilepath').val() + $('#HospitalId').val() + "/Photos/" + emp;
                            //$('#ProfilePhotoTop,#ProfilePhoto').attr('src', drphotoSrc);
                        });
                    }
                });
            }
            else {
                $('#documents').val('');

            }
            //this code is executed when all ajax calls are done
        });

    }
}




$("#Module_Type").change(function () {
    if ($('#Module_Type').val() == 1 || $('#Module_Type').val() == 2) {
        $('#div_module_subtype').show();
    }
    else {
        $('#div_module_subtype').hide();
    }
})


$('#Form_close').click(function () {
    clearform();
    //LoadBranch();
})
$('#Form_CloseX').click(function () {
    clearform();
    //LoadBranch();
})
function clearform() {
    debugger;
    //one master concept 
    //if (parseInt($('#hiddenRole_id').val()) == 2) {
    //    $("#Form_Branch").val(0);
    //}

    $("#Form_Type").val(0);
    $("#Form_Name").val('');
    $("#Module_subtype").val(0);
    $("#Module_Type").val(0);
    $("#Type_of_Admission").val(0).change();
    $("#Form_Structure").val('');
    $("#Description").val('');
    $('#hformimg').val('');
    $("#displayorder").val(''),
    $('#profile-photo').empty();
    $('#formimage').val('');
    // $('#ChkIS_mulitiple').prop("checked", false);
    $('a[data-toggle=ChkIS_mulitiple][data-title="1"]').removeClass('active');
    $('a[data-toggle=ChkIS_mulitiple][data-title="1"]').addClass('not-active');
    $('a[data-toggle=ChkIS_mulitiple][data-title="0"]').removeClass('active');
    $('a[data-toggle=ChkIS_mulitiple][data-title="0"]').addClass('not-active');

    $('#ChkIS_mulitiple').val('');
    $("#Form_submit").html("Submit");
    $('#autodevice_Id').val('');
}
//load table
function loaddata(Fb_Type) {
    debugger;
    var load = ''
    if ($('#hiddenRole_id').val() == 2) {
        load = {
            Dml_Indicator: "OP",
            Hospitalid: $('#HospitalId').val(),
            //Branch_id: Fb_branch_id,
            Moduletype: Fb_Type
        }
    }
    else {
        load = {
            Dml_Indicator: "OP",
            Hospitalid: $('#HospitalId').val(),
           // Branch_id: $('#HospitalBranchID').val(),
            Moduletype: Fb_Type
        }
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormMaster",
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(load),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            console.log(data1);
            if (data1.msg == "Success") {
                debugger;
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    $('#tbl_op').empty();
                    $('#op_formbuilder_table').dataTable().fnClearTable();
                    $('#op_formbuilder_table').dataTable().fnDraw();
                    $('#op_formbuilder_table').dataTable().fnDestroy();

                    var j = 0; tr = '';
                    var b = data1.Table;
                    $.each(b, function (i, emp) {
                        j++;

                        var status = '';
                        var edit = '', Form_Image = '';
                        var formurl = $('#Hdformurl').val()
                        status = '<span class="label label-success">Active</span>';

                        designform = '<a  title="Design New Form" class="btn btn-edit btn-xs btn_r" data-id="FB_A1" data-type="role_rights_add" data-nav="redirect" data-name="' + formurl + 'form-builder/' + emp.Formid + '"  id="form_' + i + '"  ><i class="fas fa-marker" aria-hidden="true"></i></a>';

                        if ($('#hstatus').val == 1) {
                            edit = '<a title="Edit" class="btn btn-edit btn-xs" data-id="FB_E1" data-type="role_rights_edit" data-nav="sp_div" data-name="c_details_form" href="/Form_Builder/New_FormBuilder?formid=' + emp.Formid + '&type=' + emp.Module_Type + '" data-toggle="modal" data-target=""><i class="fa fa-pencil" aria-hidden="true"></i></a>';
                        }
                        else {
                            edit = '<a title="Edit" class="btn btn-edit btn-xs" data-id="FB_E1" data-type="role_rights_edit" data-nav="sp_div" data-name="c_details_form" href="/Form_Builder/New_FormBuilder?formid=' + emp.Formid + '&type=' + emp.Module_Type + '" data-toggle="modal" data-target=""><i class="fa fa-pencil" aria-hidden="true"></i></a>';
                        }


                        del = '<a  data-toggle="tooltip" title="Delete" class="btn deleteicon-btn btn-xs" data-id="FB_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" href="javascript:void(0);" onclick=FormBuilderdel(this,"' + emp.Formid + '","DE")><i class="fa fa-trash" aria-hidden="true"></i></a>';

                        Copy_to_other_branch = '<a data-toggle="modal" title="Copy_to_other_branch" class="btn-blue"  data-target="" data-id="FB_F1" data-type="role_rights_function" aria-hidden="true"  id="copy_branch" data-nav="sp_div" data-name="c_details_form" href="javascript:void(0);" onclick=\'copy_branch(this,"' + emp.Formid + '","' + emp.Form_Name + '")\'>Copy to Other Branch</a>'

                        Map = '<a data-toggle="modal" data-target="" title="Map" class="btn-blue hide" data-id="FB_F1"  id="mapping"  data-type="role_rights_function"   data-target=""   data-nav="sp_div" data-name="c_details_form" href="javascript:void(0);" onclick=\'map(this,"' + emp.Formid + '")\'  aria-hidden="true">Map</a>'
    
                        Print = '<p <a data-toggle="tooltip" data-placement="bottom" title="Print" type="button" class="btn btn-edit btn-xs btn_r" data-id="FB_F1" data-type="role_rights_edit" data-nav="redirect" data-name=""><i class="fa fa-print" aria-hidden="true"></i></a></p>'

                        Download = '<p <a data-toggle="tooltip" data-placement="bottom" title="Download" type="button" class="btn btn-edit btn-xs btn_r" data-id="FB_F1" data-type="role_rights_edit" data-nav="redirect" data-name=""><i class="fa fa-download" aria-hidden="true"></i></a></p>'

                        if (emp.status == '1') {

                            status = '<span class="label label-success">Active</span>';
                            active = '<a  data-toggle="tooltip" title="Make In Active!" class="btn btn-xs btn-blue mr-10" href="javascript:void(0);"  data-id="FB_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" onclick=FormBuilderdel(this,"' + emp.Formid + '","INACT")><i class="fa fa-minus-square-o mr-5" aria-hidden="true"> In-Active</i></a>';

                            //one master concept //other_info = '<div class="col-md-12 padding0"><div class="disp_if">' + designform + ' ' + edit + ' ' + del + '<a href="#" class="dropdown-togglve btn btn-info-dots btn-xs" data-toggle="dropdown" aria-expanded="true"> <span class="fa fa-ellipsis-h" data-toggle="tooltip" data-placement="bottom" title="Other Options" style="color:black;" aria-hidden="true"></span><span class="sr-only">Options</span></a><div class="dropdown-menu info-dropdown" id=""><div class="text-left">' + Copy_to_other_branch + '</div><div class="text-left">' + View_old_version + '</div><div class="text-left">' + Access_Rights + '</div><div class="text-left">' + Map + '</div><div class="text-left">' + Send + '</div><div class="text-left">' + active + '</div></div></div></div>';
                            other_info = '<div class="col-md-12 padding0"><div class="disp_if">' + designform + ' ' + edit + ' ' + del + '<a href="#" class="dropdown-togglve btn btn-info-dots btn-xs" data-toggle="dropdown" aria-expanded="true"> </div></div></div>';

                        }
                        else {
                            status = '<span class="label label-warning">In Active</span>';

                            active = '<a  data-toggle="tooltip" title="Make Active!" class="btn btn-xs btn-blue mr-10" href="javascript:void(0);"  data-id="FB_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" onclick=FormBuilderdel(this,"' + emp.Formid + '","ACT")><i class="fa fa-check-square-o mr-5" aria-hidden="true"> Active</i></a>';

                            //one master concept    // other_info = '<div class="col-md-12 padding0"><div class="disp_if"> ' + del + '<a href="#" class="dropdown-togglve btn btn-info-dots btn-xs" data-toggle="dropdown" aria-expanded="true"> <span class="fa fa-ellipsis-h" data-toggle="tooltip" data-placement="bottom" title="Other Options" style="color:black;" aria-hidden="true"></span><span class="sr-only">Options</span></a><div class="dropdown-menu info-dropdown" id=""><div class="text-left">' + Copy_to_other_branch + '</div><div class="text-left">' + View_old_version + '</div><div class="text-left">' + Access_Rights + '</div><div class="text-left">' + Map + '</div><div class="text-left">' + Send + '</div><div class="text-left">' + active + '</div></div></div></div>';
                            other_info = '<div class="col-md-12 padding0"><div class="disp_if"> ' + del + '<a href="#" class="dropdown-togglve btn btn-info-dots btn-xs" data-toggle="dropdown" aria-expanded="true"> </div></div></div>';

                        }

                        if (emp.FormImage != '' && emp.FormImage != '-' && parseInt(emp.FormImage) != 0) {
                            Form_Image = '<a target="_blank" href="' + $('#hdnCDfilepath').val() + "/" + $('#HospitalId').val() + "/" + "FormBuilderFileUpload/" + emp.FormImage + '">Form Image</a>';
                        }
                        else {
                            Form_Image = '';
                        }

                        //one master concept
                        //   tr = tr + '<tr' + j + '"></td><td>' + j + '</td><td>' + emp.Form_Name + '</td><td>' + emp.Form_Type + '</td><td>' + emp.moduletype + '</td><td>' + emp.modulesubtype + '</td><td>' + emp.branch_name + '</td><td>' + emp.LastestversionId + '</td><td>' + status + '</td><td class="hide">' + emp.MappedPages + '</td><td>' + Form_Image + '</td><td>' + other_info + '</td></tr>';
                        tr = tr + '<tr' + j + '"></td><td>' + j + '</td><td>' + emp.Form_Name + '</td><td>' + emp.Form_Type + '</td><td>' + emp.moduletype + '</td><td>' + emp.modulesubtype + '</td><td>' + emp.LastestversionId + '</td><td>' + status + '</td><td class="hide">' + emp.MappedPages + '</td><td>' + Form_Image + '</td><td>' + other_info + '</td></tr>';

                    });
                    $('#tbl_op').html(tr);

                    datatable('op_formbuilder_table', 'op_form', 'Legal');

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


function HeaderFormName() {
    var formid = $('#HFormId').val();
    debugger;
    var values = {
        Dml_Indicator: 'EFM',
        Formid: formid,
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormMaster",
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(values),
        success: function (data) {
            debugger;
            var data2 = JSON.parse(data);

            var emp = data2.data.Table;
            $('#form_name_head').html(emp[0].Form_Name)
            $('#div_formtype').html(emp[0].Form_Type)
            $('#div_moduletype').html(emp[0].Module_Type)
            $('#div_modulesubtype').html(emp[0].Module_Subtype)
            $('#div_multiple').html(emp[0].is_multiple)
            if (emp[0].Module_Subtype == '') {
                $('.orange_bg').hide()
            }
        }
    });
}

///---redirect form master edit----
$('#btn_edit').click(function () {
    debugger;
    FormBuilderedit($('#HFormId').val())

})

function FormBuilderedit(Formid) {
    debugger;
    var Edit = {
        Dml_Indicator: 'FED',
        Formid: Formid,
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormMaster",
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Edit),
        success: function (data) {
            debugger;
            var data2 = JSON.parse(data);

            var emp = data2.data.Table;
            Loadmoduletype(emp[0].Module_Type, emp[0].Module_Subtype)
            $('#Type_of_Admission').val('');
            $("#Module_Type").attr('disabled', false);
            $("#Module_subtype").attr('disabled', false);

            if (emp[0].Module_Type == 1) {
                $('#div_module_subtype').show()
                $('#div_Type_of_Admission').hide()
            }
            else if (emp[0].Module_Type == 2) {
                $('#div_module_subtype').show()
                $('#div_Type_of_Admission').show()
               // var typeadmission = emp[0].Type_of_Admission
                //  $('#Type_of_Admission').val(typeadmission.split(','));
                var typeadmission = emp[0].Type_of_Admission;
                var selectedValues = typeadmission.split(',');

                $('#Type_of_Admission option').each(function () {
                    if (selectedValues.indexOf($(this).val()) !== -1) {
                        $(this).prop('selected', true);
                    }
                });

                $('#Type_of_Admission').trigger('change');
            }
            else {
                $('#div_module_subtype').hide()
                $('#div_Type_of_Admission').hide()
            }

            Formtype(emp[0].Form_Type)
            $("#Form_Type").attr('disabled', true);
            $('#Form_Name').val(emp[0].Form_Name);
            $('#Description').val(emp[0].Description);
            $("#displayorder").val(emp[0].Display_Order);

            if (emp[0].form_image != null && emp[0].form_image != "") {
                $('#profile-photo').show();
                drloimage = $('#hdnCDfilepath').val() + $('#HospitalId').val() + '/FormBuilderFileUpload/' + emp[0].form_image;
                $('#profile-photo').append('<a href="' + drloimage + '" target="_blank" id="formimage">Image</a>');
                $('#hformimg').val(emp[0].form_image);
            }


            if (emp[0].is_multiple == 1) {
                $('a[data-toggle=ChkIS_mulitiple][data-title="1"]').removeClass('not-active');
                $('a[data-toggle=ChkIS_mulitiple][data-title="1"]').addClass('active');
                $('a[data-toggle=ChkIS_mulitiple][data-title="0"]').removeClass('active');
                $('a[data-toggle=ChkIS_mulitiple][data-title="0"]').addClass('not-active');
            }
            else {
                $('a[data-toggle=ChkIS_mulitiple][data-title="1"]').removeClass('active');
                $('a[data-toggle=ChkIS_mulitiple][data-title="1"]').addClass('not-active');
                $('a[data-toggle=ChkIS_mulitiple][data-title="0"]').removeClass('not-active');
                $('a[data-toggle=ChkIS_mulitiple][data-title="0"]').addClass('active');
            }
            $('#ChkIS_mulitiple').val(emp[0].is_multiple);

            $('#autodevice_Id').val(Formid);

            $("#Form_submit").html("Update");
 
        }
    })
}


//build 
function buildiframe() {
    debugger;
    var formid = $('#autodevice_Id').val();
    selectedOptionText = $(this).find('option:selected').text();

    $('#formShow_header').html(selectedOptionText);
    $('#formShow').attr('src', $('#Hdformurl').val() + 'form/' + formid + '')

}

//---Configure Starts----
//Operation Name autocomplete
$('#configure_opname').autocomplete({
    source: function (request, response) {
        $.ajax({
            async: true,
            url: '/Ipmanagement/IPOperationSessions_Ins_Upd',
            type: "POST",
            dataType: "json",
            data: { Prefix: request.term, Dml_Indicator: "LOPN", hospital_id: $('#HospitalId').val() },
            success: function (data) {
                debugger;
                $('#HSelOperationName').val('')
                var data2 = JSON.parse(data);
                response($.map(data2.data.Table, function (item) {
                    return { label: item.ip_operation_name, value: item.ip_operation_name, id: item.ip_operation_id };
                }))
            }
        })
    },
    minLength: 1,
    select: function (event, ui) {
        debugger;
        $('#HSelOperationName').val(ui.item.id);
        LoadServiceName();
    },
    html: true,
    open: function (event, ui) {
        $(".ui-autocomplete").css("z-index", 1000);

    }
});
//service name
function LoadServiceName() {
    debugger;
    var servicename = {
        Dml_Indicator: "LSVN",
        operatio_id: $('#HSelOperationName').val(),

    };

    $.ajax({
        async: true,
        type: 'POST',
        url: '/Ipmanagement/IPOperationSessions_Ins_Upd',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(servicename),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            var emp = data1.data.Table;

            $("#configure_servicename").val(emp[0].service_name);
            $('#configure_servicename').prop('disabled', true);


        }
    })

}



// configure save
$('#btn_configure_add').on("click", function () {
    debugger;

    if ($.trim($('#configure_branch').val()) == "") {
        $('#Pconfigure_branch').show();
        $('#Pconfigure_branch').fadeOut(8000);
        $('#Pconfigure_branch').html('Select the Branch');
        $('#configure_branch').focus();
        return false;
    }

    if ($.trim($('#configure_opname').val()) == "" || $('#configure_opname').val() == '0') {
        $('#Pconfigure_opname').show();
        $('#Pconfigure_opname').fadeOut(8000);
        $('#Pconfigure_opname').html('Select Operation Name');
        $('#Pconfigure_opname').focus();
        $('#configure_opname').val('')
        return false;
    }

    if ($('#configure_servicename').val() == "" || $('#configure_servicename').val() == '0') {
        $('#Pconfigure_servicename').show();
        $('#Pconfigure_servicename').fadeOut(8000);
        $('#Pconfigure_servicename').html('Select the Service Name');
        $('#Pconfigure_servicename').focus();
        return false;
    }

    var Dml_Indicator = '', Id = '';

    if ($('#btn_configure_add').html() == 'Save') {
        Id = 0
        Dml_Indicator = 'ISCON'
    }
    else {
        Dml_Indicator = 'UPCON'
        Id = $("#Htconfigid").val()
    }
    var save = {
        operation_formid: Id,
        formid: $('#HFormId').val(),
        Branch_id: $('#configure_branch').val(),
        operatio_id: $('#HSelOperationName').val(),
        Dml_Indicator: Dml_Indicator,
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/Ipmanagement/IPOperationSessions_Ins_Upd',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(save),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            console.log(data1);
            if (data1.msg == "Success") {
                debugger;
                var data2 = data1.data.Table[0];
                if (data2.Message == 'Inserted') {
                    toastr.success('Inserted Successfully');
                    loadConfigureData();
                }
                else if (data2.Message == 'Updated') {
                    toastr.success("Updated Successfully");
                    loadConfigureData();
                }
                else {
                    toastr.success('Somthing Went Wrong');
                }

            }

        },
    });
});

//configure table
function loadConfigureData() {
    debugger;
    var values = {
        Dml_Indicator: "LCONT",
        formid: $('#HFormId').val(),
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/Ipmanagement/IPOperationSessions_Ins_Upd',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(values),
        success: function (data) {
            console.log(data);
            var data1 = JSON.parse(data);
            console.log(data1);
            if (data1.msg == "Success") {
                debugger;
                var data2 = data1.data;
                if (jQuery.isEmptyObject((data1))) {

                }
                else {
                    $('#tbl_configure tbody').empty();
                    $('#tbl_configure').dataTable().fnClearTable();
                    $('#tbl_configure').dataTable().fnDestroy();

                    var j = 0, b = '', tr = '', edit = '', del = '', active_inactive = '', active = '', other_info = '';

                    b = data2.Table;
                    $.each(b, function (i, emp) {
                        j++

                        edit = '<a data-toggle="tooltip" title="Edit" class="btn btn-edit btn-xs" data-id="SM_E1" data-type="role_rights_edit" data-nav="sp_div" data-name="c_details_form"  href="javascript:void(0);" onclick=Configureedit(this,"' + emp.operation_formid + '")><i class="fa fa-pencil" aria-hidden="true"></i></a>';
                        del = ' <a  data-toggle="tooltip" title="Delete"  id="TPAdel_' + emp.Id + '" class="btn deleteicon-btn btn-xs"  data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form"  href="javascript:void(0);" onclick=Configuredel(this,"' + emp.operation_formid + '","DECON")><i class="fa fa-trash" aria-hidden="true"></i></a>';
                        if (emp.status == '1') {
                            active_inactive = '<span class="label label-success">Active</span>';
                            active = '<a  data-toggle="tooltip" title="Make In Active" class="btn btn-xs btn-blue mr-10" href="javascript:void(0);"  data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" onclick=Configuredel(this,"' + emp.operation_formid + '","INACTCON")><i class="fa fa-minus-square-o mr-5" aria-hidden="true"></i></a>';
                            other_info = '<div class="col-md-12 padding0"><div class="disp_if">' + edit + ' ' + del + ' ' + active + '</div></div>';
                        }
                        else if (emp.status == '2') {
                            active_inactive = '<span class="label label-warning">Inactive</span>';
                            active = '<a  data-toggle="tooltip" title="Make Active" class="btn btn-xs btn-blue mr-10" href="javascript:void(0);"  data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" onclick=Configuredel(this,"' + emp.operation_formid + '","ACTCON")><i class="fa fa-check-square-o mr-5" aria-hidden="true"></i></a>';
                            other_info = '<div class="col-md-12 padding0"><div class="disp_if">' + del + ' ' + active + '</div></div>';
                        }
                        tr = tr + '<tr' + j + '"><td>' + j + '</td><td>' + emp.branch_name + '</td><td >' + emp.ip_operation_name + '</td><td>' + emp.service_name + '</td><td>' + active_inactive + '</td><td>' + other_info + '</td></tr>';

                    });
                    $('#configure_table_body').html(tr);
                    $('#tbl_configure').DataTable();

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

}

//Configure Edit
function Configureedit(event, Id) {
    debugger;
    $('#configure_modal').modal('toggle');
    $('#Htconfigid').val(Id)
    var Edit = {
        operation_formid: Id,
        Dml_Indicator: "ECON"
    };

    $.ajax({
        async: true,
        type: 'POST',
        url: '/Ipmanagement/IPOperationSessions_Ins_Upd',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Edit),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            var emp = data1.data.Table[0];
            var branch = emp.branch_id
            LoadBranch(branch)

            $("#configure_branch").val(emp.Branch_id);
            $("#configure_opname").val(emp.ip_operation_name);
            $("#configure_servicename").val(emp.service_name);
            $('#configure_servicename').prop('disabled', true);
            $("#Htconfigid").val(emp.operation_formid);
            $('#btn_configure_add').html('Update');

        }
    })
}
$('#btn_configure_addnew').on("click", function () {
    $('#btn_configure_add').html('Save');
    cleardata_configure();
})

function cleardata_configure() {
    debugger;
    $('#configure_branch').val('');
    $('#configure_opname').val('');
    $('#configure_servicename').val('');
    $('#configure_servicename').prop('disabled', false);

}

//Configure delete
function Configuredel(event, configid, indicatorid) {
    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 {
                     var status = "";
                     if (indicatorid == 'DECON') {
                         status = "Are You Sure, You Want to Delete?";
                     }
                     else if (indicatorid == 'INACTCON') {
                         status = "Are You Sure, You Want to In-Activate?";
                     }
                     else if (indicatorid == 'ACTCON') {

                         status = "Are You Sure,You Want to Activate?";
                     }
                     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) {
                                   $("#confirmationRevertYes").click(function () {

                                       var Delete = {
                                           Dml_Indicator: indicatorid,
                                           operation_formid: configid
                                       }

                                       $.ajax({
                                           async: true,
                                           type: 'POST',
                                           url: '/Ipmanagement/IPOperationSessions_Ins_Upd',
                                           contentType: 'application/json; charset=UTF-8',
                                           data: JSON.stringify(Delete),
                                           success: function (data) {
                                               debugger;
                                               var data1 = JSON.parse(data);

                                               if (indicatorid == 'DECON') {

                                                   toastr.success("Deleted Successfully");
                                               }
                                               else if (indicatorid == 'INACTCON') {

                                                   toastr.success("Inactivated Successfully");
                                               }
                                               else if (indicatorid == 'ACTCON') {

                                                   toastr.success("Activated Successfully");
                                               }
                                               loadConfigureData()
                                           }
                                       });
                                   });
                               }
                           })

                 }
             }
         }

     })

};


// --share starts----
//Load UserRole
function LoadRole() {
    var RoleData = {
        Dml_Indicator: "SS",
        created_by: $('#HiddenDoctorID').val(),
        // branch_id: $('#op_access_branch').val()       //one master concept
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/CreateRole/DoctorRole',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(RoleData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                debugger;
                if (jQuery.isEmptyObject((data))) {

                }
                else {
                    var tr = '';
                    var SelRole = '';
                    $('.Access_userrole').empty();
                    var default_opt = '<option value="0">--Select--</option>';
                    var j = 0;
                    if (data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            j++;
                            SelRole = SelRole + '<option value="' + data[i].doctor_user_role_id + '">' + data[i].doctor_user_role_name + '</option>';
                        }

                        $('.Access_userrole').append(default_opt + SelRole);
                        if ($('#user_role_id').val() != '' && $('#user_role_id').val() != null) {
                            $('.Access_userrole').val($('#user_role_id').val());

                            if ($('.Access_userrole').val() == '1') {

                                var date = new Date();

                                date.setFullYear(new Date().getFullYear() - 24);
                                $('.DOB').datepicker('destroy').datepicker({
                                    format: 'dd/mm/yyyy',
                                    endDate: date,
                                    todayHighlight: true,
                                    autoclose: true
                                })
                            }
                            else {
                                var date = new Date();

                                date.setFullYear(new Date().getFullYear() - 18);
                                $('.DOB').datepicker('destroy').datepicker({
                                    format: 'dd/mm/yyyy',
                                    endDate: date,
                                    todayHighlight: true,
                                    autoclose: true
                                })

                            }
                        }
                        if ($('#myHiddenVar1').val() != '' && $('#myHiddenVar1').val() != null) {
                            $('.Access_userrole').attr('disabled', true);
                        }
                    }


                }

            }
            else {
                console.log(data);
            }

        }

    });

}

// load User
function LoadUser(user) {
    debugger;
    var department = {
        //Dml_Indicator: "UR",
        Dml_Indicator: "BRU",
        // Dml_Indicator: "BRUR",
        branch_id: $('#op_access_branch').val(),         
        mobile_description: $('#op_access_userrole').val().toString()
    }
    //if ($('#hiddenRole_id').val() != 2) {
    //    department.type=$('#hiddenUser_id').val()
    //}
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(department),
        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 {
                    var Department;
                    $('#op_access_user').empty();

                    var default_opt = '<option value="0">--Select--</option>';
                    $.each(data1.Table, function (i, emp) {
                        Department = Department + '<option value="' + emp.doctor_user_id + '" data-id=' + emp.doctor_user_role_id + '>' + emp.Doctor + '</option>';
                    });
                    if (data1.Table.length == 1) {
                        $('#op_access_user').append(Department);
                        $("#op_access_user").change();

                    }
                    else {
                        $('#op_access_user').append(default_opt + Department);

                    }

                    if (user != '' && user != null) {
                        $('#op_access_user').val(user);
                    }

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

//Access rights Always Valid Change Function
$('#share_always_valid').change(function () {
    if ($('#share_always_valid').prop("checked") == true) {
        $('#op_access_from').val('');
        $("#op_access_from").prop("disabled", true);
        $('#op_access_to').val('');
        $("#op_access_to").prop("disabled", true);
    }
    else {
        $("#op_access_from").prop("disabled", false);
        $("#op_access_to").prop("disabled", false);
    }
})

//insert_access_rights_op
$('#btn_add_op').click(function () {
    debugger;

    if ($.trim($('#op_access_branch').val()) == '0') {
        $('#Pop_access_branch').show();
        $('#Pop_access_branch').fadeOut(8000);
        $('#Pop_access_branch').html('Select Branch');
        $('#op_access_branch').focus();
        return false;
    }

    if ($.trim($('#op_access_userrole').val()) == '0') {
        $('#Pop_access_userrole').show();
        $('#Pop_access_userrole').fadeOut(8000);
        $('#Pop_access_userrole').html('Select User Role');
        $('#op_access_userrole').focus();
        return false;
    }

    if ($.trim($('#op_access_user').val()) == '0') {
        $('#Pop_access_user').show();
        $('#Pop_access_user').fadeOut(8000);
        $('#Pop_access_user').html('Select User');
        $('#op_access_user').focus();
        return false;
    }

    var sharealwaysvalid = 0;
    if ($('#share_always_valid').prop("checked") == true) {
        sharealwaysvalid = 1;
    }

    if ($.trim($('#op_access_from').val()) == '' && sharealwaysvalid == 0) {
        $('#Pop_access_from').show();
        $('#Pop_access_from').fadeOut(8000);
        $('#Pop_access_from').html('Select Access From');
        $('#op_access_from').focus();
        return false;
    }

    if ($.trim($('#op_access_to').val()) == '0' && sharealwaysvalid == 0) {
        $('#Pop_access_to').show();
        $('#Pop_access_to').fadeOut(8000);
        $('#Pop_access_to').html('Select Access To');
        $('#op_access_to').focus();
        return false;
    }

    var oldUserid = $('#HoldUserid').val();
    var Userid = $('#op_access_user').val();
    var Branchid = $('#op_access_branch').val();

    var rowcount = $('#access_rights_table_op >tbody >tr').length;

    if (oldUserid != Userid) {
        for (var i = 0; i < rowcount; i++) {

            if (($('#tdUserid_' + i).val() == Userid) && ($('#tdbranchid_' + i).val() == Branchid)) {

                $('#Pop_access_user').show();
                $('#Pop_access_user').fadeOut(8000);
                $('#Pop_access_user').html('User already Inserted.');
                $('#op_access_user').val(0);
                $('#op_access_user').focus();
                return false;
            }

        }
    }

    //var Formid = $('#Hformid').val();

    var formid = $('#HFormId').val();
    var frm_date = $('#op_access_from').val();
    var to_date = $('#op_access_to').val();

    var from_date = null, to_date = null;
    if ($('#op_access_from').val() != '') {
        var date1 = $('#op_access_from').val().split('/');
        from_date = date1[2] + '-' + date1[1] + '-' + date1[0];
    }
    if ($('#op_access_to').val() != '') {
        var date2 = $('#op_access_to').val().split('/');
        to_date = date2[2] + '-' + date2[1] + '-' + date2[0]
    }

    var accessAlwaysValid = 0;
    if ($('#share_always_valid').prop("checked") == true) {
        accessAlwaysValid = 1;
    }

    var Submit = ''
    if ($('#Haccessformid').val() == '') {
        Submit = {
            Branch_id: $('#op_access_branch').val().toString(),
            Userrole_id: $('#op_access_userrole').val().toString(),
            User_id: $('#op_access_user').val().toString(),
            Access_from: from_date,
            Access_to: to_date,
            always_valid: accessAlwaysValid,
            // Id: $("#autodevice_Id").val(),
            Formid: formid,
            Dml_Indicator: 'INS'
        }
    }
    else {
        Submit = {

            Branch_id: $('#op_access_branch').val().toString(),
            Userrole_id: $('#op_access_userrole').val().toString(),
            User_id: $('#op_access_user').val().toString(),
            Access_from: from_date,
            Access_to: to_date,
            always_valid: accessAlwaysValid,
            Id: $("#Haccessformid").val(),
            //Id: $("#autodevice_Id").val(),
            Formid: formid,
            Dml_Indicator: 'UPD'
        }
    }


    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormAccess",
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Submit),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            var data2 = data1.data.Table;

            if (data1.msg == 'Success') {
                if (data2[0].msg == 'inserted') {
                    toastr.success("Added Successfully");
                    cleardata_op();
                    clear_op();
                    loaddata_op();

                }
                else if (data2[0].msg == 'already') {
                    toastr.warning("Device Model Name already exists");
                }
                else if (data2[0].msg == 'updated') {
                    toastr.success("Updated Successfully");
                    cleardata_op();
                    clear_op();
                    $("#btn_add_op").html("Add");
                    loaddata_op();

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

    })
});

function Devicemodeledit_op(event, Id) {
    debugger;
    $('#share_accesrights_modal').modal('toggle');
    $('#Haccessformid').val(Id)

    debugger;

    var Edit = {

        Id: Id,

        Dml_Indicator: 'EDI'
    };
    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormAccess",
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Edit),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            var emp = data1.data.Table;
            $("#op_access_branch").val(emp[0].Branchid);
            $('#op_access_branch').prop('disabled', true);

            $('#Husr_id').val(emp[0].Userid);
            $("#op_access_userrole").val(emp[0].Userroleid).change();
            $('#op_access_userrole').prop('disabled', true);
            //$("#op_access_user").val(emp[0].Userid);
            $('#op_access_user').prop('disabled', true);
            $("#op_access_from").val(emp[0].Accessfrom);
            $("#op_access_to").val(emp[0].Accessto);

            if (emp[0].always_valid == 1) {
                $('#op_access_from').prop("disabled", true);
                $('#op_access_to').prop("disabled", true);
                $("#share_always_valid").prop("checked", true)
            }
            else {
                $("#share_always_valid").prop("checked", false)

            }

            $("#btn_add_op").html("Update");
            //$('#op_access_branch').focus();
            $('#HoldUserid').val(emp[0].Userid);
            LoadUser(emp[0].Userid);
        }

    })


}

/////delete//active//inactive_for_AccessRightstable
function Devicemodeldel(event, Id, indicatorid) {
    debugger;

    var status = "";
    if (indicatorid == 'DL') {
        status = "Are You Sure, You Want to Delete?";
    }
    else if (indicatorid == 'Inactive') {
        status = "Are You Sure, You Want to In-Activate?";
    }
    else if (indicatorid == 'Active') {

        status = "Are You Sure,You Want to Activate?";
    }
    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) {
                  $("#confirmationRevertYes").click(function () {

                      var Delete = {
                          Dml_Indicator: indicatorid,
                          Id: Id
                      }

                      $.ajax({
                          async: true,
                          type: 'POST',
                          url: "/Form_builder/insert_update_deleteFormAccess",
                          contentType: 'application/json; charset=UTF-8',
                          data: JSON.stringify(Delete),
                          success: function (data) {
                              debugger;
                              var data1 = JSON.parse(data);

                              if (indicatorid == 'DL') {

                                  toastr.success("Deleted Successfully");
                              }
                              else if (indicatorid == 'Inactive') {

                                  toastr.success("In-Activate Successfully");
                              }
                              else if (indicatorid == 'Active') {

                                  toastr.success("Activate Successfully");
                              }

                              loaddata_op();
                              //loaddata_ip();
                              //loaddata_patient();
                              loaddata_survey;
                          }
                      });
                  });
              }
          })
};



/////Loaddata-Access_rights_op
function loaddata_op() {
    debugger;
    var Formid = $('#HFormId').val();
    var userid = ''
    if ($('#hiddenRole_id').val() == 2) {
        userid = 0
    }
    else {
        userid = $('#hiddenUser_id').val()
    }
    var branchid = $('#HospitalBranchID').val()
    var load = {
        Dml_Indicator: "ARO",
        Formid: Formid,
        Branch_id: parseInt(branchid),
        usr: userid
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormAccess",
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(load),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            console.log(data1);
            if (data1.msg == "Success") {
                debugger;
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    $('#tbl_access_rights_op').empty();
                    $('#access_rights_table_op').dataTable().fnClearTable();
                    $('#access_rights_table_op').dataTable().fnDestroy();
                    var j = 0; tr = '';
                    var no_user = data1.Table2[0].no_of_user;
                    $('#no_users_op').html(no_user)
                    var b = data1.Table;
                    $.each(b, function (i, emp) {
                        j++;
                        var status = '';

                        status = '<span class="label label-success">Active</span>';
                        edit = '<a data-toggle="tooltip" title="Edit" class="btn btn-edit btn-xs" data-id="FB_E1" data-type="role_rights_edit" data-nav="sp_div" data-name="c_details_form"  href="javascript:void(0);" onclick=Devicemodeledit_op(this,"' + emp.Id + '")><i class="fa fa-pencil" aria-hidden="true"></i></a>';
                        del = '<a  data-toggle="tooltip" title="Delete" class="btn deleteicon-btn btn-xs" data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" href="javascript:void(0);" onclick=Devicemodeldel(this,"' + emp.Id + '","DL")><i class="fa fa-trash" aria-hidden="true"></i></a>';
                        if (emp.status == '1') {
                            status = '<span class="label label-success">Active</span>';
                            active = '<a class="btn-blue"  data-toggle="tooltip" title="Make In Active!" class="btn btn-xs mr-10" href="javascript:void(0);"  data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" onclick=Devicemodeldel(this,"' + emp.Id + '","Inactive")><i class="fa fa-minus-square-o mr-5" aria-hidden="true">In-Active</i></a>';
                            other_info = '<div class="col-md-12 padding0"><div class="disp_if">' + edit + ' ' + del + '<a href="#" class="dropdown-togglve btn btn-info-dots btn-xs" data-toggle="dropdown" aria-expanded="true"> <span class="fa fa-ellipsis-h" data-toggle="tooltip" data-placement="bottom" title="Other Options" style="color:black;" aria-hidden="true"></span><span class="sr-only">Options</span></a><div class="dropdown-menu info-dropdown" id=""> <div class="text-left">' + active + '</div></div></div></div>';

                        }
                        else {
                            status = '<span class="label label-warning">In Active</span>';
                            active = '<a class="btn-blue" data-toggle="tooltip" title="Make Active!" class="btn btn-xs mr-10" href="javascript:void(0);"  data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" onclick=Devicemodeldel(this,"' + emp.Id + '","Active")><i class="fa fa-check-square-o mr-5" aria-hidden="true">Active</i></a>';
                            other_info = '<div class="col-md-12 padding0"><div class="disp_if">' + del + '<a href="#" class="dropdown-togglve btn btn-info-dots btn-xs" data-toggle="dropdown" aria-expanded="true"> <span class="fa fa-ellipsis-h" data-toggle="tooltip" data-placement="bottom" title="Other Options" style="color:black;" aria-hidden="true"></span><span class="sr-only">Options</span></a><div class="dropdown-menu info-dropdown" id=""> <div class="text-left">' + active + '</div></div></div></div>';
                        }


                        tr = tr + '<tr' + j + '"></td><td>' + j + '</td><td><input type="hidden" id="tdbranchid_' + i + '" value="' + emp.Branchid + '" />' + emp.Branchid + '</td><td>' + emp.Userroleid + '</td><td><input type="hidden" id="tdUserid_' + i + '" value="' + emp.user_id + '" />' + emp.Userid + '</td><td>' + emp.Accessfrom + '</td><td>' + emp.Accessto + '</td><td>' + status + '</td><td>' + other_info + '</td></tr>';
                    });
                    $('#tbl_access_rights_op').html(tr);

                    //datatable('access_rights_table_op', 'access_rights_title_op', 'Legal');
                    $('#access_rights_table_op').DataTable();
                }
            }
            else {
                console.log(data);
            }
        }
    });
}

//If the role is doctor need to check the license
$('#op_access_userrole').change(function () {
    debugger;
    LoadUser();
    if ($('#op_access_userrole').val() == '1') {

        var date = new Date();

        date.setFullYear(new Date().getFullYear() - 24);
        $('.DOB').datepicker('destroy').datepicker({
            format: 'dd/mm/yyyy',
            endDate: date,
            todayHighlight: true,
            autoclose: true
        })

        $('#divtxtfree').show();


        $('#op_access_department').prop('multiple', false);
        $('#op_access_department').val('').change();

        $('#div_NPI').removeClass('hide');



    }
    else {
        var date = new Date();

        date.setFullYear(new Date().getFullYear() - 18);
        $('.DOB').datepicker('destroy').datepicker({
            format: 'dd/mm/yyyy',
            endDate: date,
            todayHighlight: true,
            autoclose: true
        })

        $('#divtxtfree').hide();

        $('#op_access_department').prop('multiple', true);
        $('#op_access_subdepartment').prop('multiple', true);

        $('#op_access_department').val('').change();
        $('#div_NPI').addClass('hide');

    }

});


function clear_op() {
    debugger;
    $('#Husr_id').val("").change();
    $("#btn_add_op").html("Add");
    //LoadBranch();
    //LoadRole();

}

function cleardata_op() {
    debugger;
    $('#op_access_userrole').val("").change();
    $('#op_access_user').val("").change();
    //$('#autodevice_Id').val("");
    $('#op_access_from').prop('disabled', false);
    $('#op_access_to').prop('disabled', false);
    $('#share_always_valid').prop('checked', false);
    $('#op_access_user').val("");
    $('#HoldUserid').val('');
    $("#btn_add_op").html("Add");
    $('#op_access_userrole').prop('disabled', false);
    $('#op_access_user').prop('disabled', false);
    $('#op_access_branch').val(0)
    $('#op_access_branch').prop('disabled', false);
    // LoadBranch();
    // LoadRole();

}


////btn x close  op access tab
$('#Btn_x_op_acc').click(function () {
    debugger;
    clear_op();
    cleardata_op();
})


//-------Versions---------
///loaddata_view_old_version _op

$('#versions').click(function () {
    debugger;
    loaddata_version_op($('#HFormId').val())
})

function loaddata_version_op(form_id) {
    debugger;
    var load = {
        Dml_Indicator: "VOV",
        Form_id: form_id
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormversion",
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(load),
        success: function (data) {
            console.log(data);
            var data1 = JSON.parse(data);
            console.log(data1);
            if (data1.msg == "Success") {
                debugger;
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {

                }
                else {
                    $("#div_form_version").empty();
                    var j = 0, b = '';
                    var formVersion = $("#div_form_version");
                    b = data1;
                    $.each(b.Table, function (i, emp) {
                        j++                       
                        var divformversion = '<div class ="col-lg-12 version_bg" data-version-id="' + emp.Version_Id + '" " onclick=\'Restore(this, "' + emp.Version_Id + '", "RS", "' + emp.Form_id + '")\'><p class ="small_heading mb-0 pt-10">' + emp.Version_No + '</p><p class ="light_txt mb-0">' + emp.Updatedby + '</p><p class ="small_txt">' + emp.Form_Name + ' | <span>' + emp.Form_Name + '</span></p></div>'
                        formVersion.append(divformversion);
                    });
                }
            }
            else {
                console.log(data);
                $("#div_form_version").empty();
            }
        }
    });

}


$('#permissions').click(function () {
    debugger;
    loaddata_permissions($('#HFormId').val())
})


function loaddata_permissions(form_id) {
    debugger;

    var load = {
        Dml_Indicator: "ARO",
        Formid: form_id,
        Branch_id: $('#HospitalBranchID').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormAccess",
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(load),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            console.log(data1);
            if (data1.msg == "Success") {
                debugger;
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    $("#div_form_permissions").empty();

                    var j = 0;
                    var formPermissions = $("#div_form_permissions");

                    var b = data1.Table;
                    $.each(b, function (i, emp) {
                        j++;

                        var divformpermission = '<div class="pl-10"><p class="small_heading mb-0">' + emp.Userroleid + '</p><input type="hidden" id="tdUserid_' + i + '" value="' + emp.user_id + '" /><p class="light_txt mb-0">' + emp.Userid + '</p><p class ="small_txt">' + emp.access + '</p></div>'
                        formPermissions.append(divformpermission);
                    });


                }
            }
            else {
                console.log(data);
                $("#div_form_permissions").empty();
            }
        }
    });
}


////onclick view _old_version_ip
function view_old_version_ip(event, Form_Name) {
    debugger;
    loaddata_version_ip();
    Form_Name: $('#formname_ip_vov').html(Form_Name)

}
///loaddata_view_old_version _ip
function loaddata_version_ip() {
    debugger;
    var load = {
        Dml_Indicator: "VOV"
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: "/Form_builder/insert_update_deleteFormversion",
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(load),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            console.log(data1);
            if (data1.msg == "Success") {
                debugger;
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    $('#tbl_version_ip').empty();
                    $('#view_old_version_table_ip').dataTable().fnClearTable();
                    $('#view_old_version_table_ip').dataTable().fnDestroy();
                    var j = 0; tr = '';
                    var no_version = data1.Table2[0].No_of_version;
                    $('#no_of_version_ip_vov').html(no_version)
                    var b = data1.Table;
                    $.each(b, function (i, emp) {
                        j++;
                        var status = '';

                        status = '<span class="label label-success">Active</span>';
                        Print = '<a data-toggle="tooltip" data-placement="bottom" title="Print" type="button" class="btn btn-edit btn-xs btn_r" data-id="" data-type="role_rights_edit" data-nav="redirect" data-name=""><i class="fa fa-print" aria-hidden="true"></i></a>';
                        del = '<a  data-toggle="tooltip" title="Delete" class="btn deleteicon-btn btn-xs" data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" href="javascript:void(0);" onclick=Deviceversion(this,"' + emp.Version_Id + '","DL")><i class="fa fa-trash" aria-hidden="true"></i></a>';

                        Restore = '<p data-toggle="modal" data-target="#view_restore_op" aria-hidden="true"><a onclick=\'Restore_ip_vov(this,"' + emp.Version_Id + '","RS")\'>Restore</a></p>'

                        Restore_As_New_Form = '<p data-toggle="modal" data-target="#view_restore_new_op" aria-hidden="true"><a>Restore As New Form</a></p>'

                        Send = '<p data-toggle="modal" data-target="#view_send_op" aria-hidden="true"><a>Send</a></p>'

                        if (emp.status == '1') {
                            status = '<span class="label label-success">Active</span>';
                            active = '<a  data-toggle="tooltip" title="Make In Active!" class="btn btn-xs mr-10" href="javascript:void(0);"  data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" onclick=Deviceversion(this,"' + emp.Version_Id + '","IA")><i class="fa fa-minus-square-o mr-5" aria-hidden="true">In-Active</i></a>';
                            other_info = '<div class="col-md-12 padding0"><div class="disp_if">' + Print + ' ' + del + '<a href="#" class="dropdown-togglve btn btn-info-dots btn-xs" data-toggle="dropdown" aria-expanded="true"> <span class="fa fa-ellipsis-h" data-toggle="tooltip" data-placement="bottom" title="Other Options" style="color:black;" aria-hidden="true"></span><span class="sr-only">Options</span></a><div class="dropdown-menu info-dropdown" id=""> <div class="text-left">' + Restore + '</div><div class="text-left">' + Restore_As_New_Form + '</div><div class="text-left">' + Send + '</div><div class="text-left">' + active + '</div></div></div></div>';

                        }
                        else if (emp.status == '2') {
                            status = '<span class="label label-warning">In Active</span>';
                            active = '<a  data-toggle="tooltip" title="Make Active!" class="btn btn-xs mr-10" href="javascript:void(0);"  data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" onclick=Deviceversion(this,"' + emp.Version_Id + '","AC")><i class="fa fa-check-square-o mr-5" aria-hidden="true">Active</i></a>';
                            other_info = '<div class="col-md-12 padding0"><div class="disp_if"> ' + del + '<a href="#" class="dropdown-togglve btn btn-info-dots btn-xs" data-toggle="dropdown" aria-expanded="true"> <span class="fa fa-ellipsis-h" data-toggle="tooltip" data-placement="bottom" title="Other Options" style="color:black;" aria-hidden="true"></span><span class="sr-only">Options</span></a><div class="dropdown-menu info-dropdown" id=""> <div class="text-left">' + Restore + '</div><div class="text-left">' + Restore_As_New_Form + '</div><div class="text-left">' + Send + '</div><div class="text-left">' + active + '</div></div></div></div>';
                        }
                        else {
                            status = '<span class="label label-success">Active</span>';
                            active = '<a  data-toggle="tooltip" title="Make In Active!" class="btn btn-xs mr-10" href="javascript:void(0);"  data-id="SM_D1" data-type="role_rights_delete" data-nav="sp_delete" data-name="c_details_form" onclick=Deviceversion(this,"' + emp.Version_Id + '","IA")><i class="fa fa-minus-square-o mr-5" aria-hidden="true">In-Active</i></a>';
                            other_info = '<div class="col-md-12 padding0"><div class="disp_if">' + Print + ' ' + del + '<a href="#" class="dropdown-togglve btn btn-info-dots btn-xs" data-toggle="dropdown" aria-expanded="true"> <span class="fa fa-ellipsis-h" data-toggle="tooltip" data-placement="bottom" title="Other Options" style="color:black;" aria-hidden="true"></span><span class="sr-only">Options</span></a><div class="dropdown-menu info-dropdown" id=""> <div class="text-left">' + Restore + '</div><div class="text-left">' + Restore_As_New_Form + '</div><div class="text-left">' + Send + '</div><div class="text-left">' + active + '</div></div></div></div>';

                        }


                        tr = tr + '<tr' + j + '"></td><td>' + j + '</td><td>' + emp.Form_Name + '</td><td>' + emp.Version_No + '</td><td>' + status + '</td><td>' + emp.MappedPages + '</td><td>' + other_info + '</td></tr>';
                    });
                    $('#tbl_version_ip').html(tr);

                    datatable('view_old_version_table_ip', 'view_old_version_title_ip', 'Legal');

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

// Restore Version op vov

$('#restore_version').click(function () {
    debugger;
  
    Restore_op_vov($('#HVersionid').val(),"RS", $('#HFormId').val())
})

function Restore(event, Version_Id, indicatorid, form_id) {
    debugger;
    // Remove the "selected" class from all version rows
    $(".version_bg").removeClass("selected");

    // Add the "selected" class to the clicked version row
    $(event).addClass("selected");

    // Remove background color from all version rows
    $(".version_bg").css("background-color", "");

    // Add a visual indication (e.g., change background color) to the selected row
    $(".version_bg.selected").css("background-color", "lightgreen");

    $("#HVersionid").val(Version_Id)

}

function Restore_op_vov(Version_Id, indicatorid, form_id) {
    debugger;
    var status = "";

    if (indicatorid == 'RS') {
        status = "Restored Successfully";
    }

    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>", "Are You sure you Want to Restore ? ",
          {

              closeButton: true,
              progressBar: true,
              allowHtml: true,
              timeOut: 20000000,

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

                      var Delete = {
                          Dml_Indicator: indicatorid,
                          Version_Id: Version_Id,
                          Form_id: form_id
                      }

                      $.ajax({
                          async: true,
                          type: 'POST',
                          url: "/Form_builder/insert_update_deleteFormversion",
                          contentType: 'application/json; charset=UTF-8',
                          data: JSON.stringify(Delete),
                          success: function (data) {
                              debugger;
                              var data1 = JSON.parse(data);

                              toastr.success('Restored Successfully');

                              loaddata_version_op(form_id);
                              loaddata();

                          }
                      });
                  });
              }
          })

}

// restore ip vov

function Restore_ip_vov(event, Version_Id, indicatorid) {
    debugger;
    var status = "";

    if (indicatorid == 'RS') {
        status = "Restored Successfully";
    }

    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) {
                  $("#confirmationRevertYes").click(function () {

                      var Delete = {
                          Dml_Indicator: indicatorid,
                          Version_Id: Version_Id
                      }

                      $.ajax({
                          async: true,
                          type: 'POST',
                          url: "/Form_builder/insert_update_deleteFormversion",
                          contentType: 'application/json; charset=UTF-8',
                          data: JSON.stringify(Delete),
                          success: function (data) {
                              debugger;
                              var data1 = JSON.parse(data);

                              loaddata_version_ip();

                          }
                      });
                  });
              }
          })

}

// restore pat vov
function Restore_pat_vov(event, Version_Id, indicatorid) {
    debugger;
    var status = "";

    if (indicatorid == 'RS') {
        status = "Restored Successfully";
    }

    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) {
                  $("#confirmationRevertYes").click(function () {

                      var Delete = {
                          Dml_Indicator: indicatorid,
                          Version_Id: Version_Id
                      }

                      $.ajax({
                          async: true,
                          type: 'POST',
                          url: "/Form_builder/insert_update_deleteFormversion",
                          contentType: 'application/json; charset=UTF-8',
                          data: JSON.stringify(Delete),
                          success: function (data) {
                              debugger;
                              var data1 = JSON.parse(data);

                              loaddata_version_pat();

                          }
                      });
                  });
              }
          })

}

// restore sur vov
function Restore_sur_vov(event, Version_Id, indicatorid) {
    debugger;
    var status = "";

    if (indicatorid == 'RS') {
        status = "Restored Successfully";
    }

    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) {
                  $("#confirmationRevertYes").click(function () {

                      var Delete = {
                          Dml_Indicator: indicatorid,
                          Version_Id: Version_Id
                      }

                      $.ajax({
                          async: true,
                          type: 'POST',
                          url: "/Form_builder/insert_update_deleteFormversion",
                          contentType: 'application/json; charset=UTF-8',
                          data: JSON.stringify(Delete),
                          success: function (data) {
                              debugger;
                              var data1 = JSON.parse(data);

                              loaddata_version_sur();

                          }
                      });
                  });
              }
          })

}




