// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * Adds a random image to the page.
 */
function randomMood() {
  // Pick a random index.
  const idx = Math.floor(Math.random() * 4) + 1;

  const imgUrl = "images/q" + idx + ".jpg";

  // Create the image element.
  const imgElement = document.createElement('img');
  imgElement.src = imgUrl;
  imgElement.height = "500";

  // Put it in a container.
  const imageContainer = document.getElementById('mood-container');
  imageContainer.innerHTML = '';
  imageContainer.appendChild(imgElement);
}

function showGallery() {
    const gallery = document.getElementById('gallery-container');
    for (var i = 0; i < 8; ++ i) {
        /* Add each picture to gallery by creating indep elements */
        const imgElem = document.createElement('img');
        imgElem.src = "images/film/"+i+".jpg";
        imgElem.height = "150";
        imgElem.style = "margin: 40px;";
        
        gallery.appendChild(imgElem);
    }
}

/* Create new element with the messages recieved from the ./data servlet in a json;
     is called when the page is reloaded by the _onload_ prop of the html body */
async function printServletMsg() {
    const limit = document.getElementById('max-comments-limit').value;
    const response = await fetch("/data?com-limit=" + limit);
    const parsed_json = await response.json();
    
    const comment_zone = document.getElementById('servlet-msg');
    comment_zone.innerHTML = "";
    for (comm of parsed_json) {
        const elem = document.createElement('p');
        elem.innerText = comm;
        elem.classList.add("comment-zone");
        comment_zone.appendChild(elem);
    }

    if (comment_zone.innerHTML == "") {
        comment_zone.innerHTML = "<p class=\"comment-zone\">No comments to display :(. Be the first one to leave a comment!</p>";
    }
}

async function deleteAllComments() {
    await fetch(new Request('/delete-data', {method: 'POST'}));
    await printServletMsg();
}

async function loadMap () {
    const BUH = {lat: 44.43, lng: 26.10};
    const map = new google.maps.Map(
        document.getElementById('map'),
        {center: BUH, zoom: 3});

   /*
    var BUHmarker = createMarker(map, 'Bucharest, Romania', BUH, 'I live here since 2000!');
    const CONmarker = createMarker(map, 'Constanta, Romania', {lat: 44.163818, lng: 28.633451}, 'Attended a 4-night music festival by the sea.');
    const OXFmarker = createMarker(map, 'Oxford, UK', {lat: 51.752490, lng: -1.251908}, 'I study here. So many great memories!');
    const VDImarker = createMarker(map, 'Val d\'Isere, France', {lat: 45.446212, lng: 6.977692}, 'I went skiing.');
    const ZRHmarker = createMarker(map, 'Zurich, Switzerland', {lat: 47.375978, lng: 8.541283}, 'Visited some friends.');
    const Bakumarker = createMarker(map, 'Baku, Azerbaijan', {lat: 40.407327, lng: 49.854926}, 'I took part in IOI! Also called the City of Wind for a good reason.');
    const Bratmarker = createMarker(map, 'Bratislava, Slovakia', {lat: 48.140940, lng: 17.103918}, 'Central European Olympiad and went rafting!');
    const STKmarker = createMarker(map, 'Stockholm, Sweden',{lat: 59.324801, lng: 18.068571}, 'A city I wanted to visit for some time. Formed from 14 islands!');
    const DOHmarker = createMarker(map, 'Doha, Qatar', {lat: 25.287784, lng: 51.530633}, 'One of the most impressive, unique and richest cities I\'ve seen! And hottest weather!');
*/
    const response = await fetch('/map2019');
    const json = await response.json();

    json.forEach(elem => {
        createMarker(map, elem.name, {lat: elem.lat, lng: elem.lng}, elem.description)});
}

function createMarker (map, name, pos, description) {
    var marker = new google.maps.Marker({position: pos, map: map, title: name});
    var window = new google.maps.InfoWindow({content: `<h1>${name}</h1>
                        <p style=\"color:black;\">${description}</p>`});

    marker.addListener('mouseover', function() { window.open(map, marker); });
    marker.addListener('mouseout', function() { window.close(); });
}
@@ -2695,1280 +2695,10 @@
 %7D);%0A
-%0A
   
- /*%0A    var BUHmarker = createMarker(map, 'Bucharest, Romania', BUH, 'I live here since 2000!');%0A    const CONmarker = createMarker(map, 'Constanta, Romania', %7Blat: 44.163818, lng: 28.633451%7D, 'Attended a 4-night music festival by the sea.');%0A    const OXFmarker = createMarker(map, 'Oxford, UK', %7Blat: 51.752490, lng: -1.251908%7D, 'I study here. So many great memories!');%0A    const VDImarker = createMarker(map, 'Val d%5C'Isere, France', %7Blat: 45.446212, lng: 6.977692%7D, 'I went skiing.');%0A    const ZRHmarker = createMarker(map, 'Zurich, Switzerland', %7Blat: 47.375978, lng: 8.541283%7D, 'Visited some friends.');%0A    const Bakumarker = createMarker(map, 'Baku, Azerbaijan', %7Blat: 40.407327, lng: 49.854926%7D, 'I took part in IOI! Also called the City of Wind for a good reason.');%0A    const Bratmarker = createMarker(map, 'Bratislava, Slovakia', %7Blat: 48.140940, lng: 17.103918%7D, 'Central European Olympiad and went rafting!');%0A    const STKmarker = createMarker(map, 'Stockholm, Sweden',%7Blat: 59.324801, lng: 18.068571%7D, 'A city I wanted to visit for some time. Formed from 14 islands!');%0A    const DOHmarker = createMarker(map, 'Doha, Qatar', %7Blat: 25.287784, lng: 51.530633%7D, 'One of the most impressive, unique and richest cities I%5C've seen! And hottest weather!');%0A*/
 %0A   
@@ -3325,13 +3325,14 @@
 lose(); %7D);%0A
-
 %7D
+%0A

Update script.js