

/* created 2021.01.21  whh mario.js     */
/* update 2021.01.21       */
/* updated  whh     */
/* updated  whh      */




//Floating scroll and refresh buttons
    //Floating scroll and refresh buttons
      //Now in Hamburger


        // When the user scrolls down 500px from the top of the document, show the buttons
        window.onscroll = function() {scrollFunction()};

        function scrollFunction() {

          if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
            document.getElementById("myBtn").style.display = "block";
            document.getElementById("myBtnB").style.display = "block";
            //alert ("block");
          } else {
            document.getElementById("myBtn").style.display = "none";
            document.getElementById("myBtnB").style.display = "none";
            //alert ("none");
          }
        }

        //***************************************************************************

            // When the user clicks on the up button, scroll to the top of the document
            function topFunction() {
              $('html, body').animate({scrollTop:0},1200, 'swing');
            }

        //***************************************************************************

            // When the user clicks on the button, refresh/reload the page
            function refreshPageFunction(){
            //window.location.reload();
            $('html, body').animate({scrollTop:0},1200, 'swing');
             //alert ("Refresh")
            };

            //***************************************************************************

                // When the user clicks on the down button, scroll to the top of the document

            function bottomFunction() {
              $("html, body").animate({ scrollTop: $(document).height()-$(window).height()}, 1200, 'swing');
            }


        //***************************************************************************

          // When the user clicks on the explore button scrolls to id = startpage
          // When the user clicks on the explore button scrolls to id = startpage
          // When the user clicks on the explore button scrolls to id = startpage

          function goStartPage(){
              $('html, body').animate({scrollTop:$("#formstart").offset().top}, 1200);
          }



/* Toggle between showing and hiding the navigation menu links when the user clicks on the hamburger menu / bar icon */
/* Toggle between showing and hiding the navigation menu links when the user clicks on the hamburger menu / bar icon */
        function hamLinks() {
          console.log ("hamLinks");
          var x = document.getElementById("myLinks");
          if (x.style.display === "block") {
            x.style.display = "none";
          } else {
            x.style.display = "block";
          }
        };



/* Hiding the navigation menu links when mouseup on the page */
/* Hiding the navigation menu links when mouseup on the page */
document.addEventListener('mouseup', function(e) {
  var container = document.getElementById('myLinks');
  if (!container.contains(e.target)) {
    container.style.display = 'none';
  }
});

// Safety pop and cookie managment
// Safety pop and cookie managment
// Safety pop and cookie managment
/*
    function popupFunction() {

console.log("PopUPFUNCTION");

            // parameters for safety cookie
            var cookieName = "ma";
            var cookieValue = "yup";
            var daysToExpire = 1;


            // test to see if safety cookie exits
            // test to see if safety cookie exits
            var readC = accessCookie(cookieName);

//console.log("Access Cookie: " + readC);

            // test if value of safety cookie is 'yup'
            // if not show popup and create the cookie
            // is cookie exists do nothing
             if (readC !== "yup") {

               // Get the modal
               var modal = document.getElementById("myModal");
               // make popup visible
                 modal.style.display = "block";

              // no safety cookie exists so create one so popup does not always show
              // no safety cookie exists so create one so popup does not always show
              createCookie(cookieName,cookieValue,daysToExpire);

             }
             else {
               // do nothing safety cookie exists do not show popup
               // do nothing safety cookie exists do not show popup
               // do nothing safety cookie exists do not show popup
//console.log("PopUPFUNCTION_DO NOTHING: " + readC);
               // do nothing safety cookie exists do not show popup
             };


      }; // end popupFunction

      // create safety cookie is in the browser
      // create safety cookie is in the browser
      		function createCookie(cookieName,cookieValue,daysToExpire)
              {
                var date = new Date();
                date.setTime(date.getTime()+(daysToExpire*24*60*60*1000));
                document.cookie = cookieName + "=" + cookieValue + "; expires=" + date.toGMTString();
//console.log ("createCookie: " + cookieName);
              }

          // see if safety cookie is in the browser
          // see if safety cookie is in the browser
          function accessCookie(cname) {
            var name = cname + "=";
            var decodedCookie = decodeURIComponent(document.cookie);
            var ca = decodedCookie.split(';');
            for(var i = 0; i <ca.length; i++) {
              var c = ca[i];
              while (c.charAt(0) == ' ') {
                c = c.substring(1);
              }
              if (c.indexOf(name) == 0) {

                var value = c.substring(name.length, c.length);
//console.log ("createCookie: " + value);
                return c.substring(name.length, c.length);
              }
            }
//console.log ("no cookie " + cname);
            return "";
          }

          // create cookie to for safety alert
          // create cookie to for safety alert
      		function checkCookie()
              {
                var user = accessCookie("testCookie");
                if (user!="")
              	alert("Welcome Back " + user + "!!!");
                else
                {
                  user = prompt("Please enter your name");
                  num = prompt("How many days you want to store your name on your computer?");
                  if (user!="" && user!=null)
                  {
                  createCookie("testCookie", user, num);
                  }
                }
              }



       // close model click X or anywhere on screen
       // close model click X or anywhere on screen

          var modal = document.getElementById("myModal");

          // Get the <span> element that closes the modal
          var span = document.getElementsByClassName("close")[0];

          // When the user clicks on <span> (x), close the modal
          span.onclick = function() {
            modal.style.display = "none";
          };
          */

/*
          // When the user clicks anywhere outside of the modal, close it
          window.onclick = function(event) {
            if (event.target == modal) {
              modal.style.display = "none";
            }
          };
*/
