
//Get query string to determine if someone submitted their information and are returning to the page.  We want to thank them!
var qsParm = new Array();

function qs() {
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}
} 

qsParm['return'] = null;
qs();

//Check the form
function checkform ( form ) {
	
	if (form.first_name.value == "") {
		alert ("Please enter your first name.");
		form.first_name.focus();
		return false ;
	}
	
	if (form.last_name.value == "") {
		alert ("Please enter your last name.");
		form.last_name.focus();
		return false ;
		}
	
	if (form.email.value == "") {
		alert ("Please enter your email address.");
		form.email.focus();
		return false ;
	}

	var tval = "";
	if (form.Save.checked ) tval += 'Yes how much savings; ';
	if (form.ROI.checked ) tval += 'Yes ROI; ';
	if (form.Grant_interest.checked ) tval += 'Yes Grant for my facility; ';
	if (form.Grant_what_fc_can_do.checked ) tval += 'Yes how FC can get grant; ';
	if (form.Bldg_Audit.checked ) tval += 'Bldg Audit; ';
	if (form.Bldg_Phone_Audit.checked ) tval += 'Bldg Phone Audit; ';
	if (form.Bldg_Person_Audit.checked ) tval += 'Bldg Person Audit; ';
	if (form.Bldg_Exact_Audit.checked ) tval += 'Bldg Exact Audit; ';
	if (form.DC_Audit.checked ) tval += 'DC Audit; ';
	if (form.DC_Phone_Audit.checked ) tval += 'DC Phone Audit; ';
	if (form.DC_Person_Audit.checked ) tval += 'DC Person Audit; ';
	if (form.DC_Exact_Audit.checked ) tval += 'DC Exact Audit; ';

	document.RebateForm.elements['00N40000001s0oL'].value = tval;
	return true ;
  
};


function ContactForm(FormTitle ) {
	
	if (FormTitle == "Rebates" ) {
		if (qsParm['return']) document.write('<h4>Thank you for providing your information!<br />  We will be in contact with you shortly.</h4>');
		return false;	
	}
	
	document.write('<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post"  onsubmit="return checkform(this);"> ');
	document.write('<input type="hidden" name="oid" value="00D40000000Ip8v" /> ');
	document.write('<input type="hidden" name="retURL" value="' + location.href + '?return=1" /> ');
	document.write('<input type="hidden" name="Source" value="' + FormTitle + ' " /> ');

	document.write('<!--  ----------------------------------------------------------------------  --> ');
	document.write('<!--  NOTE: These fields are optional debugging elements.  Please uncomment   --> ');
	document.write('<!--  these lines if you wish to test in debug mode.                          --> ');
	document.write('<!--   input type="hidden" name="debug" value=1                              --> ');
	document.write('<!--   input type="hidden" name="debugEmail" value="ckryzan@federspielcontrols.com"  --> ');
	document.write('<!--  ----------------------------------------------------------------------  --> ');
	
	if (qsParm['return']) document.write('<h4 class="barHeader">Thank you for providing your information!<br />  We will be in contact with you shortly.</h4>');
	else {
		document.write('<h2 class="barHeader">Interested in learning more?</h2> ');
		document.write('<p class="bold">Fill out your information!</p> ');
	}
	
	document.write('<div class="formFields">');
	document.write('<label for="first_name">First Name* </label><br /><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /> ');
	document.write('<br /><label for="last_name">Last Name* </label><br /><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /> ');
	document.write('<br /><label for="email">Email* &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp;</label><br /><input  id="email" maxlength="80" name="email" size="20" type="text" /> ');
	document.write('<br /><label for="company">Company &nbsp; </label><br /><input  id="company" maxlength="40" name="company" size="20" type="text" /> ');
	document.write('<br /><label for="phone">Phone &nbsp; &nbsp; &nbsp; &nbsp; </label><br /><input  id="phone" maxlength="40" name="phone" size="20" type="text" /> ');
	document.write('<p class="italic">*Required</p>');
	document.write('<input id="00N40000001IMeh" maxlength="255" name="00N40000001IMeh" size="20" type="hidden" value="' + location.href + '" />');
	document.write('<input id="lead_source" maxlength="255" name="lead_source" size="20" type="hidden" value="Web" />');
	document.write('<div class="submitBtn"><input name="submit" type="submit" value="Send Info" /></div> ');
	document.write('</div>');
	document.write('</form> ');
	
};