$(document).ready(function () {

    var flag = 0;

    var selected_date = null;
    var selected_meeting = null;
    var search = false;
    var todays_date = new Date();
    calender_load(todays_date)

   

    function calender_load(load_date) {
        $('#calendar').fullCalendar('destroy');
        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaDay,listWeek'
            },
            defaultDate: load_date,
            selectable: true,
            selectHelper: true,
            editable: true,
            navLinks: false, // can click day/week names to navigate views
            eventLimit: true, // allow "more" link when too many events
            events: {
                url: 'get_events',
                error: function () {
                    $('#script-warning').show();
                }
            },
            loading: function (bool) {
                $('#loading').toggle(bool);
            },
            eventRender: function (event, el) {
                // render the timezone offset below the event title
                if (event.start.hasZone()) {
                    el.find('.fc-title').after(
                        $('<div class="tzo"/>').text(event.start.format('Z'))
                    );
                }
            },
            dayClick: function (date) {
                selected_date = date;
                setup_calender_data(date,'new')
                $('.data_value').show(500);
                $('#cal').hide(500);

            },
            eventMouseover: function(event, jsEvent, view) {

/*                popover({
                      animation:true,
                      delay: 300,
                      content: '<b>Inicio</b>:'+event.start+"<b>Fin</b>:"+event.end,
                      trigger: 'hover'
                  });*/
                    var start=event.start._i;
                    var end='';
                    if(event.end){
                        end=event.end._i;
                    }
                    $(this).popover({
                        html:true,
                        animation:true,
                        delay: 300,
                        title: event.title,
                        placement: 'bottom',
                        trigger: 'manual',
                        content: '<div class=""> Start Date :'+start+'</div><div class=""> End Date : '+end+'</div>',
                        container: '#calendar'
                    }).popover('show');
            },

            eventMouseout: function(event, jsEvent, view) {
                $(this).popover('hide');
            }
        });
    }
    
    
   $('#btn-agenda_reset').on('click',function(e){
       e.preventDefault()
       $('#agenda_id').val('');
       $('#agenda').val('');
   }) 
    
    
    
    
    $('#back_to_calender').on('click',function(e){
        e.preventDefault();
        $('.data_value').hide(500);
        $('#cal').show(500);
    })
    
    
    
    function setup_calender_data(date,action) {
        var callform=1;
        $('.page-loader-wrapper').fadeIn();

        empty_meeting_date(selected_date);
        
       if(action=='new'){
        $('#scheduled_btn').children('a').trigger("click");
       }
    
       if(action=='edit'){
         callform=3;
       }   
        
        var today = new Date();

        if (date <= today) {
            $('#new_meeting_btn').hide();
            $('#code-tab-2-2').removeClass('show');
            if (date == today)
                flag = 1;
            else
                flag = 2;
        } else {
             flag = 0;
            $('#new_meeting_btn').show();
        }


        var data1 = get_day_meetings('all', date, flag);
        var data2 = get_meetings_data(0,callform);

        if ((data1 == true) && (data2 == true)) {
             $('.page-loader-wrapper').fadeOut();
        }



        /*   $("#cal").load("#cal > *");*/
        /*        $('#cal').removeClass('col-md-8');
                 
                $('#cal').addClass('col-md-5');
                $('#cal').addClass('dynamic_height');*/


        $('td.fc-highlight').removeClass('fc-highlight');
        $(this).addClass('fc-highlight');

        
        $('#end_date').bootstrapMaterialDatePicker('setMinDate', selected_date);
        $('#start_date').bootstrapMaterialDatePicker('setMinDate', selected_date);

    }





                         

$('#step1').validate({
    rules: {
        start_date: {
            required: true,
        },
        start_time: {
            required: true,
        },
        end_date: {
            required: true,
        },
        end_time: {
            required: true,
        },
    },
    messages: {
        start_date: {
            required: "Start Date is mandatory",
        },
        start_time: {
            required: "Start Time is mandatory",
        },
        end_date: {
            required: "End Date is mandatory",
        },
        end_time: {
            required: "End Time is mandatory",
        }
        
    }
}); 
    
    
    
    
    
    

    /***************************    custom  ********************************/


    $('#new_meeting_btn').on('click', function (e) {
        e.preventDefault();
        $('.page-loader-wrapper').fadeIn();

        empty_meeting_date(selected_date);
        $('.page-loader-wrapper').fadeOut();
    })

    
    
    $('.add_participator').on('click', function (e) {
        e.preventDefault()
        get_district()
        get_designation(null)
        $('#block').empty();
        $('#unselect_user').empty();
        add_class_disable('add_m_participator')
        get_meeting_participator('add')
        checkbox1_reset()
        checkbox2_reset()
        
        $('.view_participator_list_data').hide();
        $('.edit_participator_list_data').show();
        
        
        $('#block').append('<option value="" disabled selected>===Select A Block===</option>');
        $('#participator_add_modal').modal({
            backdrop: 'static',
            keyboard: false
        })
    })

    
    
    $('#district').on('change', function (e) {
        e.preventDefault()
        if ($(this).val() == 'null') {
            get_designation('LEVEL-1')
            $('#block').empty();
            $('#block').append('<option value="" disabled selected>===Select A Block===</option>');
        } else {
            get_designation('LEVEL-2')
            get_block($(this).val())
        }


    })

    $('#block').on('change', function (e) {
        e.preventDefault()
        if ($(this).val() == 'null') {
            get_designation('LEVEL-2')
        } else {
            get_designation('LEVEL-3')
        }

    })

    $('#search_participant').on('click', function (e) {
        e.preventDefault();
        search = true;
        search_meeting_participator()
    })

    $('#add_m_participator').on('click', function (e) {
        e.preventDefault()
         $('.page-loader-wrapper').fadeIn();
        var participant = Array();
        $("input:checkbox[name=p_select]:checked").each(function () {
            participant.push($(this).val());
        });

        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            type: "POST",
            url: 'participator_add',
            data: {
                'participator': participant,
                'meeting_id': selected_meeting,
            },
            dataType: "json",
            success: function (data) {
                if (data.msgType = true) {
                    get_meeting_participator('add')
                    search_meeting_participator()
                    get_meetings_data(selected_meeting, 2)
                    add_class_disable('add_m_participator')

                } else {
                    toastr.error(data.msg)
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {
                $('.page-loader-wrapper').fadeOut();
            }
        });


    })

    $('#delete_m_participator').on('click', function (e) {
        e.preventDefault()
        /*$('.page-loader-wrapper').fadeIn();*/
        var participant = Array();
        $("input:checkbox[name=selected_participator]:checked").each(function () {
            participant.push($(this).val());
        });

        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            type: "POST",
            url: 'participator_delete',
            data: {
                'participator': participant,
                'meeting_id': selected_meeting,
            },
            dataType: "json",
            success: function (data) {
                if (data.msgType = true) {
                    get_meeting_participator('add')
                    get_meetings_data(selected_meeting, 2)
                    if (search)
                        search_meeting_participator()

                } else {
                    toastr.error(data.msg)
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {
                /*$('.page-loader-wrapper').fadeOut();*/
            }
        })

    })

    $('#select_all').change(function () {
        $(".p_select").prop('checked', $(this).prop('checked'));
        checkbox1_reset()

    });

    $('#select_selected_all').change(function () {
        $(".selected_participator").prop('checked', $(this).prop('checked'));
        checkbox2_reset()

    });



    function get_block(district) {

        $.ajax({
            type: "GET",
            url: 'get_block',
            data: {
                district: district
            },
            dataType: "json",
            success: function (data) {
                $('#block').empty();
                if (data.msgType == true) {
                    $('#block').append('<option value="" disabled selected>===Select A Block===</option>');
                    $('#block').append('<option value="null">No Block</option>');
                    $('#block').append('<option value="0">All Block</option>');
                    $.each(data.data, function (key, value) {
                        $('#block').append('<option value="' + value.block_id + '">' + value.block_name + '</option>');
                    })
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {

            }
        });
        return true;
    }

    function get_district() {

        $.ajax({
            type: "GET",
            url: 'get_district',
            data: {},
            dataType: "json",
            success: function (data) {
                $('#district').empty();
                if (data.msgType == true) {
                    $('#district').append('<option value="" disabled selected>===Select A District===</option>');
                    $('#district').append('<option value="null">No District</option>');
                    $('#district').append('<option value="0">All District</option>');
                    $.each(data.data, function (key, value) {
                        $('#district').append('<option value="' + value.district_code + '">' + value.district_name + '</option>');
                    })
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {

            }
        });
        return true;
    }

    function get_designation(level) {

        $.ajax({
            type: "GET",
            url: 'get_designation',
            data: {
                level: level
            },
            dataType: "json",
            success: function (data) {
                $('#designation').empty();
                if (data.msgType == true) {
                    $('#designation').append('<option value="" disabled selected>===Select A Designation===</option>');
                    $.each(data.data, function (key, value) {
                        $('#designation').append('<option value="' + value.designation_code + '">' + value.designation_name + '</option>');
                    })
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {

            }
        });
        return true;
    }

    function get_meeting_participator(flag) {

        $.ajax({
            type: "GET",
            url: 'get_meeting_participator',
            data: {
                meeting_id: selected_meeting
            },
            dataType: "json",
            success: function (data) {
                if (data.msgType == true) {
                    $('#selected_user').empty();
                    $.each(data.data, function (key, value) {
                        $('#selected_user').append(
                            '<div class="row">' +
                            '<div class="col-md-1">' +
                            '<input type="checkbox" name="selected_participator" class="selected_participator" value="' + value.employee_code + '">' +
                            '</div>' +
                            '<div class="col-md-5">' + value.name +
                            '</div>' +
                            '<div class="col-md-6">' + value.employee_code +
                            '</div>' +
                            '</div>');
                    })
                    bind_participator_list_modal(data.data)
                    
                    load_dynamically3()
                    checkbox2_reset()
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {

            }
        });
        return true;
    }

    function search_meeting_participator() {
        var district = $('#district').val()
        var block = $('#block').val()
        var designation = $('#designation').val()
        $.ajax({
            type: "GET",
            url: 'get_user_list',
            data: {
                district: district,
                block: block,
                designation: designation,
                meeting_id: selected_meeting
            },
            dataType: "json",
            success: function (data) {
                if (data.msgType == true) {
                    $('#unselect_user').empty();
                    if (data.data.length > 0) {
                        $.each(data.data, function (key, value) {
                            $('#unselect_user').append(
                                '<div class="row">' +
                                '<div class="col-md-1">' +
                                '<input type="checkbox" name="p_select" class="p_select" value="' + value.employee_code + '">' +
                                '</div>' +
                                '<div class="col-md-5">' + value.name +
                                '</div>' +
                                '<div class="col-md-6">' + value.employee_code +
                                '</div>' +
                                '</div>');
                        })
                        load_dynamically2();
                        checkbox1_reset()
                        /*remove_class_disable('add_m_participator')*/
                    } else {
                        $('#unselect_user').append(
                            '<div class="row">' +
                            '<div class="col-md-12 text-center">' +
                            'No Employee Found' +
                            '</div>');
                    }

                } else {
                    toastr.error(data.msg);
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {

            }
        });
    }

    function get_day_meetings(meeting_type, meeting_date, flag) {
        var date_data = meeting_date.format('YYYY-MM-DD')
        $.ajax({
            type: "GET",
            url: 'get_events_by_date',
            data: {
                meeting_type: meeting_type,
                meeting_date: date_data
            },
            dataType: "json",
            success: function (data) {
                $('#meeting_data').empty();
                $('#meeting_data_cancel').empty();
                $('#meeting_data_drafts').empty();
                if (data.msgType == true) {
                    var flag_sc = 0;
                    var flag_can = 0;
                    var flag_dr = 0;
                    var i_s = 0;
                    var i_c = 0;
                    var i_d = 0;
                    $.each(data.data, function (key, value) {

                        if ((value.status == 1) || (value.status == 2)) {
                            i_s += 1;
                            flag_sc = 1;
                            var dy_btn = '';
                            if (flag == 0) {
                                dy_btn = '<a href="" class="btn btn-primary btn-xs step_action" data-action="edit" data-m_id="' + value.id + '"  data-toggle="tooltip" data-placement="top" title="Edit"><i class="fa fa-edit fa-2x" aria-hidden="true"></i></a><a href="" class="btn btn-danger btn-xs  step_action" data-action="cancel" data-m_id="'+value.id+'" data-toggle="tooltip" data-placement="top" title="Cancel"><i class="fa fa-close fa-2x" aria-hidden="true"></i></a>';

                            }
                            
                            if (flag == 1) {
                                dy_btn = '<a href="" class="btn btn-danger btn-xs  step_action" data-action="cancel" data-m_id="'+value.id+'" data-toggle="tooltip" data-placement="top" title="Cancel"><i class="fa fa-close fa-2x" aria-hidden="true"></i></a>';

                            }

                            /*                  '<a href="" class="badge badge-pill red step_action" data-action="cancel" data-m_id="'+value.id+'" data-toggle="tooltip" data-placement="top" title="Cancel"><i class="fa fa-close fa-2x" aria-hidden="true"></i></a>'*/

                            $('#meeting_data').append('<tr>' +
                                '<td class="pt-3-half" >' + i_s + '</td>' +
                                '<td class="pt-3-half" >' + value.title + '</td>' +
                                '<td class="pt-3-half" >' + value.start_date + ((value.start_time) ? ' ' + value.start_time : '') + '</td>' +
                                '<td style="display:flex;">'+ 
                                '<a href="" class="btn btn-info btn-xs step_action" data-action="view" data-m_id="' + value.id + '" data-toggle="tooltip" data-placement="top" title="View"><i class="fa fa-eye fa-2x" aria-hidden="true"></i></a>' +dy_btn +
                               
                                '</td>' +
                                '</tr>');
                        } else if (value.status == 3) {
                            i_c += 1;
                            flag_can = 1;
                            var dy_btn = '';
                            if (flag == 0) {
                                /*                          dy_btn='<a href="" class="badge badge-pill red step_action" data-action="cancel" data-m_id="'+value.id+'" data-toggle="tooltip" data-placement="top" title="Cancel"><i class="fa fa-close fa-2x" aria-hidden="true"></i></a>';*/

                            }




                            $('#meeting_data_cancel').append('<tr>' +
                                '<td class="pt-3-half" >' + i_c + '</td>' +
                                '<td class="pt-3-half" >' + value.title + '</td>' +
                                '<td class="pt-3-half" >' + value.start_date + ((value.start_time) ? ' ' + value.start_time : '') + '</td>' +
                                '<td style="display:flex;">' + dy_btn +
                                '<a href="" class="btn btn-info btn-xs step_action" data-action="view" data-m_id="' + value.id + '" data-toggle="tooltip" data-placement="top" title="View"><i class="fa fa-eye fa-2x" aria-hidden="true"></i></a><a href="" class="btn btn-primary btn-xs step_action" data-action="edit" data-m_id="' + value.id + '" data-toggle="tooltip" data-placement="top" title="Edit"><i class="fa fa-edit fa-2x" aria-hidden="true"></i></a>' +

                                '</td>' +
                                '</tr>');

                        } else {
                            i_d += 1;
                            flag_dr = 1;
                            $('#meeting_data_drafts').append('<tr>' +
                                '<td class="pt-3-half" >' + i_d + '</td>' +
                                '<td class="pt-3-half" >' + value.title + '</td>' +
                                '<td class="pt-3-half" >' + value.start_date + ((value.start_time) ? ' ' + value.start_time : '') + '</td>' +
                                '<td style="display:flex;">' +
                                '<a href="" class="btn btn-info btn-xs step_action" data-action="view" data-m_id="' + value.id + '" data-toggle="tooltip" data-placement="top" title="View"><i class="fa fa-eye fa-2x" aria-hidden="true"></i></a><a href="" class="btn btn-primary btn-xs step_action" data-action="edit" data-m_id="' + value.id + '" data-toggle="tooltip" data-placement="top" title="Edit"><i class="fa fa-edit fa-2x" aria-hidden="true"></i></a><a href="" class="btn btn-danger btn-xs step_action" data-action="delete" data-m_id="' + value.id + '" data-toggle="tooltip" data-placement="top" title="Delete"><i class="fa fa-close fa-2x" aria-hidden="true"></i></a>' +

                                '</td>' +
                                '</tr>');

                        }



                    });
                    if (flag_sc == 0) {
                        $('#meeting_data').append('<tr class="text-center">' +
                            '<td class="pt-3-half" >No Meeting Scheduled on ' + date_data + '.</td>' +
                            '</tr>');
                    }

                    if (flag_can == 0) {
                        $('#meeting_data_cancel').append('<tr class="text-center">' +
                            '<td class="pt-3-half" >No Meeting Canceled on ' + date_data + '.</td>' +
                            '</tr>');
                    }

                    if (flag_dr == 0) {
                        $('#meeting_data_drafts').append('<tr class="text-center">' +
                            '<td class="pt-3-half" >No Meeting on Drafts on ' + date_data + '.</td>' +
                            '</tr>');
                    }

                    load_dynimically();
                } else {
                    $('#meeting_data').append('<tr class="text-center">' +
                        '<td class="pt-3-half" >No Meeting Scheduled on ' + date_data + '.</td>' +
                        '</tr>');
                    $('#meeting_data_cancel').append('<tr class="text-center">' +
                        '<td class="pt-3-half" >No Meeting Canceled on ' + date_data + '.</td>' +
                        '</tr>');
                    $('#meeting_data_drafts').append('<tr class="text-center">' +
                        '<td class="pt-3-half" >No Meeting on Drafts on ' + date_data + '.</td>' +
                        '</tr>');
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {

            }
        });

        return true;

    }

    function get_meetings_data(meeting_id, call_form) {
        $.ajax({
            type: "GET",
            url: 'get_meetings_data',
            data: {
                meeting_id: meeting_id
            },
            dataType: "json",
            success: function (data) {
                if (data.msgType == true) {
                    if (data.data.meeting_type.length > 0) {

                        if (call_form !=3) {
                          $('#meeting_type').empty();
                          $('#meeting_type').append('<option value="" disabled selected>-- Please select --</option>');
                          $.each(data.data.meeting_type, function (key, value) {
                             $('#meeting_type').append('<option value="' + value.id + '">' + value.name + '</option>');
                          });
                        }
                        if (call_form == 2) {
                            bind_meeting_date(data.data.meeting_data, data.data.agendas, 0, data.data.participator)
                        }
                    }

                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {

            }
        });

        return true;

    }

    function empty_meeting_date(date) {


        remove_class_disable('st_1')
        add_class_disable('st_2')
        add_class_disable('st_3')
        add_class_disable('st_4')

        $('#st_1').trigger("click");


        $('.meeting_id').val('');
        $('#meeting_type').val('');
        $('#title').val('');
        $('#venue').val('');
        $('#start_date').val('');
        $('#start_time').val('');
        $('#end_date').val('');
        $('#end_time').val('');

        $('#start_date').val(date.format('DD-MM-YYYY'));
        $('#end_date').val(date.format('DD-MM-YYYY'));
        empty_agenda_form()
    }

    function empty_agenda_form() {
        $('#agenda_id').val('');
        $('#agenda').val('');
        return true;
    }
    
    function empty_sub_agenda_form() {
        $('#display_main_agenda').empty();
        $('#sub_agenda_id').val('');
        $('#agenda_sub').val('');
        return true;
    }

    function empty_view_modal_data() {
        $('#title_d').empty();
        $('.start_date_d').empty();
        $('.start_time_d').empty();
        $('.end_time_d').empty();
        $('#end_date_d').empty();
        $('#m_type_d').empty();
        $('#agenda_d').empty();
        $('#m_venue').empty();
        $('#member_d').empty();
    }

    function bind_view_modal_data(data, agenda, participator,mm_id) {

        var start = moment(data.start_date).format('DD-MM-YYYY');
        var end = moment(data.end_date).format('DD-MM-YYYY');
        
        var start_time = moment(data.start_time, 'HH:mm:ss').format('hh:mm A')
        var end_time = moment(data.end_time, 'HH:mm:ss').format('hh:mm A')

        $('#title_d').append(data.title)
        $('.start_date_d').append(start)
        $('.start_time_d').append(start_time)
        $('.end_time_d').append(end_time)
        $('#end_date_d').append(end)
        $('#m_type_d').append(data.name)
        $('#m_venue').append(data.venue);
        
        var mm_show='';
        var mm_selected='';
        
        if (agenda.length > 0) {
/*            $.each(agenda, function (key, value) {
                $('#agenda_d').append('<li><p style="margin-bottom: .2rem;">' + value.name + '</p></li>');
            })*/
            
/*            $.each(agenda, function (key, value) {
                    var sub_agendas='';
                    if(value.sub_agenda){
                        if(value.sub_agenda.length>0){
                            var sub_list='';
                            $.each(value.sub_agenda,function(k,v){
                                sub_list=sub_list+'<li class="li_style_view">'+
                                                      '<div class="row">'+
                                                         '<div class="col-md-12">' + v.name +'</div>'+
                                                      '</div>'+
                                                   '</li>';
                            });

                        sub_agendas='<ol type="i" id="collapse'+value.agendas.id+'" class=" collapse show" data-parent="#agenda_accordion" >'+sub_list+'</ol>';
                        }
                        
                    }
                    $('#agenda_d').append('<li class="li_style_view collapsed" data-toggle="collapse" href="#collapse'+value.agendas.id+'"><div class="row"><div class="col-md-12"><span class="ml5"> ' + value.agendas.name + '</span></div>' +
                    '</div></li>'+sub_agendas+'<hr>');
                })*/
            
              $.each(agenda, function (key, value) {
                    var sub_agendas='';
                   /* if(value.sub_agenda){*/
                    if(value.sub_agenda.length>0){
                            var sub_list='';
                             
                            $.each(value.sub_agenda,function(k,v){
                                var sub_mm_agendas='';
                                if(v.meeting_minute.length>0){
                                      var sub_list_mm='';
                                      $.each(v.meeting_minute,function(k,vi){
                                         if(mm_id==vi.id){
                                            mm_show='show'; 
                                            mm_selected='mm_selected';
                                         }
                                         sub_list_mm=sub_list_mm+'<li class="li_style_view '+mm_selected+'">'+
                                                              '<div class="row">'+
                                                                 '<div class="col-md-6">' + (vi.description?vi.description:'') +'</div>'+
                                                                 '<div class="col-md-4">' + (vi.c_person?vi.c_person:'') +'</div>'+
                                                                 '<div class="col-md-2">' + (vi.resolution_date?moment(vi.resolution_date).format('DD-MM-YYYY'):'') +'</div>'+
                                                              '</div>'+
                                                           '</li>';
                                          
                                        mm_selected=''; 
                                    });  
                                    
                                    
                                    sub_mm_agendas='<ul id="mm_collapse'+v.agendas.id+'" class=" collapse '+mm_show+' main_agenda_style" data-parent="collapse'+value.agendas.id+'" >'+sub_list_mm+'</ul>';
                                    mm_show='';
                                    
                                }
                                
                                /*else{
                                    sub_list=sub_list+'<li class="li_style_view">'+
                                                      '<div class="row">'+
                                                         '<div class="col-md-12">' + v.agendas.name +'</div>'+
                                                      '</div>'+
                                                   '</li>';
                                    
                                    
                                }*/
                                 sub_list=sub_list+'<li class="li_style_view collapsed" data-toggle="collapse" href="#mm_collapse'+v.agendas.id+'">'+
                                                      '<div class="row">'+
                                                         '<div class="col-md-12"><i class="fa fa-angle-right" aria-hidden="true"></i> ' + v.agendas.name +'</div>'+
                                                      '</div>'+
                                                   '</li>'+sub_mm_agendas;
                                
                            });

                        sub_agendas='<ol type="i" id="collapse'+value.agendas.id+'" class=" collapse show" data-parent="#agenda_d" >'+sub_list+'</ol>';
                        /*}*/
                        
                    }else if(value.meeting_minute){
                        if(value.meeting_minute.length>0){
                            var sub_list='';
                            $.each(value.meeting_minute,function(k,v){
                                if(mm_id==v.id){
                                   mm_show='show';
                                   mm_selected='mm_selected';
                                }
                                sub_list=sub_list+'<li class="li_style_view '+mm_selected+'">'+
                                                      '<div class="row">'+
                                                         '<div class="col-md-6">' + (v.description?v.description:'') +'</div>'+
                                                         '<div class="col-md-4">' + (v.c_person?v.c_person:'') +'</div>'+
                                                         '<div class="col-md-2">' + (v.resolution_date?moment(v.resolution_date).format('DD-MM-YYYY'):'') +'</div>'+
                                                      '</div>'+
                                                   '</li>';
                                 mm_selected=''; 
                            });

                        sub_agendas='<ul id="collapse'+value.agendas.id+'" class=" collapse '+mm_show+'  main_agenda_style" data-parent="#agenda_d" >'+sub_list+'</ul>';
                        mm_show=''; 
                        }
                        
                    }
                  
                  
                    $('#agenda_d').append('<li class="li_style_view collapsed" data-toggle="collapse" href="#collapse'+value.agendas.id+'"><div class="row"><div class="col-md-12"> <i class="fa fa-angle-right" aria-hidden="true"></i> <span class="ml5"> ' + value.agendas.name + '</span></div>' +
                    '</div></li>'+sub_agendas+'<hr>');
                })          
            
            
            
        } else {
            $('#agenda_d').append('<p style="margin-bottom: .2rem;">No Agenda Added.</p>');
        }
        if (participator.length > 0) {
            $('#member_d').append();
        } else {
            $('#member_d').append('<p style="margin-bottom: .2rem;"> No Participator Added. </p>');
        }



        if (data.start_date != data.end_date) {
            $('.diff_day').show();
            $('.same_day').hide();
        } else {
            $('.same_day').show();
            $('.diff_day').hide();
        }
        

        bind_participator_list_modal(participator)
    }
    
    
    
    
    function bind_participator_list_modal(data){
        $('#total_participant').empty();
        if(data.length==0){
            $('#total_participant').append(0);
        }else{
            $('#total_participant').append(data.length);
        }
        
        if ( $.fn.DataTable.isDataTable('#p_data_table') ) {
							$('#p_data_table').DataTable().destroy();
        }
        $('#p_list_data').empty()
        if(data.length>0){
            var i=1;
            $.each(data,function(key,value){
               $('#p_list_data').append('<tr>'+
                                        '<th scope="row">'+i+'</th>'+
                                        '<td>'+value.name+'</td>'+
                                        '<td>'+value.employee_code+'</td>'+
                                        '<td>'+value.designation_name+'</td>'+
                                        '<td>'+value.level_name+'</td>'+
                                    '</tr>'); 
                i +=1;
            })
        }
    
        $('#p_data_table').dataTable( );
        
    }
    
    
    
    
    
    
    
    
    
   $('.view_participator').on('click',function(e){
       e.preventDefault()
        $('.view_participator_list_data').show();
        $('.edit_participator_list_data').hide();
        $('#participator_add_modal').modal({
            backdrop: 'static',
            keyboard: false
        })
       /*$('#participator_view_model').modal('show');*/
   }) 
    
    
    

    function load_dynimically() {
        $('.step_action').on('click', function (e) {
            e.preventDefault()
            var action = $(this).data('action');
            var meeting_id = $(this).data('m_id');
            var mm_id=0
            if($(this).data('mm_id'))
              mm_id=$(this).data('mm_id');
            
            
             
            if ((action != "delete") && (action != "cancel")){
                $('.page-loader-wrapper').fadeIn();
                $.ajax({
                    type: "GET",
                    url: 'get_meetings_data',
                    data: {
                        meeting_id: meeting_id
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.msgType == true) {

                            if (data.data.meeting_data) {
                                if (action == "edit") {

                                    bind_meeting_date(data.data.meeting_data, data.data.agendas, 0, data.data.participator)
                                    $('#update_meeting_btn').children('a').trigger("click");

                                } else {
                                    $('.page-loader-wrapper').fadeOut();
                                    selected_meeting=meeting_id;
                                    empty_view_modal_data();
                                    var participator = [];
                                    $('#send_notification').data('meeting_id',meeting_id)
                                    bind_view_modal_data(data.data.meeting_data, data.data.agendas, data.data.participator,mm_id)
                                    $('#meeting_info_modal').modal('show');
                                }
                            }

                        }

                    },
                    error: function (jqXHR, textStatus, errorThrown) {

                        callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                    },
                    complete: function (data) {
                        $('.page-loader-wrapper').fadeOut();
                    }
                });
            } else if(action=="delete") {
                swal({
                    title: 'Are you sure? Want to Delete?',
                    text: "You won't be able to revert this!",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes'
                }).then((result) => {
                    if (result.value) {
                        $('.page-loader-wrapper').fadeIn();
                        $.ajax({
                            type: "GET",
                            url: 'delete_meetings_data',
                            data: {
                                meeting_id: meeting_id
                            },
                            dataType: "json",
                            success: function (data) {
                                if (data.msgType == true) {
                                    get_day_meetings('all', selected_date, flag);
                                    toastr.success(data.msg)
                                } else {
                                    toastr.error(data.msg)
                                }

                            },
                            error: function (jqXHR, textStatus, errorThrown) {

                                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                            },
                            complete: function (data) {
                                $('.page-loader-wrapper').fadeOut();
                            }
                        });
                    }
                })
            }else{
                swal({
                    title: 'Are You Sure?',
                    text: "You want to cancel this meeting!",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes'
                }).then((result) => {
                    if (result.value) {
                        $('.page-loader-wrapper').fadeIn();

                        $.ajax({
                            type: "GET",
                            url: 'cancel_meeting',
                            data: {
                                meeting_id: meeting_id
                            },
                            dataType: "json",
                            success: function (data) {
                                if (data.msgType == true) {
                                    get_day_meetings('all', selected_date, flag);
                                    calender_load(todays_date)
                                    toastr.success(data.msg)
                                } else {
                                    toastr.error(data.msg)
                                }

                            },
                            error: function (jqXHR, textStatus, errorThrown) {

                                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                            },
                            complete: function (data) {
                                $('.page-loader-wrapper').fadeOut();
                            }
                        });
                    }
                })
                
            }

        })


    }

    function load_dynimically1() {



        $('.agenda_action').on('click', function (e) {
            e.preventDefault()

            var action = $(this).data('action');
            var agenda_id = $(this).data('m_id');
            if (action != "delete") {
                $('.page-loader-wrapper').fadeIn();
                $.ajax({
                    type: "GET",
                    url: 'get_agenda_data',
                    data: {
                        agenda_id: agenda_id
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.msgType == true) {

                            if (data.data) {

                                if (action == "edit") {
                                    $('#agenda_id').val(data.data.id);
                                    $('#agenda').val(data.data.name);
                                } else {

                                }
                            }

                        } else {
                            toastr.error(data.msg)
                        }

                    },
                    error: function (jqXHR, textStatus, errorThrown) {

                        callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                    },
                    complete: function (data) {
                        $('.page-loader-wrapper').fadeOut();
                    }
                });
            } else {
                swal({
                    title: 'Are you sure?Want to Delete?',
                    text: "You won't be able to revert this!",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes'
                }).then((result) => {
                    if (result.value) {
                        $('.page-loader-wrapper').fadeIn();
                        $.ajax({
                            type: "GET",
                            url: 'delete_meetings_agenda',
                            data: {
                                agenda_id: agenda_id
                            },
                            dataType: "json",
                            success: function (data) {
                                if (data.msgType == true) {
                                    bind_meeting_date(data.data.meeting, data.data.agendas, 3, data.data.participator)
                                    toastr.success(data.msg)
                                } else {
                                    toastr.error(data.msg)
                                }

                            },
                            error: function (jqXHR, textStatus, errorThrown) {

                                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                            },
                            complete: function (data) {
                                $('.page-loader-wrapper').fadeOut();
                            }
                        });
                    }
                })
            }

        })
        
        
        
        $('.add_sub_agenda_btn').on('click',function(e){
            e.preventDefault()
            var action = $(this).data('action');
            var agenda_id = $(this).data('m_id');
            var agenda=$(this).data('agenda')
            

            $('#display_main_agenda').append(agenda)
            $('#sub_agenda_id').val('');
            $('#agenda_sub').val('');          
            $('#sub_agenda_id').val(agenda_id);
            $('#add_sub_agenda_modal').modal('show');
            
        })

    }
    
    $('#sub_agenda_form').on('submit',function(e){
        e.preventDefault()
        var sub_agenda_id=$('#sub_agenda_id').val();
        var agenda_level=$('#agenda_level').val();
        var agenda_sub=$('#agenda_sub').val();
        
        
        var meeting_id = $('.meeting_id').val();
         if(agenda_sub){
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                type: "POST",
                url: 'meeting_agenda_save',
                data: {
                    'agenda': agenda_sub,
                    'meeting_id': meeting_id,
                    'agenda_id': sub_agenda_id,
                    'level': agenda_level,
                },
                dataType: "json",
                success: function (data) {
                    if (data.msgType == true) {
                        empty_sub_agenda_form()

                        bind_meeting_date(data.data.meeting, data.data.agendas, 3, data.data.participator)
                        $('#add_sub_agenda_modal').modal('hide');
                    } else {
                        toastr.error(data.msg)
                    }

                },
                error: function (jqXHR, textStatus, errorThrown) {

                    callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                },
                complete: function (data) {

                }
            });
         }else{
            toastr.error('Please Enter Agenda.') 
         }
        
    })
    

    function load_dynamically2() {
        $('input.p_select').change(function () {
            checkbox1_reset()
        });
    }

    function checkbox1_reset() {

        /*                  if($('.p_select').prop('checked')==false){
                             $("#select_all").prop('checked',false);
                          }else{
                              $("#select_all").prop('checked',true);
                          }*/

        add_class_disable('add_m_participator')

        if ($('input.p_select').is(":checked")) {
            remove_class_disable('add_m_participator')
        }

    }

    function checkbox2_reset() {

        /*                  if($('.p_select').prop('checked')==false){
                             $("#select_all").prop('checked',false);
                          }else{
                              $("#select_all").prop('checked',true);
                          }*/
        add_class_disable('delete_m_participator')

        if ($('input.selected_participator').is(":checked")) {
            remove_class_disable('delete_m_participator')
        }

    }

    function load_dynamically3() {
        $('input.selected_participator').change(function () {
            checkbox2_reset()
        });
    }

    function load_dynamically4() {

        $('.participator_action').on('click', function (e) {
            e.preventDefault()
            var employee_code = $(this).data('m_id');
            swal({
                title: 'Are you sure?Want to Delete?',
                text: "",
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Yes'
            }).then((result) => {
                if (result.value) {
                    $('.page-loader-wrapper').fadeIn();
                    var participant = Array();
                    participant.push(employee_code);


                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        type: "POST",
                        url: 'participator_delete',
                        data: {
                            'participator': participant,
                            'meeting_id': selected_meeting,
                        },
                        dataType: "json",
                        success: function (data) {
                            if (data.msgType = true) {
                                get_meetings_data(selected_meeting, 2)
                            } else {
                                toastr.error(data.msg)
                            }

                        },
                        error: function (jqXHR, textStatus, errorThrown) {

                            callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                        },
                        complete: function (data) {
                            $('.page-loader-wrapper').fadeOut();
                        }
                    })
                }
            })


        })
    }

    function bind_meeting_date(data, agendas, step, participator) {

        $(".steps-step").each(function () {
            $(this).children('a.btn-indigo').removeClass('btn-indigo');
        });


        $(".setup-content ").each(function () {
            $(this).hide();
        });


        selected_meeting = data.id;
        $('.meeting_id').val(data.id);
        if ((data.step == 1) || (data.step == 2) || (data.step == 3) || (data.step == 4)) {

            $('#start_date').val(data.start_date);
            $('#start_time').val(data.start_time);
            $('#end_date').val(data.end_date);
            $('#end_time').val(data.end_time);
        }

        if ((data.step == 2) || (data.step == 3) || (data.step == 4)) {
            $('#meeting_type').val(data.meeting_type_id);
            $('#title').val(data.title);
            $('#venue').val(data.venue);
        }

           if(data.step==1){
                remove_class_disable('st_1')
                remove_class_disable('st_2')
                add_class_disable('st_3')
                add_class_disable('st_4')
                if (step == 0)
                    $('#st_2').trigger("click");
          }else if(data.step==2){
                remove_class_disable('st_1')
                remove_class_disable('st_2')
                remove_class_disable('st_3')
                add_class_disable('st_4')
                if (step == 0)
                    $('#st_3').trigger("click");
         }else if(data.step==3){
                remove_class_disable('st_1')
                remove_class_disable('st_2')
                remove_class_disable('st_3')
                remove_class_disable('st_4')
                if (step == 0)
                    $('#st_4').trigger("click");
        }else if(data.step==4){
                remove_class_disable('st_1')
                remove_class_disable('st_2')
                remove_class_disable('st_3')
                remove_class_disable('st_4')
                if (step == 0)
                    $('#st_4').trigger("click");
        }else{
                $('#st_1').addClass('btn-indigo');
                $('#step-9').show();
                if (step == 0)
                    $('#st_1').trigger("click");
        }

        if (step != 0) {
            switch (step) {
                case 1:
                    $('#st_1').trigger("click");
                    break;
                case 2:
                    $('#st_2').trigger("click");
                    break;
                case 3:
                    $('#st_3').trigger("click");
                    break;
                case 4:
                    $('#st_4').trigger("click");
                    break;
                default:
                    $('#st_1').trigger("click");

            }
        }

        $('#agenda_list').empty();
        if (agendas) {
            if (agendas.length > 0) {
                $.each(agendas, function (key, value) {
                    var sub_agendas='';
                    if(value.sub_agenda){
                        if(value.sub_agenda.length>0){
                            var sub_list='';
                            $.each(value.sub_agenda,function(k,v){
                                sub_list=sub_list+'<li class="li_style">'+
                                                      '<div class="row">'+
                                                         '<div class="col-md-10">' + v.name +'</div>'+
                                                         '<div class="col-md-2 text-right" style="padding-right:0px !important; padding-left:5px !important;">' +
                                                            '<a href="" class="btn btn-danger btn-xs agenda_action" data-action="delete" data-m_id="' + v.id + '" data-toggle="tooltip" data-placement="top" title="Delete"><i class="fa fa-close " aria-hidden="true"></i></a>' +
                                                            '<a href="" class="btn btn-primary btn-xs agenda_action" data-action="edit" data-m_id="' + v.id + '" data-toggle="tooltip" data-placement="top" title="Edit"><i class="fa fa-edit " aria-hidden="true"></i></a>' +
                                                         '</div>'+
                                                      '</div>'+
                                                   '</li>';
                            });

                        sub_agendas='<ol type="i" id="collapse'+value.agendas.id+'" class=" collapse sub_agenda_style" data-parent="#agenda_accordion" >'+sub_list+'</ol';
                        }
                    }
                    
                    $('#agenda_list').append('<li class="li_style collapsed'+(sub_agendas?' main_agenda_style':'')+'" data-toggle="collapse" href="#collapse'+value.agendas.id+'"><div class="row"><div class="col-md-10"><span class="ml5"> ' + value.agendas.name + '</span></div>' +
                        '<div class="col-md-2 text-right" style="padding-right:0px !important; padding-left:5px !important;">' +
                        '<a href="" class="btn btn-danger btn-xs agenda_action" data-action="delete" data-m_id="' + value.agendas.id + '" data-toggle="tooltip" data-placement="top" title="Delete"><i class="fa fa-close " aria-hidden="true"></i></a>' +
                        '<a href="" class="btn btn-primary btn-xs agenda_action" data-action="edit" data-m_id="' + value.agendas.id + '" data-toggle="tooltip" data-placement="top" title="Edit"><i class="fa fa-edit " aria-hidden="true"></i></a>' +
                        '<a href="" class="btn btn-info btn-xs add_sub_agenda_btn" data-action="add" data-m_id="' + value.agendas.id + '" data-agenda="'+value.agendas.name+'" data-toggle="tooltip" data-placement="top" title="Add Sub Agenda"><i class="fa fa-plus " aria-hidden="true"></i></a>' +
                        '</div></div></li>'+sub_agendas);
                })
            }
            load_dynimically1();
        }



        $('#display_participator_list').empty();
        if (participator) {
            if (participator.length > 0) {
                $.each(participator, function (key, value) {
                    $('#display_participator_list').append('<li class="li_style"><div class="row">' +
                        '<div class="col-md-5">' + value.name + '</div>' +
                        '<div class="col-md-5">' + value.employee_code + '</div>' +
                        '<div class="col-md-2 text-right" style="padding-right:0px !important; padding-left:5px !important;">' +
                        '<a href="" class="btn btn-danger btn-xs participator_action" data-action="delete" data-m_id="' + value.employee_code + '" data-toggle="tooltip" data-placement="top" title="Delete"><i class="fa fa-close " aria-hidden="true"></i></a>' +
                        '</div></div></li>');
                })
                remove_class_disable('meeting_final_submit')
                load_dynamically4()

            } else {
                $('#display_participator_list').append('<div class="li_style"><div class="row">' +
                    '<div class="col-md-12 text-center"><span> No Participator Added.</span></div></div></div>');
                add_class_disable('meeting_final_submit')
            }

        }



    }

    function remove_class_disable(data) {
        $('#' + data).removeClass('pointer_none');
        $('#' + data).parent().removeClass('cursor_not');
    }

    function add_class_disable(data) {
        $('#' + data).addClass('pointer_none');
        $('#' + data).parent().addClass('cursor_not');
    }

    
    
    
    $('#step2').on('submit', function (e) {
        e.preventDefault();
        var meeting_type = $('#meeting_type').val();
        var title = $('#title').val();
        var venue = $('#venue').val();
        var meeting_id = $('.meeting_id').val();

$('.page-loader-wrapper').fadeIn()
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            type: "POST",
            url: 'meeting_s1_save',
            data: {
                'meeting_type': meeting_type,
                'title': title,
                'venue': venue,
                'meeting_id': meeting_id
            },
            dataType: "json",
            success: function (data) {
                if (data.msgType == true) {
                    setup_calender_data(selected_date,'edit')
                    bind_meeting_date(data.data.meeting, data.data.agendas, 3, data.data.participator)

                } else {
                    toastr.error(response.msg)
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {
                $('.page-loader-wrapper').fadeOut();
            }
        });
    });

    
    
    
    $('#step1').on('submit', function (e) {
        e.preventDefault();
        var start_date = $('#start_date').val();
        var start_time = $('#start_time').val();
        var end_date = $('#end_date').val();
        var end_time = $('#end_time').val();
        var meeting_id = $('.meeting_id').val();
        $("#step1").validate();
        if($("#step1").valid()){

$('.page-loader-wrapper').fadeIn();
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                type: "POST",
                url: 'meeting_s2_save',
                data: {
                    'start_date': start_date,
                    'start_time': start_time,
                    'end_date': end_date,
                    'end_time': end_time,
                    'meeting_id': meeting_id
                },
                dataType: "json",
                success: function (data) {
                    if (data.msgType == true) {
                        setup_calender_data(selected_date,'edit')
                        bind_meeting_date(data.data.meeting, data.data.agendas, 2, data.data.participator)

                    } else {
                        toastr.error(response.msg)
                    }

                },
                error: function (jqXHR, textStatus, errorThrown) {

                    callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                },
                complete: function (data) {
                   $('.page-loader-wrapper').fadeOut();
                }
            });
        }
        
        
    });

    $('#step3').on('submit', function (e) {
        e.preventDefault();
        var meeting_id = $('.meeting_id').val();

$('.page-loader-wrapper').fadeIn();
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            type: "POST",
            url: 'meeting_s3_save',
            data: {
                'meeting_id': meeting_id
            },
            dataType: "json",
            success: function (data) {
                if (data.msgType == true) {
                    setup_calender_data(selected_date,'edit')
                    bind_meeting_date(data.data.meeting, data.data.agendas, 4, data.data.participator)

                } else {
                    toastr.error(data.msg)
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {
                   $('.page-loader-wrapper').fadeOut();
            }
        });
    });


    $('#step4').on('submit', function (e) {
        e.preventDefault();
        var meeting_id = $('.meeting_id').val();

$('.page-loader-wrapper').fadeIn();
        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            type: "POST",
            url: 'meeting_final_save',
            data: {
                'meeting_id': meeting_id
            },
            dataType: "json",
            success: function (data) {
                if (data.msgType == true) {
                    setup_calender_data(selected_date,'new')
                    calender_load(todays_date)
                    swal({
                        type: 'success',
                        title: 'Success',
                        text: 'Meeting Scheduled Successfully.',
                        footer: ''
                    })

                } else {
                    $('.page-loader-wrapper').fadeOut();
                    if (data.data.error) {
                        bind_meeting_date(data.data.meeting, data.data.agendas, data.data.error, data.data.participator)
                    }
                    
                    swal({
                        type: 'error',
                        title: 'ERROR',
                        text: data.msg,
                        footer: ''
                    })
                    /*                    toastr.error(data.msg)*/
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {
                                   $('.page-loader-wrapper').fadeOut();
            }
        });

    })

    $('#agenda_form').on('submit', function (e) {
        e.preventDefault();
        var agenda_id = $('#agenda_id').val();
        var agenda = $('#agenda').val();


        var meeting_id = $('.meeting_id').val();

        $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            type: "POST",
            url: 'meeting_agenda_save',
            data: {
                'agenda': agenda,
                'meeting_id': meeting_id,
                'agenda_id': agenda_id,
                'level': 1,
            },
            dataType: "json",
            success: function (data) {
                if (data.msgType == true) {
                    empty_agenda_form()

                    bind_meeting_date(data.data.meeting, data.data.agendas, 3, data.data.participator)
                    $("#add_agebda_div").focus();
                } else {
                    toastr.error(data.msg)
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {

            }
        });
    });
    
    
    

$('#send_notification').on('click',function(e){
    e.preventDefault()
    var meeting_id=$(this).data('meeting_id');
            $.ajax({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            type: "POST",
            url: 'send_meeting_notification',
            data: {
                'meeting_id': meeting_id,
            },
            dataType: "json",
            success: function (data) {
                if (data.msgType == true) {
                   toastr.success(data.msg)
                } else {
                    toastr.error(data.msg)
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
            },
            complete: function (data) {

            }
        });
})
    
    
    
    

    /*******************for multistep form********************************/

    var navListItems = $('div.setup-panel div a'),
        allWells = $('.setup-content'),
        allNextBtn = $('.nextBtn'),
        allPrevBtn = $('.prevBtn');

    allWells.hide();

    navListItems.click(function (e) {
        e.preventDefault();
        var $target = $($(this).attr('href')),
            $item = $(this);

        if (!$item.hasClass('disabled')) {
            navListItems.removeClass('btn-indigo').addClass('btn-default');
            $item.addClass('btn-indigo');
            allWells.hide();
            $target.show();
            $target.find('input:eq(0)').focus();
        }
    });

    allPrevBtn.click(function () {
        var curStep = $(this).closest(".setup-content"),
            curStepBtn = curStep.attr("id"),
            prevStepSteps = $('div.setup-panel div a[href="#' + curStepBtn + '"]').parent().prev().children("a");

        prevStepSteps.removeAttr('disabled').trigger('click');
    });

    allNextBtn.click(function () {
        var curStep = $(this).closest(".setup-content"),
            curStepBtn = curStep.attr("id"),
            nextStepWizard = $('div.setup-panel div a[href="#' + curStepBtn + '"]').parent().next().children("a"),
            curInputs = curStep.find("input[type='text'],input[type='url']"),
            isValid = true;

        $(".form-group").removeClass("has-error");
        for (var i = 0; i < curInputs.length; i++) {
            if (!curInputs[i].validity.valid) {
                isValid = false;
                $(curInputs[i]).closest(".form-group").addClass("has-error");
            }
        }

        if (isValid)
            nextStepWizard.removeAttr('disabled').trigger('click');
    });

    $('div.setup-panel div a.btn-indigo').trigger('click');

    /***************** end **********************/



 load_dynimically()





    /*******************for editable table**************/
    var $TABLE = $('#table');
    var $BTN = $('#export-btn');
    var $EXPORT = $('#export');

    /*$('.table-add').click(function () {
      var $clone = $TABLE.find('tr.hide').clone(true).removeClass('hide table-line');
      $TABLE.find('table').append($clone);
    });*/

    $('.table-remove').click(function () {
        $(this).parents('tr').detach();
    });

    $('.table-up').click(function () {
        var $row = $(this).parents('tr');
        if ($row.index() === 1) return; // Don't go above the header
        $row.prev().before($row.get(0));
    });

    $('.table-down').click(function () {
        var $row = $(this).parents('tr');
        $row.next().after($row.get(0));
    });

    // A few jQuery helpers for exporting only
    jQuery.fn.pop = [].pop;
    jQuery.fn.shift = [].shift;

    $BTN.click(function () {
        var $rows = $TABLE.find('tr:not(:hidden)');
        var headers = [];
        var data = [];

        // Get the headers (add special header logic here)
        $($rows.shift()).find('th:not(:empty)').each(function () {
            headers.push($(this).text().toLowerCase());
        });

        // Turn all existing rows into a loopable array
        $rows.each(function () {
            var $td = $(this).find('td');
            var h = {};

            // Use the headers from earlier to name our hash keys
            headers.forEach(function (header, i) {
                h[header] = $td.eq(i).text();
            });

            data.push(h);
        });

        // Output the result
        $EXPORT.text(JSON.stringify(data));
    });
    /***************** end **********************/

    /*************************tooltip************************ */
    $(function () {
        $('[data-toggle="tooltip"]').tooltip()
    })

});





$(function () {

    //Datetimepicker plugin
    /*    $('.datetimepicker').bootstrapMaterialDatePicker({
            format: 'dddd DD MMMM YYYY - HH:mm',
            clearButton: true,
            weekStart: 1
        });

        $('.datepicker').bootstrapMaterialDatePicker({
            format: 'DD-MM-YYYY',
            clearButton: true,
            weekStart: 1,
            time: false
        });*/




    $('#end_date').bootstrapMaterialDatePicker({
        weekStart: 0,
        format: 'DD-MM-YYYY',
        clearButton: true,
        time: false
    });


    $('#start_date').bootstrapMaterialDatePicker({
        weekStart: 0,
        format: 'DD-MM-YYYY',
        clearButton: true,
        time: false
    }).on('change', function (e, date) {
        $('#end_date').bootstrapMaterialDatePicker('setMinDate', date);
    });



    $('.timepicker').bootstrapMaterialDatePicker({
        format: 'HH:mm',
        clearButton: true,
        date: false
    });


    $("#add_agebda_div").focus();
   
});