

function CheckEmail(checkStr)
{
// test if valid email address, must have @ and .
var checkEmail = "@.";
var EmailValid = false;
var EmailAt = false;
var EmailPeriod = false;
var error = "";

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;
error = "";
}

}


if (!EmailValid)
{
	
if ((!EmailAt) && (!EmailPeriod))
{
error = " - Email must contain an \"@\" and a \".\"\n";
}

else if (!EmailAt)
{
error = " - Email must contain an \"@\"\n";	
}

else if (!EmailPeriod)
{
error = " - Email must contain an \".\"\n";	
}

else
{
error = " - Email is invalid\n";	
}

}

return error;
}

function jobFormCheck()
{

var alertsay = "";

if (document.getElementById("jobApplyForm").firstName.value == "")
{
alertsay += "- Please enter your First Name\n";
}

if (document.getElementById("jobApplyForm").surname.value == "")
{
alertsay += "- Please enter your Surname\n";
}

if (document.getElementById("jobApplyForm").email.value == "")
{
alertsay += "- Please enter your Email Address\n";
}

if (document.getElementById("jobApplyForm").email.value != "")
{
alertsay += CheckEmail(document.getElementById("jobApplyForm").email.value);
}


if (alertsay)
{
alert("The following error(s) occurred:\n" + alertsay.substring(alertsay,alertsay.length-1) + "\n\nForm will not be processed");
return false;
}

else
{
return true;
}

return false;
}

function contactFormCheck()
{

var alertsay = "";

if (document.getElementById("ContactForm").firstName.value == "")
{
alertsay += "- Please enter your First Name\n";
}

if (document.getElementById("ContactForm").surname.value == "")
{
alertsay += "- Please enter your Surname\n";
}

if (document.getElementById("ContactForm").mobilePhone.value == "")
{
alertsay += "- Please enter your Mobile Number\n";
}

if (document.getElementById("ContactForm").email.value == "")
{
alertsay += "- Please enter your Email Address\n";
}

if (document.getElementById("ContactForm").email.value != "")
{
alertsay += CheckEmail(document.getElementById("ContactForm").email.value);
}


if (alertsay)
{
alert("The following error(s) occurred:\n" + alertsay.substring(alertsay,alertsay.length-1) + "\n\nForm will not be processed");
return false;
}

else
{
return true;
}

return false;
}

function newsLetterFormCheck()
{

var alertsay = "";

if (document.getElementById("newsLetterForm").firstName.value == "")
{
alertsay += "- Please enter your First Name\n";
}

if (document.getElementById("newsLetterForm").surname.value == "")
{
alertsay += "- Please enter your Surname\n";
}

if (document.getElementById("newsLetterForm").email.value == "")
{
alertsay += "- Please enter your Email Address\n";
}

if (document.getElementById("newsLetterForm").email.value != "")
{
alertsay += CheckEmail(document.getElementById("newsLetterForm").email.value);
}


if (alertsay)
{
alert("The following error(s) occurred:\n" + alertsay.substring(alertsay,alertsay.length-1) + "\n\nForm will not be processed");
return false;
}

else
{
return true;
}

return false;
}

function makeAppointmentFormCheck()
{

var alertsay = "";

if (document.getElementById("makeAppointmentForm").firstName.value == "")
{
alertsay += "- Please enter your First Name\n";
}

if (document.getElementById("makeAppointmentForm").surname.value == "")
{
alertsay += "- Please enter your Surname\n";
}

if (document.getElementById("makeAppointmentForm").idealAppointment.value == "")
{
alertsay += "- Please enter an ideal appointment time\n";
}

if (document.getElementById("makeAppointmentForm").idealPhone.value == "")
{
alertsay += "- Please select your ideal phone time\n";
}

if (alertsay)
{
alert("The following error(s) occurred:\n" + alertsay.substring(alertsay,alertsay.length-1) + "\n\nForm will not be processed");
return false;
}

else
{
return true;
}

return false;
}

function joinOnlineFormCheck()
{

var alertsay = "";

if (document.getElementById("joinOnlineForm").firstName.value == "")
{
alertsay += "- Please enter your First Name\n";
}

if (document.getElementById("joinOnlineForm").surname.value == "")
{
alertsay += "- Please enter your Surname\n";
}

if (document.getElementById("joinOnlineForm").email.value == "")
{
alertsay += "- Please enter your Email Address\n";
}

if (document.getElementById("joinOnlineForm").email.value != "")
{
alertsay += CheckEmail(document.getElementById("joinOnlineForm").email.value);
}


if (alertsay)
{
alert("The following error(s) occurred:\n" + alertsay.substring(alertsay,alertsay.length-1) + "\n\nForm will not be processed");
return false;
}

else
{
return true;
}

return false;
}