function pickTargetEmail(emailKey,photoID,emailName)
{
  if (emailName==undefined) {var emailName = "";} 
  if (emailName != "") { emailName = " to " + emailName; }
  hideClass('photo-toemail');
  document.getElementById('label-to-email').style.display = "block";
  document.getElementById(photoID).style.display = 'block';
  document.contactform.emailKey.value = emailKey;
  alert("Complete the form at right to send your message" + emailName + " now.");
}

function contactform_onClick()
{
  if (validate_contactform()==true)
  {
    document.contactform.method="post";
    document.contactform.action="contact-greenswitch.cfm";
    document.contactform.submit();	
  }
} 
 
function validate_contactform()
{
	document.contactform.fullname.value = GS_nolrspaces(document.contactform.fullname.value);
	document.contactform.email.value = GS_nolrspaces(document.contactform.email.value);
	document.contactform.phone.value = GS_nolrspaces(document.contactform.phone.value);
	document.contactform.companyname.value = GS_nolrspaces(document.contactform.companyname.value);
	document.contactform.city.value = GS_nolrspaces(document.contactform.city.value);
	document.contactform.state.value = GS_nolrspaces(document.contactform.state.value);
	document.contactform.county.value = GS_nolrspaces(document.contactform.county.value);
	document.contactform.ValidationString.value = GS_nolrspaces(document.contactform.ValidationString.value);
	document.contactform.heardAboutGS_other.value = GS_nolrspaces(document.contactform.heardAboutGS_other.value);
	document.contactform.GS_representative.value = GS_nolrspaces(document.contactform.GS_representative.value);
			
	var heardAboutGS_value = document.contactform.heardAboutGS[document.contactform.heardAboutGS.selectedIndex].value;
	
		
    document.getElementById('fullnameREQUIRED').style.display = "none";
    document.getElementById('emailREQUIRED').style.display = "none";
    document.getElementById('phoneREQUIRED').style.display = "none";
    document.getElementById('companynameREQUIRED').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";
  	hideClass('formRequiredValue');
	
  if (document.contactform.fullname.value == "")
  {
    document.getElementById('fullnameREQUIRED').style.display = "";
	alert("Please provide your name.");
    return false;
  }
  if (document.contactform.email.value == "")
  {
    document.getElementById('emailREQUIRED').style.display = "";
    alert("Please provide your email address.");
    return false;
  }
  if (document.contactform.phone.value == "")
  {
    document.getElementById('phoneREQUIRED').style.display = "";
    alert("Please provide your phone number.");
    return false;
  }
  /* if (document.contactform.companyname.value == "")
  {
    document.getElementById('companynameREQUIRED').style.display = "";
    alert("Please provide the name of your company.");
    return false;
  }  */
  
  if (document.contactform.city.value == "")
  {
    document.getElementById('citystateREQUIRED').style.display = "";
    alert("Please provide your city.");
    return false;
  }
  if (document.contactform.state.value == "")
  {
    document.getElementById('citystateREQUIRED').style.display = "";
    alert("Please provide your state.");
    return false;
  }
  if (document.contactform.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.contactform.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.contactform.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.contactform.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;
}
