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 ConvertToAscii(str)
{
var str		= str.toLowerCase();
var convert	= "";

for (var i=0; i<str.length; i++)
{
convert		+= str.charCodeAt(i);
}

return convert;
}

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 CheckContact()
{

var alertsay			= "";

if ((document.getElementById("ContactForm").Name) && (((IsEmpty(document.getElementById("ContactForm").Name.value)) || (document.getElementById("ContactForm").Name.value == "Name"))))
{
alertsay				+= "- Please enter your name\n";
}

if ((document.getElementById("ContactForm").EmailAddress) && (((IsEmpty(document.getElementById("ContactForm").EmailAddress.value)) || (document.getElementById("ContactForm").EmailAddress.value == "Email Address"))))
{
alertsay				+= "- Please enter a email address\n";
}

else if ((document.getElementById("ContactForm").EmailAddress) && (((!IsEmpty(document.getElementById("ContactForm").EmailAddress.value)) || (document.getElementById("ContactForm").EmailAddress.value != "Email Address"))))
{
alertsay				+= CheckEmail(document.getElementById("ContactForm").EmailAddress.value);
}

if (IsEmpty(document.getElementById("ContactForm").EnquiryArea.value))
{
alertsay				+= "- Please select your enquiry area\n";
}

if ((IsEmpty(document.getElementById("ContactForm").YourEnquiry.value)) || (document.getElementById("ContactForm").YourEnquiry.value == "YourEnquiry"))
{
alertsay				+= "- Please enter your enquiry\n";
}

if (alertsay)
{
ShowError(alertsay);
return false;
}

else
{
return true;
}

}

function FormControls()
{

// Name
if (document.getElementById("Name"))
{
Name				= document.getElementById("Name");
Name.onfocus		= new Function("FocusValues(Name, 'Name')");
Name.onblur			= new Function("BlurValues(Name, 'Name')");
}

// Email Address
if (document.getElementById("EmailAddress"))
{
EmailAddress			= document.getElementById("EmailAddress");
EmailAddress.onfocus	= new Function("FocusValues(EmailAddress, 'Email Address')");
EmailAddress.onblur		= new Function("BlurValues(EmailAddress, 'Email Address')");
}

// Enquiry
if (document.getElementById("YourEnquiry"))
{
YourEnquiry				= document.getElementById("YourEnquiry");
YourEnquiry.onfocus		= new Function("FocusValues(YourEnquiry, 'Your Enquiry')");
YourEnquiry.onblur		= new Function("BlurValues(YourEnquiry, 'Your Enquiry')");
}

}

function FocusValues(FormElement, Value)
{

if(FormElement.value == Value)
{
FormElement.value		= "";
}

}

function BlurValues(FormElement, Value)
{

if (FormElement.value == "")
{
FormElement.value		= Value;
}

}