//INITIALIZE GLOBAL VARIABLES
var bSubmitted = false;
var whitespace = " \t\n\r";
			
function validateForm(formname)
{
	var theMainForm;
	var sErrMsg;
							
	theMainForm = formname;
	sErrMsg	= "";
	if(isWhitespace(theMainForm.name.value))
		sErrMsg += "Please Enter Name \n";
	if(isWhitespace(theMainForm.company.value))
		sErrMsg += "Please Enter Company \n";
	theOption = theMainForm.state.options;
	if(isWhitespace(theOption[theOption.selectedIndex].value))
		sErrMsg += "Please Enter State \n";
	if(isWhitespace(theMainForm.title.value))
		sErrMsg += "Please Enter Title \n";
	if(isWhitespace(theMainForm.emailaddress.value))
		sErrMsg += "Please Enter Email Address\n";
	theOption = theMainForm.numberofemployees.options;
	if(isWhitespace(theOption[theOption.selectedIndex].value))
		sErrMsg += "Please Enter Number of Employees \n";
			
	//VALIDATE CHECKBOXES
	var isOneAtLeastChecked = false;
	for(var i = 1; i <= 8; i++)
	{
		var val = eval("theMainForm.dooption" + i + ".checked");
		if(val)
		{
			isOneAtLeastChecked = true;
		}
	}
	if(!isOneAtLeastChecked)
	{
		sErrMsg += "Please Inidicate What You Do \n";	
	}
			
	//SUBMIT FORM OR ALERT MESSAGE
	if (sErrMsg != "")
		alert(sErrMsg);
	else 
	{
		//Submit the form
		if (!bSubmitted)
		{
			bSubmitted = true;
			theMainForm.action = "thankyou.php4";
			theMainForm.submit();
		}
	} 	
}
			
function isWhitespace (s)
{
	var i;

	if (isEmpty(s)) 
		return true;

	for (i = 0; i < s.length; i++)
	{
		//CHECK THAT CURRENT CHAR IS NOT WHITESPACE
		var c = s.charAt(i);

		if (whitespace.indexOf(c) == -1) 
			return false;
	}

    //ALL CHARS ARE WHITE SPACE
	return true;
}
			
function isEmpty(s)
{ 
	return ((s == null) || (s.length == 0)) 
}
