function checkForm(formName)
{
	var form = __forms[formName];
	var domform = document[formName];
	var errorCount = 0;
	
	// hide all existing errors.
	hideErrors(formName);
	
	for (i in form) 
	{	
		// check if passwords require matching
		if (form[i].confirm) 
		{
			if (domform[i].value != domform[form[i].confirm].value) 
			{
				errorCount++;
				continue;
			}
			continue;
		}
		
		// check that required fields are filled out
		if (form[i].required) 
		{
			if((domform[i].type == "text" && domform[i].value == "") ||
			   (domform[i].type == "checkbox" && !domform[i].checked))
			{
				errorCount++;
				continue;
			}
		}
		// check required length
		if (form[i].minLength && domform[i].value.length > 0 && domform[i].value.length < form[i].minLength) 
		{
			errorCount++;
			continue;
		}
		
		// check regular expression
		if (form[i].regExps && domform[i].value.length != 0) 
		{
			for (var j=0; j< form[i].regExps.length; j++) 
			{
				regex = form[i].regExps[j];
				if (!regex['regex'].test(domform[i].value)) 
				{
					errorCount++;
				}
			}
		}
	}
	
	// submit form regardless of errors, as they are checked server-side by the php script.
	domform.submit();
}

function hideErrors(formName) 
{
	var form = __forms[formName];
	for (i in form) 
	{
		if (elm = document.getElementById(formName+'-'+i))
			elm.innerHTML = '';
	}
}
