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 TrimString(str)
{
str 		= this != window? this : str;
str			= str.replace(/^\s+/g, "").replace(/\s+$/g, "");
str			= str.replace(/0/g, "");

return str;
}

function IsEmpty(TmpString)
{

if (!TmpString)
{
return true;	
}

TmpString	= TrimString(TmpString);

if (TmpString.length <= 0)
{
return true;
}

return false;
}

function TrimString(str)
{
str 		= this != window? this : str;
str			= str.replace(/^\s+/g, "").replace(/\s+$/g, "");
str			= str.replace(/0/g, "");

return str;
}

function IsEmpty(TmpString)
{

if (!TmpString)
{
return true;	
}

TmpString	= TrimString(TmpString);

if (TmpString.length <= 0)
{
return true;
}

return false;
}

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 CheckCompulsary(FormName)
{
	
var alertsay			= ""; 

// Compulsary Values
if ((IsEmpty(document.getElementById(FormName).Title.value)) && (IsEmpty(document.getElementById(FormName).Other.value)))
{
alertsay				+= "- Please enter your title\n";
}

if (IsEmpty(document.getElementById(FormName).FirstName.value))
{
alertsay				+= "- Please enter your First Name\n";
}

if (IsEmpty(document.getElementById(FormName).Surname.value))
{
alertsay				+= "- Please enter your Surame\n";
}

if (IsEmpty(document.getElementById(FormName).Email.value))
{
alertsay				+= "- Please enter a Email Address\n";
}

else if (IsEmpty(document.getElementById(FormName).ConfirmEmail.value))
{
alertsay				+= "- Please confirm your Email Address\n";
}

else if (document.getElementById(FormName).Email.value != document.getElementById(FormName).ConfirmEmail.value)
{
alertsay				+= "- Your Confirm Email Address does not match\n";
}

else
{
alertsay				+= CheckEmail(document.getElementById(FormName).Email.value);
}

/*if ((document.getElementById(FormName).Telephone) && (IsEmpty(document.getElementById(FormName).Telephone.value)))
{
alertsay				+= "- Please a enter a Telephone number\n";
}*/

return alertsay;
}

function CheckForm(FormName)
{

var alertsay			= CheckCompulsary(FormName);

if (alertsay)
{
ShowError(alertsay);
return false;
}

else
{
return true;
}

}

function FormControls()
{

}