/* * * * * * * * * *    SUNTABLE SCRIPT    * * * * * * * * * *\
*                                                             *
*  Uses the SUNRISET script to computes Sun rise/set times,   *
*  start/end of twilight, and displays them in a table.       *
*                                                             *
*  In English (lCode = 0) or Swedish (lCode = 1)              *
*                                                             *
*  --  Written by Bo Johansson  1998-05-24 , 1998-06-29  --   *
*      Minor corrections 2000-01-03 , 2000-03-27              *
*                                                             *
*  --  http://w1.545.telia.com/%7Eu54504162/index_e.htm   --  *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

function toDayValues(name, lat, lon, lCode)
{
  toDay = new Date();

  var year = toDay.getYear();

  if (year < 1900)         // **** fixed 2000-01-03
    year += 1900;

  var month = (toDay.getMonth() + 1);

  var day =  toDay.getDate();

  sunRiseSet(year,month,day,lat,lon);

  civTwilight(year,month,day,lat,lon);

  showTable(name, lat, lon, year, month, day, lCode);
}


function showTable(name, lat, lon, year, month, day, lCode)
{
  var absLat = Math.abs(lat)
  var absLon = Math.abs(lon)

  document.write("<TABLE BORDER=1 WIDTH='100%' BGCOLOR='#ffffff'>\n")
  document.write("<TR><TD COLSPAN=2 ALIGN=CENTER>")
  document.write(name + "<\/TD><\/TR>\n")
  
  document.write("<TR><TD ALIGN=CENTER COLSPAN=2>" + absLat)

  if(lat < 0)
    document.write("S ")

  else
    document.write("N ")

  document.write(absLon)

  if(lon < 0)
    document.write("W")

  else
    document.write("E")

  document.write("<\/TD><\/TR>\n")
  

  document.write("<TR><TD COLSPAN=2 ALIGN=CENTER>" + year +"-")

  if(month < 10)
    document.write("0")

  document.write(month + "-")

  if(day < 10)
    document.write("0")

  document.write(day + "<\/TD><\/TR>\n")

  var twsText = "Twilight starts: "
  var tweText = "Twilight ends: "
  var twAllText = "Twilight all night"
  var twNoText = "No twilight this day"

  var srText = "Sunrise: "
  var ssText = "Sunset: "
  var sAllText = "Sun is up 24 hrs"
  var sNoText = "Sun is down 24 hrs"


  if(lCode == 1)
  {
    twsText = "Gryning: "
    tweText = "Skymning: "
    twAllText = "Gryning/skymning<BR>hela natten"
    twNoText = "Ingen gryning/skymning<BR>detta dygn"

    srText = "Soluppgång: "
    ssText = "Solnedgång: "
    sAllText = "Solen uppe 24 tim."
    sNoText = "Solen nere 24 tim."
  }


  var twst_h = Math.floor(twStartT)
  var twst_m = Math.floor((twStartT - twst_h)*60)

  var sris_h = Math.floor(sRiseT)
  var sris_m = Math.floor((sRiseT - sris_h)*60)

  var sset_h = Math.floor(sSetT)
  var sset_m = Math.floor((sSetT - sset_h)*60)

  var twen_h = Math.floor(twEndT)
  var twen_m = Math.floor((twEndT - twen_h)*60)

  if(twStatus == 0)
  {
    document.write("<TR><TD ALIGN=RIGHT>" + twsText + "<\/TD>")
    document.write("<TD>")

    if(twst_h < 10)
      document.write("0")

    document.write(twst_h + ".")

    if(twst_m < 10)
      document.write("0")

    document.write(twst_m + "<\/TD><\/TR>\n")
  }

  else if(twStatus > 0 && srStatus <= 0)
  {
    document.write("<TR><TD COLSPAN=2>" + twAllText)
    document.write("<\/TD><\/TR>\n")
  }

  else
  {
    document.write("<TR><TD COLSPAN=2>" + twNoText)
    document.write("<\/TD><\/TR>\n")
  }


  if(srStatus == 0)
  {
    document.write("<TR><TD ALIGN=RIGHT>" + srText)
    document.write("<\/TD><TD>")
    
    if(sris_h < 10)
      document.write("0")

    document.write(sris_h + ".")

    if(sris_m < 10)
      document.write("0")

    document.write(sris_m + "<\/TD><\/TR>\n")
    
    document.write("<TR><TD ALIGN=RIGHT>" + ssText)
    document.write("<\/TD><TD>")

    if(sset_h < 10)
      document.write("0")

    document.write(sset_h + ".")

    if(sset_m < 10)
      document.write("0")

    document.write(sset_m + "<\/TD><\/TR>\n")
  }

  else if(srStatus > 0)
  {
    document.write("<TR><TD COLSPAN=2>" + sAllText)
    document.write("<\/TD><\/TR>\n")
  }

  else
  {
    document.write("<TR><TD COLSPAN=2>" + sNoText)
    document.write("<\/TD><\/TR>\n")
  }

  if(twStatus == 0)
  {
    document.write("<TR><TD ALIGN=RIGHT>" + tweText + "<\/TD>")
    document.write("<TD>")

    if(twen_h < 10)
      document.write("0")

    document.write(twen_h + ".")

    if(twen_m < 10)
      document.write("0")

    document.write(twen_m + "<\/TD><\/TR>\n")
    }
  document.write("<\/TABLE>")
}

/* * * * * * * * *   SUNTABLE SCRIPT - END -  * * * * * * * * */

