+
+function find_game_start_idx(games) {
+ // Pick out a reasonable place to start the list. We'll show the last
+ // completed match and start from there.
+ let start_idx = games.length - 1;
+ for (let i = 0; i < games.length; ++i) {
+ if (isNaN(games[i].score1) || isNaN(games[i].score2) &&
+ games[i].score1 === games[i].score2) {
+ start_idx = i;
+ break;
+ }
+ }
+ if (start_idx > 0) start_idx--;
+ if (games.length >= max_list_len) {
+ start_idx = Math.min(start_idx, games.length - max_list_len);
+ }
+ return start_idx;
+}
+
+function find_num_pages(games) {
+ games = sort_game_list(games);
+ let start_idx = find_game_start_idx(games);
+ return Math.ceil((games.length - start_idx) / max_list_len);
+}
+
+function display_stream_schedule_parsed(teams, games, page) {
+ document.getElementById('entire-bug').style.display = 'none';
+
+ games = sort_game_list(games);
+ let start_idx = find_game_start_idx(games);
+
+ start_idx += page * max_list_len;
+ if (start_idx >= games.length) {
+ // Error.
+ return;
+ }
+
+ let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
+ let shortdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
+ let today = days[(new Date).getDay()];
+
+ let covered_days = [];
+ let row_num = 0;
+ for (let i = start_idx; i < games.length && row_num++ < max_list_len; ++i) {
+ if (i == start_idx || games[i].streamday != games[i - 1].streamday) {
+ covered_days.push(days[games[i].streamday]);
+ }
+ }
+
+ let carousel = document.getElementById('carousel');
+ clear_carousel(carousel);
+ addheading(carousel, 3, "Stream schedule, Trøndisk 2017<br />" + covered_days.join('/') + " (all times CET)");
+
+ let teams_to_idx = make_teams_to_idx(teams);
+ row_num = 0;
+ for (let i = start_idx; i < games.length && row_num < max_list_len; ++i) {
+ let tr = document.createElement("tr");
+
+ let name1 = teams[teams_to_idx[games[i].name1]].mediumname;
+ let name2 = teams[teams_to_idx[games[i].name2]].mediumname;
+
+ addtd(tr, "matchup", name1 + "–" + name2);
+ addtd(tr, "group", games[i].group_name);
+
+ if (!isNaN(games[i].score1) && !isNaN(games[i].score2) &&
+ games[i].score1 !== games[i].score2) {
+ addtd(tr, "streamtime", games[i].score1 + "–" + games[i].score2);
+ } else {
+ let streamtime = games[i].streamtime;
+ let streamday = days[games[i].streamday];
+ if (streamday !== today) {
+ streamtime = shortdays[games[i].streamday] + " " + streamtime;
+ }
+ addth(tr, "streamtime", streamtime);
+ }
+
+ row_num++;
+ carousel.appendChild(tr);
+ }
+
+ fade_in_rows(carousel);
+
+ carousel.style.display = 'table';
+};
+
+function get_group(group_name, cb)
+{
+ let req = new XMLHttpRequest();
+ req.onload = function(e) {
+ cb(JSON.parse(req.responseText), group_name);
+ };
+ req.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/122tIwrXTi5ug0Vv6Np5w3pVwEWE2KkjWxtzQQfGtOZA/values/\'' + group_name + '\'!A1:J50?key=AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU');