function W360(x) {
var W = x/360;
W = 360*(W-Math.floor(W));
if (W<0) W=W+360;
return W
}


function W360rd(x) {
var W = x/360;
W = 2*Math.PI*(W-Math.floor(W));
if (W<0) W=W+2*Math.PI;
return W
}

function JulDatum() {
   JJJJ=Jahr;
   MM=Monat;
   DD=Tag;
   j=JJJJ;
   m=MM;
   if (m<=2) {j--; m=m+12;}
   B = Math.floor(j/400)-Math.floor(j/100);
   if (JJJJ<=1582 && MM<=10 && DD<=4) B=-2
   JD0=Math.floor(365.25*j)+Math.floor(30.6001*(m+1))+B+1720996.5+DD
   JD=JD0 + Stunden/24+Minuten/1440+Sekunden/(1440*60);
   d = JD-2451545;
   T = d/36525;
   }


function Sa() {

with (Math) {
var Me = 356.0470 + 0.9856002585 * d; //357.526
Me = W360rd(Me);

var Mj =  19.8950 + 0.0830853001 * d;
Mj = W360rd(Mj);

var Ms = 317.020684 + 0.033444141 * d; //316.9670 + 0.0334442282 * d;
Ms = W360rd(Ms);

var V= +0.812 * sin(2*Mj - 5*Ms - 67.6);
   -0.229 * cos(2*Mj - 4*Ms - 2); 
   +0.119 * sin(Mj - 2*Ms - 3); 
   +0.046 * sin(2*Mj - 6*Ms - 69); 
   +0.014 * sin(Mj - 3*Ms + 32);
	
var N = Ms - V*PI/180;
var N9=N*180/PI;
// document.write("M="+N9.toFixed(3)+"<br>");
var B = 6.366 * sin(N) + 0.211 * sin(2*N) + 0.011 * sin(3*N);
var r = 9.5695 - 0.5304*cos(N)  - 0.0147 *cos(2*N);
var lambda = 50.07 + 0.0334982 * d + V + B;
// document.write("l="+lambda.toFixed(3)+"<br>");
var A = (1.916 * sin(Me) + 0.020 * sin(2*Me)) * PI/180;
var B = (6.366 * sin(N) + 0.211 * sin(2*N) + 0.011 * sin(3*N)) * PI/180;

var J = (50.391 + 0.95214946 * d + V);
J = W360rd(J);
}


K = J + A - B;

M=Me;
N=Ms;

Re = 1.0001 - 0.0167 * Math.cos(M);
rs = 9.5695 - 0.5304*Math.cos(N)  - 0.0147 *Math.cos(2*N);

Abstand = Math.sqrt(Re*Re + rs*rs - 2*Re*rs*Math.cos(K));
i = Math.asin(Re * Math.sin(K)/Abstand);
l = (50.07 + 0.0334982 * d - 0.814 * Math.sin(V) + B*180/Math.PI)/360;


LaengeEkl = (l - Math.floor(l)) * 2*Math.PI;
BreiteEkl = 2.49 * Math.sin(LaengeEkl - 113.55*Math.PI/180)*Math.PI/180;

LaengeGeoz = LaengeEkl - i;
BreiteGeoz = BreiteEkl * rs/Abstand;

ekl = Math.PI*23.443/180;

x = Math.cos(LaengeGeoz);
RA = Math.atan ((Math.cos(ekl)*Math.sin(LaengeGeoz) - Math.sin(ekl)*Math.tan(BreiteGeoz))/x);
if (x<0) RA = RA + Math.PI

DE = Math.asin(Math.sin(ekl)*Math.cos(BreiteGeoz)*Math.sin(LaengeGeoz) + Math.cos(ekl)*Math.sin(BreiteGeoz));

x = Math.cos(LaengeEkl);
RAs = Math.atan ((Math.cos(ekl)*Math.sin(LaengeEkl) - Math.sin(ekl)*Math.tan(BreiteEkl))/x);
if (x<0) RAs = RAs + Math.PI

DEs = Math.asin(Math.sin(ekl)*Math.cos(BreiteEkl)*Math.sin(LaengeEkl) + Math.cos(ekl)*Math.sin(BreiteEkl));
}


function Pole()
{
A0 = (40.66 + 1.182E-4*d)*Math.PI/180;
D0 = (83.52 + 1.16E-5*d)*Math.PI/180;
A4 = (37.77 + 6.99E-5*d)*Math.PI/180;
D4 = (83.69 + 7.2E-6*d)*Math.PI/180;
A5 = (318.56 - 9.54E-5*d)*Math.PI/180;
D5 = (75.49 - 9E-6*d)*Math.PI/180;
}


function DPK()
{
A0RA = A0-RA;
A4RA = A4-RA;
A5RA = A5-RA;
A0RAs = A0-RAs;
A4RAs = A4-RAs;
A5RAs = A5-RAs;
B0 = Math.asin(-Math.sin(D0)*Math.sin(DE) - Math.cos(D0)*Math.cos(DE)*Math.cos(A0RA));
B4 = Math.asin(- Math.sin(D4)*Math.sin(DE) - Math.cos(D4)*Math.cos(DE)*Math.cos(A4RA));
B5 = Math.asin(- Math.sin(D5)*Math.sin(DE) - Math.cos(D5)*Math.cos(DE)*Math.cos(A5RA));
B0s = Math.asin(- Math.sin(D0)*Math.sin(DEs) - Math.cos(D0)*Math.cos(DEs)*Math.cos(A0RAs));
B4s = Math.asin(- Math.sin(D4)*Math.sin(DEs) - Math.cos(D4)*Math.cos(DEs)*Math.cos(A4RAs));
B5s = Math.asin(- Math.sin(D5)*Math.sin(DEs) - Math.cos(D5)*Math.cos(DEs)*Math.cos(A5RAs));

x = Math.tan(D0)*Math.cos(DE) - Math.sin(DE)*Math.cos(A0RA);
P0 = Math.atan(Math.sin(A0RA)/x); 
if (x<0) P0 = P0 + Math.PI

x = Math.tan(D4)*Math.cos(DE) - Math.sin(DE)*Math.cos(A4RA);
P4 = Math.atan(Math.sin(A4RA)/x); 
if (x<0) P4 = P4 + Math.PI

x = Math.tan(D5)*Math.cos(DE) - Math.sin(DE)*Math.cos(A5RA);
P5 = Math.atan(Math.sin(A5RA)/x); 
if (x<0) P5 = P5 + Math.PI

x = Math.tan(D0)*Math.cos(DEs) - Math.sin(DEs)*Math.cos(A0RAs);
P0s = Math.atan(Math.sin(A0RAs)/x); 
if (x<0) P0s = P0s + Math.PI

x = Math.tan(D4)*Math.cos(DEs) - Math.sin(DEs)*Math.cos(A4RAs);
P4s = Math.atan(Math.sin(A4RAs)/x); 
if (x<0) P4s = P4s + Math.PI

x = Math.tan(D5)*Math.cos(DEs) - Math.sin(DEs)*Math.cos(A5RAs);
P5s = Math.atan(Math.sin(A5RAs)/x); 
if (x<0) P5s = P5s + Math.PI

x = Math.sin(A0RA);
K0 = Math.atan((Math.sin(D0)*Math.cos(A0RA) - Math.cos(D0)*Math.tan(DE))/x); 
if (x<0) K0 = K0 + Math.PI

x = Math.sin(A4RA);
K4 = Math.atan((Math.sin(D4)*Math.cos(A4RA) - Math.cos(D4)*Math.tan(DE))/x); 
if (x<0) K4 = K4 + Math.PI

x = Math.sin(A5RA);
K5 = Math.atan((Math.sin(D5)*Math.cos(A5RA) - Math.cos(D5)*Math.tan(DE))/x); 
if (x<0) K5 = K5 + Math.PI

x = Math.sin(A0RAs);
K0s = Math.atan((Math.sin(D0)*Math.cos(A0RAs) - Math.cos(D0)*Math.tan(DE))/x); 
if (x<0) K0s = K0s + Math.PI

x = Math.sin(A4RAs);
K4s = Math.atan((Math.sin(D4)*Math.cos(A4RAs) - Math.cos(D4)*Math.tan(DEs))/x); 
if (x<0) K4s = K4s + Math.PI

x = Math.sin(A5RAs);
K5s = Math.atan((Math.sin(D5)*Math.cos(A5RAs) - Math.cos(D5)*Math.tan(DEs))/x); 
if (x<0) K5s = K5s + Math.PI
}


function phys()
{
mv = -8.68 + 5 * 0.43429 * Math.log(rs*Abstand) + 0.044*i*180/Math.PI - 2.60 * Math.sin(Math.abs(B0)) + 1.25 * Math.sin(B0) * Math.sin(B0);

DAequator = 165.46/Abstand;
DPol = Math.sqrt(1 - 0.2037*Math.cos(B0)*Math.cos(B0));
DPol = DAequator * DPol;

Rax = 375.4/Abstand;
Ray = 375.4*Math.abs(Math.sin(B0))/Abstand;
Rays = 375.4*Math.abs(Math.sin(B0s))/Abstand;
Rix = 249.6/Abstand;
Riy = 249.6*Math.abs(Math.sin(B0))/Abstand;
Riys = 249.6*Math.abs(Math.sin(B0s))/Abstand;
Rcx = 327.9/Abstand;

dkorr = d-Abstand/173;
Z1 = (227.90 + 844.2999153 * dkorr - K0*180/Math.PI + 0.00977*deltaT)/360;
Z1 = (Z1 - Math.floor(Z1))*2*Math.PI;

Z2 = (104.9 + 811.9999153 * dkorr - K0*180/Math.PI + 0.00940*deltaT)/360;
Z2 = (Z2 - Math.floor(Z2))*2*Math.PI;

Z3 = (38.90 + 810.7938177 * dkorr - K0*180/Math.PI + 0.00938*deltaT)/360;
Z3 = (Z3 - Math.floor(Z3))*2*Math.PI;

}

















