function doHelp(objSrc)
{
	var strHRef = objSrc.href;
	window.open(strHRef, null, 'scrollbars=yes,resizable=yes,status=no,toolbar=yes,menubar=no,location=no,titlebar=no');
}
function doFocus(nActivePage) 
{					
	
	var oObject = null; 
	switch (nActivePage )
	{ 
		case 1: 
			oObject = document.all.item("chkKenntnis");
			break; 
		case 2: 
			oObject = document.all.item("txtName");
				break; 
		case 3: 
			oObject = document.all.item("txtEinkommenHeute");					
			break; 
		case 4: 
			oObject = document.all.item("cmdPrev");					
			break; 
		default:
			break;
	} 
	if (oObject != null) oObject.focus(); 
} 

function CheckDateRange (objSrc,strMessage,strApplicant,strSpouse)
{
	var strMessage0 = "Wert ist ung";
	strMessage0 += String.fromCharCode(252);
	strMessage0 += "ltig.";
	var strApplicant0 = "Antragsteller muss mindestens 21-j";
	strApplicant0 += " muss mindestens 21-j";
	strApplicant0 += String.fromCharCode(228);
	strApplicant0 += "hrig sein.";
	var strSpouse0 = "Ehepartner";
	strSpouse0 += " muss mindestens 21-j";
	strSpouse0 += String.fromCharCode(228);
	strSpouse0 += "hrig sein.";
	
	if (strMessage == "")
	{
		strMessage = strMessage0;
	}
	if (strApplicant == "")
	{
		strApplicant = strApplicant0;
	}
	if (strSpouse== "")
	{
		strSpouse =strSpouse0;
	}
			
	var bOK;
	bOK = checkdate(objSrc, strMessage);
	if (bOK)
	{
		var strName = objSrc.name;
		var strSrcDate = objSrc.value;		
		var dtToday = new Date();
		var iTodayYear = dtToday.getFullYear();
		var iSrcYear = parseInt(strSrcDate.substr(6,4),10);	
		switch (strName)
		{
			case "txtGeburtsdatum":
				if ((iTodayYear - iSrcYear) < 21)
				{
					strMessage += " "+ strApplicant;
					bOK = false;
				}				
				if (iSrcYear < 1850)
				{
					bOK = false;
				}
				break;
			case "txtGeburtsdatumPartner":
				if ((iTodayYear - iSrcYear) < 21)
				{
					strMessage += " " + strSpouse;
					bOK = false;
				}				
				if (iSrcYear < 1850)
				{
					bOK = false;
				}
				break;
			default:			
				if ((iSrcYear < 1850) || (iSrcYear > 2050))
				{
					bOK = false;
				}
				break;
		}
		if (!bOK)
		{
			objSrc.select();
			alert(strMessage);
			objSrc.focus();	
		}
	}
	return bOK;
}

function checkdate(objSrc,strMessage) {

	if(objSrc == null)
		return;
		
	var dtNow = new Date();
	var strCurrentYear = dtNow.getYear();
	var strCurrentMonth = dtNow.getMonth() + 1;
	var strCurrentDay = dtNow.getDate();
	
	if(objSrc.value == " "){
		objSrc.value = strCurrentDay + "." + strCurrentMonth + "." + strCurrentYear;
		return true;
	}
	
	return Validcheckdate(objSrc,strMessage);
}

function Validcheckdate(objSrc,strMessage) {
 var strMessageDefault = "Datum ist ung";
 strMessageDefault += String.fromCharCode(252);
 strMessageDefault += "ltig.";
 
 if (strMessage == "")
 {
	strMessage = strMessageDefault;
 }
 var datefield = objSrc;
  if (chkdate(objSrc) == false) {
     datefield.select();
     alert(strMessage);
     datefield.focus();
     return false;
  }
  else {
     return true;
  }
}

function chkdate(objSrc) {
  var strDate;
  var strDateArray;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var booFound = false;
  var datefield = objSrc;
  var strSeparatorArray = new Array("-"," ","/",".");
  var intElementNr;
  var err = 0;
  strDate = datefield.value;
  if (strDate.length < 1) {
     return true;
  }

  for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
    if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
      strDateArray = strDate.split(strSeparatorArray[intElementNr]);

		var runTime = new Date();

      if (strDateArray.length == 1) {
			strDay = strDateArray[0];
			strMonth = runTime.getMonth() + 1;
			strYear = runTime.getYear();
      }
      else if (strDateArray.length == 2) {
			strDay = strDateArray[0];
			if(strDateArray[1] == "")
				strDateArray[1] = runTime.getMonth() + 1;
			strMonth = strDateArray[1];
			strYear = runTime.getYear();
      }
      else if (strDateArray.length == 3) {
			strDay = strDateArray[0];
			strMonth = strDateArray[1];
			strYear = strDateArray[2];
      }
      else{
        err = 1;
        return false;
      }
     
      booFound = true;
    }
  }
  
  if (booFound == false) {
    if (strDate.length > 5) {
      strDay = strDate.substr(0, 2);
      strMonth = strDate.substr(2, 2);
      strYear = strDate.substr(4);
      booFound = true;
    }
    
    if ((strDate.length == 1) || (strDate.length == 2)) {
		var runTime = new Date();
		strDay = strDate;
		strMonth = runTime.getMonth() + 1;
		strYear = runTime.getYear();
		booFound = true;
    }
  }

  if (booFound == false)
  {
	err = 1;
	return false;
  }
  if (isNaN(strDay))
  {
	err = 2;
	return false;
  }  
  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    err = 2;
    return false;
  }
  if (isNaN(strMonth))
  {
	return false;
  }
  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    return false;
  }
  if (isNaN(strYear))
  {
	err = 4;
	return false;
  }
  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    err = 4;
    return false;
  }

  if (intYear < 100)
  {
	intYear += 1900
  }

  if (intMonth > 12 || intMonth < 1) {
    err = 5;
    return false;
   }
  if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
    err = 6;
    return false;
  }
  if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
    err = 7;
    return false;
  }
  if (intMonth == 2) {
    if (intday < 1) {
      err = 8;
      return false;
    }
    if (LeapYear(intYear) == true) {
      if (intday > 29) {
        err = 9;
        return false;
      }
    }
    else {
      if (intday > 28) {
        err = 10;
        return false;
      }
    }
  }

  // Datum formatieren
  var strDay, strMonth;
  strDay = intday.toString();
  strMonth = intMonth.toString();
  strYear = intYear.toString();
  if (intday < 10) strDay = '0' + strDay;
  if (intMonth < 10) strMonth = '0' + strMonth;
  datefield.value = strDay + "." + strMonth + "." + strYear;
  
  return true;
}


function LeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) { return true; }
  }
  else {
    if ((intYear % 4) == 0) { return true; }
  }
  return false;
}

