function Validator(){}

Validator.isAgeOlderThan = function(date, minAge) {
	log(date);
	log(minAge);
	if(typeof(date)=='string'){
		date = ValidatorTools.stringToDate(date);
		log('date'+date);
		if(!date)return null;
	}
	var t = new Date(); // today
	var limit = new Date(t.getFullYear()-minAge, t.getMonth(), t.getDate(), 0, 0, 0);
	log('limit'+limit);
	return date <= limit;
}

Validator.isAgeYoungerThan = function(date, maxAge) {
	if(typeof(date)=='string'){
		date = ValidatorTools.stringToDate(date);
		if(!date)return null;
	}
	var t = new Date(); // today
	var limit = new Date(t.getFullYear()-maxAge, t.getMonth(), t.getDate(), 0, 0, 0);
	return date > limit;	
}

Validator.isZipNL = function(zip, allowSpace) {
	var re = allowSpace ? /^\d{4}\s?[a-z]{2}$/i : /^\d{4}[a-z]{2}$/i;
	return zip.search(re) >= 0;
}

Validator.isElfTest = function(str) {
	str = str.replace(/[^\d]/g, '');
	var l = str.length;
	var t = 0;
	if(l != 8 && l != 9 && l != 10){
		return false;
	}
	
	for(var i = 0; i < l; i++){
		t += Number(str.charAt(i))*(l-i);
	}
	return t % 11 == 0;
}

Validator.isNotEmpty = function(str, ignoreSpaces) {
	return ignoreSpaces ? Boolean(!str.match(/^\s*$/)) : Boolean(!str.match(/^$/));
}

Validator.isEmpty = function(str, ignoreSpaces) {
	return ignoreSpaces ? Boolean(str.match(/^\s*$/)) : Boolean(str.match(/^$/));
}

Validator.isEmail = function(str) {
	return str.match(/^(?:[\.\w-]+)@(?:[\w-]+\.)+[a-z]{2,6}$/i) ? true : false;
}

Validator.isNumberMoreThan = function(nr, min, orEqual) {
	return orEqual ? nr  >= min : nr > min;
}

Validator.isNumberLessThan = function(nr, max, orEqual) {
	return orEqual ? nr  <= max : nr < max;
}

Validator.isNumberBetween = function(nr, min, max, orEqual) {
	return orEqual ? (nr >= min && nr <= max) : (nr > min && nr < max)
}

ValidatorTools = function() {}
ValidatorTools.stringToDate = function(str){
	var a = str.split("-");
	var m = a[1];
	var d;
	var y;
	if(str.match(/\d{4}-\d{2}-\d{2}/)){
		y = a[0];
		d = a[2];
	} else if(str.match(/\d{2}-\d{2}-\d{4}/)) {
		d = a[0];
		y = a[2];
	} else {
		return null;
	}
	var date = new Date(y,m-1,d,0,0,0);
	return date;
}