﻿//   This JavaScript program is authored by Erik Mundall, copyright 2002 and is based
//   on an algorithm for calculation of sunrise/sunset using a scientific calculator and is
//   presumed accurate for sunrise/sunset times to within three (3) seconds in the tropics.
//
//   The author acknowledges the algorithm for this calculator to be within the public
//   domain, however this program, as written, is not.  Permission must be secured from
//   the author in writing before publishing this on any other website.  Downloading for
//   personal use only from the author's site is permissible.  You may also link to the
//   author's site with no need to obtain permission.  You may not package or distribute
//   this in ANY way to other individuals without written permission of the author.
//

var daylightsavings=false; 

function int2str(n)   {  var q=n.toString(10); return q; }
function val2real(s) { var q=Number(s);       return q; }
function val2(s)      {  var q=Number(s);       return q; }
function str2(r)       {  var q=r.toString(10);   return q; }

var DEGRAD = (Math.PI/180); var RADDEG = (180/Math.PI);
function tan(x)      { var TAN       =Math.tan(x);                              return TAN; }
function arcsin(x)  { var ARCSIN =Math.asin(x);                      return ARCSIN; }
function arccos(x) { var ARCCOS=Math.acos(x);                   return ARCCOS; }
function sind  (x)   { var SIND      =Math.sin((x)*DEGRAD);        return SIND; }
function cosd  (x)  { var COSD     =Math.cos((x*DEGRAD));     return COSD; }
function tand  (x)  { var TAND     =Math.tan((x)*DEGRAD);     return TAND; }
function atand (x) { var ATAND  =(RADDEG*Math.atan(x)); return ATAND; }
function asind (x)  { var ASIND    =(RADDEG*arcsin(x));         return ASIND; }
function acosd (x) { var ACOSD   =(RADDEG*arccos(x));      return ACOSD; }

function yearday(wday,wmonth) { var YD=0; /* switch(wmonth) */ {
if (wmonth==1) { YD=0; } if (wmonth==2) { YD=31} if (wmonth==3) { YD=59} 
if (wmonth==4) { YD=90} if (wmonth==5) { YD=120} if (wmonth==6) { YD=151} 
if (wmonth==7) { YD=181} if (wmonth==8) { YD=212} if (wmonth==9) { YD=243} 
if (wmonth==10) { YD=273} if (wmonth==11) { YD=304} if (wmonth==12) { YD=334} }
YD += wday;  return YD}
function MonthText(wmonth,lang) {
 if (lang=="EN") {
    if (wmonth==1) { return "JAN"} if (wmonth==2) { return "FEB"} 
    if (wmonth==3) { return "MAR"} if (wmonth==4) { return "APR"} 
    if (wmonth==5) { return "MAY"} if (wmonth==6) { return "JUN"} 
    if (wmonth==7) { return "JUL"} if (wmonth==8) { return "AUG"} 
    if (wmonth==9) { return "SEP"}if (wmonth==10) { return "OCT"} 
   if (wmonth==11) { return "NOV"}if (wmonth==12) { return "DEC"}
 } if (lang=="SP") {
    if (wmonth==1) { return "ENE"} if (wmonth==2) { return "FEB"} 
    if (wmonth==3) { return "MAR"} if (wmonth==4) { return "ABR"} 
    if (wmonth==5) { return "MAY"} if (wmonth==6) { return "JUN"} 
    if (wmonth==7) { return "JUL"} if (wmonth==8) { return "AGO"} 
    if (wmonth==9) { return "SEP"}if (wmonth==10) { return "OCT"} 
   if (wmonth==11) { return "NOV"}if (wmonth==12) { return "DIC"}
 } if (lang=="FR") {
    if (wmonth==1) { return "JAN"} if (wmonth==2) { return "FEV"} 
    if (wmonth==3) { return "MAR"} if (wmonth==4) { return "AVR"} 
    if (wmonth==5) { return "MAI"} if (wmonth==6) { return "JUN"} 
    if (wmonth==7) { return "JUL"} if (wmonth==8) { return "AOU"} 
    if (wmonth==9) { return "SEP"}if (wmonth==10) { return "OCT"} 
   if (wmonth==11) { return "NOV"}if (wmonth==12) { return "DEC"}
 } if (lang=="TH") {
    if (wmonth==1) { return "ม.ค."} if (wmonth==2) { return "ก.พ."} 
    if (wmonth==3) { return "มี.ย."} if (wmonth==4) { return "เม.ย."} 
    if (wmonth==5) { return "พ.ค."} if (wmonth==6) { return "มิ.ย."} 
    if (wmonth==7) { return "ก.ค."} if (wmonth==8) { return "ส.ค."} 
    if (wmonth==9) { return "ก.ย."}if (wmonth==10) { return "ต.ค."} 
   if (wmonth==11) { return "พ.ย."}if (wmonth==12) { return "ธ.ค."}
 } if (lang=="GE") {
    if (wmonth==1) { return "JAN"} if (wmonth==2) { return "FEB"} 
    if (wmonth==3) { return "MAR"} if (wmonth==4) { return "APR"} 
    if (wmonth==5) { return "MAI"} if (wmonth==6) { return "JUN"} 
    if (wmonth==7) { return "JUL"} if (wmonth==8) { return "AUG"} 
    if (wmonth==9) { return "SEP"}if (wmonth==10) { return "OKT"} 
   if (wmonth==11) { return "NOV"}if (wmonth==12) { return "DEZ"}
 } if (lang=="SW") {
    if (wmonth==1) { return "JAN"} if (wmonth==2) { return "FEB"} 
    if (wmonth==3) { return "MAC"} if (wmonth==4) { return "APR"} 
    if (wmonth==5) { return "MEI"} if (wmonth==6) { return "JUN"} 
    if (wmonth==7) { return "JUL"} if (wmonth==8) { return "AGO"} 
    if (wmonth==9) { return "SEP"}if (wmonth==10) { return "OKT"} 
   if (wmonth==11) { return "NOV"}if (wmonth==12) { return "DES"}
} }
function DayinWeek(dayofweek,lang) {  
 if (lang=="EN") {
    if (dayofweek==1) { return "Sunday"}    if (dayofweek==2) { return "Monday"} 
    if (dayofweek==3) { return "Tuesday"}   if (dayofweek==4) { return "Wednesday"} 
    if (dayofweek==5) { return "Thursday"}  if (dayofweek==6) { return "Friday"} 
    if (dayofweek==7) { return "Saturday"}
 } if (lang=="SP") {
    if (dayofweek==1) { return "domingo,   "}  if (dayofweek==2) { return "lunes,     "} 
    if (dayofweek==3) { return "martes,    "}  if (dayofweek==4) { return "miercoles, "} 
    if (dayofweek==5) { return "jueves,    "}  if (dayofweek==6) { return "viernes,   "} 
    if (dayofweek==7) { return "sabado,    "}
 } if (lang=="FR") {
    if (dayofweek==1) { return "dimanche, "}  if (dayofweek==2) { return "lundi,    "} 
    if (dayofweek==3) { return "mardi,    "}  if (dayofweek==4) { return "mercredi, "} 
    if (dayofweek==5) { return "jeudi,    "}  if (dayofweek==6) { return "vendredi, "} 
    if (dayofweek==7) { return "samedi,   "}
 } if (lang=="TH") {
    if (dayofweek==1) { return "อา."}    if (dayofweek==2) { return "จ."} 
    if (dayofweek==3) { return "อ."}    if (dayofweek==4) { return "พ."} 
    if (dayofweek==5) { return "พฤ."}   if (dayofweek==6) { return "ศ."} 
    if (dayofweek==7) { return "ส."}
 } if (lang=="GE") {
    if (dayofweek==1) { return "Sonntag,    "}  if (dayofweek==2) { return "Montag,     "} 
    if (dayofweek==3) { return "Dienstag,   "}  if (dayofweek==4) { return "Mittwoch,   "} 
    if (dayofweek==5) { return "Donnerstag, "}  if (dayofweek==6) { return "Freitag,    "} 
    if (dayofweek==7) { return "Samstag,    "}
 } if (lang=="SW") {
    if (dayofweek==1) { return "Jumamosi, "}  if (dayofweek==2) { return "Jumatatu, "} 
    if (dayofweek==3) { return "Jumanne,  "}  if (dayofweek==4) { return "Jumatano, "} 
    if (dayofweek==5) { return "Alhamisi, "}  if (dayofweek==6) { return "Ijumaa,   "} 
    if (dayofweek==7) { return "Jumamosi, "}
} }

function Century(wyear) { return Math.floor(wyear/100);  }
function TwoDigitYear(wyear) { return wyear-(Math.floor(wyear/100)*100); }

function MeanSunLong(wday,wmonth,wyear,NewStyle) {var MSL=0;
//alert ("MSL");
if (wmonth<3) { wyear-=1};  if (wyear<0) { wyear=0};
/* Mean ecliptic longitude of sun listed by day (degrees) */
/* switch (wmonth) */ {
if (wmonth==3) {
/* switch (wday) */ {
if (wday==1) { MSL=339.226}if (wday==2) { MSL=340.212}if (wday==3) { MSL=341.198}
if (wday==4) { MSL=342.183}if (wday==5) { MSL=343.169}if (wday==6) { MSL=344.155}
if (wday==7) { MSL=345.140}if (wday==8) { MSL=346.126}if (wday==9) { MSL=347.112}
if (wday==10) { MSL=348.097}if (wday==11) { MSL=349.083}if (wday==12) { MSL=350.068}
if (wday==13) { MSL=351.054}if (wday==14) { MSL=352.040}if (wday==15) { MSL=353.025}
if (wday==16) { MSL=354.011}if (wday==17) { MSL=354.997}if (wday==18) { MSL=355.982}
if (wday==19) { MSL=356.968}if (wday==20) { MSL=357.954}if (wday==21) { MSL=358.939}
if (wday==22) { MSL=359.925}if (wday==23) { MSL=0.911}if (wday==24) { MSL=1.896}
if (wday==25) { MSL=2.882}if (wday==26) { MSL=3.868}if (wday==27) { MSL=4.853}
if (wday==28) { MSL=5.839}if (wday==29) { MSL=6.824}if (wday==30) { MSL=7.810}
if (wday==31) { MSL=8.796}
}} if (wmonth==4) { /* switch (wday) */ {
if (wday==1) { MSL=9.781}if (wday==2) { MSL=10.767}if (wday==3) { MSL=11.753}
if (wday==4) { MSL=12.738}if (wday==5) { MSL=13.724}if (wday==6) { MSL=14.710}
if (wday==7) { MSL=15.695}if (wday==8) { MSL=16.681}if (wday==9) { MSL=17.667}
if (wday==10) { MSL=18.652}if (wday==11) { MSL=19.638}if (wday==12) { MSL=20.624}
if (wday==13) { MSL=21.609}if (wday==14) { MSL=22.595}if (wday==15) { MSL=23.581}
if (wday==16) { MSL=24.566}if (wday==17) { MSL=25.552}if (wday==18) { MSL=26.537}
if (wday==19) { MSL=27.523}if (wday==20) { MSL=28.509}if (wday==21) { MSL=29.494}
if (wday==22) { MSL=30.480}if (wday==23) { MSL=31.466}if (wday==24) { MSL=32.451}
if (wday==25) { MSL=33.437}if (wday==26) { MSL=34.423}if (wday==27) { MSL=35.408}
if (wday==28) { MSL=36.394}if (wday==29) { MSL=37.380}if (wday==30) { MSL=38.365}
}}if (wmonth==5) { /* switch (wday) */ {
if (wday==1) { MSL=39.351}if (wday==2) { MSL=40.337}
if (wday==3) { MSL=41.322}if (wday==4) { MSL=42.308}if (wday==5) { MSL=43.293}
if (wday==6) { MSL=44.279}if (wday==7) { MSL=45.265}if (wday==8) { MSL=46.250}
if (wday==9) { MSL=47.236}if (wday==10) { MSL=48.222}if (wday==11) { MSL=49.207}
if (wday==12) { MSL=50.193}if (wday==13) { MSL=51.179}if (wday==14) { MSL=52.164}
if (wday==15) { MSL=53.150}if (wday==16) { MSL=54.136}if (wday==17) { MSL=55.121}
if (wday==18) { MSL=56.107}if (wday==19) { MSL=57.093}if (wday==20) { MSL=58.078}
if (wday==21) { MSL=59.064}if (wday==22) { MSL=60.049}if (wday==23) { MSL=61.035}
if (wday==24) { MSL=62.021}if (wday==25) { MSL=63.006}if (wday==26) { MSL=63.992}
if (wday==27) { MSL=64.978}if (wday==28) { MSL=65.963}if (wday==29) { MSL=66.949}
if (wday==30) { MSL=67.935}if (wday==31) { MSL=68.920}
}}if (wmonth==6) { /* switch (wday) */ {
if (wday==1) { MSL=69.906}if (wday==2) { MSL=70.892}if (wday==3) { MSL=71.877}
if (wday==4) { MSL=72.863}if (wday==5) { MSL=73.849}if (wday==6) { MSL=74.834}
if (wday==7) { MSL=75.820}if (wday==8) { MSL=76.805}if (wday==9) { MSL=77.791}
if (wday==10) { MSL=78.777}if (wday==11) { MSL=79.762}if (wday==12) { MSL=80.748}
if (wday==13) { MSL=81.734}if (wday==14) { MSL=82.719}if (wday==15) { MSL=83.705}
if (wday==16) { MSL=84.691}if (wday==17) { MSL=85.676}if (wday==18) { MSL=86.662}
if (wday==19) { MSL=87.648}if (wday==20) { MSL=88.633}if (wday==21) { MSL=89.619}
if (wday==22) { MSL=90.605}if (wday==23) { MSL=91.590}if (wday==24) { MSL=92.576}
if (wday==25) { MSL=93.561}if (wday==26) { MSL=94.547}if (wday==27) { MSL=95.533}
if (wday==28) { MSL=96.518}if (wday==29) { MSL=97.504}if (wday==30) { MSL=98.490}
}}if (wmonth==7) { /* switch (wday) */ {
if (wday==1) { MSL=99.475}if (wday==2) { MSL=100.461}if (wday==3) { MSL=101.447}
if (wday==4) { MSL=102.432}if (wday==5) { MSL=103.418}if (wday==6) { MSL=104.404}
if (wday==7) { MSL=105.389}if (wday==8) { MSL=106.375}if (wday==9) { MSL=107.361}
if (wday==10) { MSL=108.346}if (wday==11) { MSL=109.332}if (wday==12) { MSL=110.317}
if (wday==13) { MSL=111.303}if (wday==14) { MSL=112.289}if (wday==15) { MSL=113.274}
if (wday==16) { MSL=114.260}if (wday==17) { MSL=115.246}if (wday==18) { MSL=116.231}
if (wday==19) { MSL=117.217}if (wday==20) { MSL=118.203}if (wday==21) { MSL=119.188}
if (wday==22) { MSL=120.174}if (wday==23) { MSL=121.160}if (wday==24) { MSL=122.145}
if (wday==25) { MSL=123.131}if (wday==26) { MSL=124.117}if (wday==27) { MSL=125.102}
if (wday==28) { MSL=126.088}if (wday==29) { MSL=127.073}if (wday==30) { MSL=128.059}
if (wday==31) { MSL=129.045}
}}if (wmonth==8) { /* switch (wday) */ {
if (wday==1) { MSL=130.030}if (wday==2) { MSL=131.016}if (wday==3) { MSL=132.002}
if (wday==4) { MSL=132.987}if (wday==5) { MSL=133.973}if (wday==6) { MSL=134.959}
if (wday==7) { MSL=135.944}if (wday==8) { MSL=136.930}if (wday==9) { MSL=137.916}
if (wday==10) { MSL=138.901}if (wday==11) { MSL=139.887}if (wday==12) { MSL=140.873}
if (wday==13) { MSL=141.858}if (wday==14) { MSL=142.844}if (wday==15) { MSL=143.829}
if (wday==16) { MSL=144.815}if (wday==17) { MSL=145.801}if (wday==18) { MSL=146.786}
if (wday==19) { MSL=147.772}if (wday==20) { MSL=148.758}if (wday==21) { MSL=149.743}
if (wday==22) { MSL=150.729}if (wday==23) { MSL=151.715}if (wday==24) { MSL=152.700}
if (wday==25) { MSL=153.686}if (wday==26) { MSL=154.672}if (wday==27) { MSL=155.657}
if (wday==28) { MSL=156.643}if (wday==29) { MSL=157.629}if (wday==30) { MSL=158.614}
if (wday==31) { MSL=159.600}
}}if (wmonth==9) { /* switch (wday) */ {
if (wday==1) { MSL=160.585}if (wday==2) { MSL=161.571}if (wday==3) { MSL=162.557}
if (wday==4) { MSL=163.542}if (wday==5) { MSL=164.528}if (wday==6) { MSL=165.514}
if (wday==7) { MSL=166.499}if (wday==8) { MSL=167.485}if (wday==9) { MSL=168.471}
if (wday==10) { MSL=169.456}if (wday==11) { MSL=170.442}if (wday==12) { MSL=171.428}
if (wday==13) { MSL=172.413}if (wday==14) { MSL=173.399}if (wday==15) { MSL=174.385}
if (wday==16) { MSL=175.370}if (wday==17) { MSL=176.356}if (wday==18) { MSL=177.341}
if (wday==19) { MSL=178.327}if (wday==20) { MSL=179.313}if (wday==21) { MSL=180.298}
if (wday==22) { MSL=181.284}if (wday==23) { MSL=182.270}if (wday==24) { MSL=183.255}
if (wday==25) { MSL=184.241}if (wday==26) { MSL=185.227}if (wday==27) { MSL=186.212}
if (wday==28) { MSL=187.198}if (wday==29) { MSL=188.184}if (wday==30) { MSL=189.169}
}}if (wmonth==10) { /* switch (wday) */ {
if (wday==1) { MSL=190.155}if (wday==2) { MSL=191.141}if (wday==3) { MSL=192.126}
if (wday==4) { MSL=193.112}if (wday==5) { MSL=194.098}if (wday==6) { MSL=195.083}
if (wday==7) { MSL=196.069}if (wday==8) { MSL=197.054}if (wday==9) { MSL=198.040}
if (wday==10) { MSL=199.026}if (wday==11) { MSL=200.011}if (wday==12) { MSL=200.997}
if (wday==13) { MSL=201.983}if (wday==14) { MSL=202.968}if (wday==15) { MSL=203.954}
if (wday==16) { MSL=204.940}if (wday==17) { MSL=205.925}if (wday==18) { MSL=206.911}
if (wday==19) { MSL=207.897}if (wday==20) { MSL=208.882}if (wday==21) { MSL=209.868}
if (wday==22) { MSL=210.854}if (wday==23) { MSL=211.839}if (wday==24) { MSL=212.825}
if (wday==25) { MSL=213.810}if (wday==26) { MSL=214.796}if (wday==27) { MSL=215.782}
if (wday==28) { MSL=216.767}if (wday==29) { MSL=217.753}if (wday==30) { MSL=218.739}
if (wday==31) { MSL=219.724}
}}if (wmonth==11) { /* switch (wday) */ {
if (wday==1) { MSL=220.710}if (wday==2) { MSL=221.696}if (wday==3) { MSL=222.681}
if (wday==4) { MSL=223.667}if (wday==5) { MSL=224.653}if (wday==6) { MSL=225.638}
if (wday==7) { MSL=226.624}if (wday==8) { MSL=227.610}if (wday==9) { MSL=228.595}
if (wday==10) { MSL=229.581}if (wday==11) { MSL=230.566}if (wday==12) { MSL=231.552}
if (wday==13) { MSL=232.538}if (wday==14) { MSL=233.523}if (wday==15) { MSL=234.509}
if (wday==16) { MSL=235.495}if (wday==17) { MSL=236.480}if (wday==18) { MSL=237.466}
if (wday==19) { MSL=238.452}if (wday==20) { MSL=239.437}if (wday==21) { MSL=240.423}
if (wday==22) { MSL=241.409}if (wday==23) { MSL=242.394}if (wday==24) { MSL=243.380}
if (wday==25) { MSL=244.366}if (wday==26) { MSL=245.351}if (wday==27) { MSL=246.337}
if (wday==28) { MSL=247.322}if (wday==29) { MSL=248.308}if (wday==30) { MSL=249.294}
}}if (wmonth==12) {  /* switch (wday) */ {
if (wday==1) { MSL=250.279}if (wday==2) { MSL=251.265}if (wday==3) { MSL=252.251}
if (wday==4) { MSL=253.236}if (wday==5) { MSL=254.222}if (wday==6) { MSL=255.208}
if (wday==7) { MSL=256.193}if (wday==8) { MSL=257.179}if (wday==9) { MSL=258.165}
if (wday==10) { MSL=259.150}if (wday==11) { MSL=260.136}if (wday==12) { MSL=261.122}
if (wday==13) { MSL=262.107}if (wday==14) { MSL=263.093}if (wday==15) { MSL=264.078}
if (wday==16) { MSL=265.064}if (wday==17) { MSL=266.050}if (wday==18) { MSL=267.035}
if (wday==19) { MSL=268.021}if (wday==20) { MSL=269.007}if (wday==21) { MSL=269.992}
if (wday==22) { MSL=270.978}if (wday==23) { MSL=271.964}if (wday==24) { MSL=272.949}
if (wday==25) { MSL=273.935}if (wday==26) { MSL=274.921}if (wday==27) { MSL=275.906}
if (wday==28) { MSL=276.892}if (wday==29) { MSL=277.878}if (wday==30) { MSL=278.863}
if (wday==31) { MSL=279.849}
}}if (wmonth==1) { /* switch (wday) */ {
if (wday==1) { MSL=280.834}if (wday==2) { MSL=281.820}if (wday==3) { MSL=282.806}
if (wday==4) { MSL=283.791}if (wday==5) { MSL=284.777}if (wday==6) { MSL=285.763}
if (wday==7) { MSL=286.748}if (wday==8) { MSL=287.734}if (wday==9) { MSL=288.720}
if (wday==10) { MSL=289.705}if (wday==11) { MSL=290.691}if (wday==12) { MSL=291.677}
if (wday==13) { MSL=292.662}if (wday==14) { MSL=293.648}if (wday==15) { MSL=294.634}
if (wday==16) { MSL=295.619}if (wday==17) { MSL=296.605}if (wday==18) { MSL=297.590}
if (wday==19) { MSL=298.576}if (wday==20) { MSL=299.562}if (wday==21) { MSL=300.547}
if (wday==22) { MSL=301.533}if (wday==23) { MSL=302.519}if (wday==24) { MSL=303.504}
if (wday==25) { MSL=304.490}if (wday==26) { MSL=305.476}if (wday==27) { MSL=306.461}
if (wday==28) { MSL=307.447}if (wday==29) { MSL=308.433}if (wday==30) { MSL=309.418}
if (wday==31) { MSL=310.404}
}}if (wmonth==2) { /* switch (wday) */ {
if (wday==1) { MSL=311.390}if (wday==2) { MSL=312.375}if (wday==3) { MSL=313.361}
if (wday==4) { MSL=314.346}if (wday==5) { MSL=315.332}if (wday==6) { MSL=316.318}
if (wday==7) { MSL=317.303}if (wday==8) { MSL=318.289}if (wday==9) { MSL=319.275}
if (wday==10) { MSL=320.260}if (wday==11) { MSL=321.246}if (wday==12) { MSL=322.232}
if (wday==13) { MSL=323.217}if (wday==14) { MSL=324.203}if (wday==15) { MSL=325.189}
if (wday==16) { MSL=326.174}if (wday==17) { MSL=327.160}if (wday==18) { MSL=328.146}
if (wday==19) { MSL=329.131}if (wday==20) { MSL=330.117}if (wday==21) { MSL=331.102}
if (wday==22) { MSL=332.088}if (wday==23) { MSL=333.074}if (wday==24) { MSL=334.059}
if (wday==25) { MSL=335.045}if (wday==26) { MSL=336.031}if (wday==27) { MSL=337.016}
if (wday==28) { MSL=338.002}if (wday==29) { MSL=338.988}
}} }
/* CORRECTIONS to MEAN per century and year */
/* OLD STYLE correction per century starting at 00  OLD */
if (NewStyle==0)  { /* switch (Century(wyear)) */ { //alert ("OLD STYLE");
if (Century(wyear)==0) { MSL+=-2.227}if (Century(wyear)==1) { MSL+=-1.456}if (Century(wyear)==2) { MSL+=-.684}
if (Century(wyear)==3) { MSL+=.087}if (Century(wyear)==4) { MSL+=.858}if (Century(wyear)==5) { MSL+=1.629}
if (Century(wyear)==6) { MSL+=2.401}if (Century(wyear)==7) { MSL+=3.172}if (Century(wyear)==8) { MSL+=3.944}
if (Century(wyear)==9) { MSL+=4.715}if (Century(wyear)==10) { MSL+=5.487}if (Century(wyear)==11) { MSL+=6.258}
if (Century(wyear)==12) { MSL+=7.029}if (Century(wyear)==13) { MSL+=7.8}if (Century(wyear)==14) { MSL+=8.572}
if (Century(wyear)==15) { MSL+=9.343}if (Century(wyear)==16) { MSL+=10.114}if (Century(wyear)==17) { MSL+=10.885}
if (Century(wyear)==18) { MSL+=11.657}if (Century(wyear)==19) { MSL+=12.428}if (Century(wyear)==20) { MSL+=13.199}
if (Century(wyear)==21) { MSL+=13.97}if (Century(wyear)==22) { MSL+=14.742}if (Century(wyear)==23) { MSL+=15.513}
if (Century(wyear)==24) { MSL+=16.284}if (Century(wyear)==25) { MSL+=17.055}if (Century(wyear)==26) { MSL+=17.827}
if (Century(wyear)==27) { MSL+=18.598}if (Century(wyear)==28) { MSL+=19.369}if (Century(wyear)==29) { MSL+=20.14}
if (Century(wyear)==30) { MSL+=20.912}if (Century(wyear)==31) { MSL+=21.683}if (Century(wyear)==32) { MSL+=22.454}
if (Century(wyear)==33) { MSL+=23.225}if (Century(wyear)==34) { MSL+=23.997}if (Century(wyear)==35) { MSL+=24.768}
if (Century(wyear)==36) { MSL+=25.54}if (Century(wyear)==37) { MSL+=26.311}if (Century(wyear)==38) { MSL+=27.083}
if (Century(wyear)==39) { MSL+=27.854} 
} }else
/* NEW STYLE correction per century starting at 00   NEW */
/* switch (Century(wyear)) */ { //alert ("New Style");
if (Century(wyear)==0) { MSL+=-.255}if (Century(wyear)==1) { MSL+=-.47}if (Century(wyear)==2) { MSL+=-.684}
if (Century(wyear)==3) { MSL+=-.899}if (Century(wyear)==4) { MSL+=-.127}if (Century(wyear)==5) { MSL+=-.342}
if (Century(wyear)==6) { MSL+=-.556}if (Century(wyear)==7) { MSL+=-.771}if (Century(wyear)==8) { MSL+=.002}
if (Century(wyear)==9) { MSL+=-.213}if (Century(wyear)==10) { MSL+=-.427}if (Century(wyear)==11) { MSL+=-.642}
if (Century(wyear)==12) { MSL+=.13}if (Century(wyear)==13) { MSL+=-.085}if (Century(wyear)==14) { MSL+=-.299}
if (Century(wyear)==15) { MSL+=-.514}if (Century(wyear)==16) { MSL+=.258}if (Century(wyear)==17) { MSL+=.043}
if (Century(wyear)==18) { MSL+=-.171}if (Century(wyear)==19) { MSL+=-.386}if (Century(wyear)==20) { MSL+=.386}
if (Century(wyear)==21) { MSL+=.171}if (Century(wyear)==22) { MSL+=-.043}if (Century(wyear)==23) { MSL+=-.258}
if (Century(wyear)==24) { MSL+=.514}if (Century(wyear)==25) { MSL+=.299}if (Century(wyear)==26) { MSL+=.085}
if (Century(wyear)==27) { MSL+=-.13}if (Century(wyear)==28) { MSL+=.642}if (Century(wyear)==29) { MSL+=.427}
if (Century(wyear)==30) { MSL+=.213}if (Century(wyear)==31) { MSL+=-.002}if (Century(wyear)==32) { MSL+=.771}
if (Century(wyear)==33) { MSL+=.556}if (Century(wyear)==34) { MSL+=.342}if (Century(wyear)==35) { MSL+=.127}
if (Century(wyear)==36) { MSL+=.899}if (Century(wyear)==37) { MSL+=.684}if (Century(wyear)==38) { MSL+=.47}
if (Century(wyear)==39) { MSL+=.255} }
/*Per year correction starting at 00    YEAR */
/* switch (TwoDigitYear(wyear)) */ {
if (TwoDigitYear(wyear)==0) { MSL+=-.012}if (TwoDigitYear(wyear)==1) { MSL+=-.251}if (TwoDigitYear(wyear)==2) { MSL+=-.489}
if (TwoDigitYear(wyear)==3) { MSL+=-.728}if (TwoDigitYear(wyear)==4) { MSL+=.019}if (TwoDigitYear(wyear)==5) { MSL+=-.22}
if (TwoDigitYear(wyear)==6) { MSL+=-.458}if (TwoDigitYear(wyear)==7) { MSL+=-.697}if (TwoDigitYear(wyear)==8) { MSL+=.049}
if (TwoDigitYear(wyear)==9) { MSL+=-.19}if (TwoDigitYear(wyear)==10) { MSL+=-.428}if (TwoDigitYear(wyear)==11) { MSL+=-.667}
if (TwoDigitYear(wyear)==12) { MSL+=.08}if (TwoDigitYear(wyear)==13) { MSL+=-.159}if (TwoDigitYear(wyear)==14) { MSL+=-.397}
if (TwoDigitYear(wyear)==15) { MSL+=-.636}if (TwoDigitYear(wyear)==16) { MSL+=.111}if (TwoDigitYear(wyear)==17) { MSL+=-.128}
if (TwoDigitYear(wyear)==18) { MSL+=-.366}if (TwoDigitYear(wyear)==19) { MSL+=-.605}if (TwoDigitYear(wyear)==20) { MSL+=.142}
if (TwoDigitYear(wyear)==21) { MSL+=-.097}if (TwoDigitYear(wyear)==22) { MSL+=-.335}if (TwoDigitYear(wyear)==23) { MSL+=-.574}
if (TwoDigitYear(wyear)==24) { MSL+=.173}if (TwoDigitYear(wyear)==25) { MSL+=-.066}if (TwoDigitYear(wyear)==26) { MSL+=-.304}
if (TwoDigitYear(wyear)==27) { MSL+=-.543}if (TwoDigitYear(wyear)==28) { MSL+=.204}if (TwoDigitYear(wyear)==29) { MSL+=-.035}
if (TwoDigitYear(wyear)==30) { MSL+=-.273}if (TwoDigitYear(wyear)==31) { MSL+=-.512}if (TwoDigitYear(wyear)==32) { MSL+=.235}
if (TwoDigitYear(wyear)==33) { MSL+=-.004}if (TwoDigitYear(wyear)==34) { MSL+=-.242}if (TwoDigitYear(wyear)==35) { MSL+=-.481}
if (TwoDigitYear(wyear)==36) { MSL+=.265}if (TwoDigitYear(wyear)==37) { MSL+=.026}if (TwoDigitYear(wyear)==38) { MSL+=-.212}
if (TwoDigitYear(wyear)==39) { MSL+=-.451}if (TwoDigitYear(wyear)==40) { MSL+=.296}if (TwoDigitYear(wyear)==41) { MSL+=.057}
if (TwoDigitYear(wyear)==42) { MSL+=-.181}if (TwoDigitYear(wyear)==43) { MSL+=-.42}if (TwoDigitYear(wyear)==44) { MSL+=.327}
if (TwoDigitYear(wyear)==45) { MSL+=.088}if (TwoDigitYear(wyear)==46) { MSL+=-.15}if (TwoDigitYear(wyear)==47) { MSL+=-.389}
if (TwoDigitYear(wyear)==48) { MSL+=.358}if (TwoDigitYear(wyear)==49) { MSL+=.119}if (TwoDigitYear(wyear)==50) { MSL+=-.119}
if (TwoDigitYear(wyear)==51) { MSL+=-.358}if (TwoDigitYear(wyear)==52) { MSL+=.389}if (TwoDigitYear(wyear)==53) { MSL+=.15}
if (TwoDigitYear(wyear)==54) { MSL+=-.088}if (TwoDigitYear(wyear)==55) { MSL+=-.327}if (TwoDigitYear(wyear)==56) { MSL+=.42}
if (TwoDigitYear(wyear)==57) { MSL+=.181}if (TwoDigitYear(wyear)==58) { MSL+=-.057}if (TwoDigitYear(wyear)==59) { MSL+=-.296}
if (TwoDigitYear(wyear)==60) { MSL+=.451}if (TwoDigitYear(wyear)==61) { MSL+=.212}if (TwoDigitYear(wyear)==62) { MSL+=-.026}
if (TwoDigitYear(wyear)==63) { MSL+=-.265}if (TwoDigitYear(wyear)==64) { MSL+=.481}if (TwoDigitYear(wyear)==65) { MSL+=.242}
if (TwoDigitYear(wyear)==66) { MSL+=.004}if (TwoDigitYear(wyear)==67) { MSL+=-.235}if (TwoDigitYear(wyear)==68) { MSL+=.512}
if (TwoDigitYear(wyear)==69) { MSL+=.273}if (TwoDigitYear(wyear)==70) { MSL+=.035}if (TwoDigitYear(wyear)==71) { MSL+=-.204}
if (TwoDigitYear(wyear)==72) { MSL+=.543}if (TwoDigitYear(wyear)==73) { MSL+=.304}if (TwoDigitYear(wyear)==74) { MSL+=.066}
if (TwoDigitYear(wyear)==75) { MSL+=-.173}if (TwoDigitYear(wyear)==76) { MSL+=.574}if (TwoDigitYear(wyear)==77) { MSL+=.335}
if (TwoDigitYear(wyear)==78) { MSL+=.097}if (TwoDigitYear(wyear)==79) { MSL+=-.142}if (TwoDigitYear(wyear)==80) { MSL+=.605}
if (TwoDigitYear(wyear)==81) { MSL+=.366}if (TwoDigitYear(wyear)==82) { MSL+=.128}if (TwoDigitYear(wyear)==83) { MSL+=-.111}
if (TwoDigitYear(wyear)==84) { MSL+=.636}if (TwoDigitYear(wyear)==85) { MSL+=.397}if (TwoDigitYear(wyear)==86) { MSL+=.159}
if (TwoDigitYear(wyear)==87) { MSL+=-.08}if (TwoDigitYear(wyear)==88) { MSL+=.667}if (TwoDigitYear(wyear)==89) { MSL+=.428}
if (TwoDigitYear(wyear)==90) { MSL+=.19}if (TwoDigitYear(wyear)==91) { MSL+=-.049}if (TwoDigitYear(wyear)==92) { MSL+=.697}
if (TwoDigitYear(wyear)==93) { MSL+=.458}if (TwoDigitYear(wyear)==94) { MSL+=.22}if (TwoDigitYear(wyear)==95) { MSL+=-.019}
if (TwoDigitYear(wyear)==96) { MSL+=.728}if (TwoDigitYear(wyear)==97) { MSL+=.489}if (TwoDigitYear(wyear)==98) { MSL+=.251}
if (TwoDigitYear(wyear)==99) { MSL+=.012} }return MSL} 

function SunPerigee(wyear) { var SP = 0;
/* Ecliptic longitude of perigee of sun by century starting at 00 */
/* switch (Century(wyear)) */ {
if (Century(wyear)==0) { SP=249.39; }if (Century(wyear)==1) { SP=251.11; }if (Century(wyear)==2) { SP=252.83; }
if (Century(wyear)==3) { SP=254.55; }if (Century(wyear)==4) { SP=256.27; }if (Century(wyear)==5) { SP=257.99; }
if (Century(wyear)==6) { SP=259.71; }if (Century(wyear)==7) { SP=261.43; }if (Century(wyear)==8) { SP=263.15; }
if (Century(wyear)==9) { SP=264.87; }if (Century(wyear)==10) { SP=266.59; }if (Century(wyear)==11) { SP=268.31; }
if (Century(wyear)==12) { SP=270.03; }if (Century(wyear)==13) { SP=271.75; }if (Century(wyear)==14) { SP=273.47; }
if (Century(wyear)==15) { SP=275.19; }if (Century(wyear)==16) { SP=276.91; }if (Century(wyear)==17) { SP=278.63; }
if (Century(wyear)==18) { SP=280.35; }if (Century(wyear)==19) { SP=282.07; }if (Century(wyear)==20) { SP=283.79; }
if (Century(wyear)==21) { SP=285.51; }if (Century(wyear)==22) { SP=287.23; }if (Century(wyear)==23) { SP=288.95; }
if (Century(wyear)==24) { SP=290.67; }if (Century(wyear)==25) { SP=292.39; }if (Century(wyear)==26) { SP=294.11; }
if (Century(wyear)==27) { SP=295.83; }if (Century(wyear)==28) { SP=297.56; }if (Century(wyear)==29) { SP=299.28; }
if (Century(wyear)==30) { SP=301; }if (Century(wyear)==31) { SP=302.72; }if (Century(wyear)==32) { SP=304.44; }
if (Century(wyear)==33) { SP=306.16; }if (Century(wyear)==34) { SP=307.88; }if (Century(wyear)==35) { SP=309.6; }
if (Century(wyear)==36) { SP=311.32; }if (Century(wyear)==37) { SP=313.04; }if (Century(wyear)==38) { SP=314.76; }
if (Century(wyear)==39) { SP=316.48; }
}
/* Ecliptic longitude of perigee of sun correction to century (above) by year starting at 00 */
/* switch (TwoDigitYear(wyear)) */ {
if (TwoDigitYear(wyear)==0) { SP+=-.86; }if (TwoDigitYear(wyear)==1) { SP+=-.84; }if (TwoDigitYear(wyear)==2) { SP+=-.82; }
if (TwoDigitYear(wyear)==3) { SP+=-.8; }if (TwoDigitYear(wyear)==4) { SP+=-.79; }if (TwoDigitYear(wyear)==5) { SP+=-.77; }
if (TwoDigitYear(wyear)==6) { SP+=-.75; }if (TwoDigitYear(wyear)==7) { SP+=-.73; }if (TwoDigitYear(wyear)==8) { SP+=-.72; }
if (TwoDigitYear(wyear)==9) { SP+=-.7; }if (TwoDigitYear(wyear)==10) { SP+=-.68; }if (TwoDigitYear(wyear)==11) { SP+=-.66; }
if (TwoDigitYear(wyear)==12) { SP+=-.65; }if (TwoDigitYear(wyear)==13) { SP+=-.63; }if (TwoDigitYear(wyear)==14) { SP+=-.61; }
if (TwoDigitYear(wyear)==15) { SP+=-.59; }if (TwoDigitYear(wyear)==16) { SP+=-.58; }if (TwoDigitYear(wyear)==17) { SP+=-.56; }
if (TwoDigitYear(wyear)==18) { SP+=-.54; }if (TwoDigitYear(wyear)==19) { SP+=-.52; }if (TwoDigitYear(wyear)==20) { SP+=-.51; }
if (TwoDigitYear(wyear)==21) { SP+=-.49; }if (TwoDigitYear(wyear)==22) { SP+=-.47; }if (TwoDigitYear(wyear)==23) { SP+=-.45; }
if (TwoDigitYear(wyear)==24) { SP+=-.44; }if (TwoDigitYear(wyear)==25) { SP+=-.42; }if (TwoDigitYear(wyear)==26) { SP+=-.4; }
if (TwoDigitYear(wyear)==27) { SP+=-.38; }if (TwoDigitYear(wyear)==28) { SP+=-.37; }if (TwoDigitYear(wyear)==29) { SP+=-.35; }
if (TwoDigitYear(wyear)==30) { SP+=-.33; }if (TwoDigitYear(wyear)==31) { SP+=-.31; }if (TwoDigitYear(wyear)==32) { SP+=-.31; }
if (TwoDigitYear(wyear)==33) { SP+=-.29; }if (TwoDigitYear(wyear)==34) { SP+=-.27; }if (TwoDigitYear(wyear)==35) { SP+=-.25; }
if (TwoDigitYear(wyear)==36) { SP+=-.24; }if (TwoDigitYear(wyear)==37) { SP+=-.22; }if (TwoDigitYear(wyear)==38) { SP+=-.2; }
if (TwoDigitYear(wyear)==39) { SP+=-.18; }if (TwoDigitYear(wyear)==40) { SP+=-.17; }if (TwoDigitYear(wyear)==41) { SP+=-.15; }
if (TwoDigitYear(wyear)==42) { SP+=-.13; }if (TwoDigitYear(wyear)==43) { SP+=-.11; }if (TwoDigitYear(wyear)==44) { SP+=-.1; }
if (TwoDigitYear(wyear)==45) { SP+=-.08; }if (TwoDigitYear(wyear)==46) { SP+=-.06; }if (TwoDigitYear(wyear)==47) { SP+=-.04; }
if (TwoDigitYear(wyear)==48) { SP+=-.03; }if (TwoDigitYear(wyear)==49) { SP+=-.01; }if (TwoDigitYear(wyear)==50) { SP+=.01; }
if (TwoDigitYear(wyear)==51) { SP+=.03; }if (TwoDigitYear(wyear)==52) { SP+=.04; }if (TwoDigitYear(wyear)==53) { SP+=.06; }
if (TwoDigitYear(wyear)==54) { SP+=.08; }if (TwoDigitYear(wyear)==55) { SP+=.1; }if (TwoDigitYear(wyear)==56) { SP+=.11; }
if (TwoDigitYear(wyear)==57) { SP+=.13; }if (TwoDigitYear(wyear)==58) { SP+=.15; }if (TwoDigitYear(wyear)==59) { SP+=.17; }
if (TwoDigitYear(wyear)==60) { SP+=.18; }if (TwoDigitYear(wyear)==61) { SP+=.2; }if (TwoDigitYear(wyear)==62) { SP+=.22; }
if (TwoDigitYear(wyear)==63) { SP+=.24; }if (TwoDigitYear(wyear)==64) { SP+=.25; }if (TwoDigitYear(wyear)==65) { SP+=.27; }
if (TwoDigitYear(wyear)==66) { SP+=.29; }if (TwoDigitYear(wyear)==67) { SP+=.31; }if (TwoDigitYear(wyear)==68) { SP+=.31; }
if (TwoDigitYear(wyear)==69) { SP+=.33; }if (TwoDigitYear(wyear)==70) { SP+=.35; }if (TwoDigitYear(wyear)==71) { SP+=.37; }
if (TwoDigitYear(wyear)==72) { SP+=.38; }if (TwoDigitYear(wyear)==73) { SP+=.4; }if (TwoDigitYear(wyear)==74) { SP+=.42; }
if (TwoDigitYear(wyear)==75) { SP+=.44; }if (TwoDigitYear(wyear)==76) { SP+=.45; }if (TwoDigitYear(wyear)==77) { SP+=.47; }
if (TwoDigitYear(wyear)==78) { SP+=.49; }if (TwoDigitYear(wyear)==79) { SP+=.51; }if (TwoDigitYear(wyear)==80) { SP+=.52; }
if (TwoDigitYear(wyear)==81) { SP+=.54; }if (TwoDigitYear(wyear)==82) { SP+=.56; }if (TwoDigitYear(wyear)==83) { SP+=.58; }
if (TwoDigitYear(wyear)==84) { SP+=.59; }if (TwoDigitYear(wyear)==85) { SP+=.61; }if (TwoDigitYear(wyear)==86) { SP+=.63; }
if (TwoDigitYear(wyear)==87) { SP+=.65; }if (TwoDigitYear(wyear)==88) { SP+=.66; }if (TwoDigitYear(wyear)==89) { SP+=.68; }
if (TwoDigitYear(wyear)==90) { SP+=.7; }if (TwoDigitYear(wyear)==91) { SP+=.72; }if (TwoDigitYear(wyear)==92) { SP+=.73; }
if (TwoDigitYear(wyear)==93) { SP+=.75; }if (TwoDigitYear(wyear)==94) { SP+=.77; }if (TwoDigitYear(wyear)==95) { SP+=.79; }
if (TwoDigitYear(wyear)==96) { SP+=.8; }if (TwoDigitYear(wyear)==97) { SP+=.82; }if (TwoDigitYear(wyear)==98) { SP+=.84; }
if (TwoDigitYear(wyear)==99) { SP+=.86; }
} return SP; } 
function IsLeapYear(wyear) {
  if (wyear>=1753) {
  if ( (wyear/400)===Math.floor(wyear/400)) {return true}
  else if ((wyear/100)===Math.floor(wyear/100)) {return false}
  else if ((wyear/4)===Math.floor(wyear/4)) {return true}
  else {return false}; 
  } else {  if ((wyear/4)===Math.floor(wyear/4)) {return true} else {return false} }}

function NewYearDay(wyear,NewStyle) {    //Returns day of week of Jan. 1
  if (NewStyle==1) {
   var WD=2; // start day based on start year (Monday, January 1, 1753)
   var Y=1753;   /* start year */ 
   var wc=0;
   if (wyear==1752) {WD-=1; wc=1}
  var F=0; var T=1;   var k=Y;   var centurymark=F;
   while (Y<=(wyear+wc-28)) {     Y+=28;  
     if ( Math.floor( (k-1)/100 )!=Math.floor((Y-1)/100)) centurymark=T;   
     k=Y;     if (centurymark==T) {
       if ( (Math.floor((Y-1)/100)/4) != Math.floor(Math.floor((Y-1)/100)/4)) {
       WD--;if (WD<1) WD=7;centurymark=F}}}
   while (Y!=wyear+wc) {     Y++;     WD++;
       if (Math.floor((k-1)/100)!=Math.floor((Y-1)/100)) centurymark=T;
       k=Y;   if (centurymark==T) {
         if ( (Math.floor((Y-1)/100)/4) != Math.floor(Math.floor((Y-1)/100)/4) ) { 
           WD--;     if (WD<1) WD=7;    centurymark=F;   }     }
       if ( ((Y-1)/4) == Math.floor((Y-1)/4) ) WD++;
       if (WD>7) WD-=7; }  
   } else {   
   var WD=4; // start day based on start year (Tuesday, January 1, 1752) But 10 days removed Sept. 2 --> Sept. 14
   var Y=1752; /* start year */
   var F=0; var T=1;   var k=Y;   var centurymark=F;
   while (Y>=(wyear+28)) {Y-=28}
   while (Y!=wyear) {     Y--;     WD--;
     if ( (Y/4) == Math.floor(Y/4) ) WD--;
     if (WD<1) WD+=7;   }} 
   return WD}

function IsDay(daycount,wyear,dayofweek,NewStyle) {
  if (dayofweek==0) { return false}
  var NYD=NewYearDay(wyear,NewStyle);  var weekday=NYD+daycount-1;
  if (weekday==dayofweek) { return true; }
  if (((weekday-dayofweek)/7)==(Math.floor((weekday-dayofweek)/7))) { return true}
  else return false}

function IsDayW(daycount,wyear,NewStyle) {
  var NYDW=NewYearDay(wyear,NewStyle);  var weekdayz=NYDW+daycount-1;
 while (weekdayz >7) {weekdayz-=7; }
return weekdayz}

function ConvertSunsetTime(sundowntime,TimeZone,RoundSec,RiseorSet) {
  if (RiseorSet==3) {TimeZone=0};
  var clocktime=(sundowntime/360*24)+TimeZone;
   var hour=Math.floor(clocktime);
   var min=Math.floor( (clocktime-hour)*60);
   var sec=Math.floor((((clocktime-hour)*60)-min)*60);
       // ROUNDING TO EVEN MINUTE 
  if (sec != 0) {
     if (RoundSec==60) {if (sec>30) {min++}; if (min>59) { hour++}; if (min>59) {min=0}}
     if (RoundSec==10) {sec=(Math.round((sec/10)-Math.floor(sec/10)))*10+(Math.floor(sec/10)*10)};
 }
     if (sec>59) {sec=0;min++};   if (min>59) {min=0; hour++}
     if (hour<0) hour+=24; if (hour>23) hour-=24;
     if (hour<10) { var cohr="0"}  else var cohr ="";   
     if (min<10) {var comin="0"} else var comin=""; 
     if (sec<10) {var csec="0"}  else var csec=""; 
     if (RoundSec==60) {csec=""} else csec=":"+csec+int2str(sec);
   var CODETIME = cohr+int2str(hour)+":"+comin+int2str(min)+csec; 
return CODETIME}

function SunTime(wday,wmonth,wyear,NewStyle,latitude,longitude,RiseorSet) { 
 var NN=0;
 var Anomaly=MeanSunLong(wday,wmonth,wyear,NewStyle); //alert ("Anomaly: "+Anomaly);
 var Perigee=SunPerigee(wyear);
 var MeanAnomaly=Anomaly-Perigee;
 var EclipticLongitude=(Anomaly+1.915*sind(MeanAnomaly)+0.020*sind(MeanAnomaly*2)); 
 var Declination=asind(sind(EclipticLongitude) *0.39777);
 var RAscension=EclipticLongitude-atand(sind(EclipticLongitude*2)/(23.2377+cosd(EclipticLongitude*2)));
 var EqTime=RAscension-Anomaly /* EclipticLongitude */; 
var MeanTimeSunrise=90-longitude;
var SunriseTime=MeanTimeSunrise-asind(tand(latitude)*tand(Declination) /* */
       +0.01454/cosd(latitude)/cosd(Declination) /* */ )+EqTime;
var MeanTimeSunset=270-longitude;
if ((tand(latitude)*tand(Declination) +0.01454/cosd(latitude)/cosd(Declination))>1) 
   { NN = 10000; } 
if ((tand(latitude)*tand(Declination) +0.01454/cosd(latitude)/cosd(Declination))<-1) 
   { NN = 20000; }
var SunsetTime=MeanTimeSunset+asind(tand(latitude)
     *tand(Declination) /* */ +0.01454/cosd(latitude)
                   /cosd(Declination) /* */ )+EqTime;  
var ISNN = isNaN(SunsetTime);
if (ISNN==true) {SunsetTime=NN}
var ISNN = isNaN(SunriseTime);
if (ISNN==true) {SunriseTime=NN}
       if (NN==0) { var Daylength=(SunsetTime-SunriseTime); }
else if (NN==10000) { var Daylength=360; }
else if (NN==20000) { var Daylength=0; }

  if (RiseorSet==1) {return SunriseTime} 
else if (RiseorSet==2) {return SunsetTime}
else if (RiseorSet==3) {return Daylength};
}
function checkAll(field) { for (i = 0; i < field.length; i++)	field[i].checked = true ;  }
function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false; }
function inspectany(field,ii) { if (field[ii-1].checked == false) { return 0; } else { return (ii)} }

function SunsetDays(wday,wmonth,wyear,TimeZone,NewStyle,dayofweek,daylightsavings,latitude,longitude,RiseorSet,RoundSec,lang) {
  var savetime=false;   if (IsLeapYear(wyear)) { var j=366 }else var j=365;
  var enterstring="\n";
  var sundowntime=""; var sundown2=" ";
  if (RiseorSet==1) {sundown2+="Sunrise Times: "+enterstring} 
else if (RiseorSet==2) {sundown2+="Sunset Times: "+enterstring}
else if (RiseorSet==3) {sundown2+="Daylength (Sunrise to Sunset): "+enterstring};
  for (var i=1; (i < (j+1)); i++) {
    if (((wmonth==4) && (daylightsavings==true)) && (savetime==false)) { 
      if (IsDay(i,wyear,1,NewStyle)) { savetime=true; TimeZone+=1; }  } 
    if (((wmonth==10) && (wday>=24)) && (savetime==true)) {
      if (IsDay(i,wyear,1,NewStyle))  { savetime=false;TimeZone-=1} } 
    if ( IsDay(i,wyear, (inspectany(document.sunsetform.daycheck, IsDayW(i,wyear,NewStyle))),NewStyle) ) {
        if (IsLeapYear(wyear) && (!fix)) { var dsum=1 } else var dsum=0; 
if ((wyear==1752) && (i>=247) && (!fix)) { wday=14+(i-247); wmonth=9; i=257+(i-247); NewStyle=1; var fix=1; j-=1} else {

               if (i< 32)      { wmonth= 1;wday=i;           }
        else if (i<( 60+dsum)) { wmonth= 2;wday=i-  31;      }
        else if (i<( 91+dsum)) { wmonth= 3;wday=i-( 59+dsum)}
        else if (i<(121+dsum)) { wmonth= 4;wday=i-( 90+dsum)}
        else if (i<(152+dsum)) { wmonth= 5;wday=i-(120+dsum)}
        else if (i<(182+dsum)) { wmonth= 6;wday=i-(151+dsum)}
        else if (i<(213+dsum)) { wmonth= 7;wday=i-(181+dsum)}
        else if (i<(244+dsum)) { wmonth= 8;wday=i-(212+dsum)}
        else if (i<(274+dsum)) { wmonth= 9;wday=i-(243+dsum)}
        else if (i<(305+dsum)) { wmonth=10;wday=i-(273+dsum)}
        else if (i<(335+dsum)) { wmonth=11;wday=i-(304+dsum)}
        else if (i<(366+dsum)) { wmonth=12;wday=i-(334+dsum)}
        else                   { wmonth=1; wday=1;           }
	}
    sundowntime=SunTime(wday,wmonth,wyear,NewStyle,latitude,longitude,RiseorSet);
    var dayspace=""; 
    
    if (wday<10) {dayspace=" "}
    sundown2+=DayinWeek(IsDayW(i,wyear,NewStyle),lang) +dayspace+wday+" "+MonthText(wmonth,lang)+" "+wyear+" --> "
          +(ConvertSunsetTime(sundowntime,TimeZone,RoundSec,RiseorSet))+enterstring;
     } } 
if (!sundown2) {return "NULL"} else return sundown2; 
}

function timezone_menu() {
var TimeZone = document.sunsetform.timezonemenu.options[document.sunsetform.timezonemenu.selectedIndex].value
document.sunsetform.timezoneform.value=TimeZone; 
}
function lang_menu() {
var lang = document.sunsetform.langmenu.options[document.sunsetform.langmenu.selectedIndex].value;
if (lang=="") {lang="EN"}
return lang;
}
function latlong_menu() {
var latlong = document.sunsetform.latlongmenu.options[document.sunsetform.latlongmenu.selectedIndex].value;
    if (latlong.substring(0,4)=="http") { window.location.href = latlong; }
else {
var divi=latlong.indexOf('#'); var divl=latlong.indexOf('@');
var latit=latlong.substring(0,divi); var longit=latlong.substring(divi+1,divl);
var TimeZ=latlong.substring(divl+1,latlong.length);
document.sunsetform.latform.value=latit; document.sunsetform.longform.value=longit;
document.sunsetform.timezoneform.value=TimeZ;
}
 var d = new Date(); 
var FYD = d.getFullYear(); //JavaScript 1.2
if (!FYD) { var FYD = d.getYear(); if (FYD<1000) {FYD+=1900} } //JavaScript 1.0 fix
document.sunsetform.yearform.value=FYD;
}
function directions() {
var directs='HOW TO CALCULATE SUNSETS: \nFirst select your city from the list.\nIf your city is not listed, enter your\nlatitude, longitude, timezone and year.\n\nSecond, you must choose the days you\nwant calculated.\n\nThird, verify that the Daylight Savings\nbox is checked if your area uses the\ntimechange, or unchecked otherwise.\n\nNow, click on "CALCULATE!" and the\ntimes will show up here in this box!';
document.sunsetform.textarea.value=directs;
return directs;
}
function sundown() {
var RoundSec=str2(document.sunsetform.hidSecRound.value);
var RiseorSet=0;
if (document.sunsetform.riseform[0].checked==true) {RiseorSet=1} 
else if (document.sunsetform.riseform[1].checked==true) {RiseorSet=2}
else if (document.sunsetform.riseform[2].checked==true) {RiseorSet=3};
var dayofweek=7; var wday=1; var wmonth=1;
var latitude=val2(document.sunsetform.latform.value);
if (latitude>90) {alert ("Latitude must be between -90 and 90 inclusive."); 
   document.sunsetform.latform.value=90; latitude=90; }
if (latitude<-90) {alert ("Latitude must be between -90 and 90 inclusive."); 
   document.sunsetform.latform.value=-90; latitude=-90; }
var lang="EN";
var lang=lang_menu();
var longitude=val2(document.sunsetform.longform.value);
 var wyear=val2(document.sunsetform.yearform.value);
 var TimeZone=val2(document.sunsetform.timezoneform.value);
 var NewStyle=1; if (wyear<1753) NewStyle=0;
if ( (isNaN(latitude)) || (isNaN(longitude)) || (!wyear) ) { alert("Script cannot run without a valid entry for Latitude, Longitude, and Year.");  return ""}
 if ( (isNaN(TimeZone)) || (TimeZone>14) || (TimeZone<-14) ) { alert("Please be aware that without a valid Time Zone entered, all times will be displayed in Greenwich Mean Time (GMT) or Universal Time (UT)."); }
 if (document.sunsetform.daylightsavingsform.checked==false) {daylightsavings=false; } else daylightsavings=true;
 var SD = ""; SD=SunsetDays(wday,wmonth,wyear,TimeZone,NewStyle,dayofweek,daylightsavings,latitude,longitude,RiseorSet,RoundSec,lang) 
document.sunsetform.textarea.value=SD;
return SD}

