function getFieldCheckResult(strValue, strVerplichtBericht, strFormatBericht, strFormat)
{
	for(i=0;i<strValue.length;i++){
		intCode = strValue.charCodeAt(i);
		if((intCode>=192&&intCode<=221)||(intCode>=223&&intCode<=239)||(intCode>=241&&intCode<=246)
			||(intCode>=248&&intCode<=253)||(intCode==255)){
			return("U heeft een ongeldig teken ingevoerd: " + strValue.charAt(i) + " in " + strValue + "\n");
		}
	}
	
	if(strValue == ''){
		if(strVerplichtBericht != '')
			return(strVerplichtBericht + '\n');
	}
	else if(strFormat != ''){
		if(!strFormat.test(strValue))
			return(strFormatBericht + '\n');
	}
	return '';
}



function findRadioValue(objField){
	var result;
	var i;
	
	result = "";
	for(i=0; i < objField.length; i++){
		if(objField[i].checked == true){
			result = objField[i].value;
		}
	}
	return(result);
}

function findCheckBoxValue(objField){
	var result;
	if(objField.checked == true){
		result = objField.value;
	}else{
		result = "false";
	}
	return(result);
}

function findDDValue(objField){
	var result, strValue, i;
	strValue = objField.value;
	result = "";
	for(i=0; i<objField.options.length;i++){
		if(objField.options[i].selected){
			result = objField.options[i].value;
		}
	}
	return(result);
}


function FormCheckBankRekeningNummer(strNum, strCheckBericht)
{
	var strValue, intValue, intSum, intLength, strError, i;
	strError = '';
	strValue = strNum;
	intLength = strValue.length;
	
	document.forms[0].txtBankGiro.value = "g";

	// check format, zal al goed moeten zijn, maar voor zekerheid
	if ( (intLength==9) && !isNaN(strValue) )
	{
		//app. it is a bankrek.
		document.forms[0].txtBankGiro.value = "b";

		// calc sum
		intSum=0;
		for (i=1; i<=intLength; i++)
			intSum += i*parseInt(strValue.charAt(intLength-i))
		// 11-check
		if ((intSum%11) != 0)
			return strCheckBericht;
		}
	if(intLength > 9){
		return strCheckBericht;
	}
	return '';
}

//============================================= Date functions ======================================================================================
function checkDate(strDate, strName, maxDaysInFuture){
	var dag, maand, jaar
	var arrDate
	var strFormat = /^[0-9]{2}[-][0-9]{2}[-][0-9]{4}$/
	if(strDate == ""){
		return(strName + " is niet ingevuld.\n");
	}else{
	
		if(!strFormat.test(strDate)){
			return(strName + " heeft geen geldig formaat, gebruik: dd-mm-yyyy\n");
		}
		else{
			arrDate = strDate.split("-");
			dag = arrDate[0];
			maand = arrDate[1];
			jaar = parseInt(arrDate[2]);			
		
			if((jaar<1900||jaar>2200)||(maand<1||maand>12)||(dag<1||dag>daysInMonth(maand, jaar))){
				return(strName + " is geen geldige datum.\n");
			}else if(maxDaysInFuture != ""){
				if(!inRange(dag, maand, jaar, maxDaysInFuture)){
					return(strName + " mag niet in het verleden en maximaal " + maxDaysInFuture + " dagen in de toekomst liggen\n")
				}else{
					return('');
				}
			}else{
				return('');
			}
		}
	}	
}

function daysInMonth(m, y){
	if(m==1||m==3||m==5||m==7||m==8||m==10||m==12){return 31;}
	else if(m==4||m==6||m==9||m==11){return 30;}
	else{return (((y % 4 == 0) && ( (!(y % 100 == 0)) || (y % 400 == 0))) ? 29 : 28 );}
}
	
function inRange(d, m, y, r){
	var todayPlusTerm;
	var datum = new Date();
	datum.setDate(d);
	datum.setMonth(m - 1);
	datum.setFullYear(y);
	
	todayPlusTerm = addDays(30, new Date());
	if((datum <= todayPlusTerm)&&(datum >= new Date())){
		return true;
	}
	else{
		return false;
	}
}


function addDays(days, datum){
	var time = datum.getTime() + (days * 24 * 60 * 60 * 1000);
	return new Date(time);
}
	
