function org_corigrpCustomValidator(source, arguments)
{	
	switch(source.datatype)
	{
		case "String":
		var stringlength = parseInt(source.stringlength);
		if(stringlength > 0)
		{
			if(arguments.Value.length > stringlength)
			{
				source.errormessage = "Il campo " + source.messagefieldname + " e' piu' lungo di " + stringlength + " caratteri!";
				arguments.IsValid = false;
			}
			else arguments.IsValid = true;
		}
		break;
		
		case "Int":
		if(CheckInt(arguments.Value) == null)
		{
			source.errormessage = "Il campo " + source.messagefieldname + " non e' un numero intero!";
			arguments.IsValid = false;
		}
		else arguments.IsValid = true;
		break;
		
		case "Float":
		if(CheckFloat(arguments.Value) == null)
		{
			source.errormessage = "Il campo " + source.messagefieldname + " non e' un numero decimale!";
			arguments.IsValid = false;
		}
		else arguments.IsValid = true;
		break;
		
		case "Date":
		if(CheckDate(arguments.Value) == null)
		{
			source.errormessage = "Il campo " + source.messagefieldname + " non contiene una data valida!";
			arguments.IsValid = false;
		}
		else arguments.IsValid = true;
		break;
	}
}

function CheckInt(op)
{
	exp = new RegExp("^\\s*[-\\+]?\\d+\\s*$");
    if (op.match(exp) == null) return null;
    num = parseInt(op, 10);
    return (isNaN(num) ? null : num);
}

function CheckFloat(op)
{
	exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\,(\\d+))?\\s*$");
    m = op.match(exp);
    if (m == null) return null;
	cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
    num = parseFloat(cleanInput);
    return (isNaN(num) ? null : num);        
}

function CheckDate(op)
{
	m = op.match(new RegExp("^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$"));
    if(m != null)
	{
		var day, month, year;
		day = m[1];
		month = m[3];
		year = m[5];
		month -= 1;
		var date = new Date(year, month, day);
		return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;
	}
	return null;
}
