<!--
var r_to_d = 180 / Math.PI;
var d_to_r = 1 / r_to_d;

var convday    = 4.16666666666667E-02;
var convhour   = 6.66666666666667E-02;
var convmin    = 1.66666666666667E-02;
var convsec    = 2.77777777777778E-04;
var convcircle = 2.77777777777778E-03;

var SUNSET       = -50.0/60.0;
var CIVIL        = -6.0;
var NAUTICAL     = -12.0;
var ASTRONOMICAL = -18.0;

var Status;

var lat   = 41.02;     // your latitude
var lng   = -73.35;  // your longitude
var dtime = 5;      // timezoneoffset in hours

var ie4  = document.all && !document.getElementById;
var ns4  = document.layers;
var DOM2 = document.getElementById;

if(ie4 || DOM2)
   document.write('<div id="sun_stat"></div>');

show_sun_stat();  
  
function show_sun_stat()
{
  var text=calc_sun_stat();  
  
  if(DOM2) 
     document.getElementById("sun_stat").innerHTML=text;
  else if(ie4)
     document.all.innerHTML=text;
  else if(ns4) {
     document.write(text);
     document.close(); }
  
  setTimeout("show_sun_stat()", 60000);
}
          
function calc_sun_stat() 
{
 var jd, sid, alt;
 var mo, da, yr, hours, mm, ss;
 var s    = new pos;
 var r    = new rts;
 var now  = new Date();
 var text = "";
 
  mo = now.getMonth() + 1;
  da = now.getDate();
  yr = now.getYear();
  hh = now.getHours();
  mm = now.getMinutes();
  ss = now.getSeconds();
  hours = hh + mm/60.0 + ss/3600.0;
  if(yr < 2000) yr+=1900;

  // at UT 0h
  jd = julian(yr,mo,da,0);
  s  = calcsun(jd,0,0,0);
  r  = rmstime(jd,lat,lng,dtime,SUNSET,s.lng,s.lat);

  text='<font face="Verdana" size="-2">';
  if(Status&1) {
     text += '<b>Sunrise:</b> '+dt_hms(r.rise)+' <b>Sunset:</b> '+dt_hms(r.set)+' <b>Transit:</b> '+dt_hms(r.transit)+'<b> Daylength:</b> '+dt_hms(r.set-r.rise)+'<br>';
     r = rmstime(jd,lat,lng,dtime,CIVIL,s.lng,s.lat);
     if(Status&1)
        text += '<b>Dawn:</b> '+dt_hms(r.rise)+'<b> Dusk:</b> '+dt_hms(r.set)+'<br>'; }             
  else if(Status&2) {
     text += 'Arctic winter.<br>';
     // check if we have civil twilight at all
     r = rmstime(jd,lat,lng,dtime,CIVIL,s.lng,s.lat);
     if(Status&1)
        text += '<b>Dawn:</b> '+dt_hms(r.rise)+'<b>Dusk:</b> '+dt_hms(r.set)+'.<br>'; }
  else if(Status&4)
     text += 'Midnightsun<br>'; 
    
  jd  = julian(yr,mo,da,hours) - dtime/24.0;
  sid = sidtime(jd,lng);
  s   = calcsun(jd,hh,mm,ss);
  alt = Math.round(el_dd(sid,lat,s.lat,s.lng)); 
  azm = Math.round(az_dd(sid,lat,s.lat,s.lng,0));  

  text += '<b>Altitude:</b> '+alt+'&deg; <b>Azimuth:</b> '+azimuth(azm)+'<br>';
  text += 'It is now '+astrotype(alt)+'.<br>';

  text += '</font>';
      
/*  
  r = rmstime(jd,lat,lng,dtime,CIVIL,s.lng,s.lat);
  r = rmstime(jd,lat,lng,dtime,NAUTICAL,s.lng,s.lat);
  r = rmstime(jd,lat,lng,dtime,ASTRONOMICAL,s.lng,s.lat);
*/  

 return text;     
}

function astrotype(altitude)
{
 var type;
 
  if(altitude >= -6.0)
     type="civil twilight";
  else if(altitude >= -12.0 && altitude < -6.0)
     type="nautical twilight";
  else if(altitude >= -18.0 && altitude < -12.0)
     type="astronomical twilight";
  else // if(Altitude < -18.0)
     type="astronomical darkness";
         
 return type;       
}

function pos(lat,lng,gha,rise,transit,set) 
{
 this.lat = lat;
 this.lng = lng;
 this.gha = gha;
 this.rise = rise;
 this.transit = transit;
 this.set = set;
}

function rts(rise,transit,set) 
{
 this.rise = rise;
 this.transit = transit;
 this.set = set;
}

function radians(x) { return x * d_to_r; }
function degrees(x) { return x * r_to_d; }

// returns degrees
function myatan2(y,x) 
{ 
 var a;
 
  x = (x == 0)? 1e-30:x;
  a = degrees(Math.atan(y/x));
  if(x < 0) 
     a = 180 + a;
  if(a < 0) 
     a = 360 + a;
     
  return a;
}

// sun azimuth for ra, decl at this loc
function el_dd(sid,lat,decl,ra) 
{
 var lha,x;

  lat  = radians(lat);
  decl = radians(decl);
  lha  = radians(sid - ra);
  x    = degrees(Math.asin(Math.sin(lat)*Math.sin(decl) + 
                 Math.cos(lat)*Math.cos(decl)*Math.cos(lha)));
  // correct for atmospheric refraction 
  //x = x + (1.92792040346393E-03 + (1.02 / Math.tan(radians(x + (10.3 / (x + 5.11)))))) * convmin;

 return(x);
}

// azimuth 0 to 360 for object. az_ns allows 0 = south, magdec has local magnetic declination 
// sun elevation for ra, decl at this loc
function az_dd(sid,lat,decl,ra,magdecl) 
{
  var lha,x,a,b;
  
  lat = radians(lat);
  decl = radians(decl);
  lha = radians(sid - ra);
  a = Math.sin(lha);
  b = Math.cos(lha) * Math.sin(lat) - Math.tan(decl) * Math.cos(lat);
  x = myatan2(a,b);
  if (x < 0.0)
          x = 360.0 + x;
  x = x + 180.0;
  x = x + magdecl;
  // now force x into 0 - 360 value range
  x = x * convcircle;
  x = x - Math.floor(x);
  x = x * 360.0;
  
 return(x);
}

// compute sun's position on this date
function calcsun(xjd,hh,mm,ss) 
{
 var s = new pos;
 var h, jd, t, lo, m, al;
 var rm, e, c, tl, v, r, nut;
 var obliq, sunra, sundecl;
 
  jd = xjd-(dtime/24); // convert to GMT 
  h  = ((hh) + (mm/60) + (ss/3600)) * 15;
  t  = (jd - 2451545) * 2.7378507871321E-05;
  lo = 280.46645 + (36000.76983 * t) + (0.0003032 * t * t);
  m  = 357.5291 + (35999.0503 * t) - (0.0001559 * t * t) - (0.00000048 * t * t * t);
  rm = radians(m);
  e  = 0.016708617 - (0.000042037 * t) - (0.0000001236 * t * t);
  c  = (1.9146 - 0.004817 * t - 0.000014 * t * t) * Math.sin(rm);
  c  = c + (0.019993 - 0.000101 * t) * Math.sin(2 * rm);
  c  = c + 0.00029 * Math.sin(3 * rm);
  tl = lo + c;
  v  = m + c;
  r  = (1.000001018 * (1 - e * e)) / (1 + (e * Math.cos(radians(v))));
  nut = 125.04 - 1934.136 * t;
  al  = radians(tl - 0.00569 - 0.00478 * Math.sin(radians(nut)));
  obliq = 23.4391666666667 - 1.30041666666666E-02 * t - 0.000000163888888 * t * t + 5.03611111111E-08 * t * t * t;
  obliq = radians(obliq + 0.00256 * Math.cos(radians(nut)));
  sunra = myatan2(Math.cos(obliq) * Math.sin(al),Math.cos(al));
  if(sunra < 0)
     sunra = 360 + sunra;
  sundecl = degrees(Math.asin(Math.sin(obliq) * Math.sin(al)));
  s.lat   = sundecl;
  s.lng   = sunra;
        
 return(s);
}

// sidereal time from Julian Date 
function sidtime(jd,lng)
{
 var t,x;
 
  t = ((Math.floor(jd) + 0.5) - 2451545) *2.73785078713210E-05;
 
  x = 280.46061837;
  x = x + 360.98564736629 * (jd - 2451545);
 
  x = x + 0.000387933 * t * t;
  x = x - (t * t * t) * 2.583311805734950E-08;
  x = x - lng;
  x = x * convcircle;
  x = x - Math.floor(x);
  x = x * 360;
 
 return(x);
}

function mod1(t)
{
 var ot;
 
  ot = t;
  t = Math.abs(t);
  t = t - Math.floor(t);
  if(ot < 0)
     t = 1-t;
     
 return(t);
}

function rmstime(jd,lat,lng,timezone,atcr,ra,decl)
{
 var x,gmtsid;
 var r = new rts;
 
  timezone *= convday;
  gmtsid = sidtime(Math.floor(jd) + 0.5, 0);
  r.transit = ((ra + lng - gmtsid) / 360);
  atcr = radians(atcr);
  lat = radians(lat);
  decl = radians(decl);
  x = Math.sin(atcr) - (Math.sin(lat) * Math.sin(decl));
  x = x / (Math.cos(lat) * Math.cos(decl));

  Status=0; 

  if((x < 1) && (x > -1)) {
     x = degrees(Math.acos(x)) * convcircle;
     r.rise    = (mod1((r.transit - x)+timezone)) * 24.0;
     r.set     = (mod1((r.transit + x)+timezone)) * 24.0;
     r.transit = (mod1(r.transit+timezone)) * 24.0;
     Status    = 1; }
  else {
     x = (x >= 0) ? -100:100;
     r.rise    = x;
     r.transit = x;
     r.set     = x; 
     Status    = (x < 0) ? 2:4; } // &2=arctic winter, &4=midnightsun
  
 return r;
}

function dd_dm(x,f) 
{
 var d,m,sgn;
 var r;
 
  sgn = (x>=0)?0:1;
  x = Math.abs(x)+0.008333;
  d = Math.floor(x);
  x = (x-d)*60;
  m = Math.round(x);
  d = fix_places(d);
  m = fix_places(m);
  if(f == 0) 
     r = d;
  if(f == 1) 
     r = m;
  if(f == 2) 
     r = sgn;
     
 return r;
}


-->