document.addEventListener('DOMContentLoaded', function() {
    RefreshTitlesathenspartyrnb();
  });
  function addTimeStamp() {
    const tstmp = new Date();
    return tstmp.getTime();
  }
  function RefreshTitlesathenspartyrnb() {
    fetch("https://onair.e-radio.gr/whatson/athensparty/athenspartyrnb/NowOnAir.xml?timestamp=" + addTimeStamp())
      .then(response => response.text())
      .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
      .then(ShowTitleArtistathenspartyrnb);
    fetch("https://onair.e-radio.gr/whatson/athensparty/athenspartyrnb/AirPlayNext.xml?timestamp=" + addTimeStamp())
      .then(response => response.text())
      .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
      .then(ShowNextSongsathenspartyrnb);
    fetch("https://onair.e-radio.gr/whatson/athensparty/athenspartyrnb/AirPlayHistory.xml?timestamp=" + addTimeStamp())
      .then(response => response.text())
      .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
      .then(ShowLastSongsathenspartyrnb);
  }
  function ShowTitleArtistathenspartyrnb(xml) {
    const songs = xml.getElementsByTagName("Song");
    for (let song of songs) {
      const title = song.getAttribute("title");
      document.getElementById("athenspartyrnb_title").innerHTML = title;
      const artists = song.getElementsByTagName("Artist");
      for (let artist of artists) {
        const name = artist.getAttribute("name");
        document.getElementById("athenspartyrnb_artist").innerHTML = name;
      }
    }
  }
  function ShowNowPicathenspartyrnb(txt) {
    const img = document.getElementById("athenspartyrnb_pic");
    if (txt) {
      img.src = txt;
      img.style.display = 'block';
    } else {
      img.src = '';
      img.style.display = 'none';
    }
  }
  function ShowLastSongsathenspartyrnb(xml) {
    let tmpLastSongs = "";
    const songs = xml.getElementsByTagName("Song");
    for (let song of songs) {
      tmpLastSongs += song.getElementsByTagName("Info")[0].getAttribute("StartTime") + " > ";
      tmpLastSongs += "" + song.getAttribute("title") + " > ";
      tmpLastSongs += song.getElementsByTagName("Artist")[0].getAttribute("name") + "   
";
    }
    document.getElementById("athenspartyrnb_lastsongs").innerHTML = tmpLastSongs;
  }
  function ShowNextSongsathenspartyrnb(xml) {
    const songs = xml.getElementsByTagName("Song");
    let j = 0;
    for (let song of songs) {
      if (j === 0) {
        document.getElementById("athenspartyrnb_nexttitle").innerHTML = song.getAttribute("title");
        document.getElementById("athenspartyrnb_nextartist").innerHTML = song.getElementsByTagName("Artist")[0].getAttribute("name");
      }
      j++;
      document.getElementById("nextheader").style.display = 'block';
    }
  }
  var oRefreshathenspartyrnb;
  oRefreshathenspartyrnb = window.setInterval(RefreshTitlesathenspartyrnb, 50000);