/*

		(c) Copyright HaPpY HoRsE 2000. All Rights Reserved

		File: date.js
		Language: javascript
		Description: date functions

		Disclaimer: This script is free as long as you include this header info.
		For more info: http://www.happyhorse-int.com

		Version  Date    Author         Initials  Comment
		1.00     990221  Ed Schimmel    EAS       Start of development

*/

function IsValidDate(inDay, inMonth, inYear)
{
	if ((inDay != "") && (inMonth != "") && (inYear != ""))
	{
		if ((inYear > 1900) && (inMonth >= 1) && (inMonth <= 12))
		{
			var isLeapYear = (inYear % 4 == 0);
			isLeapYear &= !(inYear % 100 == 0);
			isLeapYear |= (inYear % 400 == 0);

			if (inMonth == 2)
			{
				if (isLeapYear)
					return (inDay >= 1) && (inDay <= 29);
				else
					return (inDay >= 1) && (inDay <= 28);
			}
			else if ((inMonth == 4) || (inMonth == 6) ||
							 (inMonth == 9) || (inMonth == 11))
				return (inDay >= 1) && (inDay <= 30);
			else
				return (inDay >= 1) && (inDay <= 31);
		}
	}

  return false;
}


/*
	Aanvullende datum functies
*/

/*
Functie			:	DateDiff
Doel			:	Verschil tussen 2 datums (in aantal dagen)
Parameters		:	Datum1 en Datum2
Versiebeheer
Naam			Datum		Reden
Maarten Nietfeld	18-05-2004	Eerste versie
*/

function DateDiffDays(myDate1, myDate2)
{
  var day1   = myDate1.substring(0,2);
  var month1 = myDate1.substring(3,5);
  var year1  = myDate1.substring(6,10);
  var day2   = myDate2.substring(0,2);
  var month2 = myDate2.substring(3,5);
  var year2  = myDate2.substring(6,10);

  var date1 = new Date(year1, month1-1, day1);
  var date2 = new Date(year2, month2-1, day2);

  var diff = date2.getTime() - date1.getTime();

  return(Math.floor(diff/1000/60/60/24));
}

/*
Functie			:	FormatDate2
Doel			:	Datum formatting met "-" tekens tussen dag-maand-jaar
Parameters		:	Datum
Versiebeheer
Naam			Datum		Reden
Maarten Nietfeld	18-05-2004	Eerste versie
*/

function FormatDate2(myDate)
{
  var dd = padout(myDate.getDate());
  var mm = padout(myDate.getMonth()+1); // 0 based
  var yy = y2k(myDate.getYear());
  return(dd+"-"+mm+"-"+yy);
}

function ToDay()
{
  var today = new Date();
  var dd = padout(today.getDate());
  var mm = padout(today.getMonth()+1); // 0 based
  var yy = y2k(today.getYear());
  return(dd+"-"+mm+"-"+yy);
}

/*
Functie			:	fIsLeeftijd
Doel			:	Berekenen Leeftijd
Parameters		:	(geboorte)Datum
Versiebeheer
Naam			Datum		Reden
Sander Hink		14-04-2005	Eerste versie
*/

function fIsLeeftijd(Gebdd)
{
	var strToday = ToDay();
	var strTodayDay   = strToday.substring(0,2);
	var strTodayMonth = strToday.substring(3,5);
	var strTodayYear  = strToday.substring(6,10);
	var strGebDay = Gebdd.substring(0,2);
	var strGebMonth = Gebdd.substring(3,5);
	var strGebYear = Gebdd.substring(6,10);
	var strLeeftijd
	
	strLeeftijd = strTodayYear - strGebYear;
	if (strGebMonth > strTodayMonth)	
	{
		strLeeftijd = strLeeftijd - 1;
	}
	if (strGebMonth == strTodayMonth)	
	{
		if (strGebDay > strTodayDay)	
		{
			strLeeftijd = strLeeftijd - 1;
		}
	}
	return(strLeeftijd);
}



function padout(number) { return (number < 10) ? '0' + number : number; }


function y2k(number) { return (number >= 1000) ? number : (number >= 30) ? number + 1900 : number + 2000; }





