function setDisplayInline(id){
	document.getElementById(id).style.display = "inline";
}
function setDisplayNone(id){
	document.getElementById(id).style.display = "none";
}

function userType() {
	var name = "";

	try {
		opt = document.getElementsByName("Description");
		name = opt[0].options[opt[0].selectedIndex].value;
		if(name == "Homeowner/DIYer") {
			// alert('setting active fields to consumer');
			setDisplayNone("trade");
			setDisplayInline("consumer");
		}
		else {
			// alert('setting active fields to trade');
			setDisplayNone("consumer");
			setDisplayInline("trade");
		}
		resetCheckboxes();
	}
	catch (err) {
		// alert("triggered catch");
	}
}

function resetCheckboxes() {
	for (i=0; i<document.myform.PleaseSend.length; i++){
		document.myform.PleaseSend[i].checked = false;
	}
}

/*****

This JS is used to toggle between a set of checkboxes for consumers and set
for trade.  If your form needs this you must have the <select> for user
type named Description.

Use this for the select element

<select name="Description" onChange="userType();">

and for the checkboxes

<div id="consumer" style="display:none;">
put your checkboxes for consumers here
</div>
<div id="trade" style="display:inline;">
put your checkboxes for trade users here
</div>

******/

var CookieName = "tempFocus";

var PageLoadTimeSeconds = 3;

// Replace alert(...) in function HandleNewFocus(), below, 
//    with your custom "'back' button was clicked" handling.
function HandleNewFocus() {
	userType();
	// alert('It seems the "back" button was clicked.');
}

// No customizations required in the rest of this JavaScript.

var now = new Date();
var Milliseconds = parseInt(now.getTime() / 1000);
var CurrentCookie = new String();
var FocusLaunched = false;
var BackHandled = false;

function HandleCookie()
{
if(BackHandled) { return; }
BackHandled = true;
var beforemillis = parseInt(CurrentCookie);
if(beforemillis > 1) {
   var aftermillis = Milliseconds - beforemillis;
   if(aftermillis > PageLoadTimeSeconds) { HandleNewFocus(); }
	}
else { SetCookie('loaded'); }
}

function LoadFunctions()
{
CurrentCookie = GetCookie();
if(CurrentCookie == 'loaded') { return; }
HandleCookie();
SetCookie('loaded');
}

function Loaded() { LoadFunctions(); }

function Unloaded() { 
var again = new Date();
Milliseconds = parseInt(again.getTime() / 1000);
SetCookie(String(Milliseconds));
}

function Focused() {
if(FocusLaunched) { return; }
FocusLaunched = true;
LoadFunctions();
}

function SetCookie(v) {
CurrentCookie = v;
document.cookie = CookieName + '=' + v;
}

function GetCookie() {
var c_content = '';
if(document.cookie.length > 0) {
   var c_name = CookieName + '=';
   var c_begin = document.cookie.indexOf(c_name);
   var c_end = 0;
   if(c_begin > -1) {
      c_begin += c_name.length;
      c_end = document.cookie.indexOf(";",c_begin);
      if(c_end < c_begin) { c_end = document.cookie.length; }
      c_content = document.cookie.substring(c_begin,c_end);
      }
   }
return c_content;
}

window.onload = Loaded;
window.onunload = Unloaded;
window.onfocus = Focused;

