// Admin Nightmode Switch
var nmButton = document.getElementById("nightmode");
var nmStylesheet = document.getElementById("nightmodeon");

if (localStorage.getItem('lastActiveNmSheet') && localStorage.getItem('lastActiveNmHtml')) {
   nmStylesheet.setAttribute('href', localStorage.getItem('lastActiveNmSheet'));
   nmButton.innerHTML = localStorage.getItem('lastActiveNmHtml');
}

function nightmode() {
  var nmButton = document.getElementById("nightmode");
  var nmIconDay = "<span><i class=\"fa fa-sun-o\"></i></span>";
  var nmIconNight = "<span><i class=\"fa fa-moon-o\"></i></span>";

  if (nmButton.innerHTML === nmIconDay) {
    nmButton.innerHTML = nmIconNight;
    nmStylesheet.setAttribute('href', 'view/stylesheet/elmigo_nighton.css');
    localStorage.setItem('lastActiveNmSheet', 'view/stylesheet/elmigo_nighton.css');
    localStorage.setItem('lastActiveNmHtml', nmIconNight);
  } else {
    nmButton.innerHTML = nmIconDay;
    nmStylesheet.setAttribute('href', '#');
    localStorage.setItem('lastActiveNmSheet', '#');
    localStorage.setItem('lastActiveNmHtml', nmIconDay);
  }
}
