// Parameter: Name des Monatfeldes, name des formulars, name des jahresfeldes, name des tagesfeldes
function setMonth(pmonth,pform,yearfield,dayfield){
	m=eval("document."+pform+"."+pmonth+".options[document."+pform+"."+pmonth+".selectedIndex].value");
	y=eval("document."+pform+"."+yearfield+".options[document."+pform+"."+yearfield+".selectedIndex].value");
	m=stripZeros(m);
	rewriteDay(parseInt(y),parseInt(m),pform,dayfield);
}

function cmpDate(pform,pmonth,yearfield,dayfield,pmonth1,yearfield1,dayfield1){
	m=eval("document."+pform+"."+pmonth+".options[document."+pform+"."+pmonth+".selectedIndex].value");
	y=eval("document."+pform+"."+yearfield+".options[document."+pform+"."+yearfield+".selectedIndex].value");
	d=eval("document."+pform+"."+dayfield+".options[document."+pform+"."+dayfield+".selectedIndex].value");
	date1=y+m+d;
	m1=eval("document."+pform+"."+pmonth1+".options[document."+pform+"."+pmonth1+".selectedIndex].value");
	y1=eval("document."+pform+"."+yearfield+".options[document."+pform+"."+yearfield1+".selectedIndex].value");
	d1=eval("document."+pform+"."+dayfield1+".options[document."+pform+"."+dayfield1+".selectedIndex].value");
	date2=y1+m1+d1;

if(date1>=date2){
	return false;
}else{
	return true;
}
}

// parameter: Jahr, Monat (als nummer von 1-12), name des formulars, name des Feldes wo die tage geschrieben werden sollen
function rewriteDay(y,m,pform,dayField){
	var la=new Date();
	var mdays=Array(31,0,31,30,31,30,31,31,30,31,30,31);
	if(m==2){
		maxdays=daysInFebruary(y);
	}else{
		maxdays=mdays[m-1];
	}
	eval("document."+pform+"."+dayField+".length=0");
	for(i=1;i<=maxdays;i++){
		if(i<10){
			i="0"+i;
		}
		NeuerEintrag = new Option(i,i,false,false);
		eval("document."+pform+"."+dayField+".options[document."+pform+"."+dayField+".length] = NeuerEintrag");
	}
}

function getIndex(formname,fieldname,wantedVal){
	for(i=0;i<eval('document.'+formname+'.'+fieldname+'.length');++i)
		if(eval('document.'+formname+'.'+fieldname+'.options[i].value') == wantedVal)
			return i;
}

function initialize(pform,dayField,monthfield,yearfield){
	var la=new Date();
	m=la.getMonth()+1;
	y=la.getYear();
	d=la.getDate();
	eval('document.'+pform+'.'+yearfield+'.selectedIndex='+getIndex(pform,yearfield,y));
	eval('document.'+pform+'.'+monthfield+'.selectedIndex='+getIndex(pform,monthfield,m));
	var mdays=Array(31,0,31,30,31,30,31,31,30,31,30,31);
	if(m==2){
		maxdays=daysInFebruary(y);
	}else{
		maxdays=mdays[m-1];
	}
	eval("document."+pform+"."+dayField+".length=0");
	for(i=1;i<=maxdays;i++){
		if(i==d){
			sel=true;
		}else{
			sel=false;
		}
		if(i<10){
			i="0"+i;
		}
		NeuerEintrag = new Option(i,i,sel,sel);
		eval("document."+pform+"."+dayField+".options[document."+pform+"."+dayField+".length] = NeuerEintrag");
	}
}

function initialize2(pform,dayField,monthfield,yearfield){
	var la=new Date();
	m=la.getMonth()+1;
	y=la.getYear();
	d=la.getDate()+1;
	eval('document.'+pform+'.'+yearfield+'.selectedIndex='+getIndex(pform,yearfield,y));
	eval('document.'+pform+'.'+monthfield+'.selectedIndex='+getIndex(pform,monthfield,m));
	var mdays=Array(31,0,31,30,31,30,31,31,30,31,30,31);
	if(m==2){
		maxdays=daysInFebruary(y);
	}else{
		maxdays=mdays[m-1];
	}
	eval("document."+pform+"."+dayField+".length=0");
	for(i=1;i<=maxdays;i++){
		if(i==d){
			sel=true;
		}else{
			sel=false;
		}
		if(i<10){
			i="0"+i;
		}
		NeuerEintrag = new Option(i,i,sel,sel);
		eval("document."+pform+"."+dayField+".options[document."+pform+"."+dayField+".length] = NeuerEintrag");
	}
}

function daysInFebruary (year){
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function stripZeros(inputStr){
	var result = inputStr
	while (result.substring(0,1) == "0"){
		result = result.substring(1,result.length)
	}
	return result
}
