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

if (checkStr.indexOf(" ") > -1)
{
EmailSpace	= true;
}

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) && (!EmailSpace))
{
EmailValid	= true
break;
error	= "";
}

}


if (!EmailValid)
{
error	= "";

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

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

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

if (EmailSpace)
{
error += " - Email must not contain a space\n";	
}

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

}

return error;
}

function TrimString(str)
{
str 		= this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

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");
return false;
}

function CheckTrackerLogin(FormName)
{

if ((IsEmpty(document.getElementById(FormName).u_username.value)) || (document.getElementById(FormName).u_username.value == "Login"))
{
return false;	
}

if ((IsEmpty(document.getElementById(FormName).u_password.value)) || (document.getElementById(FormName).u_password.value == "Password"))
{
return false;	
}

}

function CheckRegister()
{

var alertsay	= "";

if (IsEmpty(document.getElementById("RegisterForm").Email.value))
{
alertsay += "- Please enter a email address\n";
}

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

if (IsEmpty(document.getElementById("RegisterForm").Password.value))
{
alertsay += "- Please enter a password\n";
}

else if ((!IsEmpty(document.getElementById("RegisterForm").Password.value)) && (IsEmpty(document.getElementById("RegisterForm").VerifyPassword.value)))
{
alertsay += "- Please enter your Confirm your Password\n";
}

else if (document.getElementById("RegisterForm").Password.value != document.getElementById("RegisterForm").VerifyPassword.value)
{
alertsay += "- Your Passwords do not match\n";
}

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

else
{
return true;
}

}

function CheckContact()
{

var alertsay	= "";

if ((IsEmpty(document.getElementById("ContactForm").Name.value)) || (document.getElementById("ContactForm").Name.value == "Your Name"))
{
alertsay += "- Please enter your name\n";
}

if ((IsEmpty(document.getElementById("ContactForm").Email.value)) || (document.getElementById("ContactForm").Email.value == "Your Email"))
{
alertsay += "- Please enter a email address\n";
}

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

if ((IsEmpty(document.getElementById("ContactForm").Enquiry.value)) || (document.getElementById("ContactForm").Enquiry.value == "Your Enquiry"))
{
alertsay += "- Please enter a enquiry\n";
}

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

else
{
return true;
}

}

function FormControls()
{

if (document.getElementById("TrackerLoginForm"))
{
	
if (document.getElementById("TrackerLoginForm").Login)
{
Login				= document.getElementById("TrackerLoginForm").Login;
Password			= document.getElementById("TrackerLoginForm").Password;

// Login Name
Login.onfocus		= new Function("FocusValues(Login, 'Login')");
Login.onblur		= new Function("BlurValues(Login, 'Login')");

// Login Password
Password.onfocus	= new Function("FocusValues(Password, 'Password')");
Password.onblur		= new Function("BlurValues(Password, 'Password')");
}

}

if (document.getElementById("ContactForm"))
{
Name				= document.getElementById("ContactForm").Name;
Email				= document.getElementById("ContactForm").Email;
Enquiry				= document.getElementById("ContactForm").Enquiry;

// Name Name
Name.onfocus		= new Function("FocusValues(Name, 'Your Name')");
Name.onblur			= new Function("BlurValues(Name, 'Your Name')");

// Name Email
Email.onfocus		= new Function("FocusValues(Email, 'Your Email')");
Email.onblur		= new Function("BlurValues(Email, 'Your Email')");

// Name Email
Enquiry.onfocus		= new Function("FocusValues(Enquiry, 'Your Enquiry')");
Enquiry.onblur		= new Function("BlurValues(Enquiry, 'Your Enquiry')");
}

}

function FocusValues(FormElement, Value)
{

if(FormElement.value == Value)
{
FormElement.value	= "";
}

}

function BlurValues(FormElement, Value)
{

if (FormElement.value == "")
{
FormElement.value	= Value;
}

}