//Test if an input control has been filled with a value by the user
function isFilled(obj)
{
	//1. Determine the type of control we're dealing with here
	var veldsoort = String(obj.tagName).toLowerCase();
	//2. Test for input controls (text or hidden)
	if (veldsoort == "input")
	{
		if (String(obj.value).length <= 0) { return false; }
	}
	//3. Test for select boxes
	else if (veldsoort == "select")
	{
		if (obj.options[obj.selectedIndex].value == "") { return false; }
		if (obj.options[obj.selectedIndex].value == 0) { return false; }
	}
	//4. Test for textareas
	else if (veldsoort == "textarea")
	{
		if (String(obj.innerHTML).length <= 0) { return false; }
	}
	return true;
}

//Tests whether a given value is a valid date
function isValidDate(day, month, year)
{
	//1. Rewrite all input to integer values, just in case there are leading zero's and such
	day		= rewriteToInteger(day);
	month 	= rewriteToInteger(month) - 1; //JavaScript months range from 0 to 11
	year 	= rewriteToInteger(year);
	//2. Fead the input into a JavaScript Date object
	var inputDate = new Date(year, month, day, 0, 0, 0, 0);
	//3. Test if the actual value of the Date object corresponds with the input.
	if (inputDate.getFullYear() != year) { return false; }	//year is not valid
	if (inputDate.getMonth() != month) { return false; }	//month is not valid
	if (inputDate.getDate() != day) { return false; }		//day is not valid
	//4. The date has been found to be correct
	return true;
}

//Tests whether a given value is valid Dutch phone number (either mobile or regular)
function isValidPhone(net, subscriber)
{
	//1. First, remove non-numeric charachters from the input variables
	net			= String(removeNonNumeric(net));
	subscriber	= String(removeNonNumeric(subscriber));
	if ((net.length == 0) && (subscriber.length == 0)) { return true; }
	//2. Points and comma's aren't stripped yet, so do that
	net			= net.replace(".", "");
	net			= net.replace(",", "");
	subscriber	= subscriber.replace(".", "");
	subscriber	= subscriber.replace(",", "");
	//3. Test the net number length
	if ((net.length < 2) || (net.length > 4)) { return false; }
	//4. Test subscriber number length
	if ((subscriber.length < 6) || (subscriber.length > 8)) { return false; }
	//5. Test that net-number starts with a 0
	if (net.charAt(0) != "0") { return false; }
	//6. Test the validity of the second character of the net-number
	if ((net.charAt(1) == "0") || (net.charAt(1) == "8") || (net.charAt(1) == "9")) { return false; }
	//7. Test that the subscriber number does NOT start with a 0
	if (subscriber.charAt(0) == "0") { return false; }
	//8. Test combined lengths of net and subscriber numbers
	if ((net.length == 2) && (subscriber.length != 8)) { return false; }
	else if ((net.length == 3) && (subscriber.length != 7)) { return false; }
	else if ((net.length == 4) && (subscriber.length != 6)) { return false; }
	return true;
}

//Tests whether a given value is valid e-mail address
function isValidEmail(val)
{
	//1. Make sure we're dealing with a string here
	val	 = String(val);
	if (val.length == 0) { return true; }
	//2. Do regular expression test on the format of the mail string
	var emailFilter =/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(val))) { return false; }
	//3. Do regular expression test for illegal characters
	var illegalChars = /[\ \(\)\<\>\,\;\:\\\/\"\[\]]/;
	if (val.match(illegalChars)) { return false; }
	//4. Test the email string for the TLD validity
	var goodEmail = val.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.info)|(\.name)|(\.biz)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	return goodEmail;
}

//Tests whether a given value is valid Dutch social security number
function isValidSocialSecurity(val)
{
	//1. Make sure we're dealing with a string here containing only numbers
	val	= String(removeNonNumeric(val));
	val	= val.replace(".", "");
	val = val.replace(",", "");
	if (val.length == 0) { return true; }
	//2. Test value length for validity
	if (val.length != 9) { return false; }
	if (val == "000000000") { return false; }
	//3. Start calculation test to check input validity
	var sum		= 0;
	for (var l=0; l < val.length; l++)
	{
		if (l < 8) { sum+= parseInt(val.charAt(l)) * parseInt(9-l); }
		else { sum+= parseInt(val.charAt(l)) * -1; }
	}
	if (parseFloat(sum/11) - parseInt(sum/11) != 0) { return false; }
	return true;
}

//Tests whether a given value is a valid Dutch account number (either bank or giro)
function isValidAccount(val)
{
	//1. Make sure we're dealing with a string here containing only numbers
	val	= String(removeNonNumeric(val));
	val	= val.replace(".", "");
	val = val.replace(",", "");
	var testString = "";
	var bZeroOnly	=	true;
	for (var l=0; l < val.length; l++)
	{
		if (val.charAt(l) != "0")	{	bZeroOnly	=	false;	}
		testString = testString+"0";
	}
	if (val.length == 0) { return true; }
	if (bZeroOnly == true)	{	return false;	}
	//2. Do length validity testing on the string
	if ((val.length < 3) || (val.length == 8) || (val.length > 9)) { return false; }
	//3. In case of a "giro" account, we're done
	if ((val.length >= 3) && (val.length <= 7)) { return true; }
	//4. Default pattern testing
	if (val == "000000000")	{	return false;	}
	if (val == "123456789")	{	return false;	}
	//4. Still here, so we must check for bank account patterns
	var startNummer	= 0;
	var sum			= 0;
	if ((val.charAt(0) == 0) && (val.length > 9)) { startNummer++; }
	for (var l=startNummer; l < val.length; l++)
	{
		sum+= parseInt(val.length - l) * parseInt(val.charAt(l));
	}
	if (parseFloat(sum / 11) - parseInt(sum / 11) != 0) { return false; }
	return true;
}

//Tests whether a given value is valid Dutch postalcode
function isValidPostalcode(val)
{
	//1. Make sure we're dealing with a string here containing only numbers and letters
	val	= String(val);
	val	= val.replace(" ", "");
	val = val.replace(".", "");
	val = val.replace(",", "");
	//2. Do the basic length test
	if (val.length != 6) { return false; }
	//3. Hack up the string
	var numeriek	= String(removeNonNumeric(val.substr(0,4)));
	var letters		= String(removeNumeric(val.substr(4,2)));
	//4. Check the different parts for validity
	if (numeriek.length != 4) { return false; }
	if (numeriek.charAt(0) == "0") { return false; }
	if (letters.length != 2) { return false; }
	//5. We're still here so it must be OK
	return true;
}

//This function compares two variables to see if testVal is greater than baseVal.
//No test are done on whether or not the variables are of the same type and if the values are valid
function isValueGreater(baseVal, testVal)
{
	if (testVal <= baseVal) { return false; }
	return true;
}

//This function compares two variables to see if testVal is smaller than baseVal.
//No test are done on whether or not the variables are of the same type and if the values are valid
function isValueSmaller(baseVal, testVal)
{
	if (testVal >= baseVal) { return false; }
	return true;
}

function isValidLicencePlate(val)
{
	var waarde	=	String(val);
	if (waarde.length != 8)	{	return false;	}
	var aDelen	=	waarde.split("-");
	if (aDelen.length != 3)	{	return false;	}
	for (iDeel = 0; iDeel < aDelen.length; iDeel++)
	{
		var sDeel	=	String(aDelen[iDeel]);
		if ((! isNaN(sDeel.charAt(0))) && isNaN(sDeel.charAt(1)))	{	return false;	}
		if ((! isNaN(sDeel.charAt(1))) && isNaN(sDeel.charAt(0)))	{	return false;	}
	}
	return true;
}

