/*

cfvalidation.js 1.0

*/

function cfValidateDate(source, arguments)
{
	var sDate = arguments.Value;
	if (sDate == "")
	{
		arguments.IsValid = true;
	}
	else
	{
		var iDay, iMonth, iYear;
		var arrValues;
		arrValues = sDate.split(".");
		iDay = arrValues[0];
		iMonth = arrValues[1];
		iYear = arrValues[2];
		if ((iMonth == null) || (iYear == null))
		{
			arguments.IsValid = false;
		}
		else
		{
			if ((iDay > 31) || (iMonth > 12) || (iYear < 1900))
			{
				arguments.IsValid = false;
			}
			else
			{
				var dummyDate = new Date(iYear, iMonth - 1, iDay);
				arguments.IsValid =
				(
					(dummyDate.getDate() == iDay) &&
					(dummyDate.getMonth() == iMonth - 1) &&
					(dummyDate.getFullYear() == iYear)
				)
			}
		}
	}

	return arguments.IsValid;
}

function cfValidateEmail(source, arguments)
{
	var s = arguments.Value;
	if (s == "")
	{
		arguments.IsValid = true;
	}
	else
	{
		var reg = /^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
		arguments.IsValid = s.match(reg);
	}
	
	return arguments.IsValid;
}

function cfValidateInteger(source, arguments)
{
	var s = arguments.Value;
	if (s == "")
	{
		arguments.IsValid = true;
	}
	else
	{
		var reg = /^\d+$/;
		if (! s.match(reg))
		{
			arguments.IsValid = false;
		}
		else
		{
			var n = parseInt(s, 10);
			if (isNaN(n))
			{
				arguments.IsValid = false;
			}
			else
			{
				// opravdu je to nutne, parseInt klidne vezme dlouhy integer
				arguments.IsValid = ((n >= -2147483648) && (n <= 2147483647));
			}
		}
	}
	
	return arguments.IsValid;
}

function cfValidateDecimal(source, arguments)
{
	var s = arguments.Value;
	if (s == "")
	{
		arguments.IsValid = true;
	}
	else
	{
		var reg = /^[+-]?\d+[.,]?\d*$/;
		arguments.IsValid = s.match(reg);
	}

	return arguments.IsValid;
}
