var Valid = '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 CheckDateOfBirth(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;
}



function CheckDate(datDate)
{
	newDate = new Date();
	
	// check if user formatted the date like this  : 20-10-1985
	if (datDate.indexOf('-') != -1)
	{
		arrDate = datDate.split('-');
	}
	else
	{
		// check if user formatted the date like this : 20/10/1985
		if (datDate.indexOf('/') != -1)
		{
			arrDate = datDate.split('/');
		}
		else
		{
			return 'Gelieve de datum in het formaat dd-mm-yyyy op te geven.';
		}
	}
	
	if (arrDate[2].length != 4 || (arrDate[1] < 1 && arrDate[1] > 12) || (arrDate[0] < 1 && arrDate[0] > 31))
	{
		return 'Gelieve de datum in het formaat dd-mm-yyyy op te geven.';		
	}
	
	newDate.setFullYear(arrDate[2], (arrDate[1] - 1), arrDate[0]);
	
	if ((newDate.getDate() != arrDate[0]) || ((newDate.getMonth() + 1) != arrDate[1]) || (newDate.getFullYear() != arrDate[2]))
	{
		return 'U heeft een ongeldige datum ingevoerd';
	}
	
	<!-- if passed previous checks, date of birth is valid -->
	return Valid;
}



function CheckRestoParticipatesOnDate(DateRes, StringBitsParticipates)
{
	DateReservation = new Date();
	
	// check if user formatted the date like this  : 20-10-1985
	if (DateRes.indexOf('-') != -1)
	{
		arrDateRes = DateRes.split('-');
	}
	else
	{
		// check if user formatted the date like this : 20/10/1985
		if (DateRes.indexOf('/') != -1)
		{
			arrDateRes = DateRes.split('/');
		}
		else
		{
			return 'Gelieve de datum in het formaat dd-mm-yyyy op te geven.';
		}
	}
	
	DateReservation.setFullYear(arrDateRes[2], (arrDateRes[1] - 1), arrDateRes[0]);
	
	if (StringBitsParticipates.substr(DateReservation.getDay() - 1, 1) == "0")
	{
		return('U mag enkel een datum opgeven waarop het restaurant deelneemt aan de dinner4you-actie');
	}
	
	return true;
}



function ConvertDate(DateRes)
{
	DateReservation = new Date();
	
	// check if user formatted the date like this  : 20-10-1985
	if (DateRes.indexOf('-') != -1)
	{
		arrDateRes = DateRes.split('-');
	}
	else
	{
		// check if user formatted the date like this : 20/10/1985
		if (DateRes.indexOf('/') != -1)
		{
			arrDateRes = DateRes.split('/');
		}
		else
		{
			return 'Gelieve de datum in het formaat dd-mm-yyyy op te geven.';
		}
	}
	
	DateReservation.setFullYear(arrDateRes[2], (arrDateRes[1] - 1), arrDateRes[0]);
	DateReservation.setHours(23);
	DateReservation.setMinutes(59);
	DateReservation.setSeconds(59);
	
	return DateReservation;
}



<!-- 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: jan.peeters@mail.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 Valid;
}



<!-- Change image -->
function ChangeImage(imgContainer, image)
{
	imgContainer.src = image;
}




function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	{
		while(1)
		{
	  		curtop += obj.offsetTop;
	  		
			if(!obj.offsetParent)
			{
				break;
			}

			obj = obj.offsetParent;
		}
	}
	else if(obj.y)
	{
		curtop += obj.y;
	}

	return curtop;
}




function findPos(obj) 
{
	var curleft = 0;
	var curtop = 0;
	
	if (obj.offsetParent) 
	{
		do 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} 
		while (obj = obj.offsetParent);
	}
	return [curleft, curtop];
}