
function Berechnung() {
var index;
Beginn=JD;
Ende=JD + (AnzahlJahre*366+Schrittweite);
for (n=Beginn;n<=Ende;n=n+Schrittweite) // Schleife für Zeitraum 
{

Datum()
d=n-2451545;
T=d/36525;

Sonne()
Saturn()


if (index==2 && n<(Ende-90)) { document.write("<tr><td colspan=13>&#160;</td></tr><tr><th>Datum</th><th>&alpha;</th><th>&delta;</th><th>E</th><th>l - &pi;</th><th>r</th><th>&Delta;</th><th>&phi;</th><th>&#216;<sub>Ä</sub></th><th>N<sub>S</sub></th><th>N<sub>E</sub></th><th colspan=2>&#216;<sub>Ring</sub></th><th>mag</th></tr>"); }

if (abstand<=9.6)  // 18"
 { TabelleSchreiben(); index=1; }
 else
 { index++; }

}
}


function Kalender() {
// input JJJJ, MM, DD
// output d, T, JD
  var j=JJJJ; 
  var m=MM;
  if (m<=2) {j--; m=m+12;}
  var B=Math.floor(j/400)-Math.floor(j/100);
  if (JJJJ<=1582 && MM<=10 && DD<=4) B=-2;   
  JD=Math.floor(365.25*j)+Math.floor(30.6001*(m+1))+B+1720996.5+DD;
  d=JD-2451545;
  T=d/36525; 
}


function Datum() {
// input n
// output Mon, Day, JJ
  var JDatum = n;
  var c9 = Math.floor(JDatum+0.5) + 1537;
  var d9 = Math.floor((c9-122.1)/365.25);
  var e9 = Math.floor(365.25*d9);
  var f9 = Math.floor((c9-e9)/30.6001);
  Mon = f9 - 1 - 12*Math.floor(f9/14); if (Mon<10) Mon="0" + Mon
  Day = c9 - e9 - Math.floor(30.6001*f9);
  JJ = d9 - 4715 - Math.floor((1*7+1*Mon)/10);
}


function TabelleSchreiben() {

document.write("<tr>");
document.write("<td width=8% align=right>"+ Day + "." + Mon + "." + JJ +"</td>");
document.write("<td align=right width=6%>");
document.write(alpha.toFixed(1) + "<sup>h</sub>");
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(delta.toFixed(0) + "°");
document.write("</td>")
document.write("<td align=right width=6%>");
document.write(elong.toFixed(0) + "°");
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(perihel.toFixed(0) + "°");
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(radiusvektor.toFixed(2));
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(abstand.toFixed(2));
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(phasenwinkel.toFixed(1) + "°");
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(durchmesser.toFixed(1) + '"');
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(neigungsonne.toFixed(1)+ "°");
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(neigungerde.toFixed(1) + "°");
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(ringdurchmesserg.toFixed(1) + '"');
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(ringdurchmesserk.toFixed(1) + '"');
document.write("</td>");
document.write("<td align=right width=6%>");
document.write(helligkeit.toFixed(1));
document.write("</td>");
document.write("</tr>");
}

function Sonne() {
// input T
// output sonne
with (Math) {
  var Ls = (280.46645 + 36000.76983*T)/360;
  Ls = 2*PI*(Ls-floor(Ls));
  Ms = (357.52910 + 35999.05030*T)*PI/180;
  var es = 0.016708617 - 0.000042037*T;
  Cs = (1.914600 - 0.004817*T)*sin(Ms)
  + 0.019993*sin(2*Ms) + 0.000290*sin(3*Ms);
  Cs = Cs*Math.PI/180
  var vs = Ms + Cs;
  Rerde = (0.9997218*(1-es*es))/(1+es*cos(vs));
  lsonne = Ls + Cs;
  var Kmond = (125.0445 - 1934.13626*T)*PI/180; 
  lsonne = lsonne - (0.00569 - 0.00478*sin(Kmond))*PI/180;
  sonne = lsonne*180/PI;
  ekl = (23.43929 - 0.013004*T + 0.00256*Math.cos(Kmond))*Math.PI/180;
}
}


function Saturn() {

// input d
// output knoten, perihel, lampda, radiusvektor, neigung
with (Math) {

var V = (172.74 + 0.00111588*d)*PI/180;
x = (317.018  + 0.0334443*d -0.814 * sin(V))/360;
var Ns = 2* PI * (x - floor(x));
var Bs = 6.366*sin(Ns) + 0.221 * sin (2*Ns)+ 0.011 * sin (3*Ns);
var rs = 9.5695 - 0.5304 * cos (Ns) - 0.0147 * cos(2*Ns);
x = (50.391 + 0.95214946*d -0.814*sin(V))/360;
var Js = 2* PI * (x - floor(x));        
var Ks = Js + Cs - PI*Bs/180;

// x = (50.07  + 0.03346*d -0.814 * sin(V) + Bs)/360;  // 2000.0!
x = (50.07  + 0.0334443*d -0.814 * sin(V) + Bs)/360;  // zum Datum?
var laenge = 2* PI * (x - floor(x));

perihel= Ns*180/PI;

radiusvektor = rs;

abstand = sqrt(Rerde*Rerde + rs*rs - 2*Rerde*rs*cos(Ks));


i = asin(Rerde * sin(Ks)/abstand); 
phasenwinkel=180*i/PI;

neigungsonne=180/PI*asin(sin(26.74*PI/180)*sin(laenge-173.6*PI/180));
neigungerde=neigungsonne-180/PI*asin(sin(28.1*PI/180)*sin(i)*cos(laenge-169.5*PI/180))-2.49*(rs-abstand)*sin(laenge-113.9*PI/180)/abstand;

helligkeit = -8.68 + 5*LOG10E*log(rs*abstand) -2.6*sin(abs(neigungerde*PI/180)) + 1.25*sin(neigungerde*PI/180)*sin(neigungerde*PI/180) + 4.4*abs(phasenwinkel/100);


durchmesser = 166.65/abstand;
ringdurchmesserg=2*187.7/abstand;
ringdurchmesserk=2*187.7*sin(abs(neigungerde*PI/180))/abstand;

breite = 2.49*sin(laenge-113.9*PI/180)*PI/180; // *(rs-abstand)/abstand

geolaenge=laenge-i;

var x = cos(breite)*cos(geolaenge);
var y = cos(ekl)*cos(breite)*sin(geolaenge)-sin(ekl)*sin(breite);
alpha = atan(y/x);
if (x<0) alpha = alpha + PI

alpha=alpha*12/PI; if (alpha<0) alpha=alpha+24
delta = asin(sin(ekl)*cos(breite)*sin(geolaenge)+cos(ekl)*sin(breite));
delta=delta*180/PI;

if (geolaenge<lsonne) geolaenge=geolaenge+2*PI
elong =  cos(geolaenge - lsonne)*cos(breite); 
elong = acos(elong)*180/PI;
if (elong>180) elong=elong-360

}
}


