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 CheckFormDefaults(FormName)
{
var alertsay	= "";

if ((document.getElementById(FormName).FirstName) && (((IsEmpty(document.getElementById(FormName).FirstName.value)) || (document.getElementById(FormName).FirstName.value == "First Name"))))
{
alertsay		+= "- Please enter your first name\n";
}

if ((document.getElementById(FormName).LastName) && (((IsEmpty(document.getElementById(FormName).LastName.value)) || (document.getElementById(FormName).LastName.value == "Last Name"))))
{
alertsay		+= "- Please enter your last name\n";
}

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

else if ((document.getElementById(FormName).EmailAddress) && (((!IsEmpty(document.getElementById(FormName).EmailAddress.value)) || (document.getElementById(FormName).EmailAddress.value != "Email Address"))))
{
alertsay		+= CheckEmail(document.getElementById(FormName).EmailAddress.value);
}

if ((document.getElementById(FormName).SecurityImage) && (IsEmpty(document.getElementById(FormName).SecurityImage.value)))
{
alertsay		+= "- Please enter the security code\n";
}

else if ((document.getElementById(FormName).SecurityImage) && (!IsEmpty(document.getElementById(FormName).SecurityImage.value)))
{
TmpSecurityCode	= ConvertToAscii(document.getElementById(FormName).SecurityImage.value);

if (TmpSecurityCode != document.getElementById(FormName).SockVar.value)
{
alertsay		+= "- The security code does not match\n";
}

}

return alertsay;
}

function CheckContact()
{

var alertsay	= CheckFormDefaults("ContactForm");

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

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

else
{
return true;
}

}

function CheckAdvertising()
{

var alertsay	= CheckFormDefaults("AdvertisingForm");

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

else
{
return true;
}

}

function FormControls()
{

// First Name
if (document.getElementById("FirstName"))
{
FirstName				= document.getElementById("FirstName");
FirstName.onfocus		= new Function("FocusValues(FirstName, 'First Name')");
FirstName.onblur		= new Function("BlurValues(FirstName, 'First Name')");
}

// Last Name
if (document.getElementById("LastName"))
{
LastName				= document.getElementById("LastName");
LastName.onfocus		= new Function("FocusValues(LastName, 'Last Name')");
LastName.onblur			= new Function("BlurValues(LastName, 'Last 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')");
}

// Comments
if (document.getElementById("Comments"))
{
Comments				= document.getElementById("Comments");
Comments.onfocus		= new Function("FocusValues(Comments, 'Comments')");
Comments.onblur			= new Function("BlurValues(Comments, 'Comments')");
}

// Enquiry
if (document.getElementById("Enquiry"))
{
Enquiry					= document.getElementById("Enquiry");
Enquiry.onfocus			= new Function("FocusValues(Enquiry, 'Your Enquiry')");
Enquiry.onblur			= new Function("BlurValues(Enquiry, 'Your Enquiry')");
}

// Email Address
if (document.getElementById("SecurityImage"))
{
SecurityImage			= document.getElementById("SecurityImage");
SecurityImage.value		= "";
}

// Your Name
if (document.getElementById("YourName"))
{
YourName				= document.getElementById("YourName");
YourName.onfocus		= new Function("FocusValues(YourName, 'Your Name')");
YourName.onblur			= new Function("BlurValues(YourName, 'Your Name')");
}

// Your Email Address
if (document.getElementById("YourEmailAddress"))
{
YourEmailAddress		= document.getElementById("YourEmailAddress");
YourEmailAddress.onfocus= new Function("FocusValues(YourEmailAddress, 'Your Email Address')");
YourEmailAddress.onblur	= new Function("BlurValues(YourEmailAddress, 'Your Email Address')");
}

// Friend Name
if (document.getElementById("FriendName"))
{
FriendName				= document.getElementById("FriendName");
FriendName.onfocus		= new Function("FocusValues(FriendName, 'Friends Name')");
FriendName.onblur		= new Function("BlurValues(FriendName, 'Friends Name')");
}

// Your Email Address
if (document.getElementById("FriendEmailAddress"))
{
FriendEmailAddress		= document.getElementById("FriendEmailAddress");
FriendEmailAddress.onfocus= new Function("FocusValues(FriendEmailAddress, 'Friends Email Address')");
FriendEmailAddress.onblur= new Function("BlurValues(FriendEmailAddress, 'Friends Email Address')");
}

// Message
if (document.getElementById("Message"))
{
Message					= document.getElementById("Message");
Message.onfocus			= new Function("FocusValues(Message, 'Your Message')");
Message.onblur			= new Function("BlurValues(Message, 'Your Message')");
}

}

function FocusValues(FormElement, Value)
{

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

}

function BlurValues(FormElement, Value)
{

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

}