function dnes(){
datum = new Date();
  with(datum){
  h = getHours();
  n = getMinutes();
  s = getSeconds();


  da = getDate();
  m = getMonth()+1;
  if (document.all)
  r = getYear()
  else r = getYear() + 1900
  }
}


function julday(mm, id, iyyy) {

	if (iyyy == 0) {

		alert("Julday: there is no year zero");

		return 0;

	} else {

		if (iyyy < 0) { iyyy += 1; }

		if (mm > 2) {

			jy = iyyy;

			jm = 1.0 * mm + 1;

		} else {

  			jy = iyyy - 1;

  			jm = 1.0 * mm + 13;

		}

		j1 = 1.0 * Math.floor(365.25 *jy);

		j2 = 1.0 * j1 + Math.floor(30.6001 * jm);

		j3 = 1.0 * j2 + 1.0 * id;

		j4 = 1.0 * j3 + 1720995;

		if (id+31*(mm+12*iyyy) >= (15+31*(10+12*1582))) {

			  ja = 1.0 * Math.floor(0.01 * jy);

			jb = 1.0 * Math.floor(0.25 * ja);

			  j5 = 1.0 * j4 + 2;

			j6 = 1.0 * j5 - ja;

			jul = 1.0 * j6 + jb;

		} else {

			jul = j4;

		}

		return jul;

	}

}


function caldat(julian) {

	julian = 0 + julian;

	if (julian >= 2299161) {

		jalpha = Math.floor((1.0 * (julian - 1867216)-0.25)/36524.25);

		ja = 1 * julian + 1 + jalpha - Math.floor(0.25 * jalpha);

	} else {

		ja = julian;

	}

	jb = ja + 1524;

	jc = Math.floor(6680.0 + ((jb - 2439870)-122.1)/365.25);

	jd = 365 * jc + Math.floor(0.25 * jc);

	je = Math.floor((jb - jd)/ 30.6001);

	day = jb - jd - Math.floor(30.6001 * je);

	month = je - 1;

	if (month > 12) { month -= 12; }

	year = jc - 4715;

	if (month > 2) { --year; }

	if (year <= 0) { --year; }

}




function flmoon(n, nph) {

	RAD = 3.14159265/180.0;

	c = n + nph / 4.0;

	t = c / 1236.85;

	t2 = t * t;

	as = 359.2242 + 29.105356 * c;

	am = 306.0253 + 385.816918 * c + 0.010730 * t2;

	jd = 2415020 + 28 * n + 7 * nph;

	xtra = 0.75933 + 1.53058868 * c + ((1.178e-4) - (1.55e-7) * t) * t2;

	if (nph == 0 || nph == 2)

		xtra += (0.1734 - 3.93e-4 * t) * Math.sin(RAD * as) - 0.4068 * Math.sin(RAD * am);

	else if (nph == 1 || nph == 3)

		xtra += (0.1721 - 4.0e-4 * t) * Math.sin(RAD * as) - 0.6280 * Math.sin(RAD * am);

	else

		alert("nph is unknown in flmoon");

	i = (xtra > 0.0 ? Math.floor(xtra) :  Math.ceil(xtra - 1.0));

	jd += i;

	frac = xtra - i;

}




function doit(dd,mm,yy) {

	thisyear=yy

	thismonth=mm

	thisday=dd

	TZ=1

        var weekday=new Array("Ne","Po","Út","St","Čt","Pá","So");
	var mesice=new Array("1","2","3","4","5","6","7","8","9","10","11","12");



	



	timzon = TZ / 24.0;

	n = Math.floor(12.37 * (thisyear -1900 + ((1.0 * thismonth - 0.5)/12.0)));

	nph = 2;

	j1 = julday(thismonth,thisday,thisyear);

	flmoon(n,nph); 

	n += Math.floor(1.0 * (j1 - jd) / 28.0); cycle = 1;

	for (var iii = 1; iii <= 8; iii++) {

		flmoon(n, nph);

		frac = 24.0 * (frac + timzon);

		if (frac < 0) {

			--jd;

			frac += 24.0;

		}

		if (frac > 12.0) {

			++jd;

			frac -= 12.0;

		} else

			frac += 12.0;

		i1 = Math.floor(frac);

		secs = 3600.0 * (frac - i1);

		i2 = Math.floor(secs / 60.0);

		i3 = Math.floor(secs - 60 * i2 + 0.5);

		caldat(jd);

		theDate = new Date(year,month-1,day,i1,i2,i3);
		min4 = theDate.getMinutes();
		//min4 = cass;
		//min4=Math.floor(60*(cass%1));
		if (min4 < 10){
	    min4 = "0" + min4}
		

		if (nph == 2) { 

			if(cycle==1){
                        prvni = (weekday[theDate.getDay()]+" "+theDate.getDate()+"/"+mesice[theDate.getMonth()]+"/"+theDate.getFullYear()+"<br>"+theDate.getHours()+":"+min4+"<br>");

			}
			else paty = (weekday[theDate.getDay()]+" "+theDate.getDate()+"/"+mesice[theDate.getMonth()]+"/"+theDate.getFullYear()+"<br>"+theDate.getHours()+":"+min4+"<br>");
			
		} else if (nph == 3) {

			if(cycle==1){
 			druhy = (weekday[theDate.getDay()]+" "+theDate.getDate()+"/"+mesice[theDate.getMonth()]+"/"+theDate.getFullYear()+"<br>"+theDate.getHours()+":"+min4+"<br>");

			}
			else sesty = (weekday[theDate.getDay()]+" "+theDate.getDate()+"/"+mesice[theDate.getMonth()]+"/"+theDate.getFullYear()+"<br>"+theDate.getHours()+":"+min4+"<br>");
			
		} else if (nph == 0) {

			if(cycle==1){
			treti = (weekday[theDate.getDay()]+" "+theDate.getDate()+"/"+mesice[theDate.getMonth()]+"/"+theDate.getFullYear()+"<br>"+theDate.getHours()+":"+min4+"<br>");

			}
			else sedmy = (weekday[theDate.getDay()]+" "+theDate.getDate()+"/"+mesice[theDate.getMonth()]+"/"+theDate.getFullYear()+"<br>"+theDate.getHours()+":"+min4+"<br>");
			
		} else if (nph == 1) {
			if(cycle==1){

			ctvrty = (weekday[theDate.getDay()]+" "+theDate.getDate()+"/"+mesice[theDate.getMonth()]+"/"+theDate.getFullYear()+"<br>"+theDate.getHours()+":"+min4+"<br>");

			}
			else osmy = (weekday[theDate.getDay()]+" "+theDate.getDate()+"/"+mesice[theDate.getMonth()]+"/"+theDate.getFullYear()+"<br>"+theDate.getHours()+":"+min4+"<br>");
			
		}

		if (nph == 3) {

			nph = 0;

			++n;
                        

		} else

			++nph;

		if (nph == 2) {

			++cycle;

		}

	}

}



function Moon_phase(da,m,r)
{
    y=r;
    d=da;

    if (m == 1) --d;
    else if (m == 2) d += 30;
    else // m >= 3
    {
        d += 28 + (m-2)*3059/100;

        // adjust for leap years
        if (!(y & 3)) ++d;
        if ((y%100) == 0) --d;
    }
    
    g = (y-1900)%19 + 1;
    e = (11*g + 18) % 30;
    if ((e == 25 && g > 11) || e == 24) e++;

    vyss = ((((e + d)*6+11)%177)/22 & 7);
    //document.write(da+" "+m+" "+y);
     switch (vyss)
	{
  	case 0:  stav="nov";
  	break;
  	case 1:  stav="dorustající srpek";
  	break;
  	case 2:  stav="první čtvr";
  	break;
  	case 3:  stav="dorůstající měsíc";
  	break;
  	case 4:  stav="úplněk";
  	break;
  	case 5:  stav="couvající měsíc";
  	break;
  	case 6:  stav="poslední čtvr";
  	break;
  	case 7:  stav="ubývající srpek";
  	break;
  	default: stav="error";
	}
    
    return vyss;
}  //fáze měsíce





