aktuell = new Date();
tag = aktuell.getDate();
tage = aktuell.getDay();
monat = aktuell.getMonth() + 1;
jahr = aktuell.getYear();
monate= new Array("","Januar","Februar","M&auml;rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");
tagezahl = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
if (jahr < 1900) jahr = jahr +1900;	// umrechnen fuer Mozilla

werk = "#ffffff";		// Hintergrundfarbe fuer Montag bis Freitag
sams = "#ffffff";		// Hintergrundfarbe fuer Samstag
sonn = "#ffffff";		// Hintergrundfarbe fuer Sonntag
atag = "#e7e7e7";		// Hintergrundfarbe fuer aktuellen Tag (Heute)
titelhg = "#ffffff";		// Hintergrundfarbe fuer Kalenderkopf und -fuss 031b63
lhg = "none";		// Hintergrundfarbe fuer Layer bzw. Div
titelvg ="#000000";		// Schriftfarbe fuer Kalenderkopf und -fuss
bord = 0;			// Rahmendicke in Pixel
bordfarb = "black"		// Rahmenfarbe
pad = 1;			// Abstand vom Rahmen zum Kalender in Pixel
idname = "monatskalender";	// Name/ID fuer Kalender
zeitintervall = 20000;		// Aktuallisierungsintervall von Uhr/Kalender. 1000 = 1 Sekunde

// **************************

jtag = tag;
jmonat = monat;
jjahr = jahr;
jminute = "";
jstunde = "";
starttag = 1;
minute = 0;
stunde = 0;
inhalt = "";

// **************************

ns4 = document.layers;
ie4 = document.all;
ns6 = document.getElementById && !document.all;
var verfahren, posx, posy, aktuellx, aktuelly, kleben;

function kalender_schreiben() {
	if(ns4) {
		document.write("<layer name=\""+idname+"\" id=\""+idname+"\" style=\"position: relative; z-index:100; left:0px; top:0px; width:200px; padding:"+ pad +"px; border: " + bord + "px solid " + bordfarb + "; background-color : " + lhg + "\"></layer>");
		verfahren = document.layers[idname];
	}
	else {
		document.write("<div id=\"" + idname + "\"></div>");
		if (ie4 || ns6) verfahren = ns6? document.getElementById(idname) : document.all[idname];
                                           verfahren.style.width = 200;
	}
	kanzeige();
}
function kanzeige() {
	tagezahl[2] = schaltjahr(jjahr);
	jetzt();
	zeit_ermitteln();
	kalender();
	txt();
	zeitakt = window.setTimeout("kanzeige()",zeitintervall);
}
function txt() {
	if(ns4)
		if(document.layers[idname]){
			document.layers[idname].document.open('text/html');
			document.layers[idname].document.write(inhalt);
			document.layers[idname].document.close();
		}
	if(ie4)
		if(document.all[idname])
			document.all[idname].innerHTML = inhalt;
	if(ns6)
		if(document.getElementById(idname))
			document.getElementById(idname).innerHTML = inhalt;
}
function zeit_ermitteln() {
	aktuell = new Date();
	minute = aktuell.getMinutes();
	stunde = aktuell.getHours();
	jstunde = String(stunde);
	jminute = String(minute);
	if (minute < 10) jminute = "0" + String(minute);
}
function schaltjahr(j) {
	t = 28;
	if (j % 4 == 0) {
		t = 29;
		if (j % 100 == 0 && j % 400 != 0) t = 28;
	}
	return t;
}
function jetzt() {
	jdat = new Date(jjahr,jmonat-1,1);
	starttag = jdat.getDay();
	if (starttag == 0) starttag = 7;
}
function monatzurueck() {
	window.clearTimeout(zeitakt);
	jmonat--;
	if (jmonat<1) {
		jmonat = 12;
		jjahr--;
		if (jjahr < 1970) {
			jjahr = 1970;
			jmonat = 1;
		}
	}
	kanzeige();
}
function monatvor() {
	window.clearTimeout(zeitakt);
	jmonat++;
	if (jmonat > 12) {
		jmonat = 1;
		jjahr++;
	}
	kanzeige();
}
function stellen() {
	jtag = tag;
	jmonat = monat;
	jjahr = jahr;
	kanzeige();
}
function kalender() {
	trtag = "<tr align=\"center\" valign=\"middle\">";
	style1 = "style=\"background-color: "+titelhg+"; color: "+titelvg+";\"";
	tdtag = "</td><td bgcolor=\""+werk+"\" width=\"35\">";
	inhalt = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"200px\" style=\"font-size: 0.7em;\">";
  inhalt = inhalt + trtag;
	inhalt = inhalt + "<th height=\"18\" colspan=\"7\" " + style1 + ">"+monate[jmonat]+"&nbsp;"+jjahr+"</th>";
	inhalt = inhalt + "</tr>" + trtag;
	inhalt = inhalt + "<th class=\"kalender_link_zurueck\" height=\"18\" colspan=\"3\"" + style1 + "><a href=\"#\" onclick=\"monatzurueck();\" title=\"Einen Monat zur&uuml;ck\"> < "+getPrevMonth(jmonat)+" </a></th>";
	inhalt = inhalt + "<th " + style1 + "> &nbsp;</th>";
	inhalt = inhalt + "<th class=\"kalender_link_vor\" height=\"18\" colspan=\"3\"" + style1 + "><a href=\"#\" onclick=\"monatvor();\" title=\"Einen Monat weiter\"> "+getNextMonth(jmonat)+" > </a></th></tr>";
	inhalt = inhalt + trtag + "<td height=\"18\" bgcolor=\"#e7e7e7\" width=\"30\">Mo </td>";
	inhalt = inhalt + "<td height=\"18\" bgcolor=\"#e7e7e7\" width=\"30\">Di </td>";
	inhalt = inhalt + "<td height=\"18\" bgcolor=\"#e7e7e7\" width=\"30\">Mi </td>";
	inhalt = inhalt + "<td height=\"18\" bgcolor=\"#e7e7e7\" width=\"30\">Do </td>";
	inhalt = inhalt + "<td height=\"18\" bgcolor=\"#e7e7e7\" width=\"30\">Fr </td>";
	inhalt = inhalt + "<td height=\"18\" bgcolor=\"#e7e7e7\" width=\"30\">Sa </td>";
	inhalt = inhalt + "<td height=\"18\" bgcolor=\"#e7e7e7\" width=\"30\">So </td></tr>";
	zahl = 0;
	for(asl=1; asl<7; asl++) {
		inhalt = inhalt + trtag;
		for(bsl=1; bsl<8; bsl++) {
			zahl++;
			if (bsl < 6) farbe = werk;
			if (bsl == 6) farbe = sams;
			if (bsl > 6) farbe = sonn;
			akt = zahl + 1 - starttag;
			if (jmonat == 1 && akt == 1 || jmonat == 5 && akt == 1 || jmonat == 6 && akt == 17 && jjahr < 1992 || jmonat == 10 && akt == 3 && jjahr > 1990 || jmonat == 12 && (akt == 25 || akt == 26)) farbe = sonn;
			if (zahl < starttag || akt > tagezahl[jmonat]) inhalt = inhalt + "<td height=\"18\" style=\"font-style: normal; font-weight: 500; font-size: 97%;background-color: "+farbe+";\">&nbsp;</td>";
			if (zahl >= starttag && akt <= tagezahl[jmonat]) {
				if (akt == tag && jmonat == monat && jjahr == jahr)
					//inhalt = inhalt + "<td height=\"18\" style=\"font-style: normal; font-weight: 500; font-size: 97%;background-color: "+atag+";\"><a href=\"JavaScript:setday(" + String(akt) +"," + jmonat + ","+ jjahr +");\">"+String(akt)+"</a></td>";
					inhalt = inhalt + "<td class=\"akt_tag\" height=\"18\" style=\"font-style: normal; font-weight: 500; font-size: 97%;background-color: "+atag+";\"><a href=../../Veranstaltungskalender.asp?db=414&form=report&searchfieldgkdveranstbeginn.max=" + String(akt) + "." + jmonat + "." + jjahr + "&searchfieldgkdveranstende.min=" + String(akt) + "." + jmonat + "." + jjahr + "\">"+String(akt)+"</a></td>";
				else
					//inhalt = inhalt + "<td height=\"18\" style=\"font-style: normal; font-weight: 500; font-size: 97%;background-color: "+farbe+";\"><a href=\"JavaScript:setday(" + String(akt) +"," + jmonat + ","+ jjahr +");\">"+String(akt)+"</a></td>";
					inhalt = inhalt + "<td class=\"akt_tag\" height=\"18\" style=\"font-style: normal; font-weight: 500; font-size: 97%;background-color: "+farbe+";\"><a href=../../Veranstaltungskalender.asp?db=414&form=report&searchfieldgkdveranstbeginn.max=" + String(akt) + "." + jmonat + "." + jjahr + "&searchfieldgkdveranstende.min=" + String(akt) + "." + jmonat + "." + jjahr + "\">"+String(akt)+"</a></td>";
			}
		}
		inhalt = inhalt + "</tr>";
	}
		inhalt = inhalt + "</table>";
}
function startbewegen(e){
	if (ns4) {
		posx = e.pageX;
		posy = e.pageY;
		aktuellx = window.document[idname].pageX;
		aktuelly = window.document[idname].pageY;
		kleben = true;
		window.captureEvents(Event.MOUSEMOVE);
		window.onmousemove = bewegen;
	}
	if (ie4 && event.srcElement.id == idname || ns6 && e.target.id == idname) {
		posx = ie4? event.clientX : e.clientX;
		posy = ie4? event.clientY : e.clientY;
		aktuellx = parseInt(verfahren.style.left);
		aktuelly = parseInt(verfahren.style.top);
		kleben = true;
		document.onmousemove = bewegen;
	}
}
function bewegen(e){
	if (kleben) {
		if (ie4){
			verfahren.style.left = aktuellx + event.clientX - posx;
			verfahren.style.top = aktuelly + event.clientY - posy;
		}
		if (ns6){ 
			verfahren.style.left = Number(aktuellx + e.clientX - posx);
			verfahren.style.top = Number(aktuelly + e.clientY - posy);
		}
		if (ns4) 
			window.document[idname].moveTo (aktuellx + e.pageX - posx,aktuelly + e.pageY - posy);
	}
	return true;
}
function getNextMonth(monat){
  if (monat + 1 > 12) 
  {
    return monate[1];
  }
  else {
    return monate[monat +1];
  }
}
function getPrevMonth(monat){
  if (monat-1 < 1) 
  {
    return monate[12];
  }
  else {
    return monate[monat -1];
  }
}


function setday(tag, monat, jahr){
  tag = tag + "";
  monat = monat + "";
  if (monat.length < 2) { 
     monat = "0" + monat;
  }
  if (tag.length < 2) { 
     tag = "0" + tag;
  }
   
   datum = tag +"." + monat + "." + jahr;
//window.document.veranstaltungsuche.fieldgkdveranstbeginn.value = datum;

//für SelfDB2!
//Erweiterung, da es 2 Felder mit jeweils unterschiedlichen Eingaben gibt!!! ---Schwarz 2010/11/05
	if (window.document.getElementById("searchfieldgkdveranstendemax").checked == true) {	
		window.document.getElementById("searchfieldgkdveranstendemax").value = datum;
		}
	if (window.document.getElementById("searchfieldgkdveranstendemin").checked == true) {	
		window.document.getElementById("searchfieldgkdveranstendemin").value = datum;
		}
//document.getElementById("searchfieldgkdveranstendemax").value = datum;
		
}



if(ns4) {
	window.captureEvents(Event.MOUSEDOWN);
	window.captureEvents(Event.MOUSEUP);
	window.onmousedown = startbewegen;
	window.onmouseup = new Function("kleben=false");
}
else {
	document.onmousedown = startbewegen;
	document.onmouseup = new Function("kleben=false");
}

