function CheckFields(thisForm)
{
	empty = "";
	msg = "";
	firstField = "";
	
	if (thisForm.custentity1.value == "none") {
		empty += "Download choice\n";
		msg += "You must select a download choice\n";
	}
	
	if (document.getElementById('can_contact') != null) {
		if (!thisForm.can_contact.checked) {
			msg += "\nYou must agree to the contact terms before recieving a free trial.\n";
			thisForm.can_contact.style.backgoundColor="YELLOW";
		} else {
			thisForm.can_contact.style.backgroundColor="#ffffff";
		}
	}
	
	// First Name
	if (document.getElementById('firstname') != null) { 
		if (thisForm.firstname.value == "")	{
			empty += "First Name\n";
			thisForm.firstname.style.backgroundColor="YELLOW";
			firstField = thisForm.firstname;
		} else {
			thisForm.firstname.style.backgroundColor="#ffffff";
		}
	}

	// Last Name
	if (document.getElementById('lastname') != null) {
		if (thisForm.lastname.value == "") {
			empty += "Last Name\n";
			thisForm.lastname.style.backgroundColor="YELLOW";
			if (firstField == "") {firstField = thisForm.lastname;}
		} else {thisForm.lastname.style.backgroundColor="#ffffff";}
	}
	
	// Job title
	if (document.getElementById('title') != null) {
		if (thisForm.title.value == "")	{
			empty += "Job Title\n";
			thisForm.title.style.backgroundColor="YELLOW";
			if (firstField == "") {firstField = thisForm.title;}
		} else {thisForm.title.style.backgroundColor="#ffffff";}
	}

	// Company
	if (document.getElementById('companyname') != null) {
		if (thisForm.companyname.value == "") {
			empty += "Company\n";
			thisForm.companyname.style.backgroundColor="YELLOW";
			if (firstField == "") {firstField = thisForm.companyname;}
		} else {thisForm.companyname.style.backgroundColor="#ffffff";}
	}
	
	// Address Line 1
	if (document.getElementById('address1') != null) {
		if (thisForm.address1.value == "")	{
			empty += "Address 1\n";
			thisForm.address1.style.backgroundColor="YELLOW";
			if (firstField == "") {firstField = thisForm.address1;}
		} else {thisForm.address1.style.backgroundColor="#ffffff";}
	}

	
	
	
	// Country
	if(thisForm.country.selectedIndex == 0)
	{
	  	empty += "Country\n";
		thisForm.country.style.backgroundColor="YELLOW";
    	if (firstField == "") {firstField = thisForm.country;}
	} else {thisForm.country.style.backgroundColor="#ffffff";}

	// State
	if ((thisForm.country.selectedIndex == 1 || thisForm.country.selectedIndex == 39) && thisForm.state.selectedIndex == 0)
	{
		empty += "State/Province\n";
		thisForm.state.style.backgroundColor="YELLOW";
		if (firstField == "") {firstField = thisForm.state;}
	} else {thisForm.state.style.backgroundColor="#ffffff";}

	// City
	if (document.getElementById('city') != null) {
		if (thisForm.city.value == "")	{
			empty += "City\n";
			thisForm.city.style.backgroundColor="YELLOW";
			if (firstField == "") {firstField = thisForm.city;}
		} else {thisForm.city.style.backgroundColor="#ffffff";}
	}

	// Zip Code
	if (document.getElementById('zipcode') != null) {
		if (thisForm.zipcode.value == "") {
			empty += "Zip/Postal Code\n";
			thisForm.zipcode.style.backgroundColor="YELLOW";
			if (firstField == "") {firstField = thisForm.zipcode;}
		} else {thisForm.zipcode.style.backgroundColor="#ffffff";}
	}

	// Telephone
	if (document.getElementById('phone') != null) {
		if (thisForm.phone.value == "")	{
			empty += "Telephone\n";
			thisForm.phone.style.backgroundColor="YELLOW";
			if (firstField == "") {firstField = thisForm.phone;}
		} else {thisForm.phone.style.backgroundColor="#ffffff";}
	}

	// Test email address for valid format
	emailaddress = thisForm.email.value;
	var validemail = true;
	var filter=/^([\w-\.]*)@([\w-\.]*)$/i; // ULTRA-SIMPLE E-MAIL CHECK: Checks valid characters and existence of white space
	if (filter.test(emailaddress))
	{validemail = true;}
	else {validemail = false;}
	if (validemail == false)
	{
		empty += "E-mail Address\n";
		msg += "Please check the email address, it doesn't seem to be formatted correctly.\n" +
		"Email Address Example: yourname@yourdomain.com";
		thisForm.email.style.backgroundColor="YELLOW";
		if (firstField == "") {firstField = thisForm.email;}
	} else {thisForm.email.style.backgroundColor="#ffffff";}

	if (thisForm.emailconfirm.value == "") {
		empty+= "E-mail (Confirm)\n";
		thisForm.emailconfirm.style.backgroundColor="YELLOW";
		if (firstField == "") { firstField = thisForm.emailconfirm; }
	} else { thisForm.emailconfirm.style.backgroundColor="#ffffff"; }

	// check that the two email addresses match.	
	if (thisForm.email.value != thisForm.emailconfirm.value) {
		empty += "\nE-mail confirmation doesn\'t match\n";
		thisForm.emailconfirm.style.backgroundColor = "Yellow";
		thisForm.email.style.backgroundColor = "Yellow";
	}

	// Number of Seats
		if (document.getElementById('custentity34') != null) {
			if (thisForm.custentity34.value == "" || thisForm.custentity34.value == 1)	{
				empty += "How many people in your organization?\n";
				msg += " \n" + "For organizations with less than 10 computers, we recommend Spy Sweeper for Home and Small Business.\n";

				thisForm.custentity34.style.backgroundColor="YELLOW";

				if (firstField == "") {firstField = thisForm.custentity34;}

			}else {thisForm.custentity34.style.backgroundColor="#f3f3f3";}	
		}


	// What Product?
			if(thisForm.custentitycust_saasdemorequesttype.selectedIndex == 0)
			{
			  	empty += "What product?\n";
				thisForm.custentitycust_saasdemorequesttype.style.backgroundColor="YELLOW";
		    	if (firstField == "") {firstField = thisForm.custentitycust_saasdemorequesttype;}
			} else {thisForm.custentitycust_saasdemorequesttype.style.backgroundColor="#ffffff";}
	


	// What is your purchase timeframe?
	if (document.getElementById('custentity33') != null) { 
		if (thisForm.custentity33.value == "")	{
			empty += "What is your purchase timeframe?\n";
			thisForm.custentity33.style.backgroundColor="YELLOW";
			if (firstField == "") {firstField = thisForm.custentity33;}
		}else {thisForm.custentity33.style.backgroundColor="#f3f3f3";}	
	}

	// How did you hear about?
	if (document.getElementById('custentity28') != null) {
		if (thisForm.custentity28.value == "")	{
			empty += "How did you hear about us?\n";
			thisForm.custentity28.style.backgroundColor="Yellow";
			if (firstField == "") { firstField = thisForm.custentity28; }
		} else { thisForm.custentity28.style.backgroundColor="#f3f3f3"; }
	}
	
	// Check that custentity36 (Sales) is numeric, if it exists in the form
	if (document.getElementById('custentity36') != null) {
		if(IsNumeric(thisForm.custentity36.value) != true) {
			msg += "\nSales must be a number";
			thisForm.custentity36.style.backgroundColor="YELLOW";
			if (firstField == "") { firstField = thisForm.custentity36; }
		} else { thisForm.custentity36.style.backgroundColor="#f3f3f3"; }
	}
	
		// Check that custentity35 (number of employees - text field)  is numeric, if it exists in the form
	if (document.getElementById('custentity35') != null) {
		if(IsNumeric(thisForm.custentity35.value) != true) {
			msg += "\nNumber of employees must be a number";
			thisForm.custentity35.style.backgroundColor="YELLOW";
			if (firstField == "") { firstField = thisForm.custentity35; }
		} else { thisForm.custentity35.style.backgroundColor="#f3f3f3"; }
	}
	
	// Check that custentity46, if it exists, is selected
	if (document.getElementById('custentity46') != null) {
		if (thisForm.custentity46.value == "") {
			empty += "What anti-spyware software do you have?\n";
			thisForm.custentity46.style.backgroundColor="Yellow";
			if (firstField == "") { firstField = thisForm.custentity46; }
		} else { thisForm.custentity46.style.backgroundColor = "#f3f3f3"; }
	}
	
	// Validate Form
	if ((empty == "") && (msg == ""))
	{
		return (true);
	}

	var disp = "";
	if (empty != "")
	{	
		disp = "The following are required fields. Please supply the appropriate values:\n\n" + empty;
	
	}

	disp += "\n" + msg;
	alert(disp);
	//firstField.focus();
	return (false);
}

function mincomp() 
{
	if (document.getElementById("main_form").custentity34.value ==  "") {
		var disp = "";
		disp = "Spy Sweeper Enterprise is designed for corporate environments with 10 or more computers.\n\n For companies or individuals with less than 10 computers please visit http://www.webroot.com/products/spysweeper/ \n\n";
		document.getElementById("main_form").custentity34.value = "";
		alert(disp);
		return (false);
	}
}

function trialOptions() {
	if(document.getElementById("main_form").custentity1.selectedIndex == 1) {
		document.getElementById("expiration").innerHTML = '<p class="h1"><span class="isRed">Trial download links are sent via e-mail.<span> Please ensure you enter a valid e-mail address below.</p><p class="h1">Contact Terms:</p><p><input type="checkbox" name="can_contact" value="yes" id="can_contact"> I understand that by requesting this Spy Sweeper Enterprise 30-Day Trial Evaluation software, I authorize Webroot Software Inc. to contact me regarding support issues as well as possible Enterprise sales opportunities.</p><p><a href="/company/privacy.html" target="_blank">Privacy Policy</a></p>';
	/* } else if(document.getElementById("main_form").custentity1.selectedIndex == 2) {
		document.getElementById("expiration").innerHTML = '<p>When does your trial expire? <span class="smallText">(Format: mm/dd/yyyy)</span></p><p><input type="text" class="formText_200" name="custentity3" value="mm/dd/yyyy"></p>'; */
	} else if(document.getElementById("main_form").custentity1.selectedIndex == 2) {
		document.getElementById("expiration").innerHTML = '';
	}
}

function countryOptions() {
	if(document.getElementById("main_form").country.value == "US" || document.getElementById("main_form").country.value == "CA") {
		document.getElementById("main_form").state.disabled = false;
		
		// set the seatRange for US
		/*if (document.getElementById('custentity34') != null) {
		
			document.forms['main_form'].custentity34.options[7] = new Option('1000-4999','7');
			document.forms['main_form'].custentity34.options[8] = new Option('5000-9999','8');
			document.forms['main_form'].custentity34.options[9] = new Option('10,000+','9');
			document.forms['main_form'].custentity34.options[10] = null;
		}*/
	} else {
		document.getElementById("main_form").state.disabled = true;
		
		// set the seatRange for int'l
		/*if (document.getElementById('custentity34') != null) {
			
			document.forms['main_form'].custentity34.options[7] = new Option('1000-2499','10');
			document.forms['main_form'].custentity34.options[8] = new Option('2500-4999','11');
			document.forms['main_form'].custentity34.options[9] = new Option('5000-9999','8');
			document.forms['main_form'].custentity34.options[10] = new Option('10,000+','9');
		}*/
	}
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.,$";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function CheckFieldsCountryEmail(thisForm)
{
	empty = "";
	msg = "";
	firstField = "";
	
	
		// Test email address for valid format
	emailaddress = thisForm.email.value;
	var validemail = true;
	var filter=/^([\w-\.]*)@([\w-\.]*)$/i; // ULTRA-SIMPLE E-MAIL CHECK: Checks valid characters and existence of white space
	if (filter.test(emailaddress))
	{validemail = true;}
	else {validemail = false;}
	if (validemail == false)
	{
		empty += "E-mail Address\n";
		msg += "Please check the email address, it doesn't seem to be formatted correctly.\n" +
		"Email Address Example: yourname@yourdomain.com";
		thisForm.email.style.backgroundColor="YELLOW";
		if (firstField == "") {firstField = thisForm.email;}
	} else {thisForm.email.style.backgroundColor="#ffffff";}

	if (thisForm.emailconfirm.value == "") {
		empty+= "Email confirm\n";
		thisForm.emailconfirm.style.backgroundColor="YELLOW";
		if (firstField == "") { firstField = thisForm.emailconfirm; }
	} else { thisForm.emailconfirm.style.backgroundColor="#ffffff"; }

	// check that the two email addresses match.	
	if (thisForm.email.value != thisForm.emailconfirm.value) {
		empty += "\nE-mail confirmation doesn\'t match\n";
		thisForm.emailconfirm.style.backgroundColor = "Yellow";
		thisForm.email.style.backgroundColor = "Yellow";
	}
	
	// Validate Form
	if ((empty == "") && (msg == ""))
	{
		return (true);
	}

	var disp = "";
	if (empty != "")
	{	
		disp = "The following are required fields. Please supply the appropriate values:\n\n" + empty;
		
	}

	disp += "\n" + msg;
	alert(disp);
	//firstField.focus();
	return (false);
}
