const spinner = '<span class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span>';
var modalCurrent;

fn = {

        modal : '',
        modalwait  : [],

        setHeight : function(obj = ''){

                var hW = $(window).height();
                if (!obj.menos) obj.menos = 0;
                if (obj.element){

                        $(obj.element).css({ height : (hW - obj.menos)});
                }
        },
        alert : function(msg){
                 $.alert({title : '', content : msg});
        },

        wait : function(msg = '<div class="text-center">'+spinner+'<br /> Por favor espere..</div>' , options = {} ){

              var defaul = {
                        title : '',
                        class : 'col-md-4',
                        animation : 'rotateYR',
                        closeAnimation : 'scale'
              }

              var opc = $.extend( defaul , options );

                this.modalwait.push($.dialog({
                                    animation: opc.animation,
                                    closeAnimation: opc.closeAnimation,
                                    title: opc.title,
                                    closeIcon: false,
                                    columnClass : opc.class,
                                    content : msg
                                }))


        },
        
        openIframe : function(options = {}){
                
                var defaul = {
                        title : '',
                        btnClose : true,
                        class : 'col-md-12',
                        msgWait: 'Por favor espere...',
                        'url' : '#'
                }

                var opc = $.extend( defaul , options );

                $.dialog({
                        animation: opc.animation,
                        closeAnimation: opc.closeAnimation,
                        title: opc.title,
                        closeIcon: true,
                        columnClass : opc.class,
                        content : '<iframe src="'+opc.url+'" class="big-iframe"></iframe>',
                    })
        },

        dialog : function(options){

                var defaul = {
                                title : '',
                                btnClose : true,
                                class : 'col-md-4',
                                msgWait: 'Por favor espere...',
                                url : 'ajax',
                                type: 'get',
                                dataType : 'json',
                                containerFluid : '', 
                                classcontainer  : '',
                        }

                var opc = $.extend( defaul , options );

                this.modalwait.push( this.modal = $.dialog({
                                        animation: 'rotateYR',
                                        closeAnimation: 'scale',
                                        title: opc.title,
                                        closeIcon: opc.btnClose,
                                        columnClass : opc.class,
                                        containerFluid : opc.containerFluid,
                                        classcontainer  : opc.classcontainer,
                                        closeIcon: function(){
                                               $('body').removeClass('disable-scroll')
                                        },
                                        content: function () {
                                                var self = this;

                                                $.ajaxSetup({
                                                    headers: {
                                                        'X-CSRF-TOKEN': jQuery('meta[name="csrf-token"]').attr('content')
                                                    }
                                                });


                                                return $.ajax({
                                                           beforeSend: function(){
                                                                        self.setContent(opc.msgWait);
                                                                        $('body').addClass('disable-scroll')
                                                           },
                                                            data: opc,
                                                            url: opc.url,
                                                            dataType: opc.dataType,
                                                            type : opc.type,
                                                            success : function(response){

                                                                    if (opc.dataType == 'json' || opc.dataType == 'JSON'){

                                                                        if (response.title) self.setTitle(response.title);
                                                                        if (response.html) self.setContent(response.html);
                                                                        if (response.autoClose) self.close();
                                                                        if (response.callback) eval(response.callback(response));

                                                                    }else{
                                                                        self.setContent(response);

                                                                    }
                                                                    
                                                            },  
                                                            error : function(rs){
                                                                    if (rs.responseJSON.message == 'CSRF token mismatch.'){
                                                                            if (confirm('La sesión ha caducado se perderan todos los datos no almacenados')){
                                                                                location.reload();    
                                                                            }else{
                                                                                fn.alert("Es necesario volver a autenticarse nuevamente")
                                                                            }
                                                                            
                                                                    }
                                                                // alert( rs.message );
                                                            }

                                                        })
                                            }

                                    })
                );


                modalCurrent = this.modal;
        },

        setContentModal : function(msg){
                this.modal.setContent(msg)
        },

        setTitleModal: function(msg){
                this.modal.setTitle(msg);
        },

        closeModal : function(){
                                                             
                $('body').removeClass('disable-scroll');                                               
                if (this.modalwait) this.closeWait();
                if (modalCurrent) modalCurrent.close();
                $('.jconfirm').remove();
        },

        closeWaitLast : function(){
                $('body').removeClass('disable-scroll');
                $('.jconfirm:last').remove();   
        },

        closeWait : function(){
            // fn.closeModal();    
          
            if (this.modalwait.length > 0){
               this.modalwait.shift().close();
            }else{
                $('.jconfirm').remove();
            }

            $('.jconfirm').remove();

        },

        hide : function(ele){
               $(ele).hide().addClass('hidden').removeClass('visible')
        },

        show : function(ele){
                $(ele).show().removeClass('hidden').addClass('visible')
        },

        ajax : function(opc){

                opc.url = (!opc.url) ? 'ajax.php' :  opc.url;
                opc.method = (!opc.method) ? 'get' :  opc.method;
                opc.dataType = (!opc.dataType) ? 'json' :  opc.dataType;

                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': jQuery('meta[name="csrf-token"]').attr('content')
                    }
                });

               return $.ajax({
                        beforeSend: opc.beforeSend,
                        data: opc.data,
                        url: opc.url,
                        dataType: opc.dataType,
                        method: opc.method,
                        success : opc.success,
                        complete : opc.complete,
                        fail :  opc.fail,
                        error : opc.error
                })

        },

        reloadContent : function(opc){

                        opc.data.option = (opc.data.option) ? opc.data.option : 'getContent';

                        this.ajax({
                                beforeSend : function(){
                                        $(opc.container).html('<div class="waitLoagin"></div>')
                                },
                                data : opc.data,
                                success : function(resp){
                                           if (resp.html) $(opc.container).html(resp.html);

                                }
                         })
        },

        reloadPart (box , datos = {}){

            $.ajax({
                    beforeSend : function(){
                            $(box).html(fn.boxLoading())
                    },
                    data : datos,
                    type : 'post',
                    url  : 'ajax.php',
                    success: function(rs){
                            if (rs){
                                $(box).html(rs);
                            }else{
                                $(box).html('Sin informaciÃ³n');
                            }
                    }
                })

        },

        confirm (opc = {} , success = '' ){

                defaul = {
                        title : 'Confirmación',
                        content : 'Desea realizar esta acción?',
                        btnTxtConfirm : 'Aceptar',
                        btnTxtCancel  : 'Cancelar',
                        actionCancel  : function(){}
                     }

                var options = $.extend( defaul , opc );


                $.confirm({
                        title: options.title,
                        content: options.content,
                        buttons: {
                            'Aceptar' : {
                                text : options.btnTxtConfirm,
                                action : success
                            },
                            cancelar: {
                                text : options.btnTxtCancel,
                                btnClass: 'btn-danger',
                                action: options.actionCancel
                            }

                        }
                    });


        },

        disabledRightClick : function(){
           $("body").unbind('contextmenu')
           $("body").on("contextmenu",function(e){
                       return false;
           });                        
        },

        enabledRightClick : function(){
                $("body").unbind('contextmenu')
                $("body").on("contextmenu",function(e){
                            return true;
                });                        
        },


        DataTable : function(){

            $('.dataTable').each(function(index, item){
                if ( $.fn.dataTable.isDataTable( item ) ) {
                        table = $(item).DataTable();
                    }
                    else {
                        table = $(item).DataTable( {
                                "language": {"url": "https://cdn.datatables.net/plug-ins/1.10.15/i18n/Spanish.json"}
                        } );
                    }
             })
               
        },

        setOrden : function(opc){
                var i = 1;   
                var datos = [];
                $(opc.element).each(function(index , item){
                            $(item).attr("data-orden",i);
                            datos.push( {'id':  $(item).attr("data-currentid"), 'orden': i , 'modo' : opc.modo })
                            i++;
                })

                fn.ajax({
                        beforeSend: function(){},
                        method : 'POST',
                        dataType : 'json',
                        url  : ajaxUrl+'/'+opc.case,
                        data : { orden  :datos }
                })
        
        },

        setOrdenEditorElement : function(){
                var i = 1;   
                var datos = [];
                $('.ui-sortable li').each(function(index , item){
                            $(item).attr("data-orden",i);
                            datos.push( {'id':  $(item).attr("data-currentid"), 'orden': i})
                            i++;
                })

                fn.ajax({
                        beforeSend: function(){},
                        method : 'POST',
                        dataType : 'json',
                        url  : ajaxUrl+'/setOrderElement',
                        data : { orden  :datos }
                })
        
        },
        
        removeElement : function(opc){

                if (confirm('Desea eliminar este elemento?')){

                        fn.ajax({
                                beforeSend: function(){},
                                method : 'POST',
                                dataType : 'json',
                                url  : ajaxUrl+'/deleteElement',
                                data : { id: opc.currentId }
                        })

                        $('#'+opc.uniqid).fadeOut().remove();

                        return true;
                }else{
                        return false;
                }
        },
        activePlugins  : function(){

                if ($( ".text-reply-content" ).length){
                        $('.text-reply-content').ckeditor({
                                toolbar: [
                                    ['Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat','NumberedList','BulletedList',
                                     'Outdent','Indent','Blockquote','CreateDiv','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','Link','Unlink',
                                     'Styles','Format','Font','FontSize','Table','Image','Undo','Redo']
                                ],
                        });       
                }

        },
        
        editorDinamico : function(){
                
                if ($( ".players:not(.run)" ).length){
                    $( ".players:not(.run)" ).each(function(index, item){
                        var token   = $(item).data('token');
                        var pointer = $(item).data('pointer');
                        setPlayerSingle(token , $("#player-"+token), pointer);
                    }) 
                }

                if ($( ".text-reply-content" ).length){
                        $('.text-reply-content').ckeditor({
                                toolbar: [
                                    ['Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat','NumberedList','BulletedList',
                                     'Outdent','Indent','Blockquote','CreateDiv','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','Link','Unlink',
                                     'Styles','Format','Font','FontSize','Table','Image','Undo','Redo']
                                ],
                        });       
                }
                
                if (!is_student){
                $( "#sortable" ).sortable({
                        revert: true,
                        update: function (event, ui) {
                               fn.setOrdenEditorElement()
                        },
                        start: function( event, ui ) {
                                $(this).addClass('element-sortable'); 
                        },
                        receive: function( event, ui ) {

                            
                            fn.ajax({
                                       beforeSend: function(){
                                           fn.wait();
                                       },
                                       method : 'POST',
                                       dataType : 'json',
                                       url  : ajaxUrl+'/editordinamico', 
                                       data : { elemento : $(ui.item).data('element') , 
                                                parentid : $(ui.item).data('parentid') ,
                                                modo : $(ui.item).data('modo'),
                                                questionid : $(ui.item).data('questionid') ?? ''
                                        },
                                       success : function(rs){
                                                $('#sortable .draggable').css({ width : 'auto' , height : 'auto' })
                                                $('#sortable .draggable').html(rs.html)
                                                .removeClass()
                                                .addClass('box-element')
                                                .attr('id', rs.uniqid)
                                                .addClass('in_edit')
                                       }, complete : function(){
                                                fn.closeWait()
                                       }         
                            })            

                            
                        }
                    });
            
                    $( ".draggable" ).draggable({
                            connectToSortable: "#sortable",
                            helper: "clone",
                            revert: "invalid",
                            start: function() {},
                            drag: function() {},
                            stop: function() {}
                    });
            
                    $( "ul, li" ).disableSelection();   
                    
                    this.sortableModulosAndSeccion();
                }
        },

        draggable : function(elem = '.draggable'){
                $( elem ).draggable({
                        connectToSortable: "#sortable",
                        helper: "clone",
                        revert: "invalid",
                        start: function() {},
                        drag: function() {},
                        stop: function() {}
                });
        },
        deleteElement : function(opc){
                $('#'+opc.target).fadeOut().remove();
        },

        editElement : function(opc){
                
                fn.ajax({
                        beforeSend: function(){
                            fn.wait();
                        },
                        method : 'POST',
                        dataType : 'json',
                        url  : ajaxUrl+'/editElement', 
                        data : opc,
                        success : function(rs){
                                 $('#'+rs.uniqid).html(rs.html)
                                 .removeClass()
                                 .addClass('box-element')
                                 .addClass('in_edit')
                        }, complete : function(){
                                 fn.closeWaitLast()
                        }         
               })    
        },

        LoadViewElement : function(data){

                fn.ajax({
                        beforeSend: function(){
                            fn.wait();
                        },
                        method : 'POST',
                        dataType : 'json',
                        url  : ajaxUrl+'/loadElement', 
                        data : data,
                        success : function(rs){
                                 $('#'+rs.uniqid).html(rs.html)
                                 .attr('data-currentId',rs.currentId)
                                 .removeClass()
                                 .addClass('box-element')
                        }, complete : function(){
                              fn.closeWaitLast()
                        }         
              })    
        },

        saveAndViewElement : function(opc){

                if (!$('.'+opc.target).length ) return false;
                
                error = false;

                /* Se validan los campos requeridos*/
                if ($('.'+opc.target).filter('[required]:visible').length){
                        $('.'+opc.target).filter('[required]:visible').each(function(index, item){

                                var type  = $(item).attr('type');
                                var name  = $(item).attr('name');
                                var id  = $(item).attr('id');

                                switch(type){
                                      case 'radio':
                                      case 'checkbox':
                                           if (!$("#"+id+"[name='"+name+"']:checked").length){
                                                $(item).focus();
                                                error = true;
                                                fn.alert('Selecionar almenos una repuesta correcta.')
                                                return false;
                                           }     
                                      break;
                                      default:

                                        if (!$(item).val()){
                                                $(item).focus();
                                                error = true;
                                        }
                                      break;
                                }

                                
                        })  
                }

                if (error) return false;

                var serialize  = $('.'+opc.target).serializeJSON();

                opc.orden = $('#'+opc.target).attr('data-orden');
                
                var data = $.extend( opc , serialize );

                fn.ajax({
                        beforeSend: function(){
                            fn.wait();
                        },
                        method : 'POST',
                        dataType : 'json',
                        url  : ajaxUrl+'/saveElement', 
                        data : data,
                        success : function(rs){
                                 $('#'+rs.uniqid).html(rs.html)
                                 .attr('data-currentId',rs.currentId)
                                 .removeClass()
                                 .addClass('box-element')
                        }, complete : function(){
                              if (!opc.closable)
                                  fn.closeWait()
                              else
                                  fn.closeWaitLast()
                        }         
             })    
        },

        loadFile:function(event , target){

                $.ajaxSetup({ headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')} });

                $(event).parents('li').removeClass('in_edit');

                // $('.editor-dinamico').submit(function(e) {  e.preventDefault(); });

               // $('.editor-dinamico').submit(function(e) {
                       
                        var formData = new FormData( document.getElementById('editordinamico') );

                        $.ajax({
                                beforeSend:function(){
                                    fn.wait()
                                    $(event).parents('li').addClass('in_edit');
                                },
                                type:'POST',
                                url: ajaxUrl+"/uploadMedia",
                                data: formData,
                                dataType : 'json',
                                cache:false,
                                contentType: false,
                                processData: false,
                                success: (data) => {
                                       
                                        $(target).val(data.url);
                                },
                                complete : function(){
                                        fn.closeWait();
                                },
                                error: function(data){
                                        if (data.responseJSON.errors){
                                                fn.alert(data.responseJSON.message);      
                                        }
                                        fn.closeWait();
                                }
                        });

                //        e.preventDefault();
              //  });
        },
        removeActive : ()=> {
               $('.item-modulo ,  .item-seccion ').removeClass('active')   
                       
        },
        loadEditorContent : function(opc , elem = ''){

                if ($('.in_edit').length){
                        fn.alert('Tienes contenidos en el editor sin guardar')
                        return false
                }
                this.ajax({
                              beforeSend: function(){
                                 fn.wait()
                                 fn.removeActive()
                                 $(elem).addClass('active');
                              },
                              method: 'POST',
                              dataType : 'json',
                              data : opc,
                              url : ajaxUrl + '/loadEditorContent',
                              success: function(rs){
                                  fn.closeWait();
                                  isOpenContentCurs();
                                  if (rs.contenidoDinamico) $('#boxContenidoDinamico').html(rs.contenidoDinamico)
                                  if (rs.elementcontenidoDinamico) $('#boxElementContenidoDinamico').html(rs.elementcontenidoDinamico)
                                  if (!opc.preview){
                                         fn.editorDinamico();
                                  }else{
                                         fn.activePlugins()
                                  }
                              },
                              error: function(){
                                fn.closeWait();
                              },
                              complete: function(){
                                  fn.closeWait();
                              }
                              
                          })
        },

        sortableModulosAndSeccion : function(){
                if (!is_teacher){
                        $('.box-item-modulos').sortable({
                                revert: true,
                                update: function (event, ui) {
                                fn.setOrden({case : 'setOrdenModulos' , element : '.box-item-modulos li', mode : 'modulos' })
                                }
                        })
                }
        },

        addModulo : function(opc){
                var defaul = {
                        title : 'Módulo',
                        btnClose : true,
                        class : 'col-md-7',
                        msgWait: 'Por favor espere...',
                        url : ajaxUrl+'/eventModule',
                        type: 'post',
                        dataType : 'json'
                }

                var data = $.extend( defaul , opc );
                this.dialog(data);
        },

        removeModulo : function(opc){

                fn.confirm({ 'content' : '¿Desea eliminar este módulo?'},function(){
                         
                        fn.ajax({
                                beforeSend : function(){
                                            fn.wait()
                                },
                                method: 'POST',
                                dataType : 'json',
                                data : { id:  opc.id , cursoId  : opc.cursoId  },
                                url : ajaxUrl + '/removeModule',
                                success: function(rs){
                                    if (rs.success){
                                        location.reload();
                                    }
                                } 
                    })    

                })

                
        },

        removeSeccion : function(opc){

                fn.confirm({ 'content' : '¿Desea eliminar esta sección?'},function(){
                         
                        fn.ajax({
                                beforeSend : function(){
                                            fn.wait()
                                },
                                method: 'POST',
                                dataType : 'json',
                                data : { id:  opc.id , cursoId  : opc.cursoId  },
                                url : ajaxUrl + '/removeSeccion',
                                success: function(rs){
                                    if (rs.success){
                                        location.reload();
                                    }
                                } 
                    })    

                })

                
        },

        addSeccion : function(opc){
                var defaul = {
                        title : 'Sección',
                        btnClose : true,
                        class : 'col-md-7',
                        msgWait: 'Por favor espere...',
                        url : ajaxUrl+'/eventSeccion',
                        type: 'post',
                        dataType : 'json'
                }

                var data = $.extend( defaul , opc );
                this.dialog(data);
        },

        addEvalucion : function(opc){
                var defaul = {
                        title : 'Evaluación',
                        btnClose : true,
                        class : 'col-md-7',
                        msgWait: 'Por favor espere...',
                        url : ajaxUrl+'/eventTest',
                        type: 'post',
                        dataType : 'json'
                }

                var data = $.extend( defaul , opc );
                this.dialog(data);
        },

        addEvalucionStandard : function(opc){
                var defaul = {
                        title : 'Evaluación',
                        btnClose : true,
                        class : 'col-md-7',
                        msgWait: 'Por favor espere...',
                        url : ajaxUrl+'/eventTestStandard',
                        type: 'post',
                        dataType : 'json'
                }

                var data = $.extend( defaul , opc );
                this.dialog(data);
        },
        
        removeTest : function(opc){

                fn.confirm({ 'content' : '¿Desea eliminar esta evaluación?'},function(){
                         
                        fn.ajax({
                                beforeSend : function(){
                                            fn.wait()
                                },
                                method: 'POST',
                                dataType : 'json',
                                data : { id:  opc.id , cursoId  : opc.cursoId  },
                                url : ajaxUrl + '/removeTest',
                                success: function(rs){
                                    if (rs.success){
                                        location.reload();
                                    }
                                } 
                    })    

                })

                
        },

        addForo : function(opc){
                var defaul = {
                        title : 'Foro',
                        btnClose : true,
                        class : 'col-md-7',
                        msgWait: 'Por favor espere...',
                        url : ajaxUrl+'/eventForo',
                        type: 'post',
                        dataType : 'json'
                }

                var data = $.extend( defaul , opc );
                this.dialog(data);
        },

        openInfoForum :function(opc, event){

                var defaul = {
                        title : 'Foro',
                        btnClose : true,
                        class : 'col-md-7',
                        msgWait: 'Por favor espere...',
                        url : ajaxUrl+'/'+event,
                        type: 'post',
                        dataType : 'json'
                }

                var data = $.extend( defaul , opc );
                this.dialog(data);
        },
        
        removeForo : function(opc){

                fn.confirm({ 'content' : '¿Desea eliminar este foro?'},function(){
                         
                        fn.ajax({
                                beforeSend : function(){
                                            fn.wait()
                                },
                                method: 'POST',
                                dataType : 'json',
                                data : { id:  opc.id , cursoId  : opc.cursoId  },
                                url : ajaxUrl + '/removeForo',
                                success: function(rs){
                                    if (rs.success){
                                        location.reload();
                                    }
                                } 
                    })    

                })

                
        },

        addCommentForum : function(opc){
                var defaul = {
                        title : '',
                        btnClose : true,
                        class : 'col-md-9',
                        msgWait: 'Por favor espere...',
                        url : ajaxUrl+'/eventCommentForum',
                        type: 'post',
                        dataType : 'json'
                }

                var data = $.extend( defaul , opc );
                this.dialog(data);
        },

        openListComment : function(opc){
                var defaul = {
                        title : '',
                        btnClose : true,
                        class : 'col-md-9',
                        msgWait: 'Por favor espere...',
                        url : ajaxUrl+'/openListComment',
                        type: 'post',
                        dataType : 'json'
                }

                var data = $.extend( defaul , opc );
                this.dialog(data);
        },

        viewContent : function(id , modoVista){

                this.ajax({
                            beforeSend : function(){
                                        fn.wait()
                            },
                            method: 'POST',
                            dataType : 'json',
                            data : { id:  id , modoVista : modoVista },
                            url : ajaxUrl + '/viewContent',
                            success: function(rs){
                                $('#contenedorEditorDinamico').html(rs.html);
                                if (modoVista == 'edit') fn.editorDinamico();
                            },
                            complete : ()=>{
                                fn.closeWait()
                            }

                })        

                

        },

        SaveAndDraw : function(token , currentId , svg = '' , json = ''){
                
                this.ajax({
                        beforeSend : function(){
                            $('#svg-map-'+token).html(svg);
                            fn.wait()
                        },
                        method: 'POST',
                        dataType : 'json',
                        data : { id:  currentId , 
                                 svg : svg ,  
                                 json : json },
                        url : ajaxUrl + '/saveMap',
                        success: function(rs){
                              
                        },
                        complete : ()=>{
                                fn.closeWait();
                        }

                })        

                
        },

        reloadActivities : function(token , elementId){
                        fn.ajax({ 
                        
                            url : ajaxUrl , 
                            beforeSend: function(){
                                fn.wait();
                            },
                            data: { opc : 'reload-activity-content' , 
                                    id : elementId , 
                                    token : token , 
                                  } ,  
                            method: 'POST',
                            success: function(rs){
                                 if(rs.success) {
                                    $('.box-list-activity-'+token).html(rs.html);
                                    eval('Reload'+token+'()');
                                 } 
                            },complete : function(){
                                fn.closeWait()
                            } 
                        })  
    
        },

        openActivity : function(opc={}){

                var defaul = {
                        title : '',
                        btnClose : true,
                        class : 'col-md-7',
                        msgWait: 'Por favor espere...',
                        url : ajaxUrl+'/show-answer-test',
                        type: 'post',
                        dataType : 'json',
                        id : 0,
                        userid : 0
                }

                var data = $.extend( defaul , opc );
                this.dialog(data);

        },

        setValueFieldTbl : function(obj, id , tbl, field){
                var type  = $(obj).attr('type'); 
                var value = '';

                switch(type){
                    case 'checkbox':
                        value =  $(obj).is(':checked') ? 1 : 0;
                    break;
                    default:
                        value =  $(obj).val();
                    break;
                }



                fn.ajax({ 
                        url : ajaxUrl , 
                        beforeSend: function(){
                            fn.wait();
                        },
                        data: { opc : 'set-value-field' , 
                                id : id , 
                                tbl : tbl , 
                                field : field,
                                value : value
                              } ,  
                        method: 'POST',
                        success: function(rs){
                        },
                        complete : function(){
                            fn.closeWait()
                        } 
                    })  
        }


        
       
}
 