/* * * * * * * * * *    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   --  *
*                                                             *
*  2009-01-04	Modified by me.                               *
*               - No html-table                               *
*               - MET instead of GMT                          *
*               - code cleaning etc.                          *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

function toDayValues(name, lat, lon, lCode)
{
  toDay = new Date();

  var year = toDay.getYear();

  if (year < 1900) 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)

	/*****************/
	/* Print Name    */
	/*****************/
	document.write("<p><b>" + name + "</b><br />")

	/*****************/
	/* Print Latitud */
	/*****************/
	document.write("Lat." + absLat)

	if(lat < 0) document.write("S&nbsp;")

	else document.write("N&nbsp;")

	/******************/
	/* Print Longitud */
	/******************/
	document.write("Long." + absLon)

	if(lon < 0) document.write("V<br />")

	else document.write("O<br />")

	/**************/
	/* Print Date */
	/**************/
	/* document.write("Ber\u00E4knade v\u00E4rden " + year +"-") */
	document.write("Ber\u00E4kn. v\u00E4rden " + year +"-")

	if(month < 10) document.write("0")
	document.write(month + "-")

	if(day < 10) document.write("0")
	document.write(day + "<br />")

	/***********************/
	/* Prepare textstrings */
	/***********************/
	var timeoffset = 0
	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)
	{
		timeoffset = +1
		twsText = "Gryning: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
		tweText = "Skymning: &nbsp;&nbsp;&nbsp;"
		twAllText = "Gryning/skymning<br />hela natten"
		twNoText = "Ingen gryning/skymning<br />detta dygn"

		srText = "Soluppg\u00E5ng: "
		ssText = "Solnedg\u00E5ng: "
		sAllText = "Solen uppe 24 tim."
		sNoText = "Solen nere 24 tim."
	}

	var twst_h = Math.floor(twStartT + timeoffset)
	var twst_m = Math.floor((twStartT + timeoffset - twst_h)*60)

	var sris_h = Math.floor(sRiseT + timeoffset)
	var sris_m = Math.floor((sRiseT + timeoffset - sris_h)*60)

	var sset_h = Math.floor(sSetT + timeoffset)
	var sset_m = Math.floor((sSetT + timeoffset - sset_h)*60)

	var twen_h = Math.floor(twEndT + timeoffset)
	var twen_m = Math.floor((twEndT + timeoffset - twen_h)*60)

	/***************************************/
	/* Print Twilight text string with data */
	/***************************************/
	if(twStatus == 0)
	{
		document.write(twsText)

		if(twst_h < 10) document.write("0")
		document.write(twst_h + ".")

		if(twst_m < 10) document.write("0")
		document.write(twst_m + "<br />")
	}

	else if(twStatus > 0 && srStatus <= 0) document.write(twAllText + "<br />")

	else document.write(twNoText + "<br />")

	/***************************************/
	/* Print Sunrise text string with data */
	/***************************************/
	if(srStatus == 0)
	{
		document.write(srText)
    
		if(sris_h < 10) document.write("0")
		document.write(sris_h + ".")

		if(sris_m < 10) document.write("0")
		document.write(sris_m + "<br />")
    
		document.write(ssText)

		if(sset_h < 10) document.write("0")
		document.write(sset_h + ".")

		if(sset_m < 10) document.write("0")
		document.write(sset_m + "<br />")
	}

	else if(srStatus > 0) document.write(sAllText + "<br />")

	else document.write(sNoText + "<br />")

	/***************************************/
	/* Print Twilight text string with data */
	/***************************************/
	if(twStatus == 0)
	{
		document.write(tweText)

		if(twen_h < 10) document.write("0")
		document.write(twen_h + ".")

		if(twen_m < 10) document.write("0")
		document.write(twen_m)
	}
	document.write("</p>")
}

/* * * * * * * * *   SUNTABLE SCRIPT - END -  * * * * * * * * */

