var ValidEmail = 'valid';

<!-- Trims all spaces before and after the input string -->
function Trim(strString)
{
	while (strString.substr(0, 1) == ' ')
	{
		strString = strString.substring(1, strString.length);
	}
	
	while (strString.substr(strString.length - 1, 1) == ' ')
	{
		strString = strString.substr(0, strString.length - 1);
	}
	
	return strString;
}



<!-- Check first string for valid chars provided in second string -->		
function IsValid(strString, strValidChars)
{
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
	  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)
		 {
		 blnResult = false;
		 }
	  }
   return blnResult;
}



<!-- Check date of birth -->
function CheckDataOfBirth(DoB, minAge)
{
	Today = new Date();
	DateOfBirth = new Date();
	
	// check if user formatted the date like this  : 20-10-1985
	if (DoB.indexOf('-') != -1)
	{
		arrDateOfBirth = DoB.split('-');
	}
	else
	{
		// check if user formatted the date like this : 20-10-1985
		if (DoB.indexOf('/') != -1)
		{
			arrDateOfBirth = DoB.split('/');
		}
		else
		{
			return 'Gelieve uw geboortedatum in het formaat dd-mm-yyyy op te geven.';
		}
	}
	
	if (arrDateOfBirth[2].length != 4 || (arrDateOfBirth[1] < 1 && arrDateOfBirth[1] > 12) || (arrDateOfBirth[0] < 1 && arrDateOfBirth[0] > 31))
	{
		return 'Gelieve uw geboortedatum in het formaat dd-mm-yyyy op te geven.';		
	}
	
	DateOfBirth.setFullYear(arrDateOfBirth[2], (arrDateOfBirth[1] - 1), arrDateOfBirth[0]);
	
	if (DateOfBirth > Today)
	{
		return 'De geboortedatum kan niet in de toekomst liggen';
	}
	
	if ((DateOfBirth.getDate() != arrDateOfBirth[0]) || ((DateOfBirth.getMonth() + 1) != arrDateOfBirth[1]) || (DateOfBirth.getFullYear() != arrDateOfBirth[2]))
	{
		return 'U heeft een ongeldige datum ingevoerd';
	}
	
	// if current year - year date of birth lower than minAge
	// if current year - year date of birth is equal to minAge and current month lower than month date of birth
	// if current year - year date of birth is equal to minAge and cuurent month is equal to month date of birth and current day lower than day date of birth
	// the user is under age
	if ((Today.getFullYear() - DateOfBirth.getFullYear() < minAge) ||
		(Today.getFullYear() - DateOfBirth.getFullYear() == minAge && Today.getMonth() < DateOfBirth.getMonth()) ||
		(Today.getFullYear() - DateOfBirth.getFullYear() == minAge && Today.getMonth() == DateOfBirth.getMonth() && Today.getDate() < DateOfBirth.getDate()))
	{
		return 'De minimum leeftijd is ' + minAge + ' jaar';
	}
	
	<!-- if passed previous checks, date of birth is valid -->
	return 'valid';
}



<!-- Check E-mail is valid -->
function CheckEmail(Emailaddress)
{
	CharAt = Emailaddress.indexOf('@');
	RemainingStr = Emailaddress.substr(CharAt, (Emailaddress.length - CharAt));
	CharPoint = RemainingStr.indexOf('.');
	
	// when @ is not present in the e-mail address
	// when @ is present but is the first character
	// when . is not present after @
	// when . is present but is the last character of the e-mail address
	if ((CharAt == -1) || (CharAt == 0) || (CharPoint == -1) || (CharPoint == RemainingStr.length - 2))
	{
		return 'Het e-mail adres is niet in het juiste formaat\nHet e-mail adres dient er als volgt uit te zien : gebuiker@domeinnaam.net\n(bvb: info@genietgezond.be)';
	}
	
	
	if (Emailaddress.indexOf(' ') != '-1')
	{
		return 'Het e-mail adres mag geen spaties bevatten';
	}
	
	<!-- if passed previous checks, e-mail seems to be valid -->
	return ValidEmail;
}



<!-- Change image -->
function ChangeImage(imgContainer, image)
{
	imgContainer.src = image;
}
