/*
**
** Checks the validity of the fields from the
** mailing list form on the Contact page.
**
** NOTE:
**   1 -> subscribe / 2 -> unsubscribe
*/
function validateMailingList(action_)
{
	var result = true;
	
	/*
	** Display status message
	*/
	document.getElementById('mlist_status').innerHTML = '<img src="../graphics/icons/busy.gif" alt="Busy" align="absbottom" />&nbsp;&nbsp;Validating form...'
	document.getElementById('mlist_status').style.display = "inline";
	
	/*
	** Restore all labels (there may be errors displayed from earlier)
	*/
	document.getElementById('mlist_email_msg').innerHTML = 'Email:';
	document.getElementById('mlist_code_msg').innerHTML = 'In order to help us avoid spammers, please enter the code which appears in the box below and click Send:';
	
	/*
	** Field: Email
	** Test : Not empty - More complete test done later
	*/
	var memail = document.getElementById('mlist_email').value;
	memail = trim(memail);
	if (memail.length == 0)
	{
		result = false;
		document.getElementById('mlist_email_msg').innerHTML = 'Email: <span class="error"><strong>ERROR - </strong>Please enter your email address</span>';
	}

	/*
	** Field: Code
	** Test : Not empty - More complete test done later
	*/
	var mcode = document.getElementById('mlist_code').value;
	mcode = trim(mcode);
	if (mcode.length == 0)
	{
		result = false;
		document.getElementById('mlist_code_msg').innerHTML = '<span class="error"><strong>ERROR - </strong>In order to help us avoid spammers, please enter the code which appears in the box below and click Send:</span>';
	}

	// If any of these tests have failed, we are done
	if (result == false)
	{
		document.getElementById('mlist_status').innerHTML = '<span class="error"><strong>ERROR - Your request was not sent.</strong></span>';
		return result;
	}
	
	/*
	** Field: Email
	** Test : Validity through AJAX and Perl
	*/
	ajaxValidateEmail('mlist_email', 'mlist', 'mlist_form' + action_, true); // true -> proceed to check the code
}