var dayExclude=false;
function set_startday () {
	var tage  = new Array("So","Mo","Di","Mi","Do","Fr","Sa");
	
	var jahr  = document.forms["datum"].year1.options[document.forms["datum"].year1.selectedIndex].value;
	var monat = document.forms["datum"].month1.options[document.forms["datum"].month1.selectedIndex].value - 1;
	var tag   = document.forms["datum"].day1.options[document.forms["datum"].day1.selectedIndex].value;
	var datum = new Date(jahr,monat,tag);
	if(dayExclude) {
		var wtag=datum.getDay();
		if(wtag==dayExclude) { 
			alert(tage[datum.getDay()]+', der '+document.forms["datum"].day1.options[document.forms["datum"].day1.selectedIndex].value+'.'+(document.forms["datum"].month1.options[document.forms["datum"].month1.selectedIndex].value)+'.'+document.forms["datum"].year1.options[document.forms["datum"].year1.selectedIndex].value+' ist Ruhetag!'+"\n"+'Bitte waehlen Sie ein anderes Datum!'); 
			document.forms["datum"].day1.selectedIndex=document.forms["datum"].day1.selectedIndex+1;
			set_startday();
		}
		else {
			if (document.forms["datum"].start_weekday)  document.forms["datum"].start_weekday.value = tage[datum.getDay()];
			if (document.forms["datum"].start_weekday1) document.forms["datum"].start_weekday1.value = tage[datum.getDay()];
		}
	}
	else {
		if (document.forms["datum"].start_weekday)  document.forms["datum"].start_weekday.value = tage[datum.getDay()];
		if (document.forms["datum"].start_weekday1) document.forms["datum"].start_weekday1.value = tage[datum.getDay()];
	}
	if (document.forms["datum"].start_weekday2) {
		var jahr  = document.forms["datum"].year2.options[document.forms["datum"].year2.selectedIndex].value;
		var monat = document.forms["datum"].month2.options[document.forms["datum"].month2.selectedIndex].value - 1;
		var tag   = document.forms["datum"].day2.options[document.forms["datum"].day2.selectedIndex].value;
		var datum = new Date(jahr,monat,tag);
		document.forms["datum"].start_weekday2.value = tage[datum.getDay()];
	}
}

function GetCurYear() {
	today = new Date();
	var cyear = today.getYear();
	if (cyear < 1900) cyear += 1900;
	return cyear;
}

function DateSel_MonthNYear(fob,cn) {
	MonthNames = new Array('Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
	var mso = eval("document."+fob+".month"+cn+".options");
	for (var i=0; i < MonthNames.length; i++) mso[i] = new Option(MonthNames[i],i+1);
	var yso = eval("document."+fob+".year"+cn+".options");
	var ycnt = GetCurYear()-3;
	for (var i=0; i < 10; i++) yso[i] = new Option(i+ycnt,i+ycnt);
  yso[3].selected = true;
}

function DateSel_Day(fob,cn) {
	var ys = eval("document."+fob+".year"+cn);
	var ms = eval("document."+fob+".month"+cn);
	var ds = eval("document."+fob+".day"+cn);
	var selectedday = ds.selectedIndex;
	if ((ms.selectedIndex == -1) || (ys.selectedIndex == -1)) return;
	for (i=0; i < ds.options.length; i++) ds.options[0] = null;
	timeA = new Date(ys.options[ys.selectedIndex].value,ms.options[ms.selectedIndex].value,1);
	timeB = new Date(timeA-86400000);
	var daysInMonth = timeB.getDate();
	for (i=0; i < daysInMonth; i++) ds.options[i] = new Option(i+1,i+1);
	if (selectedday != -1) ds.options[selectedday].selected = true;
	else ds.options[0].selected = true;
}

function DateSel_Init() {
	for (var i=1; i < arguments.length; i++) {
		DateSel_MonthNYear(arguments[0],i);
		var hf = heute(); //eval("document."+arguments[0]+"."+arguments[i]+".value");
		if (hf != '') {
			re = /(\d{4})-(\d{2})-(\d{2})/;
			dspl = re.exec(hf);
			eval("document."+arguments[0]+".month"+i+".options["+(dspl[2]-1)+"].selected = true");
			eval("document."+arguments[0]+".year"+i+".options["+(dspl[1]-GetCurYear()+3)+"].selected = true");
			DateSel_Day(arguments[0],i);
			eval("document."+arguments[0]+".day"+i+".options["+(dspl[3]-1)+"].selected = true");
		}
	}
}

function heute () {
	today = new Date();
	return today.getYear() + '-' + null2((today.getMonth()+1)) + '-' + null2(today.getDate());
}

function null2 (wert) {
	if (wert < 10) wert = '0' + wert;
	return wert;
}

