RegEx =
{
	Empty: /^$/
	,Email: /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
	,Phone: /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
};

function ValidateForm( oForm )
{
	try
	{
		var rv = false;
		var err_msg = "";
		var oFirst = null;
		//# find the fields that require validationa and validate them
		for( var i = 0; i < oForm.length; i++ )
		{
			if(oForm[i].getAttribute("regex") != null)
			{
				var res = eval(oForm[i].getAttribute("regex")).test(oForm[i].value)
				res = (oForm[i].getAttribute("regex")=="RegEx.Email")?!res:res;
				if(res)
				{
					err_msg += ">" + oForm[i].getAttribute("message") + "\n";
					oForm[i].className = "valid_err";
					if(oFirst==null){ oFirst = oForm[i]; }
				}
				else
				{
					oForm[i].className = "";
				}
			}
		}
		
		if(err_msg=="")
		{
			var interests = "";
			for(var i = 0; i < oForm.length; i++)
			{
				if(oForm[i].type == "checkbox")
				{
					if(oForm[i].checked){interests+=", "+oForm[i].value;}
				}
			}
			oForm["cb_list_hidden"].value = interests.substring(2);
			oForm.action = location.href;
			return true;
		}
		else
		{
			alert("There were issues processing the form,\n\n"+err_msg+"\nPlease correct the entries before submitting the form.");
			oFirst.focus();
		}
		
		return rv;
	}
	catch(e)
	{
		throwException( 'contact_form.js : ValidateForm()', e.lineNumber, e, e.message ); 
		return false;
	}
}


