<script src="<?php echo BASE_URL;?>js/editor/tinymce.min.js"></script>
<?php if ($ticketwrite && $ticketopen && $uploadactive) { ?>
<script src="<?php echo BASE_URL;?>js/dropzone.js"></script>
<?php } ?>

<script>
$(document).ready(function() {
  tinymce.init({
    selector: '#content-editor',
    height: 300,
    menubar: false,
    paste_as_text: true,
    entity_encoding : "raw",
    plugins: [
      'advlist autolink lists charmap print preview textcolor',
      'searchreplace visualblocks code fullscreen',
      'table contextmenu paste code codesample'
    ],
    toolbar: 'undo redo | bold italic underline | bullist numlist | removeformat codesample code',
    language: '<?php echo $BT_LANGUAGE;?>',
    <?php if ($jkl["rtlsupport"]) { ?>
    directionality : 'rtl',
    <?php } ?>
    relative_urls: false
  });

  $("#loader").hide();
    
  // JavaScript to disable send button and show loading.gif image
  $("#sendTM").click(function() {
    $("#loader").show();
    $('#sendTM').attr("disabled", "disabled");
    $('.jak_form').submit();
  });
});

<?php if ($ticketwrite && $ticketopen && $uploadactive) { ?>
Dropzone.autoDiscover = false;
  $(function() {
      // Now that the DOM is fully loaded, create the dropzone, and setup the
      // event listeners
      var myDropzone = new Dropzone("#share-attachments", {dictResponseError: "SERVER ERROR",
      dictDefaultMessage: '<i class="fa fa-upload fa-3x"></i>',
      acceptedFiles: "<?php echo JAK_ALLOWED_FILES;?>",
      addRemoveLinks: true,
      url: "<?php echo BASE_URL;?>uploader/uploadert.php"});
    myDropzone.on("sending", function(file, xhr, formData) {
        // Will send the filesize along with the file as POST data.
        formData.append("ticketId", <?php echo $page2;?>);
        formData.append("userIDU", <?php echo (JAK_USERID ? $jakuser->getVar("id") : 0);?>);
        formData.append("userIDC", <?php echo (JAK_CLIENTID ? $jakclient->getVar("id") : 0);?>);
        formData.append("base_url", "<?php echo BASE_URL;?>");
    });
    myDropzone.on("success", function(file, serverResponse) {
        //myDropzone.removeAllFiles();
        // Update the counter
        var thefile = "";
        var countSpan = $('#upload-counter').text();
        var newSpan = parseInt(countSpan) + 1;
        $('#upload-counter').html(newSpan);
        data = JSON.parse(serverResponse);
        if (data.isimage) {
          thefile = '<li class="account space-top"><div class="row"><div class="col-md-3"><div class="avatar"><img src="<?php echo BASE_URL;?>_showfile.php?i='+data.filepath+'" alt="'+data.filename+'" class="attachment-thumbnail img-no-padding img-responsive"></div></div><div class="col-md-8 description-section"><span><a href="<?php echo BASE_URL;?>_showfile.php?i='+data.filepath+'" target="_blank">'+data.filename.substr(17)+'</a></span><br><span class="text-muted"><small>'+data.filesize+'</small></span></div></div></li>';
        } else {
          thefile = '<li class="account space-top"><div class="row"><div class="col-md-3"><div class="avatar"><img src="<?php echo BASE_URL;?>template/<?php echo JAK_FRONT_TEMPLATE;?>/assets/img/attachments.jpg" alt="Circle Image" class="img-circle img-no-padding img-responsive"></div></div><div class="col-md-8 description-section"><span><a href="<?php echo BASE_URL;?>_showfile.php?i='+data.filepath+'" target="_blank">'+data.filename.substr(17)+'</a></span><br><span class="text-muted"><small>'+data.filesize+'</small></span></div></div></li>';
        }

        $('#attach-list').append(thefile);

        $.notify({icon: 'check', message: '<?php echo $jkl['hd92'];?>'}, {type: 'success', animate: {
          enter: 'animated fadeInDown',
          exit: 'animated fadeOutUp'
        }});
        
    });
  });

<?php } if (JAK_SUPERADMINACCESS || JAK_USERISLOGGED) { ?>
function edit_post(id) {
  var editmsg = this.document.getElementById("edit-content"+id).innerHTML;
  tinymce.activeEditor.setContent(editmsg);
  tinyMCE.activeEditor.focus();
  document.getElementById("edit-post").value = id;
  $(".show_editor").fadeIn();
}
<?php } ?>
</script>
