// this file contains functions for validating a form
// author:    Dominik Scholz, schlotzz@go4u.de
// changed:   2009-05-02

function mail2formValidate(field, regexp, mandatory)
{
	if (regexp == '')
		return;

	// read value
	var value;
	if (field.tagName == 'SELECT')
		value = field.options[field.selectedIndex].text;
	else
		value = field.value;

	// get corresponding label
	var label = field;
	while ((label.tagName != 'LABEL') && (label != null))
		label = label.previousSibling;

	// execute regular expression
	var test;
	eval('test = value.match('+regexp+') != null;');

	// optional field not filled in...
	if (!mandatory && value == '')
	{
		label.className = '';
		return;
	}

	// decide, if field is valid or not
	if (test)
	{
        label.className = 'mailform_valid';
	}
	else
	{
        label.className = 'mailform_invalid';
	}

}
