// JavaScript Document
// email form validation
/* Note, 
*/
<!--
/* clearfield can be called for onfocus event for form fields. If initial value of the field matches the string below, it will be cleared automatically. Allows for instructions or comments to be in the field, which clear when the field gets focus */
function clearfield(fieldname) {
	if (fieldname.value == "(if different from above)") {
		fieldname.value = ""
	}
}

function Form1_Validator(theForm)
{

var alertsay = ""; // define for long lines
// alertsay is not necessary for your code,
// but I need to break my lines in multiple lines
// so the code won't extend off the edge of the page

// check to see if the field is blank
if (theForm.student_name.value == "")
{
alert("You must enter your name.");
theForm.student_name.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 a valid email address.");
theForm.email.focus();
return (false);
}

//The checkbox at the end
// alert if the box is NOT checked
if (!theForm.I_agree.checked)
{
alertsay = "You must agree to the terms by checking "
alertsay = alertsay + "the I agree box at the bottom of the form, "
alert(alertsay);
theForm.I_agree.focus();
return (false);

}


// wish to exit the page
return (true);
// replace the above with return(true); if you have a valid form to submit to
}
//-->
				
