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)
{
error = " - Email must contain an \"@\" and a \".\"\n";
}

return error;
}

function SetCheckedByValue(theSelect, avalue)
{

if (theSelect)
{

if (avalue != 0)
{
theSelect.checked = true;
}

}

}

function ShowError(Errors)
{
Errors	= Errors.toLowerCase();
alert("The following error(s) occurred:\n" + Errors.substring(Errors,Errors.length-1) + "\n\nSorry can not Process the form");
}

function CheckCandidate()
{

var alertsay = ""; 

// Compulsary Values

if (document.getElementById("CandidateForm").FirstName.value == "")
{
alertsay += "- Please enter your first name\n";
}

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

if (document.getElementById("CandidateForm").DOB.value == "")
{
alertsay += "- Please enter your Date of Birth\n";
}

if (document.getElementById("CandidateForm").Age.value == "")
{
alertsay += "- Please enter your age\n";
}

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

if (document.getElementById("CandidateForm").Telephone.value == "")
{
alertsay += "- Please enter your address\n";
}

if (document.getElementById("CandidateForm").Email.value == "")
{
alertsay += "- Please Enter a contact Email address\n";
}

else
{
alertsay += CheckEmail(document.getElementById("CandidateForm").Email.value);
}

if (document.getElementById("CandidateForm").CurrentJob.value == "")
{
alertsay += "- Please enter your current job title\n";
}

if (document.getElementById("CandidateForm").PositionSought.value == "")
{
alertsay += "- Please enter the position you are looking for\n";
}

if (document.getElementById("CandidateForm").CurrentSalary.value == "")
{
alertsay += "- Please enter your current salary\n";
}

if (document.getElementById("CandidateForm").SalarySought.value == "")
{
alertsay += "- Please enter the salary you are looking for\n";
}

if (document.getElementById("CandidateForm").SalarySought.value == "")
{
alertsay += "- Please enter the salary you are looking for\n";
}

if (document.getElementById("CandidateForm").NoticePeriod.value == "")
{
alertsay += "- Please enter the notice period your current job requires\n";
}

if (document.getElementById("CandidateForm").CoveringNote.value == "")
{
alertsay += "- Please enter your covering note\n";
}

if (alertsay)
{
ShowError(alertsay);
return false;
}

else
{
return true;
}

}

function CheckJob()
{

var alertsay = ""; 

// Compulsary Values

if (document.getElementById("JobForm").Company.value == "")
{
alertsay += "- Please enter your company name\n";
}

if (document.getElementById("JobForm").ContactName.value == "")
{
alertsay += "- Please enter the contacts name\n";
}

if (document.getElementById("JobForm").Telephone.value == "")
{
alertsay += "- Please enter the contacts telephone\n";
}

if (document.getElementById("JobForm").Email.value == "")
{
alertsay += "- Please enter your contacts Email address\n";
}

else
{
alertsay += CheckEmail(document.getElementById("JobForm").Email.value);
}

if (document.getElementById("JobForm").JobTitle.value == "")
{
alertsay += "- Please enter the job title available\n";
}

if (document.getElementById("JobForm").Department.value == "")
{
alertsay += "- Please enter the department for the position\n";
}

if (document.getElementById("JobForm").Salary.value == "")
{
alertsay += "- Please enter the salary for position\n";
}

if (document.getElementById("JobForm").Duration.value == "")
{
alertsay += "- Please enter the duraiation for position\n";
}

if (document.getElementById("JobForm").Description.value == "")
{
alertsay += "- Please enter a short description for position\n";
}

if (alertsay)
{
ShowError(alertsay);
return false;
}

else
{
return true;
}

}

function CheckApply()
{

var alertsay = ""; 

// Compulsary Values

if (document.getElementById("ApplyForm").FirstName.value == "")
{
alertsay += "- Please enter your First name\n";
}

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

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

if (document.getElementById("ApplyForm").Telephone.value == "")
{
alertsay += "- Please enter your Phone number\n";
}

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

else
{
alertsay += CheckEmail(document.getElementById("ApplyForm").Email.value);
}

if (document.getElementById("ApplyForm").CoveringNote.value == "")
{
alertsay += "- Please enter a Covering note\n";
}

if (document.getElementById("ApplyForm").CVDocument.value == "")
{
alertsay += "- Please select your CV\n";
}

if (alertsay)
{
ShowError(alertsay);
return false;
}

else
{
return true;
}

}
