function daysInFebruary (year)
{ // 29 days in febr, when it's a leap year. Not with a century, unless dev. by 400
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}
function isEmpty(s)
{   
	s = Trim(s)
	return ((s == null) || (s.length == 0))
}
function isDate (year, month, day)
{
	if (isEmpty(year) || isNaN(year)) return false
	if (isEmpty(month) || isNaN(month)) return false
	if (isEmpty(day) || isNaN(day)) return false
	var longMonth
	var isFebruary
	longMonth = false
	isFebruary = false
	if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
	{
		longMonth = true		
	}
	if (month == 2)
	{
		isFebruary = true
	}
	if (longMonth && day > 31) return false
	if (!longMonth && day > 30) return false
	if (isFebruary && day > daysInFebruary(year)) return false
	return true
}

function LTrim(str)
/***
        PURPOSE: Remove leading blanks from our string.
        IN: str - the string we want to LTrim
        RETVAL: An LTrimmed string!
***/
{
        var whitespace = new String(" \t\n\r "); // last space character is not a space, but alt+0160, another invisible char. Added by Imar Spaanjaars at 07-09-2000

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(0)) != -1) {
            // We have a string with leading blank(s)...

            var j=0, i = s.length;

            // Iterate from the far left of string until we
            // don't have any more whitespace...
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                j++;


            // Get the substring from the first non-whitespace
            // character to the end of the string...
            s = s.substring(j, i);
        }
        return s;
}

function RTrim(str)
/***
        PURPOSE: Remove trailing blanks from our string.
        IN: str - the string we want to RTrim

        RETVAL: An RTrimmed string!
***/
{
        // We don't want to trip JUST spaces, but also tabs,
        // line feeds, etc.  Add anything else you want to
        // "trim" here in whitespace
        var whitespace = new String(" \t\n\r "); // last space character is not a space, but alt+0160, another invisible char. Added by Imar Spaanjaars at 07-09-2000

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            // We have a string with trailing blank(s)...

            var i = s.length - 1;       // Get length of string

            // Iterate from the far right of string until we
            // don't have any more whitespace...
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;


            // Get the substring from the front of the string to
            // where the last non-whitespace character is...
            s = s.substring(0, i+1);
        }

        return s;
}

function Trim(str)
/***
        PURPOSE: Remove trailing and leading blanks from our string.
        IN: str - the string we want to Trim

        RETVAL: A Trimmed string!
***/
{
        return RTrim(LTrim(str));
}


// isEmail (STRING s , BOOLEAN emptyOK)
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
function isEmail (s, emptyOK)
{   
	if (isEmpty(s)) // empty field
	{ 
		if (emptyOK == true) // if E-mail not required
		{
			return true;
		}
	}
	var sMsg = 'Dit is geen geldig e-mail adres.';
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;
    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { 
		i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@"))
    {
		alert(sMsg)
		return false;
	}
    else
    {
		i += 2;
	}
    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { 
		i++
    }
    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != "."))
    {
		alert(sMsg)
		return false;
	}
    else
    {
		return true;
	}
}

function isRequiredFieldFilled (fieldValue, friendlyFieldName, extraOptionalDescription)
{
    if (isEmpty(Trim(fieldValue)))
    {
		var sMessage
		sMessage = extraOptionalDescription
		if (arguments.length == 2) // extraOptionalArgument is not sent.
		{
			sMessage = ' is verplicht.'
		}
		else // use the optional argument
		{
			sMessage = '. ' + extraOptionalDescription
		}
		alert ('Het veld ' + friendlyFieldName + sMessage)
		return false;
	}
	return true;
}