
function showHelp()
{
	if(document.getElementById("helpDiv").style.display == 'inline')
	{
		document.getElementById("helpDiv").style.display = 'none';
	}
	else
	{
		document.getElementById("helpDiv").style.display = 'inline';
	}
}


function checkFields()
{
	if(document.loginForm.pCode.value == '')
	{
		alert('Please enter your participation & security codes into the form as they appear on the invitation');
		return false;
	}
	else
	{
		return true;
	}
}

function createSurvey()
{
	if(document.form1.survey_title.value == '')
	{
		alert('Please enter a descriptive title for this survey, e.g. A&E Dept');
		return false;
	}
	else if((isNaN(document.form1.participant_count.value) != false)||(document.form1.participant_count.value == ''))
	{
		alert('You must enter an integer for the number of participants taking the survey');
		return false;
	}
	else
	{
		return true;
	}
}

function checkPayment()
{
	if(document.form1.iname.value == '')
	{
		alert('Please enter the name of the person this invoice is for.');
		return false;
	}
	else if((document.form1.iad1.value == '')||(document.form1.iad2.value == ''))
	{
		alert('Please enter the full address.');
		return false;
	}
	else
	{
		return true;
	}
}

// JavaScript Document
function print_mail_to(mailto_name, mailto_domain, mailto_subject, mailto_body, mailto_style)
{
	document.write('<a href=\"mailto:');
	document.write(mailto_name+'@');
	document.write(mailto_domain+'?');
	document.write('Subject='+mailto_subject+'&amp;');
	document.write('body='+mailto_body+'\" onFocus=\"if(this.blur)this.blur()\" ');
	document.write(' class=\"'+mailto_style+'\">'+mailto_name);
	document.write('@'+mailto_domain);
	document.write('</a>');
}

// ADDING PARTICIPANTS FORM CHECKING

function checkParticipantsToAdd(rows)
{
	var failed = '';
	for(a = 1; a <= rows; a++)
	{
		if(document.form1['email' + a].value != '')
		{
			if(validate_email('email' + a) == false)
			{
				failed = 'y';
			}
			if(document.form1['groupa' + a].value == '')
			{
				failed = 'y';
			}
			if(document.form1['groupb' + a].value == '')
			{
				failed = 'y';
			}
		}
	}
	if(failed == 'y')
	{
		alert('There are errors in your data. Please correct and try again.');
	}
	else
	{
		document.form1.submit();
	}
}

function validate_email(field)
{
	var x = document.form1[field].value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x))
	{
		return true;
	}
	else
	{
		return false;
	}
}
