1let count = 0;
2$(document).ready(function () {
3    //Default Start date value
4    let today = new Date().toISOString().split('T')[0];
5    $("#lstartdate").val(today);
6
7    //Default end date value minus one month
8    let todayminusOneMonth = new Date();
9    todayminusOneMonth.setMonth(todayminusOneMonth.getMonth() + 1);
10    $("#lenddate").val(todayminusOneMonth.toISOString().split('T')[0]);
11
12    // Sets the values in the preview
13    const author = document.getElementsByClassName("lauthor")[0].value;
14
15    document.getElementsByClassName("date-author")[0].innerHTML = `( ${today}, ${author} )`;
16
17    // selecting the elements for which we want to add a tooltip
18    const target = document.getElementById("target-icon");
19    const tooltip = document.getElementById("tooltip-text");
20
21    // change display to 'block' on mouseover
22    target.addEventListener('mouseover', () => {
23        tooltip.style.display = 'block';
24    }, false);
25
26    // change display to 'none' on mouseleave
27    target.addEventListener('mouseleave', () => {
28        tooltip.style.display = 'none';
29    }, false);
30
31    if (window.location.href.includes("&submitted=true")) {
32        createInfoMessage();
33    }
34    if (window.location.href.includes("&fileexists=false")) {
35        pageMissing();
36    }
37
38});
39async function pageMissing() {
40    $('.error-message')[0].style.display = "block";
41    await new Promise(r => setTimeout(r, 4000));
42    $('.error-message')[0].style.animation = "fadeOutAnimation 1s";
43    await new Promise(r => setTimeout(r, 1000));
44    $('.error-message')[0].style.display = "none";
45
46    // removes the param from url without reloading
47    window.history.pushState({}, '', window.location.href.replace("&fileexists=false", ""));
48}
49/**
50 * creates a pop up message when
51 */
52async function createInfoMessage() {
53    $('.info-message')[0].style.display = "block";
54    await new Promise(r => setTimeout(r, 4000));
55    $('.info-message')[0].style.animation = "fadeOutAnimation 1s";
56    await new Promise(r => setTimeout(r, 1000));
57    $('.info-message')[0].style.display = "none";
58
59    // removes the param from url without reloading
60    window.history.pushState({}, '', window.location.href.replace("&submitted=true", ""));
61}
62/**
63 * adds bold into the textarea
64 */
65function addBold() {
66    document.getElementById("lnews").value += "<b></b>";
67}
68/**
69 * adds italic into the textarea
70 */
71function addItalic() {
72    document.getElementById("lnews").value += "<i></i>";
73}
74/**
75 * adds underline into the textarea
76 */
77function addUnderline() {
78    document.getElementById("lnews").value += "<u></u>";
79}
80
81function HeaderChange() {
82    document.getElementsByClassName("header")[0].innerHTML = document.getElementsByClassName("lheader")[0].value;
83}
84function SubtitleChange() {
85    document.getElementsByClassName("subtitle")[0].innerHTML = document.getElementsByClassName("lsubtitle")[0].value;
86}
87function DateAuthorChange() {
88    const startdate = document.getElementsByClassName("lstartdate")[0].value;
89    const author = document.getElementsByClassName("lauthor")[0].value;
90
91    document.getElementsByClassName("date-author")[0].innerHTML = `( ${startdate}, ${author} )`;
92}
93function NewsChange() {
94    document.getElementsByClassName("news")[0].innerHTML = document.getElementsByClassName("textlnews")[0].value;
95}