function MakeArray(n) {
    	this.length = n;
    	for (i = 1; i <= n; i++) {
    	    this[i] = "";
	}
	return(this);
}

function init(){
	diold = 0;
	pi=3.141592654;
	pi2= pi * 2;
	rd=pi / 180;
	rt = 1.00273791;
	nd = new MakeArray(12);
	nd[1] = 0;
	nd[2] = 31;
	nd[3] = 59;
	nd[4] = 90;
	nd[5] = 120;
	nd[6] = 151;
	nd[7] = 181;
	nd[8] = 212;
	nd[9] = 243;
	nd[10] = 273;
	nd[11] = 304;
	nd[12] = 334;
	l1=140.3;
	l2=35.21;
	freq=144;
	lo = l1 * rd;
	la = l2 * rd;
	n1 = 10;
	n2 = 10;
	dp = -692.743 * Math.sin(2 * la) + 1.1633 * Math.sin(4 * la) - .0026 * Math.sin(6 * la);
	lg = la + (dp * pi2 / 1.296e+06);
	ra = .998327073 + 1.67644e-03 * Math.cos(2 * lg) - 3.519e-06 * Math.cos(4 * lg);
	xs = ra * Math.cos(lg) * Math.cos(lo);
	ys = ra * Math.cos(lg) * Math.sin(lo);
	zs = ra * Math.sin(lg);
}

function cal(){
	now = new Date();
	x = new Date();
	t = new Date(Date.UTC(x.getYear(),x.getMonth(),x.getDate(),x.getHours(),x.getMinutes(),x.getSeconds()));
	z = new Date(x.getYear(),x.getMonth(),x.getDate(),x.getHours(),x.getMinutes(),x.getSeconds());
	y=t.getTime()-z.getTime();
	now.setTime(z.getTime()-y);
	yr = now.getYear();
	if(yr<0){
		yr=yr+3800;
	}
	if(yr<100){
		yr+=1900;
	}
	m1 = now.getMonth()+1;
	dy = now.getDate();
	hr = now.getHours();
	mn = now.getMinutes();
	sec = now.getSeconds();
	mn=mn+(sec/60);
	ut = ( pi2 * (60 * hr + mn)) / 1440;
	ym = yr - 1900;
	kd = Math.floor((ym - 1) / 4);
	j0 = 2415019.5;
	jd = ym * 365 + nd[m1] + dy + kd;
	if ((ym / 4) - Math.floor(ym / 4) > .2) {
		ym=ym;
	} 
	else {
		if (m1 > 2){
			jd = jd + 1;
		}
	}
	ce = (jd - 36525.5) / 36525;
	st = .2790573 + ce * 100.002139 + .093104 * (ce * ce / 86400);
	st = st - Math.floor(st);
	st = pi2 * st;
	ds = jd - 36525.5 + ut * .5 / pi;
	so = 280.46 + .9856474 * ds;
	if (so >= 0) {
		 so = so - 360 * Math.floor(so / 360);
	}
	if (so < 0) {
		so = so - 360 * Math.floor(so / 360);
	}
	if (so < 0) {
		so = so + 360;
	}
	sa = rd * (357.528 + .9856003 * ds);
	if (sa >=0) {
		sa = sa + pi2 * Math.floor(sa * .5 / pi);
	}
	if (sa < 0) {
		sa = sa - pi2 * Math.floor(sa * .5 / pi);
	}
	if (sa < 0) {
		sa = sa + pi2;
	}
	ec = rd * (so + 1.915 * Math.sin(sa) + .02 * Math.sin(2 * sa));
	if (ec >= 0) {
		ec = ec + pi2 * Math.floor(ec * .5 / pi);
	}
	if (ec <  0) {
		ec = ec - pi2 * Math.floor(ec * .5 / pi);
	}
	iq = 1 + Math.floor(ec * 2 / pi);
	ob = rd * (23.439 - .0000004 * ds);
	su = Math.atan(Math.cos(ob) * Math.tan(ec));
	if (iq == 2) {
		su = su + pi;
	}
	if (iq == 3) {
		su = su - pi;
	}
	if (iq == 4) {
		su = su - pi2;
	}
	ar = Math.sin(ob) * Math.sin(ec)
	sd = Math.atan(ar / Math.sqrt(1 - ar * ar));
	ce = ce + ut / (pi * 73050);
	a = rd * (134.9 + 477198.85 * ce);
	b = rd * (259.2 - 413335.38 * ce);
	c = rd * (235.7 + 890534.23 * ce);
	d = rd * (269.9 + 954397.7 * ce);
	e = rd * (357.5 + 35999.05 * ce);
	f = rd * (186.6 + 966404.05 * ce);
	mo = 218.32 +481267.883*ce +6.29*Math.sin(a)- 1.27*Math.sin(b);
	mo = mo + .66*Math.sin(c) + .21*Math.sin(d)- .19*Math.sin(e)- .11*Math.sin(f);
	mo = mo * rd;
	a = rd * (93.3 + 483202.03 * ce);
	b = rd * (228.2 + 960400.87 * ce);
	c = rd * (318.3 + 6003.18 * ce);
	d = rd * (217.6 - 407332.2 * ce);
	ma = rd * (5.13 * Math.sin(a)+ .28*Math.sin(b)- .28*Math.sin(c)- .17*Math.sin(d));
	a = rd * (134.9 + 477198.85 * ce);
	b = rd * (259.2 - 413335.38 * ce);
	c = rd * (235.7 + 890534.23 * ce);
	d = rd * (269.9 + 954397.7 * ce);
	ho = .9508 + .0518*Math.cos(a)+ .0095*Math.cos(b)+ .0078*Math.cos(c)+ .0028*Math.cos(d);
	ho = ho * rd;
	md = 1 / Math.sin(ho);
	ll = Math.cos(ma) * Math.cos(mo);
	mm = .9175 * Math.cos(ma) * Math.sin(mo) - .3978 * Math.sin(ma);
	nn = .3978 * Math.cos(ma) * Math.sin(mo) + .9175 * Math.sin(ma);
	mr = Math.atan(mm / ll);
	if (ll < 0) {
		mr = mr + pi;
	}
	if (mr < 0) {
		mr = mr + pi2;
	}
	me = Math.atan(nn / Math.sqrt(1 - nn * nn));
	gs = st + ut * rt;
	xm = md * Math.cos(me) * Math.cos(mr);
	ym = md * Math.cos(me) * Math.sin(mr);
	zm = md * Math.sin(me);
	xe = xm * Math.cos(gs) + ym * Math.sin(gs);
	ye = -xm * Math.sin(gs) + ym * Math.cos(gs);
	xx = xe - xs;
	yy = ye - ys;
	zz = zm - zs;
	di = Math.sqrt(xx * xx + yy * yy + zz * zz) * 6373;
	co = (383100 / di) * (383100 / di);
	vm = (diold - di) * 1000 / n1 / 60;
	dop = vm * freq / 150000;
	if (diold < 300000) {
		dop = 0;
	}
	diold = di;
	me = Math.atan(zz / Math.sqrt(xx * xx + yy * yy));
	mh = lo - Math.atan(yy / xx);
	if (xx < 0) {
		mh = mh - pi;
	}
	if (mh < -pi) {
		mh = mh + pi2;
	}
	 ha = gs + lo - su;
	 de = sd;
	 sub1430();
	 sa = Math.floor(10 * az /rd ) /10;
	 se = Math.floor(10 * el /rd ) /10;
	 ha = mh;
	 de = me;
	 sub1430();
	 ma = Math.floor(10 * az /rd ) /10;
	 me = Math.floor(10 * el /rd ) /10;
	return;
}

function sub1430(){
	while(ha > pi){
		ha = ha - 2 * pi;
	}
	el = Math.sin(de) * Math.sin(la) + Math.cos(de) * Math.cos(la) * Math.cos(ha);
	el = Math.atan(el / Math.sqrt(1 - el * el));
	az = (Math.sin(de) - Math.sin(la) * Math.sin(el)) / (Math.cos(la) * Math.cos(el));
	az = Math.atan(Math.sqrt(1 - az * az) / az);
	if (az < 0) {
		az = az + pi;
	}
	if (ha > 0) {
		az = 2 * pi -az;
	}
}
document.write('<STYLE TYPE="text/css">')
document.write('th	{	font-size:8pt;')
document.write('font-style:normal;')
document.write('}')
document.write('td 	{	font-size:8pt;')
document.write('font-style:normal;')
document.write('}')
document.write('input	{	font-size:8pt;')
document.write('font-style:normal;')
document.write('}')
document.write('</STYLE>')
document.write('<center>')
document.write('<FORM name="form" METHOD="post">')
document.write('<table border=1 width=66 height=200 CELLSPACING=0 CELLPADDING=0>')
document.write('<tr><th height=200 ROWSPAN=18 bgcolor="#6C99DD"><img src=sunmoon/sun-moon.jpg></th><tr>')
document.write('<tr><th bgcolor="#6C99DD"><img src=sunmoon/sun-moon-year.jpg></th></tr>')
document.write('<tr><td><INPUT NAME="year" SIZE="6"></td></tr>')
document.write('<tr><th bgcolor="#6C99DD"><img src=sunmoon/sun-moon-month.jpg></th></tr>')
document.write('<tr><td><INPUT NAME="month" SIZE="6"></td></tr>')
document.write('<tr><th bgcolor="#6C99DD"><img src=sunmoon/sun-moon-day.jpg></th></tr>')
document.write('<tr><td><INPUT NAME="day" SIZE="6"></td></tr>')
document.write('<tr><th bgcolor="#6C99DD"><img src=sunmoon/sun-moon-utc.jpg></th></tr>')
document.write('<tr><td><INPUT NAME="hhmm" SIZE="6"></td></tr>')
document.write('<tr><th bgcolor="#6C99DD"><img src=sunmoon/sun-moon-sun_az.jpg></th></tr>')
document.write('<tr><td><INPUT NAME="sa" SIZE="6"></td></tr>')
document.write('<tr><th bgcolor="#6C99DD"><img src=sunmoon/sun-moon-sun_el.jpg></th></tr>')
document.write('<tr><td><INPUT NAME="se" SIZE="6"></td></tr>')
document.write('<tr><th bgcolor="#6C99DD"><img src=sunmoon/sun-moon-moon_az.jpg></th></tr>')
document.write('<tr><td><INPUT NAME="ma" SIZE="6"></td></tr>')
document.write('<tr><th bgcolor="#6C99DD"><img src=sunmoon/sun-moon-moon_el.jpg></th></tr>')
document.write('<tr><td><INPUT NAME="me" SIZE="6"></td></tr>')
document.write('</table>')
document.write('</FORM>')
init();
function update() {
	cal();
	mn=Math.floor(mn);
	if(hr<10){
		hr="0"+hr;
	}
	if(mn<10){
		mn="0"+mn;
	}
	if(sec<10){
		sec="0"+sec;
	}
	document.form.year.value = "  "+yr;
	document.form.month.value = "    "+m1;
	document.form.day.value = "    "+dy;
	document.form.hhmm.value = hr+":"+mn+":"+sec;
	document.form.sa.value = "   "+sa;
	document.form.se.value = "   "+se;
	document.form.ma.value = "   "+ma;
	document.form.me.value = "   "+me;
	setTimeout('update()', 10000);
}
update();
