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 ShowError(Errors)
{
alert("The following error(s) occurred:\n" + Errors.substring(Errors,Errors.length-1) + "\n\nSorry can not Process the form");
}

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

return str;
}

function IsEmpty(TmpString)
{

if (!TmpString)
{
return true;	
}

TmpString			= TrimString(TmpString);

if (TmpString.length <= 0)
{
return true;
}

return false;
}

function CheckCompulsary(FormName)
{
	
var alertsay 		= ""; 

// Compulsary Values

if (IsEmpty(document.getElementById(FormName).Name.value))
{
alertsay			+= "- You must enter your Name\n";
}

if (IsEmpty(document.getElementById(FormName).Company.value))
{
alertsay			+= "- You must enter your Company\n";
}

if (!IsEmpty(document.getElementById(FormName).EmailAddress.value))
{
alertsay			+= CheckEmail(document.getElementById(FormName).EmailAddress.value);
}

if ((document.getElementById(FormName).TelephoneNumber) && (IsEmpty(document.getElementById(FormName).TelephoneNumber.value)))
{
alertsay			+= "- You must a enter a Telephone number\n";
}

return alertsay;
}

function CheckQuote()
{
var alertsay 		= CheckCompulsary("QuoteForm");

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

}