
function SubmitForm( formName )
{	
	var theForm = eval('document.' + formName);

	for( var i=0; i<theForm.length; i++ )
		{
		var fName = theForm.elements[i].name;
			fName = fName.replace(/^\d+_/,"");
			fName = fName.replace(/\*$/,"");
		
		//test for compulsory fields	
		if( theForm.elements[i].name.search(/\*$/) > 0 &&  theForm.elements[i].value == '' )
			{			
			alert('The field ' + fName + ' is compulsory!');
			if( theForm.elements[i].type == 'text' )
				theForm.elements[i].focus();
			return false;
			}
			
		//validate email address
		if( fName.search(/^EMAIL/i) != -1 && !IsValidEmail(theForm.elements[i].value) )
			{
			alert('The email address appears to be invalid!');
			theForm.elements[i].focus();
			return false;
			}
		}
			
	theForm.action = "http://www.rowingnsw.asn.au/cgi-bin/submitform.cgi";
	//now called as onsubmit handler
	//theForm.submit();
	return true;
}

function IsValidEmail(string) 
{
//ua is defined in nswra.js and the re is too long for webkit
if( typeof(ua) != "undefined" && ua.webkit )
	return true;
	
//from VRFY.pm (FF4 complains regex is too complicated!!)
//return (string.search(/^(([a-z0-9_\.\+\-\=\?\^\#]){1,64})\@((([a-z0-9\-]){1,251}\.){1,252}[a-z0-9]{2,4})$/i) != -1);

//from http://www.regular-expressions.info/email.html
return (string.search(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) != -1);
}
