function dealerform_onClick()
{
  if (validate_dealerform()==true)
  {
    document.dealerform.method="post";
    document.dealerform.action="home-site-analysis.cfm";
    document.dealerform.submit();	
  }
}

function validate_dealerform()
{
	document.dealerform.fullname.value = GS_nolrspaces(document.dealerform.fullname.value);
	document.dealerform.email.value = GS_nolrspaces(document.dealerform.email.value);
	document.dealerform.phone.value = GS_nolrspaces(document.dealerform.phone.value);
	document.dealerform.county.value = GS_nolrspaces(document.dealerform.county.value);
	document.dealerform.SqFoot.value = GS_nolrspaces(document.dealerform.SqFoot.value);
	document.dealerform.stories.value = GS_nolrspaces(document.dealerform.stories.value);
	document.dealerform.thermostats.value = GS_nolrspaces(document.dealerform.thermostats.value);
	document.dealerform.entertainment_centers.value = GS_nolrspaces(document.dealerform.entertainment_centers.value);
	document.dealerform.computer.value = GS_nolrspaces(document.dealerform.computer.value);
	document.dealerform.bedrooms.value = GS_nolrspaces(document.dealerform.bedrooms.value);
	document.dealerform.bathrooms.value = GS_nolrspaces(document.dealerform.bathrooms.value);	
	document.dealerform.lightslefton.value = GS_nolrspaces(document.dealerform.lightslefton.value);
	document.dealerform.utility.value = GS_nolrspaces(document.dealerform.utility.value);
	document.dealerform.heardAboutGS_other.value = GS_nolrspaces(document.dealerform.heardAboutGS_other.value);
	document.dealerform.GS_representative.value = GS_nolrspaces(document.dealerform.GS_representative.value);	 
	document.dealerform.ValidationString.value = GS_nolrspaces(document.dealerform.ValidationString.value);
	
	var heardAboutGS_value = document.dealerform.heardAboutGS[document.dealerform.heardAboutGS.selectedIndex].value;
	
    document.getElementById('fullnameREQUIRED').style.display = "none";
    document.getElementById('emailREQUIRED').style.display = "none";
    document.getElementById('phoneREQUIRED').style.display = "none";
    document.getElementById('citystateREQUIRED').style.display = "none";
    document.getElementById('countyREQUIRED').style.display = "none";
    document.getElementById('heardAboutGSREQUIRED').style.display = "none";
    document.getElementById('GS_representativeREQUIRED').style.display = "none";
    document.getElementById('heardAboutGS_otherREQUIRED').style.display = "none";
    document.getElementById('SqFootREQUIRED').style.display = "none";
	document.getElementById('storiesREQUIRED').style.display = "none";
	document.getElementById('thermostatsREQUIRED').style.display = "none";
	document.getElementById('entertainment_centersREQUIRED').style.display = "none";
	document.getElementById('computerREQUIRED').style.display = "none";
	document.getElementById('bedroomsREQUIRED').style.display = "none";
	document.getElementById('bathroomsREQUIRED').style.display = "none";
	document.getElementById('lightsleftonREQUIRED').style.display = "none";	
	document.getElementById('utilityREQUIRED').style.display = "none";
	
  if (document.dealerform.fullname.value == "")
  {
    document.getElementById('fullnameREQUIRED').style.display = "";
	alert("Please provide your name.");
    return false;
  }
  if (document.dealerform.email.value == "")
  {
    document.getElementById('emailREQUIRED').style.display = "";
    alert("Please provide your email address.");
    return false;
  }
  if (document.dealerform.phone.value == "")
  {
    document.getElementById('phoneREQUIRED').style.display = "";
    alert("Please provide your phone number.");
    return false;
  }
  
  if (document.dealerform.city.value == "")
  {
    document.getElementById('citystateREQUIRED').style.display = "";
    alert("Please provide your city.");
    return false;
  }
  if (document.dealerform.state.value == "")
  {
    document.getElementById('citystateREQUIRED').style.display = "";
    alert("Please provide your state.");
    return false;
  }
  if (document.dealerform.county.value == "")
  {
    document.getElementById('countyREQUIRED').style.display = "";
    alert("Please provide your county.");
    return false;
  }
  
  if (heardAboutGS_value == "")
  {
    document.getElementById('heardAboutGSREQUIRED').style.display = "";
	alert("How did you hear about us?");
    return false;
  }
  if ((heardAboutGS_value == "GreenSwitch Representative") && (document.dealerform.GS_representative.value == ""))
  {
    document.getElementById('GS_representativeREQUIRED').style.display = "";
	alert("Which GreenSwitch Representative referred you?\nIf you do not know their name then enter 'unknown'.");
    return false;
  }
  if ((heardAboutGS_value == "Other") && (document.dealerform.heardAboutGS_other.value == ""))
  {
    document.getElementById('heardAboutGS_otherREQUIRED').style.display = "";
	alert("Please take a moment to fill out the 'Other' box and let us know where you heard about GreenSwitch.");
    return false;
  }
  
  if (document.dealerform.SqFoot.value == "")
  {
    document.getElementById('SqFootREQUIRED').style.display = "";
    alert("Please provide the square footage of your house.");
    return false;
  }  
  if (document.dealerform.stories.value == "")
  {
    document.getElementById('storiesREQUIRED').style.display = "";
    alert("Please provide the number of stories of your house.");
    return false;
  } 
  if (document.dealerform.thermostats.value == "")
  {
    document.getElementById('thermostatsREQUIRED').style.display = "";
    alert("Please provide the number of thermostats of your house.");
    return false;
  } 
  if (document.dealerform.entertainment_centers.value == "")
  {
    document.getElementById('entertainment_centersREQUIRED').style.display = "";
    alert("Please provide the number of entertainment centers in your house.");
    return false;
  } 
  if (document.dealerform.computer.value == "")
  {
    document.getElementById('computerREQUIRED').style.display = "";
    alert("Please provide the number of computer stations in your house.");
    return false;
  } 
  if (document.dealerform.bedrooms.value == "")
  {
    document.getElementById('bedroomsREQUIRED').style.display = "";
    alert("Please provide the number of bedrooms.");
    return false;
  } 
  if (document.dealerform.bathrooms.value == "")
  {
    document.getElementById('bathroomsREQUIRED').style.display = "";
    alert("Please provide the number of bathrooms.");
    return false;
  }   
  if (document.dealerform.lightslefton.value == "")
  {
    document.getElementById('lightsleftonREQUIRED').style.display = "";
    alert("Please provide the number of lights frequently left on by accident.");
    return false;
  }   
  if (document.dealerform.utility.value == "")
  {
    document.getElementById('utilityREQUIRED').style.display = "";
    alert("Please provide your monthly utility bill.");
    return false;
  } 
  if (document.dealerform.ValidationString.value == "")
  {
    alert("Please type the verification code to continue.");
    return false;
  }
  
  return true;
}

// strip off leading and trailing spaces from string ///////////////////
function GS_nolrspaces(strinx)
{
	while (strinx.charCodeAt(0)==32)
		{ strinx = strinx.substring(1, strinx.length); 
		}
	while (strinx.charCodeAt(strinx.length-1)==32)
		{ strinx = strinx.substring(0, strinx.length - 1); 
		}
	return strinx;
}
