function makeTests(tests)
{
	messages = "";
	focusfield = null;
	for(t=0; t<tests.length; t++)
	{
		result = check(tests[t]);
		if(result==false)
		{
			messages = messages + "\n - " + tests[t][2];
			if(focusfield==null)
			{
				focusfield = tests[t][0];
			}
		}
	}
	if(messages != "")
	{
		alert("Bitte korrigieren Sie die folgenden Fehler:\n"+messages);
		focusfield.focus();
		return false;
	}
	return true;
}

function check(test)
{
	field = test[0];
	checkname = test[1];
	code = checkname+"(field";
	for(p=3;p<test.length;p++)
	{
		code = code + ",'"+test[p]+"'";
	}
	code = code + ")";
	result = eval(code);
	return result;
}
function checkEmpty(field)
{
	if(field.value.replace(/\s*/,"").length == 0) return true;
	return false;	
}
function checkPattern(field,pattern)
{
	result = field.value.match(pattern);
	if(result) return true; else return false;
}
function checkLength(field,minLength,maxLength)
{
	if(minLength>-1 && field.value.replace(/\s*/,"").length<minLength) return false;
	if(maxLength>-1 && field.value.replace(/\s*/,"").length>maxLength) return false;
	return true;
}
function evalDate(field)
{
	result = checkPattern(field,/^[0-9]{2}\.[0-9]{2}\.([0-9]{2}|[0-9]{4})$/);
	if(!result) return false;
	else return true;
}
function checkPassword(field,minLength,maxLength,isRequired)
{
	if(isRequired == 1)
		return (!checkEmpty(field) && checkLength(field,minLength,maxLength) && checkPattern(field,/^[a-zA-Z0-9]*[0-9][a-zA-Z0-9]*$/));
	else
	{ 
		if(!checkEmpty(field))
		{
			return (checkLength(field,minLength,maxLength) && checkPattern(field,/^[a-zA-Z0-9]*[0-9][a-zA-Z0-9]*$/));
		}
	}
	return true;
}
function checkEmail(field,minLength,maxLength,isRequired)
{
	if(isRequired == 1)
		return (!checkEmpty(field) && checkPattern(field,/^[\w\.\-]+@([\w\-]+\.)*[\w\-]{2,63}\.[a-zA-Z]{2,4}/));
	else
	{
		if(!checkEmpty(field))
		{
			return checkPattern(field,/^[\w\.\-]+@([\w\-]+\.)*[\w\-]{2,63}\.[a-zA-Z]{2,4}/);
		}
	}
	return true;	
}
function checkEntry(field,minLength,maxLength,isRequired)
{
	if(isRequired == 1)
		return (!checkEmpty(field) && checkLength(field,minLength,maxLength));
	else
	{
		if(!checkEmpty(field))
		{
			return checkLength(field,minLength,maxLength);
		}
	}
	return true;
}
function checkNumber(field,minLength,maxLength,isRequired)
{
	if(isRequired == 1)
		return (!checkEmpty(field) && checkLength(field,minLength,maxLength) && !checkPattern(field,/[^0-9\s\:\.\+]/));
	else 
	{
		if(!checkEmpty(field))
		{
			return (checkLength(field,minLength,maxLength) && !checkPattern(field,/[^0-9\s\:\.\+]/));
		}
	}
	return true;
}
function checkDate(field,minLength,maxLength,isRequired)
{
	if(isRequired == 1)
		return (!checkEmpty(field) && evalDate(field));
	else
	{
		if(!checkEmpty(field))
		{
			return evalDate(field);
		}
	}
	return true;
}
function checkSelection(field,minLength,maxLength,isRequired)
{
	count = 0;
	for(i=0;i<field.options.length;i++)
	{
		 if(field.options[i].selected == true)
			{
				 count++;
			}
	}
	if(count<minLength || count>maxLength)
	{
		 return false;
	}
	else
	{
		 return true;
	}
}

