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			= "";

if ((document.getElementById("AdvertisingForm").CompanyName) && (((IsEmpty(document.getElementById("AdvertisingForm").CompanyName.value)) || (document.getElementById("AdvertisingForm").CompanyName.value == "Company Name"))))
{
alertsay				+= "- Please enter your company name\n";
}

if ((document.getElementById("AdvertisingForm").ContactName) && (((IsEmpty(document.getElementById("AdvertisingForm").ContactName.value)) || (document.getElementById("AdvertisingForm").ContactName.value == "Contact Name"))))
{
alertsay				+= "- Please enter a contact name\n";
}

if ((document.getElementById("AdvertisingForm").ContactEmail) && (((IsEmpty(document.getElementById("AdvertisingForm").ContactEmail.value)) || (document.getElementById("AdvertisingForm").ContactEmail.value == "Contact Email"))))
{
alertsay				+= "- Please enter a contact email address\n";
}

else if ((document.getElementById("AdvertisingForm").ContactEmail) && (((!IsEmpty(document.getElementById("AdvertisingForm").ContactEmail.value)) || (document.getElementById("AdvertisingForm").ContactEmail.value != "Contact Email"))))
{
alertsay				+= CheckEmail(document.getElementById("AdvertisingForm").ContactEmail.value);
}

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

else
{
return true;
}

}

function CommentLimit()
{
Comment					= document.getElementById("AddViralComment").Comment;
Comments				= Comment.value;
CommentLength			= Comments.length;
CharRemaining			= document.getElementById("CharRemain")

if (CommentLength >= 250)
{
Comment.value			= Comments.substr(0, 250);
CommentLength			= 250;
}

CharRemaining.innerHTML	= 250 - CommentLength;
}

function FormControls()
{

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

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

// Viral Comments
if (document.getElementById("AddViralComment"))
{
Comment					= document.getElementById("AddViralComment").Comment;
Comment.onkeyup			= new Function("CommentLimit()");
}

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

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

// 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')");
}

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

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

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

// Confirm Password
if ((!document.getElementById("EditUser")) && (document.getElementById("ConfirmPassword")))
{
ConfirmPassword			= document.getElementById("ConfirmPassword");
ConfirmPassword.onfocus	= new Function("FocusValues(ConfirmPassword, 'Confirm Password')");
ConfirmPassword.onblur	= new Function("BlurValues(ConfirmPassword, 'Confirm Password')");
}

// 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')");
}

// Message
if (document.getElementById("SignUp"))
{
DoSignUp				= document.getElementById("SignUp");
DoSignUp.onclick		= new Function("ShowSignUp()");
ShowSignUp();
}

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

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

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

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

}

function FocusValues(FormElement, Value)
{

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

}

function BlurValues(FormElement, Value)
{

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

}