ClockID = 0;

function UpdateClock() {
  CountDown = CountDown - 1;
  CountDownSubtitle = "";
  
  if (CountDown > 86400) {
    CountDownText = "The DoZ begins in ";
    RemCountDown = CountDown - 86400;
  } else
  if (CountDown > 0) {
    CountDownText = "The DoZ enters grace period in ";
    RemCountDown = CountDown;
  } else
  if (CountDown > -(60*60)) {
    CountDownText = "The grace period ends in ";
    RemCountDown = CountDown + (60*60);
    
    if (CountDown > -(15*60)) {
      CountDownSubtitle = "(Currently penalty-free)";
    } else
    if (CountDown > -(30*60)) {
      CountDownSubtitle = "(10% penalty)";
    } else
    if (CountDown > -(45*60)) {
      CountDownSubtitle = "(20% penalty)";
    } else
    if (CountDown > -(60*60)) {
      CountDownSubtitle = "(30% penalty)";
    } 
  } else {
    document.getElementById("dozclock").innerHTML = "Submissions closed. The DoZ is over.";
    document.getElementById("dozclocksubtitle").innerHTML = "";
    clearInterval(ClockID);
    return;
  }
  
  
  CountDownDays = Math.floor(RemCountDown / 86400);
  CountDownHours = Math.floor(RemCountDown % 86400 / 3600);
  CountDownMinutes = Math.floor(RemCountDown % 3600 / 60);
  CountDownSeconds = Math.floor(RemCountDown % 60);
  
  ClockString = CountDownText;
  
  if (RemCountDown >= 86400) {
    ClockString += "<strong>" + CountDownDays + "</strong>" + (CountDownDays == 1 ? " day, " : " days, ");
  }
  if (RemCountDown >= 3600) {
    ClockString += "<strong>" + CountDownHours + "</strong>" + (CountDownHours == 1 ? " hour, " : " hours, ");
  }
  if (RemCountDown >= 60) {
    ClockString += "<strong>" + CountDownMinutes + "</strong>" + (CountDownMinutes == 1 ? " minute and " : " minutes and ");
  }
  ClockString += "<strong>" + CountDownSeconds + "</strong>" + (CountDownSeconds == 1 ? " second." : " seconds.");
  
  if (CountDown == 86400) {
    location.reload();
  }
  
  document.getElementById("dozclock").innerHTML = ClockString;
  document.getElementById("dozclocksubtitle").innerHTML = CountDownSubtitle;
}

if (CountDown > -3600) {
  ClockID = setInterval("UpdateClock()", 1000);
}

