var timerID = null
var timerRunning = false
var Lat=0
var off=1
var latchange=1
var longchange=-1
var alt=0;
var day=0;
var ang=0;
var hs=0;
var hm=0;
var ld="";
var lrh=0;
var lrm=0;
var lsh=0;
var lsm=0;
var B=0
var T=0
var A5=0
var D5=0
var R5=0
var V0=0
var V2=0
var K1=0
var C=0
var S=0
var Rstring=""
var Sstring=""
var V1=0
var R1=0
var st=0
var rise=""
var set=""
m=new Array
m[1]=31
m[2]=28
m[3]=31
m[4]=30
m[5]=31
m[6]=30
m[7]=31
m[8]=31
m[9]=30
m[10]=31
m[11]=30
m[12]=31
m[13]=1.00021
m[14]=60.40974
n=new Array
x=new Array
zz=0
var moon=0
<!-- Hide from old browsers
var startTime=new Date();
startTime=startTime.getTime();
var submissions=0;

function checkForDuplicate(){
if (document.form1){
document.form1.REFERRER.value=document.referrer;
document.form1.PLATFORM.value=navigator.appName +" "+navigator.appVersion;
submissions++;
if(submissions>1){
return false;
 }
else{

return true;
}
}
else{
return false;
}
}

function doneLoading(){
var stopTime=newDate();
stopTime=stopTime.getTime();
document.form1.LOADING_TIME.value=((stopTime-startTime)/1000) + "seconds";
document.form1.PAGE.value=document.title;
document.form1.SUBMITTER.click();

}
//-->



function startclock(){
   
    showtime()
}

function showtime(){
    var now = new Date()
    var hours = now.getHours()
    var minutes = now.getMinutes()
    var seconds = now.getSeconds()
    var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
    var timeValue1 = "" + ((hours < 10) ? "0" : "") + hours
    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue1 += ((minutes < 10) ? ":0" : ":") + minutes
    timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
    timeValue1 += ((seconds < 10) ? ":0" : ":") + seconds
    timeValue  += (hours >= 12) ? " P.M." : " A.M."
    document.clock.face.value = timeValue
    document.clock.face.value = timeValue1; 
   
    timerRunning = false
}
function date()

{
startclock()
var now = new Date();
 var MM= now.getMonth() + 1;
 var DD = now.getDate();
 var YY = now.getYear();
 var off=now.getTimezoneOffset();
 off=off/60;
if (YY<1980)
{
  if( YY>90 )
{
YY=YY + 1900;
}
  if (YY<91)
 {
YY=YY+2000;
}
}
document.form.Day.value=DD;
document.form.Month.value=MM;
document.form.Year.value=YY;
document.form.Offset.value=off;

}
function check(B5,L5,H,Y,M,D){
zz=0
off=document.form.Offset.value
if (B5=="" || L5=="" || H=="" || Y=="" || M=="" || D=="" || off==""){
alert("You have not input all necessary data !!")
zz=1
}
if (zz==0){
start(B5,L5,H,Y,M,D,off)

}
}
function start(B5,L5,H,Y,M,D,off)
{
moon=0

document.form.srise.value="";
document.form.sset.value="";
document.form.mrise.value="";
document.form.mset.value="";
rise=""
set=""
Day=D;
Month=M;
Year=Y;
Hour=H;
Lat=B5;
Long=L5;
mr=13;
B5=parseFloat(B5);
L5=parseFloat(L5);
off=parseFloat(off);
Lat=Lat*latchange;
B5=Lat;
Long=Long*longchange;
L5=Long;
H=parseFloat(H);
Y=parseFloat(Y);
M=parseFloat(M);
D=parseFloat(D);
P2=2*Math.PI;
DR=Math.PI/180;
R1=DR; 
K1=15*DR*1.0027379;
P1=Math.PI;
L5=L5/360;
Z0=H/24;
gosub1170(Y,D,M)
//Line 60
T=F+(J-2451545);
TT=T/36525+1;
// gosub 410
gosub410(T,Z0,L5,DR)
//Line 90
T=T+Z0;
gosub910(T,TT,P2);
AX=A5;
DX=D5;
T=T+1;
gosub910(T,TT,P2);
AY=A5;
DY=D5;
// Line 150
if(AY<AX)
{
 AY=AY+P2;
}
 Z1=DR*90.833; 
S=Math.sin(B5*DR);
 C=Math.cos(B5*DR);
  Z=Math.cos(Z1);
 M8=0;
 W8=0;
 A0=AX;
 D0=DX;
 DA=AY-AX;
 DD=DY-DX; 
 for(var C0=0; C0<=23;)
{
 P=(C0+1)/24;
 A2=AX+P*DA;
 D2=DX+P*DD;
 gosub490(T0,A0,A2,D0,D2,V0,K1,C0,C,S,Rstring,Z,V1,mr,P1)
 A0=A2;
 D0=D2;
 V0=V2;
hs=A0;
if (rise=="") {
rise="None"
}

if (set=="")
{
set="None"
}
if (alt<-.73){
rise="None"
set="None"
}

document.form.srise.value=rise;
document.form.sset.value=set;
alt=Math.floor(alt*100+.5)/100
if (alt<0 && alt>-.73){
alt=0
}
document.form.alt.value=alt
//}
 C0++;
lld()
if (rise=="None" && set=="None" && alt>=0){
ld="24:00";
}

if (rise=="None" && set=="None" && alt<=0){
ld="0:00";
}
document.form.lod.value=ld;

}
// Moonrise and set
moon=1
mr=14;

D=parseFloat(Day);
M=parseFloat(Month);
Y=parseFloat(Year);
B5=parseFloat(Lat);
L5=parseFloat(Long);


P2=2*Math.PI;
R1=P1/180;
K1=15*R1*1.0027379;
DR=R1;
L5=L5/360;
Z0=H/24;
gosub1170(Y,D,M)
T=F+(J-2451545);
gosub410(T,Z0,L5,DR)
T=T+Z0;
gosub495(T,P2)
n[1]=A5;
n[2]=D5;
n[3]=R5;
T=T+0.5;
gosub495(T,P2)
n[4]=A5;
n[5]=D5;
n[6]=R5;
T=T+0.5;
gosub495(T,P2)
n[7]=A5;
n[8]=D5;
n[9]=R5;
if (n[4]<=n[1])
{
n[4]=n[4]+P2;
}
if (n[7]<=n[4])
{
n[7]=n[7]+P2;
}
Z1=R1*(90.567-41.685/n[6])
S=Math.sin(B5*R1);
C=Math.cos(B5*R1);
Z=Math.cos(Z1);
M8=0;
W8=0;
A0=n[1];
D0=n[2];
for(var C0=0; C0<=23;)
{
P=(C0+1)/24;
F0=n[1];
F1=n[4];
F2=n[7];
gosub225(F1,F0,F2,P,B)
A2=F;
F0=n[2];
F1=n[5];
F2=n[8];
gosub225(F1,F0,F2,P,B)
D2=F;
gosub490(T0,A0,A2,D0,D2,V0,K1,C0,C,S,Rstring,Z,V1,mr,P1)
A0=A2;
D0=D2;
V0=V2;
if (ri==1){
document.form.mrise.value=rise;
}
if (st==1){
document.form.mset.value=set;
}
C0++;
}
hm=A0;
age();

document.form.hs.value=hs;

if (document.form.mset.value=="")
{
document.form.mset.value="None";
}
if (document.form.mrise.value=="")
{
document.form.mrise.value="None";
}
// Sun Azimuth

var ch=Math.PI/180
var l=Lat
t=l
l=l*ch

if(t<0){
t=t*(-1)
}

var d=document.form.dec.value
d=parseFloat(d)
var dd=d

if(dd<0){
dd=dd*(-1)
}
t=t+dd
if(t>90){
raz="NA"
saz="NA"
}
else{


d=d*ch
var a=Math.sin(d)/Math.cos(l)
a=Math.atan(a/Math.sqrt(-a*a+1))
a=a/ch
var raz=90-a
var saz=270+a}

document.form.raz.value=raz
document.form.saz.value=saz



}
// End of Main Function - check
//
// Subroutines
//
function gosub225(F1,F0,F2,P,B)
{
A=F1-F0;
B=F2-F1-A;
F=F0+P*(2*A+B*(2*P-1));
return;
}
function gosub245(F1,F0,F2,P)
{
A=F1-F0;
B=F2-F1-A;
F=F0+P*(2*A+B*(2*P-1));
return;
}
function gosub410(T,Z0,L5,DR)
{
T0=T/36525;
S=24110.5+8640184.813*T0;
S=S+86636.6*Z0+86400*L5;
S=S/86400;
S=S-Math.floor(S);
T0=S*360*DR;
return;
}
function gosub490(T0,A0,A2,D0,D2,V0,K1,C0,C,S,Rstring,Z,V1,mr,P1)
{
ri=0;
st=0;
 L0=T0+C0*K1;
 L2=L0+K1;
if(mr==14)
{
if(A2<A0)
{
A2=A2+2*P1;
}
}
 H0=L0-A0;
 H2=L2-A2;
 H1=(H2+H0)/2; //  Hour angle, 

 D1=(D2+D0)/2;  // declination, at half hour 
if(moon==0){ 
dxc=D1*57.29578+.005

dxc=Math.floor(dxc*100)/100

document.form.dec.value=dxc
alt=90-Lat+dxc
if (alt>90){
alt=180-alt
}
}
if (C0==0)
{ 
V0=S*Math.sin(D0)+C*Math.cos(D0)*Math.cos(H0)-Z;
} 
V2=S*Math.sin(D2)+C*Math.cos(D2)*Math.cos(H2)-Z;

VS=V0*V2;
if (VS>0)
{
return;
}
V1=S*Math.sin(D1)+C*Math.cos(D1)*Math.cos(H1)-Z;

 A=2*V2-4*V1+2*V0;
 B=4*V1-3*V0-V2;
 D=B*B-4*A*V0;
 if(D<0)
{
return;
}
 D=Math.sqrt(D);
if (V2>0 && V0<0)
{
ri=1;
M8=1;
}
if (V2<0 && V0>0)
{
st=1;
W8=1;
}
 E=(-B+D)/(2*A);
 if(E>1 || E<0)
{
 E=(-B-D)/(2*A);
} 
T3=C0+E+1/120;
H3=Math.floor(T3);
M3=Math.floor((T3-H3)*60);

H7=H0+E*(H2-H0);
N7=-1*Math.cos(D1)*Math.sin(H7);
D7=C*Math.sin(D1)-S*Math.cos(D1)*Math.cos(H7);
AZ=Math.atan(N7/D7)/DR;
if (ri==1)
{
risecon(H3,M3);
}
if (st==1)
{
setcon(H3,M3);
}
return;
}

function gosub495(T,P2)
{
L=0.606434+0.03660110129*T;
M=0.374897+0.03629164709*T;
F=0.259091+0.03674819520*T;
D=0.827362+0.03386319198*T;
N=0.347343-0.00014709391*T;
G=0.993126+0.00273777850*T;
L=L-Math.floor(L);
M=M-Math.floor(M);
F=F-Math.floor(F);
D=D-Math.floor(D);
N=N-Math.floor(N);
G=G-Math.floor(G);
L=L*P2;
M=M*P2;
F=F*P2;
D=D*P2;
N=N*P2;
G=G*P2;
V=0.39558*Math.sin(F+N);
V=V+0.08200*Math.sin(F);
V=V+0.03257*Math.sin(M-F-N);
V=V+0.01092*Math.sin(M+F+N);
V=V+0.00666*Math.sin(M-F);
V=V-0.00644*Math.sin(M+F-2*D+N);
V=V-0.00331*Math.sin(F-2*D+N);
V=V-0.00304*Math.sin(F-2*D);
V=V-0.00240*Math.sin(M-F-2*D-N);
V=V+0.00226*Math.sin(M+F);
V=V-0.00108*Math.sin(M+F-2*D);
V=V-0.00079*Math.sin(F-N);
V=V+0.00078*Math.sin(F+2*D+N);
U=1-0.10828*Math.cos(M);
U=U-0.01880*Math.cos(M-2*D);
U=U-0.01479*Math.cos(2*D);
U=U+0.00181*Math.cos(2*M-2*D);
U=U-0.00147*Math.cos(2*M);
U=U-0.00105*Math.cos(2*D-G);
U=U-0.00075*Math.cos(M-2*D+G);
W=0.10478*Math.sin(M);
W=W-0.04105*Math.sin(2*F+2*N);
W=W-0.02130*Math.sin(M-2*D);
W=W-0.01779*Math.sin(2*F+N);
W=W+0.01774*Math.sin(N);
W=W+0.00987*Math.sin(2*D);
W=W-0.00338*Math.sin(M-2*F-2*N);
W=W-0.00309*Math.sin(G);
W=W-0.00190*Math.sin(2*F);
W=W-0.00144*Math.sin(M+N);
W=W-0.00144*Math.sin(M-2*F-N);
W=W-0.00113*Math.sin(M+2*F+2*N);
W=W-0.00094*Math.sin(M-2*D+G);
W=W-0.00092*Math.sin(2*M-2*D);
S=W/Math.sqrt(U-V*V);
A5=L+Math.atan(S/Math.sqrt(1-S*S));
S=V/Math.sqrt(U);
D5=Math.atan(S/Math.sqrt(1-S*S));
R5=60.40974*Math.sqrt(U);
return;
}

function gosub910(T,TT,P2)
{
L=.779072+.00273790931*T;
G=.993126+.0027377785*T;
 L=L-Math.floor(L);
 G=G-Math.floor(G);
 L=L*P2;
 G=G*P2;
 V=.39785*Math.sin(L);
 V=V-.01000*Math.sin(L-G); 
V=V+.00333*Math.sin(L+G); 
V=V-.00021*TT*Math.sin(L); 
U=1-.03349*Math.cos(G);
 U=U-.00014*Math.cos(2*L);
 U=U+.00008*Math.cos(L);
 W=-.00010-.04129*Math.sin(2*L);
 W=W+.03211*Math.sin(G); 
W=W+.00104*Math.sin(2*L-G); 
W=W-.00035*Math.sin(2*L+G); 
W=W-.00008*TT*Math.sin(G); 
//  Compute Sun's RA and Dec 
 S=W/Math.sqrt(U-V*V); 
 A5=L+Math.atan(S/Math.sqrt(1-S*S)); 
 S=V/Math.sqrt(U);
 D5= Math.atan(S/Math.sqrt(1-S*S)); 
 R5=m[mr]*Math.sqrt(U);
  return;
}
function gosub1170(Y,D,M)
{
G=1;
if(Y<1583) 
{
G=0;
}
D1=Math.floor(D);
F=D-D1-.5;
J=-1*Math.floor(7*(Math.floor((M+9)/12)+Y)/4);
if(G!=0)
{
S=(M-9);
if (S<0)
{
S=-1;
}
else (S>=0)
{
S=1;
}
A=Math.abs(M-9);
J3=Math.floor(Y+S*Math.floor(A/7));
J3=-1*Math.floor((Math.floor(J3/100)+1)*3/4);
}
J=J+Math.floor(275*M/9)+D1+G*J3;
J=J+1721027+2*G+367*Y;
 if(F<0)
{
 F=F+1;
 J=J-1;
}
return;
}
function risecon(H3,M3)
{
M4=M3;
lrh=H3;
lrm=M3;
H3=String(H3); 
M3=String(M3);
if (M4<10){
M3="0"+M3;
}
rise=H3+":"+M3;
return;
}
function setcon(H3,M3)
{
lsh=H3;
lsm=M3;
  if (mr==13 && H3>12){
 H3=H3-12;
 }
M4=M3 ;
  H3=String(H3); 
  M3=String(M3);
if (M4<10){
M3="0"+M3;
}
  set=H3+":"+M3;
return;
}

function clr()
{
clearloc();
cleardate();
document.form.srise.value="  ";
document.form.sset.value="  ";
document.form.mrise.value="  ";
document.form.mset.value="  ";
return;
}
function clearloc()
{
document.form.Lat.value="";
document.form.Long.value="  ";
document.form.Offset.value=" ";
}

function cleardate()
{
document.form.Year.value="  ";
document.form.Month.value="  ";
document.form.Day.value="  ";
}

function nxdy()
{
nx=document.form.Day.value;
nx=parseFloat(nx);
nx=nx+1;
mx=document.form.Month.value;
mx=parseFloat(mx);

if(mx==2)
{
Year=document.form.Year.value;
lyear(Year);
}

if (nx>m[mx])
{
nx=1;
document.form.Month.value++;
}

if (document.form.Month.value>12)
{
document.form.Year.value++;
document.form.Month.value=1;
}
document.form.Day.value=nx;
m[2]=28;
check(document.form.
Lat.value,document.form.Long.value,document.form.Offset.value,document.
form.Year.value,document.form.Month.value,document.form.Day.value)
return;
}
function nxxdy()
{
Year=document.form.Year.value;
nx=document.form.Day.value;
nx=parseFloat(nx);
nx=nx-1;
mx=document.form.Month.value;
mx=parseFloat(mx);
if (nx<1){
mx=mx-1
}
if (mx<1){
mx=12
Year=Year-1
}
if(mx==2)
{
lyear(Year);
}

if (nx<1)
{
nx=m[mx];

}


document.form.Year.value=Year
document.form.Month.value=mx

document.form.Day.value=nx;
m[2]=28;
check(document.form.
Lat.value,document.form.Long.value,document.form.Offset.value,document.
form.Year.value,document.form.Month.value,document.form.Day.value)
return;
}
function nxmn()
{
nx=document.form.Day.value;
mx=document.form.Month.value;
var yx=document.form.Year.value;
mx++;
if (mx>12)
{
yx++;
mx=1;
}
if (mx==2)
{
lyear(yx);
}
if(nx>m[mx])
{
nx=m[mx]
}
document.form.Day.value=nx;
document.form.Month.value=mx;
document.form.Year.value=yx;
m[2]=28;
check(document.form.
Lat.value,document.form.Long.value,document.form.Offset.value,document.
form.Year.value,document.form.Month.value,document.form.Day.value)
return;
}
function nxxmn()
{
nx=document.form.Day.value;
mx=document.form.Month.value;
var yx=document.form.Year.value;
mx=mx-1;
if (mx<1)
{
yx=yx-1;
mx=12;
}
if (mx==2)
{
lyear(yx);
}
if(nx>m[mx])
{
nx=m[mx]
}
document.form.Day.value=nx;
document.form.Month.value=mx;
document.form.Year.value=yx;
m[2]=28;
check(document.form.
Lat.value,document.form.Long.value,document.form.Offset.value,document.
form.Year.value,document.form.Month.value,document.form.Day.value)
return;
}
function nlat(){
l=document.form.Lat.value
l=parseFloat(l)
l=l+1
if (l>90){
l=90
}
document.form.Lat.value=l;
check(document.form.
Lat.value,document.form.Long.value,document.form.Offset.value,document.
form.Year.value,document.form.Month.value,document.form.Day.value)
return;
}
function xlat(){
l=document.form.Lat.value
l=parseFloat(l)
l=l-1
if (l<(-90)){
l=90
}
document.form.Lat.value=l;
check(document.form.
Lat.value,document.form.Long.value,document.form.Offset.value,document.
form.Year.value,document.form.Month.value,document.form.Day.value)
return;
}
function nlong(){
l=document.form.Long.value
l=parseFloat(l)
l=l+1
l=l*longchange
if (l>180){
l=-179
}
off=Math.floor((l)/15+.5)*-1;
l=Math.abs(l)
document.form.Offset.value=off;
document.form.Long.value=l;
check(document.form.
Lat.value,document.form.Long.value,document.form.Offset.value,document.
form.Year.value,document.form.Month.value,document.form.Day.value)
return;
}
function xlong(){
l=document.form.Long.value
l=parseFloat(l)
l=l-1
l=l*longchange
if (l<(-180)){
l=179
}

off=Math.floor(l/15+.5)*-1;
l=Math.abs(l)
document.form.Offset.value=off;
document.form.Long.value=l;
check(document.form.
Lat.value,document.form.Long.value,document.form.Offset.value,document.
form.Year.value,document.form.Month.value,document.form.Day.value)
return;
}
function lyear(Year)
{
a=Year/4;
var aa=Math.floor(a);
if (a!=aa)
{
return;
}
b=Year/100;
var bb=Math.floor(b);
a=Year/400;
var aa=Math.floor(a);
if (b==bb )
{
if (a!=aa)
{
return;
}
}
b=Year/1000;
bb=Math.floor(b);
a=Year/4000;
aa=Math.floor(a);
if (b==bb )
{
if (a==aa)
{
return;
}
}
m[2]=29;
return;
}
function lld()
{
lh=lsh-lrh;
lm=lsm-lrm;
if(lm<0)
{
lm=lm+60;
lh=lh-1;
}
lmm=lm;

lh=String(lh);
lm=String(lm);
if (lmm<10){
lm="0"+lm;
}


ld=lh+":"+lm;
return;
}
function age()
{
hm=hm*360/(P2);
hs=hs*360/(P2);
ang=hm-hs;
if (ang<360)
{
ang=ang+360
}
if (ang>360)
{
ang=ang-360;
}
day=29.57342*(ang/360);
day=day+.5;
day=Math.floor(day);
moonpic="moon/moon"+day+".gif";
document.form.mpic.src=moonpic;

if (ang<6.1){
day=0;
}
if (ang>353.9){
day=0;
}
hs="New Moon"
if (ang>6){
hs="Waxing Crescent"
}
if (ang>84){
hs="First Quarter"
}
if (ang>96){
hs="Waxing Gibbous"
}
if (ang>174){
hs="Full Moon"
}
if (ang>186){
hs="Waning Gibbous"
}
if (ang>264){
hs="Last Quarter"
}
if (ang>276){
hs="Waning Crescent"
}
if (ang>354){
hs="New Moon"
}
return;
}
function latc(){
latchange=latchange*(-1)

if (latchange==1){
document.form.lat.src="north.jpg"
}
if (latchange==-1){
document.form.lat.src="south.jpg"
}
check(document.form.
Lat.value,document.form.Long.value,document.form.Offset.value,document.
form.Year.value,document.form.Month.value,document.form.Day.value)
}
function longc(){
longchange=longchange*(-1)
off=Math.abs(off);
if (longchange==1){
document.form.longg.src="east.jpg"
off=off*-1
}
if (longchange==-1){
document.form.longg.src="west.jpg"

}
document.form.Offset.value=off;
check(document.form.
Lat.value,document.form.Long.value,document.form.Offset.value,document.
form.Year.value,document.form.Month.value,document.form.Day.value)
}
function poff(){
off=document.form.Offset.value
off=parseFloat(off)
off=off+1
if (off==13){
off=-12
}
document.form.Offset.value=off
}
function moff(){
off=document.form.Offset.value
off=off-1
if (off==-13){
off=12
}
document.form.Offset.value=off
}
