// Author:      Jason McReynolds // -->
// Email:       jason@typeslowly.co.uk // -->
// Studio:      Typeslowly // -->
// Location:    Manchester, Uk // -->
// Web:         typeslowly.co.uk // -->

// Description:  // -->
// The script is developed to validate form input data // -->


// Script Starts Here That Validates User Input
function checkform(thisform)
{

// Check User Has Inputted a name // -->
if(thisform.name.value == null || thisform.name.value == "")
{
	alert("Please enter your name"); 
	thisform.name.focus();
	thisform.name.select();
	return false;
}
// Check User Has Inputted a surname // -->
if(thisform.Surname.value == null || thisform.Surname.value == "")
{
	alert("Please enter your surname"); 
	thisform.Surname.focus();
	thisform.Surname.select();
	return false;
}
// Check User Has Inputted an email address // -->
if(thisform.email.value == null || thisform.email.value == "")
{
	alert("Please enter an email address");
	thisform.email.focus();
	thisform.email.select();
	return false;
}
// Check the user has input a valid email address. 1. Check for Bad Characters //-->
invalidChars = " /:,;=(){}[]*$";
for (i=0; i<invalidChars.length;i++)
{
	badChar = invalidChars.charAt(i)
	if (thisform.email.value.indexOf(badChar,0) > -1)
	{
		alert("You entered and invalid email address");
		thisform.email.focus();
		thisform.email.select();
		return false
	}
}
// Check the user has input a valid email address. 2. Check for @ within the email address //-->
atPos = thisform.email.value.indexOf("@",1)
if (atPos == -1)
{
	alert("You entered and invalid email address");
	thisform.email.focus();
	thisform.email.select();
	return false
}
// Check the user has input a valid email address. 3. Check for only one @ within the email address //-->
if (thisform.email.value.indexOf("@",atPos+1) > -1)
{
	alert("You entered and invalid email address");
	thisform.email.focus();
	thisform.email.select();
	return false
}
// Check the user has input a valid email address. 4. Check that a . appears after the @ within the email address //-->
periodPos = thisform.email.value.indexOf(".",atPos)
if (periodPos == -1)
{
	alert("You entered and invalid email address");
	thisform.email.focus();
	thisform.email.select();
	return false
}
// Check the user has input a valid email address. 5. Check that at least two characters appear after the . //-->
if (periodPos+3>thisform.email.value.length)
{
	alert("You entered and invalid email address");
	thisform.email.focus();
	thisform.email.select();
	return false
}
return true;
}
// Script Ends-->