jQuery(function ($) { // DOM ready and $ alias secured

                        $("a").removeClass("active");
                        $(".dashbord_class").addClass("active");
                        var table = $('#table1').DataTable({
                            "paging": false,
                            "scrollX": true,
							dom: 'Bfrtip',
							buttons: [
								'copy', 'csv', 'excel', 'pdf', 'print'
							]
                        });


                        $('#table1 tbody').on('click', 'tr', function () {
                            HoldOn.open({
                                theme: "sk-bounce",
                                message: "Please wait...."
                            });
                            var data = table.row(this).data();
                            if (data == undefined) {
                                return true;
                            }
                            $(".activity_input").val('');
                            $(".hr_input").val('1');

                            var empId = data[0];
                            loadData(empId);
                            $("#empId").val(data[0]);
                            $("#emp_mod_head").html(data[1]);
                            $("#update_model").modal();
                            HoldOn.close();

                        });

                        $('#activity1').on('input', function (e) {
                            Activity_Suggestions("activity1");
                        });
                        $('#activity2').on('input', function (e) {
                            Activity_Suggestions("activity2");
                        });
                        $('#activity3').on('input', function (e) {
                            Activity_Suggestions("activity3");
                        });
                        $('#activity4').on('input', function (e) {
                            Activity_Suggestions("activity4");
                        });
                        $('#activity5').on('input', function (e) {
                            Activity_Suggestions("activity5");
                        });
                        $('#activity6').on('input', function (e) {
                            Activity_Suggestions("activity6");
                        });
                        $('#activity7').on('input', function (e) {
                            Activity_Suggestions("activity7");
                        });
                        $('#activity8').on('input', function (e) {
                            Activity_Suggestions("activity8");
                        });




                    });


                    function Activity_Suggestions(input) {
                        var keyword = $("#" + input).val().trim();
                        if (keyword.length < 2) {
                            return true;
                        }
                        if (keyword == "" || keyword == null) {
                            return false;
                        }
                        $.ajax({
                            url: base_urlJs+"Public_Controller/Activity_Suggestions",
                            type: "post",
                            data: {Key: keyword},
                            success: function (data) {
                                var activityList = [];
                                var arr = JSON.parse(data);
//                    console.log(arr);
                                for (i = 0; i < arr.length; i++) {
//                        console.log(arr[i]['activity'])
                                    if (arr[i]['activity'] != "") {
                                        activityList.push(arr[i]['activity']);
                                    }
                                }
//            console.log(activityList);
//            autocomplete(document.getElementById("activity"), activityList);
                                $("#" + input).autocomplete({
                                    source: activityList
                                });
                            },
                            error: function (jqXhr) {
                                if (jqXhr.status == 400) { //Validation error or other reason for Bad Request 400
                                    var json = $.parseJSON(jqXhr.responseText);
                                    console.log(json);
                                }
                            }
                        });
                    }

                    function updateTime() {
                        HoldOn.open({
                            theme: "sk-bounce",
                            message: "Please wait...."
                        });
                        var empId = $("#empId").val();
                        var activityarr = $("input[name='activityArr[]']").map(function () {
                            return $(this).val().trim();
                        }).get();
                        var hourArr = $("input[name='hourArr[]']").map(function () {
                            return $(this).val().trim();
                        }).get();

                        var accArryNew = [];
                        var hourArrNew = []
                        for (i = 0; i < activityarr.length; i++) {
                            if (activityarr[i].trim() == "" || activityarr[i].trim() == null || hourArr[i].trim() == "" || hourArr[i].trim() == null) {
////                                HoldOn.close();
//                                toastsCall('bg-danger', 'Error', 'Please Complete 8 activities!');
//                                return false;
                            } else {
                                accArryNew.push(activityarr[i].trim());
                                hourArrNew.push(hourArr[i].trim());
                            }
                        }

                        if (accArryNew.length === 0 || hourArrNew.length === 0) {
                            HoldOn.close();
                            toastsCall('bg-danger', 'Error', 'Please add at least one activity!');
                            return false;
                        }

                        if (accArryNew.length !== hourArrNew.length) {
                            HoldOn.close();
                            toastsCall('bg-danger', 'Error', 'Internal server error!');
                            console.log(accArryNew);
                            console.log(hourArrNew);
                            return false;
                        }

                        var dataarr = {
                            'activityarr': accArryNew,
                            'empId': empId,
                            'hourArr': hourArrNew

                        };
                        $.ajax({
                            url: base_urlJs+"Supervisor_Contoller/addPrediction",
                            type: "post",
                            data: dataarr,
                            success: function (data) {
                                var st = JSON.parse(data);
                                HoldOn.close();
                                if (st == true) {
                                    toastsCall('bg-success', 'Success', 'Activities successfully Recorded !');
//
                                } else {
                                    HoldOn.close();
//                alert('Invalid Information');
                                    toastsCall('bg-danger', 'Error', 'Invalid Information !');
                                }

                            },
                            error: function (jqXhr) {
//            alert('Internal Server Error');
                                HoldOn.close();
                                toastsCall('bg-danger', 'Error', 'Internal Server Error!');
                            }
                        });

                        HoldOn.close();
                    }

                    function loadData(emp_id) {
                        $.ajax({
                            url: base_urlJs+"Supervisor_Contoller/loadPrediction",
                            type: "post",
                            data: {empId: emp_id},
                            success: function (data) {
                                var st = JSON.parse(data);
                                if (st.length) {
                                    for (x = 0; x < st.length; x++) {
                                        $("#activity" + (x + 1)).val(st[x]['activity']);
                                        $("#hour" + (x + 1)).val(st[x]['time']);
                                    }

                                }


                            },
                            error: function (jqXhr) {
                                toastsCall('bg-danger', 'Error', 'Internal Server Error!');
                            }
                        });
                    }
