// JavaScript Document
function checkform() {

//set the variables
var correct = true
var a = '';
var b = '';
var c = '';
var d = '';
var email = '';
var theemail = '';
var checks = '';
var fieldsList = "\n";

// check the form values to make sure they are valid
if (document.contact.firstname.value.length == 0) {a = 'First Name';correct = false;}
if (document.contact.surname.value.length == 0) {b = 'Surname';correct = false;}
if (document.contact.company.value.length == 0) {c = 'Company Name';correct = false;}
if (document.contact.comments.value.length == 0) {d = 'Comments/Enquiry';correct = false;}

//make sure the email is valid
var EmailCorrect = false
var theemail = document.contact.email.value;

for (var i = 0; i <= theemail.length; i++)
{
 if (theemail.charAt(i) == "@") {
 EmailCorrect = true;
 var marker = i;
 }

}

if (EmailCorrect == true){
for (var j = marker; j <= theemail.length; j++)
{
 if (theemail.charAt(j) != ".") {
 EmailCorrect = false
 } else {
 EmailCorrect = true
 j = theemail.length;
 }
 }
}


var EMLength = theemail.length
if (EmailCorrect == false){email = 'Valid Email Address'; correct= false}


if (a != ''){fieldsList = fieldsList + a + "\n";} 
if (b != ''){fieldsList = fieldsList + b + "\n";} 
if (c != ''){fieldsList = fieldsList + c + "\n";} 
if (d != ''){fieldsList = fieldsList + d + "\n";} 
if (email != ''){fieldsList = fieldsList + email + "\n";}

if (correct != true){alert("The Following Fields are Required:\n " + fieldsList + "\nPlease Fill in and Re-Submit");}
return correct;
}
