function fnEmailNote(){$("#emailNoteError").hide();$("#emailNoteModal").modal()}function fnEmailNoteSend(){var n=$("#emailNoteEmail").val(),t=$("input[name=emailNoteType]:checked").val(),i=$("#notenumber").val();$.post("/note/email",{number:i,type:t,email:n},function(n){n.status==="success"?($("#emailNoteModal").modal("hide"),fnShowAlert(n.status,n.message)):($("#emailNoteError").html(n.message),$("#emailNoteError").show())})}function fnPremiumUpgrade(){$(".modal").not("#premiumPlanModal").modal("hide");$("#premiumPlanModal").modal()}function fnImportFile(){$("#importFileModal").modal()}function fnAttachFile(){$("#attachFileModal").modal()}function fnUpgradeNow(){$("#formUpgradeToPremium").submit()}function fnMobileMenu(){$("#header").append('<div id="mobile-menu-bar"><\/div>');$("#mobile-menu-bar").on("click",function(){$("#mobile-main-menu").slideToggle();$(this).toggleClass("active")})}function fnEnableRichTextEditor(){$("#btnEnableRichText").toggleClass("hidden");$("#btnDisableRichText").toggleClass("hidden");$("#notetype").val("RichText");$("#edit_textarea").val($("#edit_textarea").val().replace(/\n/g,"<br />"));tinymce.execCommand("mceToggleEditor",!1,"edit_textarea")}function fnDisableRichTextEditor(){$("#btnEnableRichText").toggleClass("hidden");$("#btnDisableRichText").toggleClass("hidden");$("#notetype").val("PlainText");tinymce.execCommand("mceToggleEditor",!1,"edit_textarea");$("#edit_textarea").val($("#edit_textarea").val().replace(/<br\ \/>/g,"\n"))}function fnSortByTitle(){$.post("/note/list",{sort:"title"},function(n){$("#savedNotes").html(n)})}function fnSortByUpdated(){$.post("/note/list",{sort:"updated"},function(n){$("#savedNotes").html(n)})}function fnManageFolders(){fnLoadManageFolderContent();$("#manageFolderModal").modal()}function fnLoadManageFolderContent(){$.get("/note/managefolder",{},function(n){$("#manageFolderContent").html(n)})}function fnShowNoteVersions(n){fnLoadNoteVersions(n);$("#noteVersionsModal").modal()}function fnLoadNoteVersions(n){$.get("/notes/"+n+"/versions",{},function(n){$("#noteVersionsContent").html(n)})}function fnCreateFolder(){$("#newFolder").val()!=""&&$.post("/note/createfolder",{name:$("#newFolder").val()},function(){fnLoadManageFolderContent()})}function fnDeleteFolder(n){var t=confirm("Do you want to delete folder '"+$("#editFolder_"+n).val()+"'? Notes in that folder will NOT be deleted.");t==!0&&$.post("/note/deletefolder",{number:n},function(){fnLoadManageFolderContent()})}function fnRenameFolder(n){$("#row_"+n).addClass("hidden");$("#edit_"+n).removeClass("hidden")}function fnRenameFolderSave(n){$("#editFolder_"+n).val()!=""&&$.post("/note/renamefolder",{number:n,name:$("#editFolder_"+n).val()},function(){fnLoadManageFolderContent()})}function fnRenameFolderCancel(n){$("#row_"+n).removeClass("hidden");$("#edit_"+n).addClass("hidden")}function fnOpenFolder(n){n&&($("#folderList > li").removeClass("active"),$("#folderList > #folder_"+n).addClass("active"));$.post("/note/list",{folder:n},function(n){$("#savedNotes").html(n);fnEnableNoteDragDrop()})}function fnLoadFolderList(){$.get("/note/folderlist",{},function(n){$("#folderList").html(n)})}function fnMoveNoteToFolder(n,t){$.post("/note/movetofolder",{notenumber:n,foldernumber:t},function(){$("#actionMessage").text("Note Moved").show().delay(1e3).fadeOut(1e3);fnOpenFolder()})}function fnEnableNoteDragDrop(){$("#savedNotes li").draggable({delay:200,revert:"invalid",helper:"clone",cursor:"move"});$("#folderList li.droppable").droppable({hoverClass:"highlight",drop:function(n,t){fnMoveNoteToFolder(t.draggable.attr("id").replace("note_",""),$(this).attr("id").replace("folder_",""))}})}function fnSaveNote(){Notepad.NoteEditMode=="new"?fnSaveNoteNew():Notepad.NoteEditMode=="edit"?fnSaveNoteEdit():Notepad.NoteEditMode=="quickedit"&&fnSaveNoteQuickEdit()}function fnSaveNoteNew(){var n=$("input[name='autosavenotenumber']").val(),t=$("input[name='notetype']").val(),r=$("input[name='access']:checked").val(),u=$("input[name='password']").val(),f=$("#quickedit").is(":checked")?"true":"false",e=$("input[name='quickeditpassword']").val(),o=$("input[name='notetitle']").val(),i=t=="RichText"?tinymce.get("edit_textarea").getContent():$("textarea[name='notecontent']").val();if(i.length>1048576){fnShowAlert("error","Note NOT saved! Note content is too long (over 1MB limit).");return}$("#saveNoteMessage").html("Saving...");n.length==0?$.post("/note/create",{notetype:t,noteaccess:r,notepassword:u,notequickedit:f,notequickeditpassword:e,notetitle:o,notecontent:i},function(n){n.status==="success"?window.location="/notes/"+n.notenumber:fnShowAlert(n.status,n.message)}):$.post("/note/save",{number:n,notetype:t,noteaccess:r,notepassword:u,notequickedit:f,notequickeditpassword:e,notetitle:o,notecontent:i},function(t){t.status==="success"?window.location="/notes/"+n:fnShowAlert(t.status,t.message)})}function fnSaveNoteEdit(){var i=$("input[name='notenumber']").val(),n=$("input[name='notetype']").val(),r=$("input[name='access']:checked").val(),u=$("input[name='password']").val(),f=$("#quickedit").is(":checked")?"true":"false",e=$("input[name='quickeditpassword']").val(),o=$("input[name='notetitle']").val(),t=n=="RichText"?tinymce.get("edit_textarea").getContent():$("textarea[name='notecontent']").val();if(t.length>1048576){fnShowAlert("error","Note NOT saved! Note content is too long (over 1MB limit).");return}$("#saveNoteMessage").html("Saving...");$.post("/note/save",{number:i,notetype:n,noteaccess:r,notepassword:u,notequickedit:f,notequickeditpassword:e,notetitle:o,notecontent:t},function(n){n.status==="success"?($("#saveNoteMessage").html(n.message),$("#actionMessage").text("Note Saved").show().delay(1e3).fadeOut(1e3)):fnShowAlert(n.status,n.message)})}function fnSaveNoteQuickEdit(){var t=$("input[name='notenumber']").val(),i=$("input[name='notetype']").val(),n=i=="RichText"?tinymce.get("edit_textarea").getContent():$("textarea[name='notecontent']").val();if(n.length>1048576){fnShowAlert("error","Note NOT saved! Note content is too long (over 1MB limit).");return}$("#saveNoteMessage").html("Saving...");$.post("/note/quickeditsave",{number:t,notecontent:n},function(n){n.status==="success"?($("#saveNoteMessage").html(n.message),$("#actionMessage").text("Note Saved").show().delay(1e3).fadeOut(1e3)):fnShowAlert(n.status,n.message)})}function fnAutoSaveInit(){$("input[name='notetitle']").keydown(function(){Notepad.NoteTitleChanged=!0});$("textarea[name='notecontent']").keydown(function(){Notepad.NoteContentChanged=!0});Notepad.AutoSaveEnabled&&setInterval(fnAutoSaveNote,6e4)}function fnAutoSaveNote(){Notepad.NoteEditMode=="new"?fnAutoSaveNoteNew():Notepad.NoteEditMode=="edit"?fnAutoSaveNoteEdit():Notepad.NoteEditMode=="quickedit"&&fnAutoSaveNoteQuickEdit()}function fnAutoSaveNoteNew(){if(Notepad.NoteTitleChanged||Notepad.NoteContentChanged){var i=$("input[name='autosavenotenumber']").val(),t=$("input[name='notetype']").val(),r=$("input[name='access']:checked").val(),u=$("input[name='password']").val(),f=$("#quickedit").is(":checked")?"true":"false",e=$("input[name='quickeditpassword']").val(),o=$("input[name='notetitle']").val(),n=t=="RichText"?tinymce.get("edit_textarea").getContent():$("textarea[name='notecontent']").val();if(n.length<20||n.length>1048576)return;$("#saveNoteMessage").html("Saving...");i.length==0?$.post("/note/create",{notetype:t,noteaccess:r,notepassword:u,notequickedit:f,notequickeditpassword:e,notetitle:o,notecontent:n},function(n){Notepad.NoteTitleChanged=!1;Notepad.NoteContentChanged=!1;$("input[name='autosavenotenumber']").val(n.notenumber);$("#saveNoteMessage").html(n.message)}):$.post("/note/save",{number:i,notetype:t,noteaccess:r,notepassword:u,notequickedit:f,notequickeditpassword:e,notetitle:o,notecontent:n},function(n){Notepad.NoteTitleChanged=!1;Notepad.NoteContentChanged=!1;$("#saveNoteMessage").html(n.message)})}}function fnAutoSaveNoteEdit(){if(Notepad.NoteTitleChanged||Notepad.NoteContentChanged){var i=$("input[name='notenumber']").val(),n=$("input[name='notetype']").val(),r=$("input[name='access']:checked").val(),u=$("input[name='password']").val(),f=$("#quickedit").is(":checked")?"true":"false",e=$("input[name='quickeditpassword']").val(),o=$("input[name='notetitle']").val(),t=n=="RichText"?tinymce.get("edit_textarea").getContent():$("textarea[name='notecontent']").val();if(t.length>1048576)return;$("#saveNoteMessage").html("Saving...");$.post("/note/save",{number:i,notetype:n,noteaccess:r,notepassword:u,notequickedit:f,notequickeditpassword:e,notetitle:o,notecontent:t},function(n){Notepad.NoteTitleChanged=!1;Notepad.NoteContentChanged=!1;$("#saveNoteMessage").html(n.message)})}}function fnAutoSaveNoteQuickEdit(){if(Notepad.NoteTitleChanged||Notepad.NoteContentChanged){var t=$("input[name='notenumber']").val(),i=$("input[name='notetype']").val(),n=i=="RichText"?tinymce.get("edit_textarea").getContent():$("textarea[name='notecontent']").val();if(n.length>1048576)return;$("#saveNoteMessage").html("Saving...");$.post("/note/quickeditsave",{number:t,notecontent:n},function(n){Notepad.NoteTitleChanged=!1;Notepad.NoteContentChanged=!1;$("#saveNoteMessage").html(n.message)})}}function fnManageNoteAccess(){$("#manageNoteAccessModal").modal()}function fnUpdateNoteAccessText(n){$("#noteAccessText").html(n)}function fnCommentLoad(){$.post("/note/loadcomment",{notenumber:Notepad.CurrentNoteNumber},function(n){$("#comments_container").html(n)})}function fnCommentAdd(){var i=Notepad.CurrentNoteNumber,n=$("#comment_name").val(),t=$("#comment_content").val(),r=$("#comment_reply").val();if(n===""||t===""){$("#commentErrorMessage").html("Your name and comment are required");return}$.post("/note/addcomment",{notenumber:i,name:n,content:t,reply:r},function(n){n.message==="success"&&fnCommentLoad()})}function fnCommentDelete(n){$.post("/note/deletecomment",{number:n},function(t){t.message==="success"&&$("#comments_list #comment_"+n).remove()})}function fnCommentReply(n){$("#comment_reply").val(n);var t=$("#comment_"+n+" .name").text();$("#comment_content").val("@"+t+" "+$("#comment_content").val());document.getElementById("comment_content").scrollIntoView()}function fnShowAlert(n,t){$("#msgDanger, #msgWarning, #msgInfo, #msgSuccess").hide();n==="danger"||n==="error"?$("#msgDanger").html(t).show():n==="warning"?$("#msgWarning").html(t).show():n==="info"?$("#msgInfo").html(t).show():n==="success"&&$("#msgSuccess").html(t).show()}function fnLoadNoteFileList(){var n=$("input[name='notenumber']").val();(n&&n.length!==0||(n=$("input[name='autosavenotenumber']").val()),n&&n.length!==0)&&$.post("/note/filelist",{notenumber:n},function(n){$("#noteFileList").html(n)})}function fnDeleteNoteFile(n){var t=confirm("Do you want to delete this file?");t===!0&&$.post("/note/filedelete",{file:n},function(){fnLoadNoteFileList()})}var Notepad=Notepad||{};$(document).ready(function(){fnMobileMenu();$("#savedNotes").length&&fnOpenFolder();$("#edit_title").length&&$("#edit_title").focus();$("#registerEmail").length&&$("#registerEmail").focus();$("#manageFolderModal").on("hide.bs.modal",function(){fnLoadFolderList()});$("#manageNoteAccessModal").on("hide.bs.modal",function(){Notepad.NoteContentChanged=!0;fnAutoSaveNote()});$(window).bind("keydown",function(n){if(n.ctrlKey||n.metaKey)switch(String.fromCharCode(n.which).toLowerCase()){case"s":n.preventDefault();fnAutoSaveNote()}});fnAutoSaveInit();Notepad.NoteCommentsEnabled&&fnCommentLoad();fnLoadNoteFileList()})