var url = params = new URLSearchParams(window.location.search);
var _menuid = '';
if (url.has('M')) {
    _menuid = url.get('M');
}

var selected_lang = localStorage.getItem(_Language);

$(document).ready(function() {
    
});
var btnupd = $('#btn_upd');
var btnsav = $('#btn_sav');
var imgload = $("#img_load");
var imgloadsav = $("#img_load");
var btnnew = $("#btn_new ");
var _Currency_ID = '0';
var _Currency_Name = '';
var _BankType_ID = '0';
var _BankType_Name = '';
var _Tax_ID = '0';
var _Tax_Name = '';
var _lmsid='';

//Pagination
var PageNo = 1;
var PageSize = 10;
var totalRecord = 0;
var PageLength = 0;
var Search = '';
let keyupTimer;
//Pagination
var ApiForm = '';

$(document).ready(function () {
    ApiForm = apiUrl + '/api/Admin/v1';
    imgload.hide();
    ComponentsDropdowns.init(); 
    $("#page-titleText").text(selected_lang=='Arabic' ?'مكافأة التلعيب' :"Gamification Reward");
    $("#course_list").hide();
    $("#gamification_list").hide();
});

function discon() {
    document.getElementById('create_form').reset();
    btnsav.hide();
    btnupd.hide();

    var txtid = $('#txt_id');
    var txtbktyp = $('#txt_bktyp');
    var txtcurrency = $('#txt_currency');
    var lmsuser = $("#txt_lmsuser").val("");
    var coursetraining = $("#txt_coursetraining").val("");
    var gamification = $("#txt_gamification").val("");

    $("#div_course").hide();
    $("#div_gamification").hide();
    txtid.html('');


    txtbktyp.val ('');
    txtbktyp.html('');

    // txtcurrencytxtbktyp.val ('');
    txtcurrency.html('');

    _Currency_ID = '0';
    _Currency_Name = '';
    _BankType_ID = '0';
    _BankType_Name = '';


    Onload();
    imgload.hide();
}
function Onload() {
    $('#Table_View').DataTable().clear().destroy();
    $.ajax({
        url: ApiForm + '/GamificationReward',
        type: "Get",
        contentType: "application/json",
        dataType: "json",
        beforeSend: function (xhr) {
            xhr.setRequestHeader("Authorization", "Bearer " + strkey);
            xhr.setRequestHeader("MenuId", _menuid);
            xhr.setRequestHeader("PageSize", PageSize);
            xhr.setRequestHeader("PageNo", PageNo);
            xhr.setRequestHeader("Language", selected_lang);
            xhr.setRequestHeader("Search", Search);
            imgload.show();
        },
        success: function (response) {

            if (response.statusCode == 200) {
                var action_button = ' ';
                //New
                if (response["data"]["newPermission"] == 'true') {
                    btnnew.show();
                }

                //Update

                if (Boolean(response["data"]["updatePermission"])) {
                    action_button += `<a href='#' class='modify_btn btn-edit' data-toggle='tooltip' title='Edit'>${selected_lang=='Arabic'?getArabic('Edit'):'Edit'}</a>`;
                }
                //Delete
                if (Boolean(response["data"]["deletePermission"])) {
                    action_button += ` | <a href='#' class='modify_btn btn-delete' data-toggle='tooltip' title='Delete'>${selected_lang=='Arabic'?getArabic('Delete'):'Delete'}</a>`;
-                }
-
-                if (response["data"] != null) {
-                    detailsTableBody = $("#Table_View").DataTable({
-                        data: response["data"]["gamificationrewardListViewModels"],
-                        destroy: true,
-                        retrieve: true,
-                        ordering: false,
-                        dom: 'lrt',
-                        "bLengthChange": false, 
-                        "language": {
-                            "url": selected_lang=='Arabic' && "/assets/rtl/dataTables_AR.json"
-                        },
-                        columns: [
-                            { data: 'lmsUserName_EN',
-                                render: function (data, type, row) {
-                                    if (action_button !== 'undefined' && action_button !== '') {
-                                        return data + "<div class='modify_row'>" + action_button + "</div>"
-                                    } else { return '-' }
-                                }
-                            },
-                            {
-                                data: 'courseTraningTitle_EN',
-                            },
-                            { data: 'gamificationTitle_EN' },
-                        ],
-                       // "order": [[1, "asc"]],
-                       "pageLength": PageSize,
-                    });
-                    imgload.hide();
-
-                    //ARSALAN'JS FOR DATA TABLES CONFIG
-                    //CUSTOM TOOLBAR OF DATA TABLE
-                    var buttons = new $.fn.dataTable.Buttons(detailsTableBody, {
-                        buttons: [
-                            // { extend: 'copy', className: 'btn btn-primary our-datatable-btns ' },
-                            {
-                                extend:    'pageLength',
-                                titleAttr: 'PAGE LENGTH',
-                                className: 'btn btn-primary our-datatable-btns out-dt-btn-for-pg-len',
-                            },
-                            {
-                                extend:    'excelHtml5',
-                                text:      '<i class="fa-regular fa-file-excel"></i>',
-                                titleAttr: 'Excel',
-                                className: 'btn btn-primary our-datatable-btns '
-                            },
-                            {
-                                extend:    'csvHtml5',
-                                text:      '<i class="fa-solid fa-file-csv"></i>',
-                                titleAttr: 'CSV',
-                                className: 'btn btn-primary our-datatable-btns '
-                            },
-                            // {
-                            //     extend:    'pdfHtml5',
-                            //     text:      '<i class="fa-regular fa-file-pdf"></i>',
-                            //     titleAttr: 'PDF',
-                            //     className: 'btn btn-primary our-datatable-btns '
-                            // },
-                            // {
-                            //     extend:    'print',
-                            //     text:      '<i class="fa-solid fa-print"></i>',
-                            //     titleAttr: 'PRINT',
-                            //     className: 'btn btn-primary our-datatable-btns '
-                            // },
-
-                        ]
-                    }).container().appendTo($('#buttons'));
-                    //SEARCHING WITH CUTOM FIELD
-
-                    //pagination
-                    paginate(totalRecord,PageSize,PageNo);
-
-                    $("#Table_View tbody tr").on('click',function(event) {
-                        $("#Table_View tbody tr").removeClass('our_row_selected');
-                        $(this).addClass('our_row_selected');
-                    });
-
-                    //to recalculate table on screen resize
-                    $(window).on("resize", function () {
-                        detailsTableBody.columns.adjust()
-                        detailsTableBody.responsive.recalc();
-                    })
-
-                }
-            }else if (response.statusCode == 404) {
-                imgload.hide();
-                $("#Table_View").DataTable({
-                    destroy: true,
-                    retrieve: true,
-                    ordering: false,
-                    dom: 'lrt',
-                    "bLengthChange": false, 
-                        "language": {
-                            "url": selected_lang=='Arabic' && "/assets/rtl/dataTables_AR.json"
-                        },
-                    "oLanguage": {
-                        "sEmptyTable": `<img class='dataTable-custom-empty-icon' src='/images/no-record-found.svg'><br>${_tbNoFound}`
-                    }
-                });
-            }
-
-        },
-        error: function (xhr, status, err) {
-            imgload.hide();
-            Swal.fire({
-                title: xhr.status.toString() + ' ' + err.toString(),
-
-                icon: 'warning',
-                showConfirmButton: true,
-
-                showClass: {
-                    popup: 'animated fadeInDown faster'
-                },
-                hideClass: {
-                    popup: 'animated fadeOutUp faster'
-                }
-
-            })
-        }
-    })
-
-
-    return true;
-
-}
-
-//pagination start
-$("#Table_View").DataTable().on('length',function(e,s,l){
-    PageSize = l;
-    PageNo = 1
-    Onload();
-});
-
-function paginate(totalRecord,PageSize,PageNo) {
-    var total_record  = totalRecord;
-    var page_length = PageSize;
-    var total_pages = Math.ceil(total_record / page_length);
-    var pagination = page_length<0?1:total_pages;
-    var current_page = PageNo;
-    let html ='';
-    $("table").after('');
-    if (pagination > 0) {
-        for (let i = 1; i <= pagination; i++) {
-            if (PageNo == i) {
-                html += `<li class="paginate_button page-item active">
-                    <a href="javascript:void(0)" aria-controls="Table_View" data-dt-idx="0" onclick="page_change(`+i+`)" tabindex="0" class="page-link">`+i+`</a>
-                </li>`;
-            }else{
-                html += `<li class="paginate_button page-item">
-                    <a href="javascript:void(0)" data-value="`+i+`" aria-controls="Table_View" onclick="page_change(`+i+`)" data-dt-idx="0" tabindex="0" class="page-link">`+i+`</a>
-                </li>`;
-            }
-        }
-    }else{
-        html += `<li class="paginate_button page-item">
-        <a href="javascript:void(0)" data-value="1" aria-controls="Table_View" onclick="page_change(1)" data-dt-idx="0" tabindex="0" class="page-link">1</a>
-        </li>`;
-    }
-
-    $("table").after(`<div class="dataTables_paginate paging_simple_numbers" id="Table_View_paginate">
-        <ul class="pagination">
-            <li class="paginate_button page-item previous `+(current_page-1 > 0 ? '' : 'disabled')+`" id="Table_View_previous">
-            <a href="javascript:void(0)" aria-controls="Table_View" onclick="page_change(`+(current_page-1)+`)" data-dt-idx="previous" tabindex="0" class="page-link ">${selected_lang=='Arabic'?getArabic('Previous'): 'Previous'}</a>
-            </li>
-            `+html+`
-            <li class="paginate_button page-item next `+(current_page == total_pages ? 'disabled' : '')+` `+(PageSize > totalRecord ? 'disabled' : '')+`" id="Table_View_next" >
-            <a href="javascript:void(0)" aria-controls="Table_View" onclick="page_change(`+(current_page+1)+`)" data-dt-idx="next" tabindex="0" class="page-link ">${selected_lang=='Arabic'?getArabic('Next'): 'Next'}</a>
-            </li>
-        </ul>
-    </div>`);
-}
-function page_change(page_num) {
-    PageNo = page_num;
-    Onload();
-}
-$(document).on('change',"#showRecord",function (e) {
-     
-    Onload();
-});
-$('#searchFieldForDatatable').on('keyup', function () {
-    clearTimeout(keyupTimer);
-    Search = this.value;
-    if(Search.length >= 3 || Search.length == 0){
-        keyupTimer = setTimeout(() => {
-             
-            Onload();
-        }, 1000);
-    }
-} );
-//pagination end
-
-$(document).on("click", '#btn_new', function () {
-    $('#data_Modal').modal('show');
-    $("#popup_title").html(selected_lang=='Arabic'?'إضافة تقنية التلعيب الجديدة' :"Add New Gamification");
-    discon();
-    btnupd.hide();
-    btnsav.show();
-    imgload.hide();
-    imgloadsav.hide();
-});
-
-//Save Record Start
-function savrec() {
-    var ck = ckvalidation();
-    var ckval = ck.ckval;
-    if (ckval == 1) { return; }
-    var _cre = JSON.stringify(ck.creteria);
-    Swal.fire({
-        title: _saveConfirmMsg,
-        icon: 'warning',
-        showCancelButton: true,
-        confirmButtonColor: '#a87e33',
-        cancelButtonColor: '#0c5439',
-        confirmButtonText: _save,
-cancelButtonText: _cancel,
-        showClass: {
-            popup: 'animated fadeInDown faster'
-        },
-        hideClass: {
-            popup: 'animated fadeOutUp faster'
-        }
-    }).then((result) => {
-        if (result.value) {
-            $.ajax({
-                url: ApiForm + '/GamificationReward',
-                type: "Post",
-                processData: false,
-                contentType: 'application/json',
-                dataType: "json",
-                data: _cre,
-                beforeSend: function (xhr) {
-                    xhr.setRequestHeader("Authorization", "Bearer " + strkey);
-                    xhr.setRequestHeader("MenuId", _menuid);
-                    imgload.show();
-                    imgloadsav.show();
-                    btnsav.hide();
-                },
-                success: function (response) {
-                    if (response.statusCode == 200) {
-                        imgload.hide();
-                        imgloadsav.hide();
-                        discon();
-                        btnsav.show();
-                        $('#data_Modal').modal('hide');
-                        Swal.fire({
-                            title: response.message,
-
-                            icon: 'success',
-                            showConfirmButton: true,
-
-                            showClass: {
-                                popup: 'animated fadeInDown faster'
-                            },
-                            hideClass: {
-                                popup: 'animated fadeOutUp faster'
-                            }
-
-                        })
-                    }
-                },
-                error: function (xhr, status, err) {
-                    imgload.hide();
-                    imgloadsav.hide();
-                    btnsav.show();
-                    Swal.fire({
-                        title: xhr.status.toString() + ' ' + err.toString(),
-
-                        icon: 'error',
-                        showConfirmButton: true,
-
-                        showClass: {
-                            popup: 'animated fadeInDown faster'
-                        },
-                        hideClass: {
-                            popup: 'animated fadeOutUp faster'
-                        }
-
-                    })
-                }
-            })
-
-        }
-    })
-
-}
-//Save End
-
-//Update Start
-function updrec() {
-    var ck = ckvalidation();
-    if (ck == 1) { return; }
-    var ckval = ck.ckval;
-    if (ckval == 1) { return; }
-    var _cre = JSON.stringify(ck.creteria);
-    Swal.fire({
-        title: _editConfirmMsg,
-        icon: 'warning',
-        showCancelButton: true,
-        confirmButtonColor: '#a87e33',
-        cancelButtonColor: '#0c5439',
-        confirmButtonText: selected_lang=='Arabic'?'تحديث':'Update',
-        showClass: {
-            popup: 'animated fadeInDown faster'
-        },
-        hideClass: {
-            popup: 'animated fadeOutUp faster'
-        }
-    }).then((result) => {
-        if (result.value) {
-            $.ajax({
-                url: ApiForm + '/GamificationReward',
-                type: "Put",
-                processData: false,
-                contentType: 'application/json',
-                dataType: "json",
-                data: _cre,
-                beforeSend: function (xhr) {
-                    xhr.setRequestHeader("Authorization", "Bearer " + strkey);
-                    xhr.setRequestHeader("MenuId", _menuid);
-                    imgload.show();
-                    imgloadsav.show();
-                    btnsav.hide();
-                    btnupd.hide();
-                },
-                success: function (response) {
-
-                    if (response.statusCode == 200) {
-                        imgloadsav.hide();
-                        discon();
-                        //btnsav.show();
-                        btnupd.show();
-                        $('#data_Modal').modal('hide');
-                        Swal.fire({
-                            title: response.message,
-
-                            icon: 'success',
-                            showConfirmButton: true,
-
-                            showClass: {
-                                popup: 'animated fadeInDown faster'
-                            },
-                            hideClass: {
-                                popup: 'animated fadeOutUp faster'
-                            }
-
-                        })
-                    }
-
-                },
-                error: function (xhr, status, err) {
-                    imgload.hide();
-                    imgloadsav.hide();
-                    btnupd.show();
-                    Swal.fire({
-                        title: xhr.status.toString() + ' ' + err.toString(),
-
-                        icon: 'error',
-                        showConfirmButton: true,
-
-                        showClass: {
-                            popup: 'animated fadeInDown faster'
-                        },
-                        hideClass: {
-                            popup: 'animated fadeOutUp faster'
-                        }
-
-                    })
-                }
-            })
-
-        }
-    })
-
-}
-//Update end
-
-$("#Table_View").DataTable().on('length',function(e,s,l){
-    PageSize = l
-    PageNo = 1
-    Onload();
-});
-
-function paginate(totalRecord,PageSize,PageNo) {
-    var total_record  = totalRecord;
-    var page_length = PageSize;
-    var total_pages = Math.ceil(total_record / page_length);
-    var pagination = page_length<0?1:total_pages;
-    var current_page = PageNo;
-    let html ='';
-    $("table").after('');
-    if (pagination > 0) {
-        for (let i = 1; i <= pagination; i++) {
-            if (PageNo == i) {
-                html += `<li class="paginate_button page-item active">
-                    <a href="javascript:void(0)" aria-controls="Table_View" data-dt-idx="0" onclick="page_change(`+i+`)" tabindex="0" class="page-link">`+i+`</a>
-                </li>`;
-            }else{
-                html += `<li class="paginate_button page-item">
-                    <a href="javascript:void(0)" data-value="`+i+`" aria-controls="Table_View" onclick="page_change(`+i+`)" data-dt-idx="0" tabindex="0" class="page-link">`+i+`</a>
-                </li>`;
-            }
-        }
-    }else{
-        if (PageNo == 1) {
-            html += `<li class="paginate_button page-item active">
-                <a href="javascript:void(0)" aria-controls="Table_View" data-dt-idx="0" onclick="page_change(1)" tabindex="0" class="page-link">1</a>
-            </li>`;
-        }else{
-            html += `<li class="paginate_button page-item">
-                <a href="javascript:void(0)" data-value="1" aria-controls="Table_View" onclick="page_change(1)" data-dt-idx="0" tabindex="0" class="page-link">1</a>
-            </li>`;
-        }
-    }
-    $("table").after(`<div class="dataTables_paginate paging_simple_numbers" id="Table_View_paginate">
-        <ul class="pagination">
-            <li class="paginate_button page-item previous `+(current_page-1 > 0 ? '' : 'disabled')+`" id="Table_View_previous">
-            <a href="javascript:void(0)" aria-controls="Table_View" onclick="page_change(`+(current_page-1)+`)" data-dt-idx="previous" tabindex="0" class="page-link">Previous</a>
-            </li>
-            `+html+`
-            <li class="paginate_button page-item next `+(current_page == total_pages ? 'disabled' : '')+` `+(PageSize > totalRecord ? 'disabled' : '')+`" id="Table_View_next" >
-            <a href="javascript:void(0)" aria-controls="Table_View" onclick="page_change(`+(current_page+1)+`)" data-dt-idx="next" tabindex="0" class="page-link">Next</a>
-            </li>
-        </ul>
-    </div>`);
-}
-
-function page_change(page_num) { 
-    PageNo = page_num;
-    Onload();
-}
-
-//Edit Start
-$('table').on('click', '.btn-edit', function (e) {
-    e.preventDefault();
-    $("#popup_title").html(selected_lang=='Arabic'?'تعديل التلعيب' :"Modify Gamification");
-    var currentRow = $(this).closest("tr");
-    var data = $('#Table_View').DataTable().row(currentRow).data();
-    var _id = data['id'];
-    var _name = data['lmsUserName_EN'];
-    var _type = data['type'];
-    if (_type == "S") {
-        Swal.fire({
-            title: _systemGeneratedMsg,
-            icon: 'warning',
-            showConfirmButton: true,
-            showClass: {
-                popup: 'animated fadeInDown faster'
-            },
-            hideClass: {
-                popup: 'animated fadeOutUp faster'
-            }
-
-        })
-        return;
-    }
-    $.ajax({
-        url: ApiForm + '/GamificationReward/GetGamificationRewardById',
-        type: "Get",
-        contentType: "application/json",
-        dataType: "json",
-        beforeSend: function (xhr) {
-            xhr.setRequestHeader("Authorization", "Bearer " + strkey);
-            xhr.setRequestHeader("MenuId", _menuid);
-            xhr.setRequestHeader("Id", _id);
-            imgload.hide();
-            imgloadsav.hide();
-            btnsav.hide();
-            btnupd.hide();
-        },
-
-        success: function (response) {
-            if (response.statusCode == 200) {
-
-                $('#data_Modal').modal('show'); 
-                $('#txt_id').html(response["data"]["id"]);
-
-                _LMSUSER_ID = response["data"]["lmsUserId"];
-                _LMSUSER_Name_EN = response["data"]["lmsUserName_EN"];
-                _LMSUSER_Name_AR = response["data"]["lmsUserName_AR"];
-                // $('#txt_lmsuser').val(_LMSUSER_ID);
-                // $('#txt_lmsuser').trigger("change");
-                var newOption = new Option(selected_lang=='Arabic'?(_LMSUSER_Name_AR?_LMSUSER_Name_AR:_LMSUSER_Name_EN):_LMSUSER_Name_EN,_LMSUSER_ID, false, false);
-                $('#txt_lmsuser').append(newOption).trigger('change');
-
-                _COURSE_RecordType = response["data"]["recordType"]
-                _COURSE_ID= response["data"]["courseTrainingId"];
-                _COURSE_Name_EN = response["data"]["courseTraningTitle_EN"];
-                _COURSE_Name_AR = response["data"]["courseTraningTitle_AR"];
-                // $('#txt_coursetraining').val(_COURSE_ID);
-                // $('#txt_coursetraining').trigger("change");
-                var newOption = new Option(selected_lang=='Arabic'?(_COURSE_Name_AR?_COURSE_Name_AR:_COURSE_Name_EN):_COURSE_Name_EN,_COURSE_ID, false, false);
-                $('#txt_coursetraining').append(newOption).trigger('change');
-                
-                _GAMIFICATION_ID = response["data"]["gamificationId"];
-                _GAMIFICATION_Name = response["data"]["gamificationTitle_EN"];
-                _GAMIFICATION_Name_AR = response["data"]["gamificationTitle_AR"];
-                // $('#txt_gamification').val(_GAMIFICATION_ID);
-                // $('#txt_gamification').trigger("change");
-                var newOption = new Option(selected_lang=='Arabic'?(_GAMIFICATION_Name_AR?_GAMIFICATION_Name_AR:_GAMIFICATION_Name):_GAMIFICATION_Name,_GAMIFICATION_ID, false, false);
-                $('#txt_gamification').append(newOption).trigger('change');
-                
-                imgload.hide();
-                imgloadsav.hide();
-                btnsav.hide();
-                btnupd.show();
-            }
-
-            else {
-                imgload.hide();
-                var _title = response.statusCode == 405 ? "Error # <a href='" + apiUrl_View + "/Configuration/Report/ErrorLog?I=" + response.message + "' target='_blank'>" + " " + response.message + "</a>" : response.message;
-                Swal.fire({
-
-                    title: _title,
-
-                    icon: 'warning',
-                    showConfirmButton: true,
-
-                    showClass: {
-                        popup: 'animated fadeInDown faster'
-                    },
-                    hideClass: {
-                        popup: 'animated fadeOutUp faster'
-                    }
-
-                })
-            }
-
-        },
-        error: function (xhr, status, err) {
-            imgload.hide();
-            imgloadsav.hide();
-            btnsav.show();
-            Swal.fire({
-                title: xhr.status.toString() + ' ' + err.toString(),
-
-                icon: 'error',
-                showConfirmButton: true,
-
-                showClass: {
-                    popup: 'animated fadeInDown faster'
-                },
-                hideClass: {
-                    popup: 'animated fadeOutUp faster'
-                }
-
-            })
-        }
-
-    })
-});
-
-//Delete Start
-$('table').on('click', '.btn-delete', function (e) {
-    e.preventDefault();
-    var currentRow = $(this).closest("tr");
-    var data = $('#Table_View').DataTable().row(currentRow).data();
-    console.log(data);
-    var _id = data['id'];
-    var _name = selected_lang == 'Arabic' ? data['lmsUserName_AR'] : data['lmsUserName_EN'];
-    var _type = data['type'];
-
-    if (_type == "S") {
-        Swal.fire({
-            title: _systemGeneratedMsg,
-            icon: 'warning',
-            showConfirmButton: true,
-            showClass: {
-                popup: 'animated fadeInDown faster'
-            },
-            hideClass: {
-                popup: 'animated fadeOutUp faster'
-            }
-
-        })
-        return;
-    }
-    Swal.fire({
-        title: _deleteConfirmMsg.replace('{name}',_name),
-        icon: 'warning',
-        showCancelButton: true,
-        confirmButtonColor: '#a87e33',
-        cancelButtonColor: '#0c5439',
-        confirmButtonText:  selected_lang=='Arabic'?'يمسح':'Delete',
-        showClass: {
-            popup: 'animated fadeInDown faster'
-        },
-        hideClass: {
-            popup: 'animated fadeOutUp faster'
-        }
-    }).then((result) => {
-        if (result.value) {
-            $.ajax({
-                url: ApiForm + '/GamificationReward' ,
-                type: "Delete",
-                contentType: "application/json",
-                dataType: "json",
-                beforeSend: function (xhr) {
-                    xhr.setRequestHeader("Authorization", "Bearer " + strkey);
-                    xhr.setRequestHeader("MenuId", _menuid);
-                    xhr.setRequestHeader("Id", _id);
-                    imgload.show();
-                },
-                success: function (response) {
-
-                    if (response.statusCode == 200) {
-                        imgload.hide();
-                        discon();
-                        Swal.fire({
-                            title: response.message,
-
-                            icon: 'success',
-                            showConfirmButton: true,
-
-                            showClass: {
-                                popup: 'animated fadeInDown faster'
-                            },
-                            hideClass: {
-                                popup: 'animated fadeOutUp faster'
-                            }
-
-                        })
-                    }
-                    else {
-                        imgload.hide();
-                        var _title = response.statusCode == 405 ? "Error # <a href='" + apiUrl_View + "/Configuration/Report/ErrorLog?I=" + response.message + "' target='_blank'>" + " " + response.message + "</a>" : response.message;
-                        Swal.fire({
-
-                            title: _title,
-
-                            icon: 'warning',
-                            showConfirmButton: true,
-
-                            showClass: {
-                                popup: 'animated fadeInDown faster'
-                            },
-                            hideClass: {
-                                popup: 'animated fadeOutUp faster'
-                            }
-
-                        })
-                    }
-
-                },
-                error: function (xhr, status, err) {
-                    imgload.hide();
-                    imgloadsav.hide();
-                    btnsav.show();
-                    Swal.fire({
-                        title: xhr.status.toString() + ' ' + err.toString(),
-
-                        icon: 'error',
-                        showConfirmButton: true,
-
-                        showClass: {
-                            popup: 'animated fadeInDown faster'
-                        },
-                        hideClass: {
-                            popup: 'animated fadeOutUp faster'
-                        }
-
-                    })
-                }
-            })
-        }
-    })
-});
-//Delete End
-
-_LMSUSER_ID = 0;
-_LMSUSER_Name_EN = '';
-_COURSE_ID= 0;
-_COURSE_Name_EN = '';
-_COURSE_RecordType = '';
-_GAMIFICATION_ID = 0;
-_GAMIFICATION_Name = '';
-
-//Select2 Start
-
-var ComponentsDropdowns = function () {
-    var handleSelect2 = function () {
-        FILLLMSUSER();
-    }
-    return {
-        //main function to initiate the module
-        init: function () {
-            handleSelect2();
-        }
-    };
-}();
-
-function FILLLMSUSER() {
-    $("#txt_lmsuser").select2({
-        placeholder: selected_lang=='Arabic'?'ابحث عن مستخدم LMS': "Search LMS User",
-        //  minimumInputLength: 1,
-        triggerChange: true,
-        allowClear: true,
-        width: '100%',
-        theme: 'bootstrap-5',
-        dropdownCssClass: "bigdrop font-smaller",
-        dropdownParent: $('#data_Modal'),
-        ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
-            ///api/Admin/v{version}/LMSLOVServices/GetCourseTrainingMasterCategory
-            url: ApiForm + '/LMSLOVServices/GetLMSUserRegisteredCourseTrainingAllLov',
-            type: "Get",
-            contentType: "application/json",
-            dataType: "json",
-            beforeSend : function (request) {
-                request.setRequestHeader("Authorization", 'Bearer ' + strkey);
-                // request.setRequestHeader("_id", $('#txt_cat').val());
-            },
-            data: function (params) {
-                return {
-                  _srch: params.term, // search term                            
-                  // page: page // page number
-                };
-              },
-              processResults: function (data) { // parse the results into the format expected by Select2.
-                // since we are using custom formatting functions we do not need to alter remote JSON data
-                var myResults = [];
-                if (data.statusCode != 200) {
-                    myResults.push({
-                        id: data.statusCode,
-                        text: data.message
-                    })
-                }
-                else {
-                    $.each(data.data, function (index, item) {
-                        myResults.push({
-                            id: item.id,
-                            text: selected_lang=='Arabic'?(item.name_AR?item.name_AR:item.name_EN):item.name_EN,
-                            //gstper: item.gstPer,
-                        })
-                    })
-
-                }
-            
-
-                return { results: myResults };
-            },
-
-            cache: true
-        },
-        initSelection: function (element, callback) {
-            var data = { "id": _LMSUSER_ID, "text": _LMSUSER_Name_EN };
-            callback(data);
-        },
-        escapeMarkup: function (m) {
-            return m;
-        } // we do not want to escape markup since we are displaying html in results
-
-    }).on("change",function (e) { 
-        _LMSUSER_ID = $(this).val();
-        if (_LMSUSER_ID != '') {
-            console.log("select: ",_LMSUSER_ID);
-            $('#txt_coursetraining').val(_LMSUSER_ID);
-            $('#txt_coursetraining').trigger('change');
-            FILLCOURSE();
-            $("#div_course").show();
-        }else{
-            console.log("Unselect: ",_LMSUSER_ID);
-            _LMSUSER_ID = '';
-            $('#txt_coursetraining').select2('val',_LMSUSER_ID);
-            $('#txt_coursetraining').trigger('change');
-            $("#div_course").hide();
-            FILLCOURSE();
-        }
-    })
-}
-function FILLCOURSE() {
-    $("#txt_coursetraining").select2({
-        placeholder: selected_lang=='Arabic'?'بحث في الدورة': "Search Course",
-        //  minimumInputLength: 1,
-        triggerChange: true,
-        allowClear: true,
-        width: '100%',
-        theme: 'bootstrap-5',
-        dropdownParent: $('#data_Modal'),
-        dropdownCssClass: "bigdrop font-smaller",
-        ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
-            url: ApiForm + '/LMSLOVServices/GetCourseTrainingByLMSUserIdLov',
-            type: "Get",
-            contentType: "application/json",
-            dataType: "json",
-            beforeSend : function (request) {
-                request.setRequestHeader("Authorization", 'Bearer ' + strkey);
-                request.setRequestHeader("_LMSUserId", _LMSUSER_ID);
-                // request.setRequestHeader("_id", $('#txt_cat').val());
-            },
-            data: function (params) {
-                return {
-                  _srch: params.term, // search term                            
-                  // page: page // page number
-                };
-              },
-              processResults: function (data) { // parse the results into the format expected by Select2.
-                // since we are using custom formatting functions we do not need to alter remote JSON data
-                var myResults = [];
-                if (data.statusCode != 200) {
-                    myResults.push({
-                        id: data.statusCode,
-                        text: data.message
-                    })
-                }
-                else {
-                    $.each(data.data, function (index, item) {
-                        myResults.push({
-                            id: item.id,
-                            text: selected_lang=='Arabic'?(item.name_AR?item.name_AR:item.name_EN):item.name_EN,
-                            recordtype: item.recordType,
-                            //gstper: item.gstPer,
-                        })
-                    })
-
-                }
-            
-                return { results: myResults };
-            },
-            cache: true
-        },
-        initSelection: function (element, callback) {
-            //,'recordtype':_COURSE_Record 
-            // ,"recordtype":_COURSE_RecordType
-            var data = { "id": _COURSE_ID, "text": _COURSE_Name_EN,'recordtype':_COURSE_RecordType};
-            callback(data);
-        },
-        dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
-        escapeMarkup: function (m) {
-            return m;
-        } // we do not want to escape markup since we are displaying html in results
-    }).on("change",function(e){
-        _COURSE_ID = $(this).val();
-        if (_COURSE_ID != '') {
-            _COURSE_RecordType = $(this).select2('data').recordtype;
-            $("#txt_gamification").val('');
-            $("#div_gamification").show();
-            FILLGAMIFICATION();
-        }else{
-            _COURSE_RecordType = '';
-            $("#txt_gamification").val(_COURSE_RecordType);
-            $("#div_gamification").hide();
-            FILLGAMIFICATION();
-        }
-    });
-}
-function FILLGAMIFICATION() {
-    $("#txt_gamification").select2({
-        placeholder: selected_lang=='Arabic'?'البحث في التلعيب': "Search Gamification",
-        //  minimumInputLength: 1,
-        triggerChange: true,
-        allowClear: true,
-        width: '100%',
-        theme: 'bootstrap-5',
-        dropdownParent: $('#data_Modal'),
-        ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
-            ///api/Admin/v{version}/LMSLOVServices/GetCourseTrainingMasterCategory
-            url: ApiForm + '/LMSLOVServices/GetGamificationByCourseTrainingRecordTypeLov',
-            type: "Get",
-            contentType: "application/json",
-            dataType: "json",
-            beforeSend : function (request) {
-                request.setRequestHeader("Authorization", 'Bearer ' + strkey);
-                request.setRequestHeader("_RecordType", _COURSE_RecordType);
-            },
-            data: function (params) {
-                return {
-                  _srch: params.term, // search term                            
-                  // page: page // page number
-                };
-            },
-            processResults: function (data) { // parse the results into the format expected by Select2.
-                // since we are using custom formatting functions we do not need to alter remote JSON data
-                var myResults = [];
-                if (data.statusCode != 200) {
-                    myResults.push({
-                        id: data.statusCode,
-                        text: data.message
-                    })
-                }
-                else {
-                    $.each(data.data, function (index, item) {
-                        myResults.push({
-                            id: item.id,
-                            text: selected_lang=='Arabic'?(item.name_AR?item.name_AR:item.name_EN):item.name_EN,
-                        })
-                    })
-                    $("#div_gamification").show();
-                }
-            
-
-                return { results: myResults };
-            },
-            cache: true
-        },
-        initSelection: function (element, callback) {
-            var data = { "id": _GAMIFICATION_ID, "text": _GAMIFICATION_Name };
-            callback(data);
-        },
-        escapeMarkup: function (m) {
-            return m;
-        } // we do not want to escape markup since we are displaying html in results
-
-    });
-}
-
-//Select2 End
-
-//Validation
-function ckvalidation() {
-    var ck = 0, _Error = '';
-    var txtid = $('#txt_id').html();
-    var lmsuser = $("#txt_lmsuser").val();
-    var coursetraining = $("#txt_coursetraining").val();
-    var gamification = $("#txt_gamification").val();
-    if (lmsuser == '') {
-        ck = 1;
-        _Error = selected_lang == 'Arabic' ? "الرجاء تحديد مستخدم LMS" : 'Please Select LMS User'; 
-    }else if (coursetraining == '') {
-        ck = 1;
-        _Error = selected_lang == 'Arabic' ? "يرجى تحديد الدورة التدريبية" : 'Please Select Course Training'; 
-    }else if (gamification == '') {
-        ck = 1;
-        _Error = selected_lang == 'Arabic' ? "الرجاء تحديد التلعيب" : 'Please Select Gamification'; 
-    }
-
-    if (Boolean(ck)) {
-        Swal.fire({
-            title: _Error,
-            icon: 'error'
-        })
-        return;
-    }
-    var data = {
-        "id":txtid,
-        "lmsUserId": lmsuser,
-        "courseTrainingId": coursetraining,
-        "gamificationId": gamification,
-    };
-    
-    return { ckval: ck, creteria: data };
-}
-
-
-
-//to convert into arabic number
-
-
-
-