/***********************************************************
checkForm( form, errorMsgRef, xtraFunctionRef )

checks form fields for blank or all-space entries. also can 
call an externally-defined function to perform additional 
checks on data

the associative array containing the names of the fields to 
be checked and their corresponding error messages must be 
defined above the function.
************************************************************/

function checkForm( form, errorMsgRef, xtraFunctRef ) {
    var mess;
    mess = ""

	var prop;
	for ( prop in errorMsgRef )
	{
		//  if the value isn't undefined or null, trim 
		//  leading/trailing spaces
		if (form[ prop ].value != null)
		{
			form[ prop ].value = form[ prop ].value.replace(/^\s*/, "").replace(/\s*$/, "");
		}

		//  check for blank fields
		if (form[ prop ].value == "")
		{
			mess += (errorMsgRef[ prop ] + " \n" );
		}
		else
		{	
			
			if(form[ prop ].name == "email")
			{	
				var emailStr = form[ prop ].value;
				var emailPat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
				var matchArray = emailStr.match(emailPat);
				
				if (matchArray == null) {
					mess += "This e-mail address seems incorrect (check \"@\" and \".\") \n";
				}
			}
		}
	}

	//  call externally-defined function if argument passed
	if( xtraFunctRef )
	{
		mess = xtraFunctRef( form, mess );
	}
	

	if ( mess == "" )
	{
		return true;
	} 
	
	else 
	{
		window.alert("The following information must be entered to proceed: \n \n" + mess);
		return false;
    }
}


