// This is the Javascript validation to check that the personal details have been 
// completed correctly.

function Form1_Validator(theForm)
// This is the Javascript validation to check that the card details have been 
// completed correctly.

{

// check to see if the field is blank
if (theForm.firstnames.value == "")
{
alert("You must enter your First Name(s).");
theForm.firstnames.focus();
return (false);
}

// require at least 3 characters be entered
if (theForm.firstnames.value.length < 3)
{
alert("Please enter at least 3 characters in the \"First Name(s)\" field.");
theForm.firstnames.focus();
return (false);
}

// allow ONLY alphanumeric and space keys.
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
var checkStr = theForm.firstnames.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert("Please enter only letter and numeric characters in the \"First Name(s)\" field.");
theForm.firstnames.focus();
return (false);
}

// check to see if the field is blank
if (theForm.surname.value == "")
{
alert("You must enter your Surname.");
theForm.surname.focus();
return (false);
}

// require at least 3 characters be entered
if (theForm.surname.value.length < 3)
{
alert("Please enter at least 3 characters in the \"Surname\" field.");
theForm.surname.focus();
return (false);
}

// allow ONLY alphanumeric and space keys.
var checkOK = "'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
var checkStr = theForm.surname.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert("Please enter only letter and numeric characters in the \"Surname\" field.");
theForm.surname.focus();
return (false);
}

// check if email field is blank
if (theForm.email.value == "")
{
alert("Please enter a value for the \"email\" field.");
theForm.email.focus();
return (false);
}


// test if valid email address, must have @ and .
var checkemail = "@.";
var checkStr = theForm.email.value;
var emailValid = false;
var emailAt = false;
var emailPeriod = false;
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)
{
		emailValid = true
		break;
	}
}
if (!emailValid)
{
alert("The \"email\" field must contain an \"@\" and a \".\".");
theForm.email.focus();
return (false);
}

alert("All Validations have succeeded. ")
return (true);

}