
function correctDate(dfeld,param1)
{
	var temp, temp2 = new Array();
	var dstring;
	dstring=dfeld.value;
	if (dstring == "") return 0;
	dstring = dstring.replace(/\-/g, ".");
	dstring = dstring.replace(/\,/g, ".");
	dstring = dstring.replace(/\ /g, ".");
	dstring = dstring.replace(/\//g, ".");

	dstring = dstring.replace(/[^0-9\.]*/g, "");
	if (dstring=="") dstring="000000";
	
	if ((dstring.length == 8)&&(dstring.indexOf(".") == -1))
	{
   	if (dstring.substr(4,2)>12)
			tempdate = dstring.substr(0,2) + "." + dstring.substr(2,2) + "." + dstring.substr(4);
		else
			tempdate = dstring.substr(6,2) + "." + dstring.substr(4,2) + "." + dstring.substr(0,4);
    dstring=tempdate;
	}
	else if ((dstring.length == 6)&&(dstring.indexOf(".") == -1))
	{
    	tempdate=dstring.substr(0,2) + "." + dstring.substr(2,2) + "." + dstring.substr(4,2);
      dstring=tempdate;
	}
	
	if (dstring.search(/.*\..*\..*/)==-1)
	{
    dstring="000000";
		dfeld.value=dstring;
		dfeld.focus();
		correctDate(dfeld, param1);
		return true;
	}

	temp = dstring.split('.');

	tempdate = new Date(temp[2], temp[1]-1, temp[0]);
	tempstring = tempdate.toLocaleString();

	if ((temp[0]>31)&&(temp[0].length==4))
	{
		var jahr=temp[0];
		var tag=temp[2];
		temp[2]=jahr;
		temp[0]=tag;
	}

	var neutag=correctDate_anzTageMonat(temp[1],temp[2]);
	if (temp[1]>12) {temp[1]=12}
	if (temp[1]<1) {temp[1]="1"}	
	if (temp[0]<1) {temp[1]="1"}
	if (temp[0]>neutag) {temp[0]=neutag}
	if (temp[0]<1) {temp[0]="1"}
	if (temp[1].length < 2){temp[1] = '0'+temp[1]}
	if (temp[0].length < 2){temp[0] = '0'+temp[0]}

	if ((temp[2].length == 2 && temp[2] > 31)) {temp[2]='19'+temp[2]}
	if ((temp[2].length == 2 && temp[2] < 32)) {temp[2]='20'+temp[2]}

	dstring = temp[0]+'.'+temp[1]+'.'+temp[2];
	dfeld.value=dstring;

	if (param1=="NOF")
	{
		Zeit = new Date();
		nowJahr = Zeit.getYear();
		nowMonat= Zeit.getMonth()+1;
		nowTag = Zeit.getDate();
		if (nowJahr<1900) {nowJahr+=1900;}
		nowstring=Date.UTC(nowJahr,nowMonat,nowTag,0,0,0);
		dchkstring=Date.UTC(temp[2],temp[1],temp[0],0,0,0);
  	if (dchkstring>nowstring)
 	  {
			alert ("Datum darf nicht in der Zukunft liegen");
			dfeld.focus();
		}
	}
	if (param1=="NOPAST")
	{
		Zeit = new Date();
		nowJahr = Zeit.getYear();
		nowMonat= Zeit.getMonth();
		nowTag = Zeit.getDate();

		if (nowJahr<1900) {nowJahr+=1900;}
//		alert(nowJahr+" "+nowMonat+" "+nowTag);
		nowstring=Date.UTC(nowJahr,nowMonat,nowTag,0,0,0);
		var monat=parseInt(temp[1],10)-1;
		dchkstring=Date.UTC(temp[2],monat,temp[0],0,0,0);
		//alert(temp[2]+" "+temp[1]+" "+temp[0]);
		var Zeit = new Date();

	//	alert(dchkstring.toGMTString()+"\n"+nowstring.toGMTString()+"\n");
		
  	if (dchkstring<=nowstring)
 	  {
			alert ("Datum darf nicht in der Vergangenheit liegen");
			dfeld.focus();
		}
	}
}
function correctDate_anzTageMonat(M, J)
{
	var monat=M;
	var jahr=J;
	var maxtage = 0;

	while(monat < 1)
    monat = monat + parseInt(12);
		
	while(monat > 12)
		monat-=12;

	if ((monat == 1)||(monat == 3)||(monat == 5)||(monat == 7)||(monat == 8) ||(monat == 10) || (monat == 12))
    maxtage = 31; /* monat mit 31 tagen */
  else if ((monat == 4)||(monat == 6)||(monat == 9)||(monat == 11))
	  maxtage = 30; /* monat mit 30 tagen */
	else if (((jahr % 4 == 0) && (jahr % 100 != 0))||(jahr % 400 == 0))
	  maxtage = 29; /* Februar mit Schaltjahr */
  else
	  maxtage = 28; /* Februar ohne Schaltjahr */
	return maxtage;
}
