


function askmess(msg) 
	{
	if (confirm(msg))
		return true;
	else
		return false;	
	}

//-------------------------------------------------------------
// Functie die van d-m-yyyy dd-mm-yyyy maakt, maw indien nodig nullen toevoegd:
// 1-1-2001 wordt 01-01-2001
// Martin Wachters 16-10-2001
//


function format_date(DateString)
{
	isplit = DateString.indexOf('-');
	
	day = DateString.substring(0, isplit); isplit = DateString.indexOf('-', isplit + 1);
	
	new_day = day;
	if (day.length == 1) 
	{
		new_day = "0" + day;
	}
	
	
	month = DateString.substring((day.length + 1), isplit);
	new_month = month;
	if (month.length == 1) 
	{
		new_month = "0" + month;
	}
	
	year = DateString.substring(isplit + 1);
	
	if (year == "")
	{
		return(new_day + "" + new_month + "" + year);
	} 
	else
	{
		return(new_day + "-" + new_month + "-" + year);
	}

}



//Datum van vandaag in het juiste formaat dd-mm-yyyy
function vandaag()
{
	var NowDate = new Date();
	NowDateDay = NowDate.getDate();
	NowDateMonth = NowDate.getMonth() + 1;
	NowDateYear = NowDate.getFullYear();
	NowDateString = NowDateDay + "-" + NowDateMonth + "-" + NowDateYear;
	NowDateString = format_date(NowDateString);
	return(NowDateString);
}
//-------------------------------------------------------------


// Haal huidige jaar op
function getCurrentYear()
{
	var NowDate = new Date();
	NowDateYear = NowDate.getFullYear();
	return NowDateYear;
}

function getYearFromString(DateString1)
{
	isplit = DateString1.indexOf('-');
	day1 = DateString1.substring(0, isplit); isplit = DateString1.indexOf('-', isplit + 1);
	month1 = DateString1.substring((day1.length + 1), isplit);
	year1 = DateString1.substring(isplit + 1);
	
	return year1;
}

// get the month specified in a date object
function getMonthFromString(DateString1)
{
	isplit = DateString1.indexOf('-');
	day1 = DateString1.substring(0, isplit); 
	isplit = DateString1.indexOf('-', isplit + 1);
	month = day1.length + 1;
	month1 = DateString1.substring(month , isplit);
	year1 = DateString1.substring(isplit + 1);
	
	return month1;
}
//-------------------------------------------------------------

// function to calculate the amount of months between 'date a' and 'date b'
function diffMonths(startDate, endDate) {
	// define our processing vars
	var iPlusMonths = 0;
		iMinusMonths = 0;
		iStartYear = 0;
		iEndYear = 0;
		iDifference = 0;
	
		
	// get the year as integer
	iStartYear = parseInt(getYearFromString(startDate));
	iEndYear = parseInt(getYearFromString(endDate));
	// get the amount of months we are into 'date b'
	
	
	iPlusMonths = getMonthFromString(endDate);
	//iPlusMonths = iPlusMonths.substring(1,2);
	// get the amount of months we are into 'date a'
	iMinusMonths = parseInt(getMonthFromString(startDate));
	
	// work out the amount of years we differ
	iDifference = iEndYear - iStartYear;
	// work out the amount of months that difference is
	iDifference = iDifference * 12;
	// subtract the amount of months we are into the start date, and add the amount of months we are into the end date
	
	iDifference = iDifference - iMinusMonths;
	
	iDifference = iDifference + parseInt(iPlusMonths);
	
	// return the difference in months to our caller
	return iDifference;
}
//-------------------------------------------------------------




// Functie om 2 datums te vergelijken
// Returnt 1 als datum1 LATER is dan datum2
// Returnt -1 als dateum1 VROEGER is dan datum2
// Return 0 als de datums gelijk zijn
// Martin Wachters
function DateCompare(DateString1, DateString2)
{
	isplit = DateString1.indexOf('-');
	day1 = DateString1.substring(0, isplit); isplit = DateString1.indexOf('-', isplit + 1);
	month1 = DateString1.substring((day1.length + 1), isplit);
	year1 = DateString1.substring(isplit + 1);
	
	isplit = DateString2.indexOf('-');
	day2 = DateString2.substring(0, isplit); isplit = DateString2.indexOf('-', isplit + 1);
	month2 = DateString2.substring((day2.length + 1), isplit);
	year2 = DateString2.substring(isplit + 1);
	
	year_diff = year1 - year2;
	month_diff = month1 - month2;
	day_diff = day1 - day2;
	
	if ( (year_diff > 0) ||
		((year_diff == 0) && (month_diff > 0)) ||
		((year_diff == 0) && (month_diff == 0) && (day_diff > 0)) ) {
		return 1;
	}
	if ((year_diff == 0) && (month_diff == 0) && (day_diff == 0)) {
		return 0;
	}
	return -1; 
}	

//-------------------------------------------------------------

// Functies geript uit de CF checks om te checken of een string een legitieme datum is.
// CheckEurodate returnt TRUE als object_value voldoet aan: dd-mm-yyyy
// Martin Wachters 28-9-2001

function CheckEurodate(object_value)
    {
    //Returns true if value is a eurodate format
    //otherwise returns false	

    //Returns true if value is a date in the dd-mm-yyyy format
		
	isplit = object_value.indexOf('-');
	
	
	if (isplit == -1 || isplit == object_value.length){
		return false;
	}
	
    sDay = object_value.substring(0, isplit);	
	
	monthSplit = isplit + 1;

	isplit = object_value.indexOf('-', monthSplit);

	
	if (isplit == -1 ||  (isplit + 1 )  == object_value.length)
	{		
		return false;
	}

    sMonth = object_value.substring((sDay.length + 1), isplit);

	sYear = object_value.substring(isplit + 1);
	
	//check month
	if (!_CF_checkinteger(sMonth)) {		
		return false;
	}

	// check month
	if (!_CF_checkrange(sMonth, 1, 12)){		
		return false;
	}
	
	//check year
	if (!_CF_checkinteger(sYear)) {
		return false;
	}
	
	//check year
	if (!_CF_checkrange(sYear, 1000, 9999)){			
		return false;
	}
	
 	//check day
	if (!_CF_checkinteger(sDay)){		
		return false;
	}
	//check day
	
	if (!_CF_checkday(sYear, sMonth, sDay)){ 
		return false;
	}
	return true;
}



function _CF_checkday(checkYear, checkMonth, checkDay)
    {

	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
			checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else
	if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else
		if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}

	return _CF_checkrange(checkDay, 1, maxDay); //check day
    }



function _CF_checkinteger(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
	return _CF_checknumber(object_value);
    else
	return false;
    }



function _CF_numberrange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
	{
        if (object_value < min_value)
		return false;
	}

    // check maximum
    if (max_value != null)
	{
	if (object_value > max_value)
		return false;
	}
	
    //All tests passed, so...
    return true;
    }



function _CF_checknumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks

		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
    }



function _CF_checkrange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false
	if (object_value.length == 0)
        return true;


    if (!_CF_checknumber(object_value))
	{
	return false;
	}
    else
	{
	return (_CF_numberrange((eval(object_value)), min_value, max_value));
	}
	
    //All tests passed, so...
    return true;
    }


function GetCurrectAge(DateString1)
{
	var NowDate = new Date();

	isplit = DateString1.indexOf('-');
	day1   = DateString1.substring(0, isplit); isplit = DateString1.indexOf('-', isplit + 1);
	month1 = DateString1.substring((day1.length + 1), isplit);
	year1  = DateString1.substring(isplit + 1);
	
	NowDateDay   = NowDate.getDate();
	NowDateMonth = NowDate.getMonth() + 1;
	NowDateYear  = NowDate.getFullYear();
	year_diff    = NowDateYear  - year1;	
	month_diff   = NowDateMonth - month1;	
	day_diff     = NowDateDay   - day1;
	
	// Indien jarig vandaag of eerder, leeftijd is year_diff.
	// Indien vandaag, of later

	if ( (month_diff > 0) || ((month_diff == 0) && (day_diff >= 0)) ) 
	{
		// Al jarig geweest
		age = year_diff;
	}
	else
	{
		age = year_diff - 1;
	}
	return (age); 
}
