<!--
// Coded by: Golddess
// Version:  1.00 August 3, 2005
// Use:      Displays basic timers for the schedule of the Chocobo races.
//           Uses some items from mithratime.js
//
// Feel free to copy and display on your website, but please give credit where credit is due
// by mentioning MithraPride as the source and linking back to http://www.mithrapride.org/
// on the page that displays the clock.
//
// Version Update List:
//   1.20: Implemented ability to chose a different starting time other than the present.
//   1.00: Initial version!!
//           -Windy, Basty, and Sandy schedules, time limits, and rewards for making the time limits listed.
//           -Time limits and rewards obtained from mysterytour.

//Various variables used in the construction of the page
DayTable    = "";
DayNum      = -1;
CityFrom    = -1;
UserTime    = 0;

// Chocobo Races
WindyChoco = new Array("<font color=#008811>Windurst Woods -> Port Jeuno</font>",             "<font color=#008811>Windurst Woods -> Southern San&nbsp;d'Oria</font>", "<font color=#008811>Windurst Woods -> Bastok Mines</font>"          );
SandyChoco = new Array("<font color=#DD0000>Southern San&nbsp;d'Oria -> Bastok Mines</font>", "<font color=#DD0000>Southern San&nbsp;d'Oria -> Windurst Woods</font>", "<font color=#DD0000>Southern San&nbsp;d'Oria -> Upper Jeuno</font>" );
BastyChoco = new Array("<font color=#0000DD>Bastok Mines -> Windurst Woods</font>",           "<font color=#0000DD>Bastok Mines -> Lower Jeuno</font>",                "<font color=#0000DD>Bastok Mines -> Southern San&nbsp;d'Oria</font>");
WindyChocoTime = new Array("<font color=#008811>15:29</font>", "<font color=#008811>28:29</font>", "<font color=#008811>32:29</font>");
SandyChocoTime = new Array("<font color=#DD0000>20:00</font>", "<font color=#DD0000>28:29</font>", "<font color=#DD0000>13:29</font>");
BastyChocoTime = new Array("<font color=#0000DD>32:29</font>", "<font color=#0000DD>18:29</font>", "<font color=#0000DD>20:00</font>");
WindyChocoReward = new Array("<font color=#008811>Windurst Woods Glyph</font>", "<font color=#008811>Miratete's Memoirs</font>", "<font color=#008811>Miratete's Memoirs</font>"            );
SandyChocoReward = new Array("<font color=#DD0000>Dragon Chronicles</font>",    "<font color=#DD0000>Miratete's Memoirs</font>", "<font color=#DD0000>Southern San&nbsp;d'Oria Glyph</font>");
BastyChocoReward = new Array("<font color=#0000DD>Miratete's Memoirs</font>",   "<font color=#0000DD>Bastok Mines Glyph</font>", "<font color=#0000DD>Dragon Chronicles</font>"             );

function printTime() {
  // The current Earth time
  Now = new Date();

  // Calculates the current Earth time in milliseconds and the Vana'diel time in seconds
  eTime = Now.getTime();
  vTime = (eTime + Diff) * VanaToEarth;

  // Formats the current Earth and Vana'diel Time for display
  EarthTxt = CalculateEarthTime(Now);
  VanaTxt  = CalculateVanaTime(vTime);

  // Calculates the Conquest update
  ConqLimit = ConqUpdate(vTime);

  // # of Vana'diel seconds into the new Vana'diel day  
  VDSiD  = (vTime - ((Math.floor(vTime / (HourPDay * MinPHour * SecPMin))) * HourPDay * MinPHour * SecPMin));



  /////////////////////////////////////////////////////////////////////////////
  // Chocobo Race Time Table                                                 //
  /////////////////////////////////////////////////////////////////////////////
  if (UserTime == 0) {
    vTempTime1 = Math.floor( vTime            / (SecPMin * MinPHour * HourPDay)) * (SecPMin * MinPHour * HourPDay);
    vTempTime2 = Math.floor((vTime - SecPMin) / (SecPMin * MinPHour * HourPDay)) * (SecPMin * MinPHour * HourPDay);

    if ((eval(document.MithraTimer.DayNumBox.value) != 0 || DayNum != 0) && (DayNum != eval(document.MithraTimer.DayNumBox.value) || CityFrom != eval(document.MithraTimer.CityFromBox.value) || vTempTime1 != vTempTime2)) {
      DayNum   = eval(document.MithraTimer.DayNumBox.value);
      CityFrom = eval(document.MithraTimer.CityFromBox.value);
      DayTable = "";
      if (DayNum != 0) {
        DayTable = DayTimeTable(DayNum, DayTable, CityFrom, vTime);
      }

      document.getElementById("DayTableBox").innerHTML = DayTable;
    }
  } else {
    if ((eval(document.MithraTimer.DayNumBox.value) != 0 || DayNum != 0) && (DayNum != eval(document.MithraTimer.DayNumBox.value) || CityFrom != eval(document.MithraTimer.CityFromBox.value))) {
      DayNum   = eval(document.MithraTimer.DayNumBox.value);
      CityFrom = eval(document.MithraTimer.CityFromBox.value);
      DayTable = "";
      if (DayNum != 0) {
        DayTable = DayTimeTable(DayNum, DayTable, CityFrom, UserTime);
      }

      document.getElementById("DayTableBox").innerHTML = DayTable;
    }
  }
  /////////////////////////////////////////////////////////////////////////////
  // Chocobo Race Time Table                                                 //
  /////////////////////////////////////////////////////////////////////////////



  /////////////////////////////////////////////////////////////////////////////
  // Assigns all other values to the webpage                                 //
  /////////////////////////////////////////////////////////////////////////////
  document.getElementById("VanaBox"     ).innerHTML = VanaTxt;
  document.getElementById("EarthBox"    ).innerHTML = EarthTxt;
  document.getElementById("ConqLimitBox").innerHTML = ConqLimit;
  /////////////////////////////////////////////////////////////////////////////
  // Assigns all values to the webpage                                       //
  /////////////////////////////////////////////////////////////////////////////



  setTimeout("printTime()", 1000);
}



function DayTimeTable(DayNum, DayTable, CityFrom, LocalTime) {
  var i          = 0;
  var vTempTime  = Math.floor(LocalTime / (SecPMin * MinPHour * HourPDay)) * (SecPMin * MinPHour * HourPDay);
  var vTempDay   = 0;
  var SpanLength = 3;

  DayTable  = "<table border=0 cellpadding=2 cellspacing=0 width=100%>";
  DayTable += "<tr><td valign=bottom>Starting</td><td valign=bottom>Ending</td><td valign=bottom>From -> To</td><td valign=bottom>Max Time</td><td valign=bottom>Reward</td></tr>";

  do {
    vTempDay  = Math.floor(vTempTime / (HourPDay * MinPHour * SecPMin));

    if (CityFrom == 0) {
      SpanLength = 3;
    } else if (CityFrom < 10 || (CityFrom == 10 && vTempDay % 3 != 1)) {
      SpanLength = 1;
    } else {
      SpanLength = 2;
    }
    DayTable += "<tr>"
    DayTable += "<td rowspan=" + SpanLength + "><small>" + CalculateEarthTime2(new Date(Math.floor(vTempTime / VanaToEarth) - Diff)) + "</td>";
    vTempTime = vTempTime + (SecPMin * MinPHour * HourPDay);
    DayTable += "<td rowspan=" + SpanLength + "><small>" + CalculateEarthTime2(new Date(Math.floor(vTempTime / VanaToEarth) - Diff)) + "</td>";

    if ((CityFrom == 0                        ) ||
        (CityFrom == 1                        ) ||
        (CityFrom == 5  && (vTempDay % 3 == 2)) ||
        (CityFrom == 6  && (vTempDay % 3 == 1)) ||
        (CityFrom == 7  && (vTempDay % 3 == 0)) ||
        (CityFrom == 8  && (vTempDay % 3 == 0)) ||
        (CityFrom == 10 && (vTempDay % 3 != 0)) ) {
      DayTable += "<td><small>" + WindyChoco[vTempDay % 3] + "</td>";
      DayTable += "<td><small>" + WindyChocoTime[vTempDay % 3] + "</td>";
      DayTable += "<td><small>" + WindyChocoReward[vTempDay % 3] + "</td>";
      DayTable += "</tr>"
      DayTable += "<tr>"
    }
    if ((CityFrom == 0                        ) ||
        (CityFrom == 2                        ) ||
        (CityFrom == 4  && (vTempDay % 3 == 0)) ||
        (CityFrom == 6  && (vTempDay % 3 == 2)) ||
        (CityFrom == 7  && (vTempDay % 3 == 1)) ||
        (CityFrom == 8  && (vTempDay % 3 == 1)) ||
        (CityFrom == 9  && (vTempDay % 3 == 2)) ||
        (CityFrom == 10 && (vTempDay % 3 == 0)) ) {
      DayTable += "<td><small>" + BastyChoco[vTempDay % 3] + "</td>";
      DayTable += "<td><small>" + BastyChocoTime[vTempDay % 3] + "</td>";
      DayTable += "<td><small>" + BastyChocoReward[vTempDay % 3] + "</td>";
      DayTable += "</tr>"
      DayTable += "<tr>"
    }
    if ((CityFrom == 0                        ) ||
        (CityFrom == 3                        ) ||
        (CityFrom == 4  && (vTempDay % 3 == 1)) ||
        (CityFrom == 5  && (vTempDay % 3 == 0)) ||
        (CityFrom == 7  && (vTempDay % 3 == 2)) ||
        (CityFrom == 8  && (vTempDay % 3 == 2)) ||
        (CityFrom == 9  && (vTempDay % 3 == 0)) ||
        (CityFrom == 10 && (vTempDay % 3 == 1)) ) {
      DayTable += "<td><small>" + SandyChoco[vTempDay % 3] + "</td>";
      DayTable += "<td><small>" + SandyChocoTime[vTempDay % 3] + "</td>";
      DayTable += "<td><small>" + SandyChocoReward[vTempDay % 3] + "</td>";
      DayTable += "</tr>"
    }

    DayTable += "<tr>"
    DayTable += "<td colspan=5></td>";
    DayTable += "</tr>"

    i++;
  } while (i < DayNum);

  DayTable += "</table>";

  return DayTable;
}



function SetClock() {
  UserTimeTemp = new Date();
  UserTimeTemp.setFullYear(eval(document.getElementById("DateYear"   ).value)    );
  UserTimeTemp.setMonth(   eval(document.getElementById("DateMonth"  ).value) - 1);
  UserTimeTemp.setDate(    eval(document.getElementById("DateDay"    ).value)    );
  UserTimeTemp.setHours(   eval(document.getElementById("DateHours"  ).value)    );
  UserTimeTemp.setMinutes( eval(document.getElementById("DateMinutes").value)    );
  UserTimeTemp.setSeconds( 0);
  UserTime = (UserTimeTemp.getTime() + Diff) * VanaToEarth;

  DayNum   = eval(document.MithraTimer.DayNumBox.value);
  CityFrom = eval(document.MithraTimer.CityFromBox.value);
  DayTable = "";

  if (DayNum != 0) {
    DayTable = DayTimeTable(DayNum, DayTable, CityFrom, UserTime);
  }

  document.getElementById("DayTableBox").innerHTML = DayTable;
}



function ResetClock() {
  var eTime = Now.getTime();
  var vTime = (eTime + Diff) * VanaToEarth;

  document.getElementById("DateYear").value = "Year";
  document.getElementById("DateMonth").value = "Month";
  document.getElementById("DateDay").value = "Day";
  document.getElementById("DateHours").value = "Hours";
  document.getElementById("DateMinutes").value = "Minutes";
  UserTime = 0;

  DayNum   = eval(document.MithraTimer.DayNumBox.value);
  CityFrom = eval(document.MithraTimer.CityFromBox.value);
  DayTable = "";

  if (DayNum != 0) {
    DayTable = DayTimeTable(DayNum, DayTable, CityFrom, vTime);
  }

  document.getElementById("DayTableBox").innerHTML = DayTable;
}
// -->
