
function checkForm(theForm)
{
	var i;
	var ok=true;
	var theElement=null;
	var description="";
	for (i=0;i<theForm.elements.length;i++)
	{
		var frmElement=theForm.elements[i];
		theElement=frmElement;
		if (theElement.oldTextColor)
		{
			theElement.parentNode.style.background='transparent';
			theElement.parentNode.style.color=theElement.oldTextColor;
			theElement.oldTextColor=null;
		}
		description="Please specify " + (theElement.getAttribute("description") ? theElement.getAttribute("description") : theElement.name);
		if (frmElement.getAttribute("required"))
		{
			if (frmElement.selectedIndex+''=='undefined' && theForm[frmElement.name].length+''!='undefined')  //this is a grouped object
			{
				theElement=theForm[frmElement.name];
				if (theElement[0]!=frmElement) continue;  //not first element of group
				var len=theElement.length;
				for (j=0;j<len;j++)
				if (theElement[j].checked) break;
				theElement=theElement[0];
				if (j==len)
				{
					ok=false;
					break;
				}
			}
			else
			{
				theElement=frmElement;
				switch (frmElement.type)
				{
					case 'radio':
					case 'checkbox':
						ok=frmElement.checked;
						break;
						
					case 'textarea':
						ok=!!frmElement.value;
						break;
						
					default:
						ok=!!frmElement.value;
						break;
				}
				if (!ok) break;
			}
		}
		if (theElement.getAttribute("format") && theElement.value)
		{
			var r=new RegExp(theElement.getAttribute("format"),"gi");
			if (!(ok=r.test(theElement.value)))
			{
				description+='.\nThe format is wrong';
				if (theElement.getAttribute("formatdescription"))
					description+=': '+theElement.getAttribute("formatdescription");
				break;
			}
		}
		if (theElement.getAttribute("eval") && theElement.value)
		{
			var strFunction=theElement.getAttribute("eval") + "(" + theElement.value + ")";
			if (!(ok=eval(strFunction)))
			{
				if (theElement.getAttribute("evaldescription"))
					description+='.\n'+theElement.getAttribute("evaldescription");
				break;
			}
		}
	}
	for (;i<theForm.elements.length;i++)  //clean the rest of the backgrounds if any
	{
		if (theForm.elements[i].oldTextColor)
		{
			theForm.elements[i].parentNode.style.background='transparent';
			theForm.elements[i].parentNode.style.color=theForm.elements[i].oldTextColor;
			theForm.elements[i].oldTextColor=null;
		}
	}
	if (!ok)
	{
		//description=(theElement.getAttribute("description") ? theElement.getAttribute("description") : theElement.name);
		//if (wrongFormat) description+='.\nThe format is wrong';
		var c=theElement.parentNode.style.color;
		if (theElement.parentNode.currentStyle) c=theElement.parentNode.currentStyle.color;
		theElement.oldTextColor= c ? c : 'inherit';
		theElement.parentNode.style.background='#ED1D24';
		theElement.parentNode.style.color='white';
		alert(description + '.');
		theElement.focus();
	}

	return ok;
}


