﻿function WriteEmailAddress (name, domain, topLevelDomain, css)
{
  document.write('<a');
  if (css.length > 0)
  {
    document.write(' class=\"' + css + '\"');
  }
  document.write(' href=\"mailto:' + name + '@' + domain + '.' + topLevelDomain + '\">');
  document.write(name + '@' + domain + '.' + topLevelDomain + '</a>;');
}

function isEmpty(s)
{   
  s = Trim(s)
  return ((s == null) || (s.length == 0))
}

// Trims all spaces to the left of a specific string
function LTrim(str)
{
  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;
  }

// Trims all spaces to the right of a specific string
function RTrim(str)
{
  // 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;
}

// Trims all spaces to the left and right of a specific string by calling RTim and LTrim
function Trim(str)
{
  return RTrim(LTrim(str));
}

// Checks if the three date elements together form a valid date
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;
}

// Internal function. Returns 29 when a leap year, else 28
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 ValidateDates()
{
	var result;
	var iDay = document.getElementById('ctl00_cpMainContent_lstDay').value;
	var iMonth = document.getElementById('ctl00_cpMainContent_lstMonth').selectedIndex;
	var iYear = document.getElementById('ctl00_cpMainContent_lstYear').value;

	if (iDay == 0 || iMonth == 0 || iYear == 0)
	{
		alert('Dit is geen geldige begindatum');
		return false;
	}

	if (isDate(iYear, iMonth, iDay))
	{
		return true;
	}
	else
	{
		alert('Dit is geen geldige datum');
		return false;
	}
	
	return false;
}
