function CheckEmail(checkStr)
{
// test if valid email address, must have @ and .
var checkEmail	= "@.";
var EmailValid	= false;
var EmailAt	= false;
var EmailPeriod	= false;
var EmailSpace	= false;
var error		= "";

if (checkStr.indexOf(" ") > -1)
{
EmailSpace	= true;
}

for (i	= 0;i < checkStr.length;i++)
{
ch	= checkStr.charAt(i);

for (j	= 0;j < checkEmail.length;j++)
{

if (ch == checkEmail.charAt(j) && ch == "@")
EmailAt	= true;

if (ch == checkEmail.charAt(j) && ch == ".")
EmailPeriod	= true;

if (EmailAt && EmailPeriod)
break;

if (j == checkEmail.length)
break;
}

// if both the @ and . were in the string
if ((EmailAt) && (EmailPeriod) && (!EmailSpace))
{
EmailValid	= true
break;
error	= "";
}

}


if (!EmailValid)
{
error	= "";

if ((!EmailAt) && (!EmailPeriod))
{
error	+= " - Email must contain an \"@\" and a \".\"\n";
}

if (!EmailAt)
{
error += " - Email must contain an \"@\"\n";	
}

if (!EmailPeriod)
{
error += " - Email must contain an \".\"\n";	
}

if (EmailSpace)
{
error += " - Email must not contain a space\n";	
}

else
{
error	= " - Email is invalid\n";	
}

}

return error;
}

function ShowErrors(Errors)
{
Errors	= Errors.toLowerCase();
alert("The following error(s) occurred:\n" + Errors.substring(Errors,Errors.length-1) + "\n\nForm will not be processed");
return false;
}

function CheckSignUp()
{
var alertsay	= "";

if (document.getElementById("First Name").value == "")
{
alertsay += "- Please enter your first name\n";
}

if (document.getElementById("Last Name").value == "")
{
alertsay += "- Please enter your Last Name\n";
}

if (document.getElementById("SignUpForm").DOB.value == "")
{
alertsay += "- Please enter your date of birth\n";
}

if (document.getElementById("Email Address").value == "")
{
alertsay += "- Please enter a email address\n";
}

else if (document.getElementById("SignUpForm").ConfirmEmail.value == "")
{
alertsay += "- Please confirm your email address\n";
}

else if (document.getElementById("Email Address").value != document.getElementById("SignUpForm").ConfirmEmail.value)
{
alertsay += "- Your email address does not match\n";
}

else
{
alertsay += CheckEmail(document.getElementById("Email Address").value);
}

if (document.getElementById("Post Code").value == "")
{
alertsay += "- Please enter your post code\n";
}

if ((document.getElementById("SignUpForm").Gender[0].checked == false) && (document.getElementById("SignUpForm").Gender[1].checked == false))
{
alertsay += "- Please enter your gender\n";
}

if (document.getElementById("Guardian Email").value != "")
{
alertsay += CheckEmail(document.getElementById("Guardian Email").value);
}

if (!alertsay)
{
document.getElementById("SignUpForm").ValidForm.value = "true";
return true;
}

else
{
ShowErrors(alertsay);
return false;
}

return false;
}
