function fnLookup(n){var i="SiteJs."+n,t=Notepad.Language[i];return t&&t.length?t:i}function fnLanguage(){$("#languageModal").modal()}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 fnTaskSave(){var n=fnTaskToTextNote();n&&fnSaveNote()}function fnTaskSaveClicked(){fnTaskSave()}function fnTaskNewClicked(n){var r=$(n).parent().children("input[type=checkbox]").first().is(":checked")?"checked":"",t=$(n).parent().children(".task-text").first().text().trim(),i;t&&t!==fnLookup("AddTask")&&(i=$("<div class='task-item'><input type='checkbox' class='task-checkbox' "+r+" onclick='fnTaskCheckboxClicked(this);' /> <span class='task-text' contenteditable='true' onfocus='fnTaskTextFocus(this);' onblur='fnTaskTextBlur(this);' onkeydown='fnTaskTextKeyDown(event, this);'><\/span> <span class='task-save' style='display:none' onclick='fnTaskSaveClicked(this);'><\/span><span class='task-delete' onclick='fnTaskDeleteClicked(this);'><\/span><span class='task-sort handle'><\/span><\/div>"),i.children(".task-text").first().text(t),$(n).parent().before(i),$("#taskList>.task-item-new>.task-text").text(""),fnTaskSave())}function fnTaskCheckboxClicked(){fnTaskSave()}function fnTaskDeleteClicked(n){$(n).parent().remove();fnTaskSave()}function fnTaskTextFocus(n){$(n).parent().children(".task-save").show()}function fnTaskTextBlur(n){$(n).parent().children(".task-save").hide();var t=fnTaskToTextNote();t&&fnSaveNote()}function fnTaskTextNewFocus(n){$(n).text()===fnLookup("AddTask")&&$(n).text("")}function fnTaskTextNewBlur(n){$(n).text()||$(n).text(fnLookup("AddTask"))}function fnTaskTextNewKeyDown(n,t){n.keyCode===13&&(n.preventDefault(),fnTaskNewClicked(t))}function fnTaskTextKeyDown(n,t){n.keyCode===13&&(n.preventDefault(),fnTaskSaveClicked(t),$(t).blur())}function fnTextNoteToTask(){$("#taskList").empty();var n=$("#edit_textarea").val(),t=n.split("\n");t.forEach(function(n){if(n&&n.trim()){var t=n.includes("[Checked]")?"checked":"";n=n.replace("[Checked]","").trim();$("#taskList").append("<div class='task-item'><input type='checkbox' class='task-checkbox' "+t+" onclick='fnTaskCheckboxClicked(this);' /> <span class='task-text' contenteditable='true' onfocus='fnTaskTextFocus(this);' onblur='fnTaskTextBlur(this);' onkeydown='fnTaskTextKeyDown(event, this);'><\/span> <span class='task-save' style='display:none' onclick='fnTaskSaveClicked(this);'><\/span><span class='task-delete' onclick='fnTaskDeleteClicked(this);'><\/span><span class='task-sort handle'><\/span><\/div>");$("#taskList .task-text").last().text(n)}});$("#taskList").append("<div class='task-item task-item-new'><input type='checkbox' class='task-checkbox' /> <span class='task-text' contenteditable='true' onfocus='fnTaskTextNewFocus(this);' onblur='fnTaskTextNewBlur(this);' onkeydown='fnTaskTextNewKeyDown(event, this);'>"+fnLookup("AddTask")+"<\/span><span class='task-save' onclick='fnTaskNewClicked(this);'><\/div>")}function fnTaskToTextNote(){var t=$("#edit_textarea").val(),n="";return $("#taskList").children(".task-item").not(".task-item-new").each(function(){var t=$(this).children(".task-text").first().text().trim();n+=$(this).children("input[type=checkbox]").first().is(":checked")?"[Checked] "+t+"\n":t+"\n"}),$("#edit_textarea").val(n),t!==n}function fnRichTextEditor(){$("#notetype").val()==="PlainText"?($("#edit_textarea").val($("#edit_textarea").val().replace(/\n/g,"<br />")),tinymce.execCommand("mceToggleEditor",!1,"edit_textarea")):$("#notetype").val()==="Task"&&(fnTaskToTextNote(),$("#edit_textarea").val($("#edit_textarea").val().replace(/\n/g,"<br />")),tinymce.execCommand("mceToggleEditor",!1,"edit_textarea"),$("#textNoteContainer").show(),$("#taskContainer").hide());$("#notetype").val("RichText");$("#noteTypeDropdown").text(fnLookup("RichTextNote"))}function fnPlainTextEditor(){if($("#notetype").val()==="RichText"){var n=tinymce.get("edit_textarea").getContent({format:"text"});tinymce.execCommand("mceToggleEditor",!1,"edit_textarea");$("#edit_textarea").val(n)}else $("#notetype").val()==="Task"&&(fnTaskToTextNote(),$("#textNoteContainer").show(),$("#taskContainer").hide());$("#notetype").val("PlainText");$("#noteTypeDropdown").text(fnLookup("PlainTextNote"))}function fnTaskEditor(){if($("#notetype").val()==="PlainText")fnTextNoteToTask(),$("#textNoteContainer").hide(),$("#taskContainer").show();else if($("#notetype").val()==="RichText"){var n=tinymce.get("edit_textarea").getContent({format:"text"});tinymce.execCommand("mceToggleEditor",!1,"edit_textarea");$("#edit_textarea").val(n);fnTextNoteToTask();$("#textNoteContainer").hide();$("#taskContainer").show()}$("#notetype").val("Task");$("#noteTypeDropdown").text(fnLookup("TaskList"))}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 fnMenuActionShareFolder(n){$.get("/note/sharefolder",{number:n},function(n){$("#shareFolderContent").html(n)});$("#shareFolderModal").modal()}function fnFolderShareClicked(n){var t=$("#chkShareFolder").is(":checked");t?$("#folderShareUrl").removeClass("hidden"):$("#folderShareUrl").addClass("hidden");$.post("/note/updatefolder",{number:n,share:t},function(){fnLoadFolderList()})}function fnShowNoteVersions(n){fnLoadNoteVersions(n);$("#noteVersionsModal").modal()}function fnLoadNoteVersions(n){$.get("/notes/"+n+"/versions",{},function(n){$("#noteVersionsContent").html(n)})}function fnMenuActionDeleteFolder(n){var t=confirm(fnLookup("DeleteFolderConfirm1")+" '"+$("#folder_"+n+">a").text().trim()+"'? "+fnLookup("DeleteFolderConfirm2"));t==!0&&$.post("/note/deletefolder",{number:n},function(){fnLoadFolderList()})}function fnMenuActionRenameFolder(n){var t=prompt("Message",$("#folder_"+n+">a").text().trim());t&&$.post("/note/renamefolder",{number:n,name:t},function(){fnLoadFolderList()})}function fnCreateFolder(){$("#newFolder").val()!=""&&$.post("/note/createfolder",{name:$("#newFolder").val()},function(){fnLoadManageFolderContent()})}function fnDeleteFolder(n){var t=confirm(fnLookup("DeleteFolderConfirm1")+" '"+$("#editFolder_"+n).val()+"'? "+fnLookup("DeleteFolderConfirm2"));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",fnLookup("NoteContentOverLimit"));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",fnLookup("NoteContentOverLimit"));return}$("#saveNoteMessage").html(fnLookup("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(fnLookup("NoteSaved")).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",fnLookup("NoteContentOverLimit"));return}$("#saveNoteMessage").html(fnLookup("Saving"));$.post("/note/quickeditsave",{number:t,notecontent:n},function(n){n.status==="success"?($("#saveNoteMessage").html(n.message),$("#actionMessage").text(fnLookup("NoteSaved")).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(fnLookup("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(fnLookup("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(fnLookup("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,t){$("#noteAccessText").html(n);t=="Private"?($("#noteAccessText").parent().addClass("link-lock"),$("#noteAccessText").parent().removeClass("link-lockopen"),$("#noteAccessText").parent().removeClass("link-lockpassword")):t=="Password"?($("#noteAccessText").parent().addClass("link-lockpassword"),$("#noteAccessText").parent().removeClass("link-lock"),$("#noteAccessText").parent().removeClass("link-lockopen")):($("#noteAccessText").parent().addClass("link-lockopen"),$("#noteAccessText").parent().removeClass("link-lock"),$("#noteAccessText").parent().removeClass("link-lockpassword"))}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(fnLookup("CommentRequired"));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(fnLookup("DeleteFileConfirm"));t===!0&&$.post("/note/filedelete",{file:n},function(){fnLoadNoteFileList()})}function fnDeleteNote(n){var t=confirm(fnLookup("DeleteNoteConfirm"));t===!0&&$.post("/note/delete",{number:n},function(){window.location.href.indexOf(n)>0?window.location="/":($("#actionMessage").text(fnLookup("NoteDeleted")).show().delay(1e3).fadeOut(1e3),fnOpenFolder())})}function fnCopyNote(n){$.post("/note/copy",{number:n},function(){fnOpenFolder()})}function fnTinymceInit(n,t,i,r,u){u?tinymce.init({mode:"exact",elements:n,theme:"modern",content_css:t,body_class:"theme-"+i,plugins:["advlist autolink lists link image hr wordcount fullscreen media table textcolor tabfocus"],external_plugins:{emoticons:"/Scripts/tinymce4/custom-plugins/emoticons/plugin.js"},toolbar1:"undo redo | fontselect | fontsizeselect | bold | italic | styleselect | alignleft aligncenter | bullist numlist | outdent indent | hr | link | image | table | forecolor backcolor | emoticons | fullscreen",fontsize_formats:"8pt 10pt 12pt 14pt 16pt 18pt 20pt 22pt 24pt 36pt 48pt 72pt",image_advtab:!0,menubar:!1,height:"300px",relative_urls:!1,browser_spellcheck:!0,tabfocus_elements:"edit_title,btnSaveNote",auto_focus:!0,lanugage:r,file_picker_types:"image",images_upload_handler:function(n,t,i){var r=new XMLHttpRequest,u;r.withCredentials=!0;r.open("POST","/note/fileupload");r.onload=function(){if(r.status!==200){i("File failed to upload");return}var n=JSON.parse(r.responseText);if(n&&n.files||(n.hasWarnings=!0),n.isSuccess&&n.files[0]){t(n.files[0].path);n.autosavenotenumber!==null&&n.autosavenotenumber.length>0&&$("input[name='autosavenotenumber']").val(n.autosavenotenumber);fnLoadNoteFileList();return}if(n.hasWarnings&&n.warnings[0]){n.warnings[0].indexOf("Premium")>=-1?(tinymce.activeEditor.windowManager.close(),fnPremiumUpgrade()):i(n.warnings[0]);return}i("File failed to upload")};u=new FormData;u.append("file",n.blob(),n.filename());u.append("notenumber",Notepad.NoteEditMode==="new"?$("input[name='autosavenotenumber']").val():$("input[name='notenumber']").val());r.send(u)},setup:function(n){n.on("init",function(){this.getDoc().body.style.fontSize="14pt";this.getContentAreaContainer().firstChild.setAttribute("tabindex","2")});n.on("keydown",function(){Notepad.NoteContentChanged=!0});n.shortcuts.add("meta+s","",function(){fnAutoSaveNote()})}}):tinymce.init({mode:"exact",elements:n,theme:"modern",content_css:t,body_class:"theme-"+i,plugins:["advlist autolink lists link image hr wordcount fullscreen media table textcolor tabfocus"],external_plugins:{emoticons:"/Scripts/tinymce4/custom-plugins/emoticons/plugin.js"},toolbar1:"undo redo | fontselect | fontsizeselect | bold | italic | styleselect | alignleft aligncenter | bullist numlist | outdent indent | hr | link | image | table | forecolor backcolor | emoticons | fullscreen",fontsize_formats:"8pt 10pt 12pt 14pt 16pt 18pt 20pt 22pt 24pt 36pt 48pt 72pt",image_advtab:!0,menubar:!1,height:"300px",relative_urls:!1,browser_spellcheck:!0,tabfocus_elements:"edit_title,btnSaveNote",auto_focus:!0,lanugage:r,file_picker_types:"image",setup:function(n){n.on("init",function(){this.getDoc().body.style.fontSize="14pt";this.getContentAreaContainer().firstChild.setAttribute("tabindex","2")});n.on("keydown",function(){Notepad.NoteContentChanged=!0});n.shortcuts.add("meta+s","",function(){fnAutoSaveNote()})}})}var Notepad=Notepad||{};$(document).ready(function(){fnMobileMenu();$("#savedNotes").length&&fnOpenFolder();$("#edit_title").length&&($("#edit_title").val().length?$("#edit_textarea").focus():$("#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()})