//Show/Hide script for displaying the calculate button's on/off state	
function showHide() {		
	var section = document.SBS.reps;
	var section2 = document.SBS.topics;	
	//check to see if any representatives are selected, if any are then check to make sure that
	//at least one topic is also selected.  If both are true, show the button.
	//alert(section.length + 'Section Length');
	for ( index=0; index < section.length ; index++) {
		var ColClass = 'Col' + section[index].className;
		if ( section[index].checked == true ) {
			//alert('You have selected ' + ColClass + '.');
			//if a rep is checked, show its column in the results
			showClass(ColClass);
			for ( index2=0; index2 < section2.length ; index2++) {
				if(navigator.appName.indexOf("Microsoft") > -1)
					{ var canSee = 'block' } 
				else
					{ var canSee = 'table-row'; }							
				if ( section2[index2].checked == true ) {
					
					//if a topic is selected, show its row
					var theValue = 'Results_' + section2[index2].id;
					//alert(theValue + 'will be displayed');
					document.getElementById(theValue).style.display = canSee;
				}
				else
				{
					//if a topic isn't selected, make sure it's row is hidden
					var theValue = 'Results_' + section2[index2].id;
					//alert(theValue + 'will be hidden');
					document.getElementById(theValue).style.display = 'none';
				}			
			}	
		}
		else
		{
			//if a rep is not checked, hide their column
			hideClass(ColClass);
		}		
	}
	//if any topic AND any rep is selected, show the submit button.  Otherwise, keep it hidden.
	document.getElementById('buttons').style.display = 'none';
	for (index3=0; index3 < section.length; index3++) {
		if (section[index3].checked == true) {
			for (index4=0; index4 < section2.length; index4++) {
				if (section2[index4].checked == true) {
					document.getElementById('buttons').style.display = 'block';
					break;
				}
			}							
		}
	}
	//If no reps are selected, hide all rows of the results table.
	var bhideTheRows = true;
	for(var i=0;i<section.length;i++)
	{
			if (section[i].checked)
			{
				bhideTheRows = false;
				break;
			}
	}
	
	if (bhideTheRows)
	{
		hideAllRows();
	}
} // End ShowHide

function checkAll(field) {
	for (index=0; index < field.length; index++)
		field[index].checked = true;
		showHide();
} // end checkAll

function uncheckAll(field)
{
	for (index = 0; index < field.length; index++)
		field[index].checked = false;
		showHide();
} // end uncheckAll

//hide all topics in the results table
function hideAllRows()
{
	var section2 = document.SBS.topics;	
	for ( index5=0; index5 < section2.length ; index5++) {							
		var theValue = 'Results_' + section2[index5].id;														
		document.getElementById(theValue).style.display = 'none';
	}
}

//Begin: Show/Hide Column
//  Scriptlets code written by Jeremy Edmiston and modified by Chris Castle
//  The functions have been adapted from various sources and re-written to provide maximum flexibility
//  and compatability with various browsers
var ie = (document.all) ? true : false;
function hideClass(objClass){
	//  This function will hide Elements by object Class
	//  Works with IE and Mozilla based browsers			
	var elements = (ie) ? document.all : document.getElementsByTagName('*');
	for (i=0; i<elements.length; i++){
		if (elements[i].className==objClass){
			elements[i].style.display="none"
		}
	}
}

function showClass(objClass){
if(navigator.appName.indexOf("Microsoft") > -1)
	{ var canSee = 'block' } 
else
	{ var canSee = 'table-cell'; }
//  This function will show Elements by object Class
//  Works with IE and Mozilla based browsers
var elements = (ie) ? document.all : document.getElementsByTagName('*');
	for (i=0; i<elements.length; i++){
		if (elements[i].className==objClass){
			elements[i].style.display= canSee;
		}
	}
}
//End: Show/Hide Column

//Show Results Table and back button; hide the other options
function showResults() {
	document.getElementById('ResultsArea').style.display = 'block';
	document.getElementById('representatives').style.display = 'none';
	document.getElementById('topics').style.display = 'none';	
	document.getElementById('btnSubmit').style.display = 'none';				
	document.getElementById('btnBack').style.display = 'block';
	document.getElementById('printThis').style.display = 'block';
	document.getElementById('PrintWarning').style.display = 'block';
	document.getElementById('btnSubmit').style.display = 'none';
}

//Hide the results table and show the other options
function showAgain() {
	document.getElementById('ResultsArea').style.display = 'none';
	document.getElementById('representatives').style.display = 'block';
	document.getElementById('topics').style.display = 'block';	
	document.getElementById('btnSubmit').style.display = 'block';				
	document.getElementById('btnBack').style.display = 'none';
	document.getElementById('printThis').style.display = 'none';
	document.getElementById('PrintWarning').style.display = 'none';
	document.getElementById('btnSubmit').style.display = 'block';
}