<script src="<?php echo $Position; ?>assets/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap tether Core JavaScript -->
<script src="<?php echo $Position; ?>assets/plugins/bootstrap/js/popper.min.js"></script>
<script src="<?php echo $Position; ?>assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script> -->

<!-- slimscrollbar scrollbar JavaScript -->
<script src="<?php echo $Position; ?>js/jquery.slimscroll.js"></script>
<!-- Wave Effects -->
<script src="<?php echo $Position; ?>js/waves.js"></script>
<!-- Menu sidebar -->
<script src="<?php echo $Position; ?>js/sidebarmenu.js"></script>
<!-- stickey kit -->
<script src="<?php echo $Position; ?>assets/plugins/sticky-kit-master/dist/sticky-kit.min.js"></script>
<script src="<?php echo $Position; ?>assets/plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="<?php echo $Position; ?>js/chosen/chosen.jquery.min.js"></script>
<!-- Sortable -->
<script src="<?php echo $Position; ?>js/sortable/jquery.sortable.js"></script>
<!-- Custom JavaScript -->
<script src="<?php echo $Position; ?>js/custom.min.js"></script>

<!-- Parsley -->
<script src="<?php echo $Position; ?>js/parsley/parsley.min.js"></script>
<script src="<?php echo $Position; ?>js/parsley/parsley.extend.js"></script>
<script src="<?php echo $Position; ?>assets/plugins/tinymce/tinymce.min.js"></script>

<!-- Color Picker Plugin JavaScript -->
<script src="<?php echo $Position ; ?>assets/plugins/jquery-asColorPicker-master/libs/jquery-asColor.js"></script>
<script src="<?php echo $Position ; ?>assets/plugins/jquery-asColorPicker-master/libs/jquery-asGradient.js"></script>
<script src="<?php echo $Position ; ?>assets/plugins/jquery-asColorPicker-master/dist/jquery-asColorPicker.min.js"></script>

<!-- <script src="<?php echo $Position; ?>assets/plugins/tinymce/tinymce.min.js"></script> -->

<script>
  // Colorpicker
  $(".colorpicker").asColorPicker();
  $(".complex-colorpicker").asColorPicker({
      mode: 'complex'
  });
  $(".gradient-colorpicker").asColorPicker({
      mode: 'gradient'
  });
</script>



<!-- Date Picker Plugin JavaScript -->
<script src="<?php echo $Position; ?>assets/plugins/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>

<!-- Sweet-Alert  -->
<script src="<?php echo $Position; ?>assets/plugins/sweetalert/sweetalert.min.js"></script>

<script src="<?php echo $Position; ?>assets/plugins/dropify/dist/js/dropify.min.js"></script>
<script>
  $(document).ready(function() {

    //Areas de Texto
    tinymce.init({
      selector: ".TextArea",
      theme: "modern",
      height: 300,
      force_br_newlines : true,
      force_p_newlines : false,
      forced_root_block : '',
      plugins: "paste",
      paste_as_text: true,
      plugins: [
          "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
          "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
          "save table contextmenu directionality emoticons template paste textcolor"
      ],
      toolbar: "insertfile undo redo | bold italic | alignleft aligncenter alignright alignjustify | bullist | link image",
    });
    //End Areas de Texto

    $(".chosen-select").chosen();

    // Basic
    $('.dropify').dropify();

    // Translated
    $('.dropify-fr').dropify({
      messages: {
        default: 'Glissez-déposez un fichier ici ou cliquez',
        replace: 'Glissez-déposez un fichier ou cliquez pour remplacer',
        remove: 'Supprimer',
        error: 'Désolé, le fichier trop volumineux'
      }
    });

    // Used events
    var drEvent = $('#input-file-events').dropify();

    drEvent.on('dropify.beforeClear', function(event, element) {
      return confirm("Do you really want to delete \"" + element.file.name + "\" ?");
    });

    drEvent.on('dropify.afterClear', function(event, element) {
      alert('File deleted');
    });

    drEvent.on('dropify.errors', function(event, element) {
      console.log('Has Errors');
    });

    var drDestroy = $('#input-file-to-destroy').dropify();
    drDestroy = drDestroy.data('dropify')
    $('#toggleDropify').on('click', function(e) {
      e.preventDefault();
      if (drDestroy.isDropified()) {
        drDestroy.destroy();
      } else {
        drDestroy.init();
      }
    })
  });
</script>

<script>

  $(document).ready(function() {

    //Validación de Formulario
    $(".BtnGoSave").click(function () {
      $('#FormPer').parsley().validate();
      if ($('#FormPer').parsley().isValid()) {
          console.log('valid');
        swal({
          title: "¡Guardando datos!",
          text: "",
          showConfirmButton: false
        });
        $('#BtnGoDo').click();
      } else {
        console.log('not valid');
        swal("", "Falta llenar algunos campos", "error");
      }
    });
    //End Validación de Formulario

    //Recordatorio Guardado
    <?php if( $Saved == 'Ok' || $Save == 'Ok' || $_GET['New'] == 'Ok' ){ ?>
      swal({
        title: "¡Guardado!",
        text: "El elemento se ha guardado correctamente.",
        timer: 2000,
        showConfirmButton: false
      });
    <?php } ?>
    //End Recordatorio Guardado

    // Actualiza Imagenes
    $("img").each(function(){
      $(this).attr('src', $(this).attr('src')+'?'+Math.random());
    });

    //Date datepicker
    $('.datepicker').datepicker({
      autoclose: true,
      todayHighlight: true,
      format: "dd / MM / yyyy",
      startView: 0
    });
    //End Date datepicker

    //Date datepicker
    $('.datepicker-year').datepicker({
      autoclose: true,
      todayHighlight: true,
      format: "dd / MM / yyyy",
      startView: 3
    });
    //End Date datepicker

    AnchoScreen = $( window ).width();
    if( $( '.fix-sidebar' ).hasClass( ".mini-sidebar" ) ){
      Ancho = AnchoScreen - 60;
    }else{
      Ancho = AnchoScreen - 260;
    }
    $('.page-titles-fixed').width(Ancho);

    $( window ).resize(function() {
      AnchoScreen = $( window ).width();
      if( $( '.fix-sidebar' ).hasClass( ".mini-sidebar" ) ){
        Ancho = AnchoScreen - 60;
      }else{
        Ancho = AnchoScreen - 260;
      }
      $('.page-titles-fixed').width(Ancho);
    });

    $('.sidebartoggler').click(function(){
      AnchoScreen = $( window ).width();
      if( $( '.fix-sidebar' ).hasClass( '.mini-sidebar' ) ){
        //Ancho = AnchoScreen - 60;
        //alert('Si');
      }else{
        //Ancho = AnchoScreen - 240;
        //alert('No');
      }
      //$('.page-titles-fixed').width(Ancho);
    });


  });
</script>

<!--Nestable js -->
<script src="<?php echo $Position; ?>assets/plugins/nestable/jquery.nestable.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    // Nestable
    var updateOutput = function(e) {
      var list = e.length ? e : $(e.target),
        output = list.data('output');
      if (window.JSON) {
        output.val(window.JSON.stringify(list.nestable('serialize'))); //, null, 2));
      } else {
        output.val('JSON browser support required for this demo.');
      }
    };

    $('#nestable').nestable({
      group: 1
    }).on('change', updateOutput);

    $('#nestable2').nestable({
      group: 1
    }).on('change', updateOutput);

    updateOutput($('#nestable').data('output', $('#nestable-output')));
    updateOutput($('#nestable2').data('output', $('#nestable2-output')));

    $('#nestable-menu').on('click', function(e) {
      var target = $(e.target),
        action = target.data('action');
      if (action === 'expand-all') {
        $('.dd').nestable('expandAll');
      }
      if (action === 'collapse-all') {
        $('.dd').nestable('collapseAll');
      }
    });

    $('#nestable-menu').nestable();
  });
</script>
