﻿/*
Latest update: 28th February 2004 at 16:58 UT

Moon phases, graphics, and DHTML
copyright (c) Adrian R. Ashford
9th September 2004.

Modified by M.J. Muracco June 2006
*/

myImage = new Array("images/moon phase/0.gif","images/moon phase/1.gif","images/moon phase/2.gif","images/moon phase/3.gif","images/moon phase/4.gif","images/moon phase/5.gif","images/moon phase/6.gif","images/moon phase/7.gif","images/moon phase/8.gif","images/moon phase/9.gif","images/moon phase/10.gif","images/moon phase/11.gif","images/moon phase/12.gif","images/moon phase/13.gif","images/moon phase/14.gif","images/moon phase/15.gif","images/moon phase/16.gif","images/moon phase/17.gif","images/moon phase/18.gif","images/moon phase/19.gif","images/moon phase/20.gif","images/moon phase/21.gif","images/moon phase/22.gif","images/moon phase/23.gif","images/moon phase/24.gif","images/moon phase/25.gif","images/moon phase/26.gif","images/moon phase/27.gif","images/moon phase/28.gif","images/moon phase/29.gif");
thisImage = 0;
images = myImage.length - 1;

function setup()
{
var nowdate = new Date();
var utc_day = nowdate.getUTCDate();
var utc_month = nowdate.getUTCMonth() + 1;
var utc_year = nowdate.getUTCFullYear();
zone = -(nowdate.getTimezoneOffset() / 60);
var utc_hours = nowdate.getUTCHours();
var utc_mins = nowdate.getUTCMinutes();
var utc_secs = nowdate.getUTCSeconds();
utc_mins += utc_secs / 60.0;
utc_mins = Math.floor((utc_mins + 0.5));
if (utc_mins < 10) utc_mins = "0" + utc_mins;
if (utc_mins > 59) utc_mins = 59;
if (utc_hours < 10) utc_hours = "0" + utc_hours;
if (utc_month < 10) utc_month = "0" + utc_month;
if (utc_day < 10) utc_day = "0" + utc_day;
document.moon.date_txt.value = utc_day + "/" + utc_month + "/" + utc_year;
document.moon.ut_h_m.value = utc_hours + ":" + utc_mins;
frac_day = utc_hours / 24 + utc_mins / 1440;
moon_phase();
}

function proper_ang(big)
{
with (Math)
{
var tmp = 0;
if (big > 0)
{
tmp = big / 360.0;
tmp = (tmp - floor(tmp)) * 360.0;
}
else
{
tmp = ceil(abs(big / 360.0));
tmp = big + tmp * 360.0;
}
}
return tmp;
}

function round_10(num)
{
return Math.floor((num + 0.05) * 10) / 10;
}

function round_100(num)
{
return Math.floor((num + 0.005) * 100) / 100;
}

function julian_date()
{
var dt_as_str, mm, dd, yy;
var yyy, mmm, a, b;

dt_as_str = document.moon.date_txt.value;

dd = eval(dt_as_str.substring(0,2));
mm = eval(dt_as_str.substring(3,5));
yy = eval(dt_as_str.substring(6,10));

with (Math) {
var yyy=yy;
var mmm=mm;
if (mm < 3)
{
yyy = yy - 1;
mmm = mm + 12;
}
a = floor(yyy/100);
b = 2 - a + floor(a/4);

return floor(365.25*yyy) + floor(30.6001*(mmm+1)) + dd + 1720994.5 + b;
}
}

function moon_phase()
{
with (Math) {

var RAD = 180 / PI;

var jd = julian_date() + frac_day;

document.moon.julian_date.value = jd;

var moon_days = 29.5306;
var D = jd + 1.1 / 1440 - 2444238.5;
var N = proper_ang(D / 1.01456167);
var M_sun = proper_ang(N - 3.762863);
var Ec = 1.91574168 * sin(M_sun / RAD)
var lambda_sun = proper_ang(N + Ec + 278.83354);
var l0 = 64.975464;
var P0 = 349.383063;
var N0 = 151.950429;
var i = 5.145396;
var e = 0.0549;
var l = proper_ang(13.1763966 * D + l0);
var Mm = proper_ang(l - 0.111404 * D - P0);
var N = proper_ang(N0 - 0.0529539 * D);
var Ev = 1.2739 * sin((2 * (l - lambda_sun) - Mm) / RAD);
var Ae = 0.1858 * sin(M_sun / RAD);
var A3 = 0.37 * sin(M_sun / RAD);
Mm = Mm + Ev - Ae - A3;
Ec = 6.2886 * sin(Mm / RAD);
var moon_distance = round_100((1 - pow(e,2)) / (1 + e * cos((Mm + Ec) / RAD)) * 238855.7);
var A4 = 0.214 * sin(2 * Mm / RAD);
l += Ev + Ec - Ae + A4;
l += 0.6583 * sin(2 * (l - lambda_sun) / RAD);
D = proper_ang(l - lambda_sun);
var age = D / 360 * moon_days;

document.moon.moon_age.value = round_10(age);

thisImage = floor(age);

document.myPicture.src = myImage[thisImage];

}
}


/*
Cross browser Marquee script- ? Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and Terms Of Use,
visit http://www.dynamicdrive.com
Credit MUST stay intact
*/

var marqueewidth="450px"
var marqueeheight="25px"
var marqueespeed=3
var marqueebgcolor="#000000"
var pauseit=1

//Specify the marquee's content (don't delete <nobr> tag)
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

var marqueecontent='<nobr><font face="verdana" size="3" color="orange"></font></nobr>'

marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var iedom=document.all||document.getElementById
if (iedom)
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+marqueecontent+'</span>')
var actualwidth=''
var cross_marquee, ns_marquee

function populate(){
if (iedom){
cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
cross_marquee.innerHTML=marqueecontent
actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
}
else if (document.layers){
ns_marquee=document.ns_marquee.document.ns_marquee2
ns_marquee.left=parseInt(marqueewidth)+8
ns_marquee.document.write(marqueecontent)
ns_marquee.document.close()
actualwidth=ns_marquee.document.width
}
lefttime=setInterval("scrollmarquee()",20)
}
setup()
window.onload=populate

function scrollmarquee(){
if (iedom){
if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
else
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"

}
else if (document.layers){
if (ns_marquee.left>(actualwidth*(-1)+8))
ns_marquee.left-=copyspeed
else
ns_marquee.left=parseInt(marqueewidth)+8
}
}

if (iedom||document.layers){
with (document){
document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
if (iedom){
write('<div style="position:relative;width:'+marqueewidth+';height:'+marqueeheight+';overflow:hidden">')
write('<div style="position:absolute;width:'+marqueewidth+';height:'+marqueeheight+';background-color:'+marqueebgcolor+'" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
write('<div id="iemarquee" style="position:absolute;left:0px;top:0px"></div>')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee" bgColor='+marqueebgcolor+'>')
write('<layer name="ns_marquee2" left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
write('</ilayer>')
}
document.write('</td></table>')
}
}