function multimodeChange(field, mode, object) {
	parentForm = object.form;
	for (i = 0; i < parentForm.elements.length; i++) {
		elementName = parentForm.elements[i].name;
		if (elementName.substr(0, field.length) == field) {
			elementMode = elementName.substr(field.length + 1);
			
		elementMode = elementMode.replace(/^(\w*)(\-\w*)?$/,"$1");
			if (elementMode == mode) {
				parentForm.elements[i].disabled = false;
				parentForm.elements[i].style.backgroundColor = "#ffffff";
			} else if (elementMode != "") {
				parentForm.elements[i].disabled = true;
				parentForm.elements[i].style.backgroundColor = "#dddddd";
			}
		}
	}
}

function confirmDeleteSolution(solution, solutionLabel) {
	var ok = confirm("Are you sure you want to delete solution '" + solutionLabel + "'?");
	
	if (ok == true) window.location = "/index.php?module=ett&func=deletesolution&solution=" + solution;
}

function toggleSectionCollapse(section) {
	sectionFoldStatus[ section - 1 ] = 1 - sectionFoldStatus[ section - 1 ];
	if (sectionFoldStatus[ section - 1 ] == 1) { 
		var displayMode = "";
		buttonSrc = collapseSectionButton.src;
	} else {
		var displayMode = "none";
		buttonSrc = expandSectionButton.src;
	}
	leftCollapseButton = document.getElementById("section-collapse-button-" + section);
	rightCollapseButton = document.getElementById("section-collapse-button-right-" + section);
	leftCollapseButton.src = buttonSrc;
	if ( rightCollapseButton ) rightCollapseButton.src = buttonSrc;

	for (j = 0; j < subSectionFoldLengths[ section - 1 ].length; j++) {
		if (subSectionHasSummary[ section - 1 ][ j ] == 1) {
			document.getElementById("row-" + section + "-" + (j + 1) + "-summary").style.display = displayMode;
		}
		if (subSectionHasSummary[ section - 1 ][ j ] == 0 || displayMode == "none" || subSectionFoldStatus[ section - 1 ][ j ] == 1) {
			for (k = 0; k < subSectionFoldLengths[ section - 1 ][ j ]; k++) {
				document.getElementById("row-" + section + "-" + (j + 1) + "-" + (k + 1)).style.display = displayMode;
			}
		}
	}
}

function toggleSubSectionCollapse(section, subsection) {
	subSectionFoldStatus[ section - 1 ][ subsection - 1 ] = 1 - subSectionFoldStatus[ section - 1 ][ subsection - 1 ];
	if (subSectionFoldStatus[ section - 1 ][ subsection - 1] == 1) { 
		var displayMode = "";
		buttonSrc = collapseSubSectionButton.src;
	} else {
		var displayMode = "none";
		buttonSrc = expandSubSectionButton.src;
	}
	leftCollapseButton = document.getElementById("subsection-collapse-button-" + section + "-" + subsection);
	rightCollapseButton = document.getElementById("subsection-collapse-button-right-" + section + "-" + subsection);
	leftCollapseButton.src = buttonSrc;
	if ( rightCollapseButton ) rightCollapseButton.src = buttonSrc;
	for (i = 0; i < subSectionFoldLengths[ section - 1 ][ subsection - 1]; i++) {
		document.getElementById("row-" + section + "-" + subsection + "-" + (i + 1)).style.display = displayMode;
	}
}

function openSectionScore(section, solution, url) {
	thisUrl = url;
	if (thisUrl.indexOf("set=") != -1) {
		thisUrl = thisUrl.substr(0, thisUrl.indexOf("set=") - 1 );
	}
	sectionScoreWindow  = window.open("/modules/ett/xaruser/setsectionscore.php?section=" + section + "&solution=" + solution, "setsectionstarswindow", "resizable=no,scrollbars,titlebar,width=140,height=300,left=" + ((screen.width - 140) / 2) + ",top=" + ((screen.height  - 300) / 2));
}

function setSectionScore(section, solution, score) {
	sectionScoreWindow.close();
	location = thisUrl + "&set=sectionscore&section=" + section + "&solution=" + solution + "&score=" + score;
}

function openChangeStatus(solution, status, url) {
	thisUrl = url;
	if (thisUrl.indexOf("set=") != -1) {
		thisUrl = thisUrl.substr(0, thisUrl.indexOf("set=") - 1 );
	}
	currentSolution = solution;
	currentStatus = status;
	changeStatusWindow  = window.open("/modules/ett/xaruser/setstatus.html", "changestatuswindow", "resizable=no,scrollbars,titlebar,width=200,height=100,left=" + ((screen.width - 200) / 2) + ",top=" + ((screen.height  - 100) / 2));
}

function changeStatus(status) {
	location = thisUrl + "&set=status&solution=" + currentSolution + "&status=" + status;
}

function deleteSolution(solution, url) {
	thisUrl = url;
	if (thisUrl.indexOf("set=") != -1) {
		thisUrl = thisUrl.substr(0, thisUrl.indexOf("set=") - 1 );
	}
	var ok = confirm("Are you sure you want to delete this solution?");
	
	if (ok == true) window.location = thisUrl + "&set=delete&solution=" + solution;
}

function openSectionText(section, solution, existing, url) {
	thisUrl = url;
	if (thisUrl.indexOf("set=") != -1) {
		thisUrl = thisUrl.substr(0, thisUrl.indexOf("set=") - 1 );
	}
	newText = window.prompt("Please enter the summary text for this section", existing);
	if (newText != null) location = thisUrl + "&set=sectiontext&section=" + section + "&solution=" + solution + "&newtext=" + newText ;
}

function formFieldChanged( object, nodeName ) {
	
	if ( responseTimer ) clearTimeout( responseTimer );
	if ( inputTimer ) clearTimeout( inputTimer );
	
	//document.getElementById( "validsolutioncount_top" ).innerHTML = "Please wait...";
	document.getElementById( "validsolutioncount_bottom" ).innerHTML = "Please wait...";
	if ( document.getElementById( "validsolutioncount_advanced" ) ) document.getElementById( "validsolutioncount_advanced" ).innerHTML = "Please wait...";
	
	var parentForm = object.form;
	
	var dataString = generateGetString( parentForm );
	
	//var d = new Date();
	//responseTimer = d.getTime();
	
	//alert( "section:" + sectionNumber + " name:" + sectionName + " data:" + dataString + " node:" + nodeName );
	
	globalSection = sectionNumber;
	globalSectionName = sectionName;
	globalDataString = dataString;
	if ( globalNodeNames != "" ) globalNodeNames = globalNodeNames + ",";
	globalNodeNames = globalNodeNames + nodeName;
	
	inputTimer = setTimeout( formSendAjaxRequest, inputTimeout );
	
	//x_updateValidSolutionCount( sectionNumber, sectionName, dataString, nodeName, formFieldChanged_cb );
}

function formSendAjaxRequest() {
	//alert( "section:" + globalSection + " name:" + globalSectionName + " data:" + globalDataString + " nodes:" + globalNodeNames );
	x_updateValidSolutionCount( globalSection, globalSectionName, globalDataString, globalNodeNames, formFieldChanged_cb );
	globalNodeNames = "";
	responseTimer = setTimeout( formResendAjaxRequest, responseTimeout );
}

function formResendAjaxRequest() {
	//alert( "timeout" );
	x_updateValidSolutionCount( globalSection, globalSectionName, globalDataString, globalNodeNames, formFieldChanged_cb );
	responseTimer = setTimeout( formResendAjaxRequest, responseTimeout );
}

function formFieldChanged_cb( valid ) {
	
	if ( responseTimer ) clearTimeout( responseTimer );
	
	//var d = new Date();
	//responseTime = d.getTime() - responseTimer;
	
	//alert( "took " + responseTime + " milliseconds." );
	
	oldValid = validSolutions;
	validSolutions = valid;

	viewSolutionsElement = document.getElementById( "viewsolutions" );
	messageElement = document.getElementById( "message" );
	                                                
	//document.getElementById( "validsolutioncount_top" ).innerHTML = validSolutions + " of " + totalSolutions;
	document.getElementById( "validsolutioncount_bottom" ).innerHTML = validSolutions + " of " + totalSolutions;
	if ( document.getElementById( "validsolutioncount_advanced" ) ) document.getElementById( "validsolutioncount_advanced" ).innerHTML = validSolutions + " of " + totalSolutions;
	
	if ( ( oldValid == 0 || oldValid > maxSliders ) && validSolutions > 0 && validSolutions <= maxSliders ) {
		viewSolutionsEnabled = true;
	}
	if ( validSolutions <= maxSliders && oldValid > maxSliders ) messageElement.innerHTML = "&nbsp;";
	if ( ( validSolutions == 0 || validSolutions > maxSliders ) && oldValid <= maxSliders && oldValid > 0 ) {
		viewSolutionsEnabled = false;
	}
	if ( validSolutions > maxSliders && oldValid <= maxSliders ) messageElement.innerHTML = "You must reduce the number of suitable solutions to " + maxSliders + " or less before proceeding.";
}

function generateGetString( parentForm ) {
	var dataString = "";
	var fieldNumber = 0;
	for (i = 0; i < parentForm.elements.length; i++) {
		elementName = parentForm.elements[i].name;
		elementValue = parentForm.elements[i].value;
		if ( parentForm.elements[i].type == "checkbox" ) {
			if ( parentForm.elements[i].checked ) {
				if ( fieldNumber++ ) dataString += "&";
				dataString += elementName + "=on";
			}
		} else if ( parentForm.elements[i].type == "radio" ) {
			if ( parentForm.elements[i].checked ) {
				if ( fieldNumber++ ) dataString += "&";
				dataString += elementName + "=" + parentForm.elements[i].value;
			}
		} else if ( elementName != "action" && elementName != "" && parentForm.elements[i].type != "button" ) {
			if ( fieldNumber++ ) dataString += "&";
			dataString += elementName + "=" + parentForm.elements[i].value;
		}
	}
	return dataString;
}

function initSliderVars() {
	for ( i = 0; i < sliders; i++ ) {
		minArrowPos[ i ] = 0;
		maxArrowPos[ i ] = 100;
		minArrow[ i ] = document.getElementById( "minArrow-" + i );
		maxArrow[ i ] = document.getElementById( "maxArrow-" + i );
		minArrowFigure[ i ] = document.getElementById( "minArrowFigure-" + i );
		maxArrowFigure[ i ] = document.getElementById( "maxArrowFigure-" + i );
		slider[ i ] = document.getElementById( "slider-" + i );
		if ( sliderDisabled[ i ] == 0 && minArrow[ i ] != null ) Drag.init( minArrow[ i ], null, -9, 90, 10, 10 );
		if ( sliderDisabled[ i ] == 0 && maxArrow[ i ] != null ) Drag.init( maxArrow[ i ], null, -10, 90, 10, 10 );
	}
}

function onMinDrag( i, x, y ) {
	minArrowPos[ i ] = x + 9;
	if ( maxArrow[ i ] != null ) maxArrow[ i ].minX = x;
	slider[ i ].style["width"] = ( maxArrowPos[ i ] - minArrowPos[ i ] ) + "px";
	slider[ i ].style["left"] = minArrowPos[ i ] + "px";
	newvalue = Math.round( minArrowPos[ i ] / 100 * ( maxSliderValue[ i ] - minSliderValue[ i ] ) + minSliderValue[ i ] );
	
	// Deal with maximum value when we are not in a min/max situation
	valueabovenewvalue = Math.round( ( minArrowPos[ i ] + 1 ) / 100 * ( maxSliderValue[ i ] - minSliderValue[ i ] ) + minSliderValue[ i ] );
	if ( maxArrow[ i ] == null && valueabovenewvalue == maxSliderValue[ i ] && fixedMax[ i ] )
	minArrowFigure[ i ].innerHTML = "&gt;" + maxSliderValue[ i ];
	else minArrowFigure[ i ].innerHTML = newvalue;
	setValidSolutions();
}

function onMaxDrag( i, x, y ) {
	maxArrowPos[ i ] = x + 10;
	if ( minArrow[ i ] != null ) minArrow[ i ].maxX = x;
	slider[ i ].style["width"] = ( maxArrowPos[ i ] - minArrowPos[ i ] ) + "px";
	slider[ i ].style["left"] = minArrowPos[ i ] + "px";
	newvalue = Math.round( maxArrowPos[ i ] / 100 * ( maxSliderValue[ i ] - minSliderValue[ i ] ) + minSliderValue[ i ] );
	if ( newvalue == maxSliderValue[ i ] && fixedMax[ i ] )
	maxArrowFigure[ i ].innerHTML = "&gt;" + newvalue;
	else maxArrowFigure[ i ].innerHTML = newvalue;
	setValidSolutions();
}

function setValidSolutions() {
	totalSliders = sliders;
	totalCheckboxes = checkboxes;
	totalSolutions = solutionSliderFormulaValue.length;
	selectedChanged = 0;
	for ( j = 0; j < totalSolutions; j++ ) {
		ok = true;
		for ( i = 0; i < totalSliders; i++ ) {
			minSliderScaled = Math.round( minArrowPos[ i ] / 100 * ( maxSliderValue[ i ] - minSliderValue[ i ] ) + minSliderValue[ i ] );
			maxSliderScaled = Math.round( maxArrowPos[ i ] / 100 * ( maxSliderValue[ i ] - minSliderValue[ i ] ) + minSliderValue[ i ] );
			
			value = solutionSliderFormulaValue[ j ][ i ];
			if ( value < minSliderScaled || value > maxSliderScaled ) {
				ok = false;
			}
		}
		
		for ( i = 0; i < totalCheckboxes; i++ ) {
			checked = document.getElementById( "searchcheckbox-" + i ).checked;
			if ( checked && solutionCheckboxFormulaValue[ j ][ i ] == 0 ) ok = false;
		}
		
		imageElement = document.getElementById( "solutionimage-" + j );
		imageGreyElement = document.getElementById( "solutionimagegrey-" + j );
		checkboxElement = document.getElementById( "solutioncheckbox-" + j );
		
		if ( !ok ) {
			imageElement.style.display = "none";
			imageGreyElement.style.display = "";
			if ( checkboxElement.checked ) selectedChanged--;
			checkboxElement.checked = false;
			checkboxElement.disabled = true;
		} else {
			imageElement.style.display = "";
			imageGreyElement.style.display = "none";
			checkboxElement.disabled = false;
		}
	}
	if ( selectedChanged != 0 ) ssChangeCount( selectedChanged );
}

function ssSolutionCheckboxChanged( o ) {
	if ( o.checked ) ssChangeCount( 1 ); else ssChangeCount( -1 );
}

function ssChangeCount( change ) {
	oldChecked = checkedSolutions;
	checkedSolutions += change;
	
	//graphButtonElement = document.getElementById( "viewGraph" );
	//datasheetButtonElement = document.getElementById( "viewDatasheet" );
	graphMessageElement = document.getElementById( "graphMessage" );
	datasheetMessageElement = document.getElementById( "datasheetMessage" );
	
	if ( ( oldChecked == 0 || oldChecked > maxGraph ) && checkedSolutions > 0 && checkedSolutions <= maxGraph ) {
		//graphButtonElement.disabled = false;
    viewGraphEnabled = true;
	}
	if ( checkedSolutions <= maxGraph && oldChecked > maxGraph ) graphMessageElement.innerHTML = "&nbsp;";
	if ( ( checkedSolutions == 0 || checkedSolutions > maxGraph ) && oldChecked <= maxGraph && oldChecked > 0 ) {
		//graphButtonElement.disabled = true;
    viewGraphEnabled = false;
	}
	if ( checkedSolutions > maxGraph && oldChecked <= maxGraph ) graphMessageElement.innerHTML = "You must reduce the number of suitable solutions to " + maxGraph + " or less to Graph.";
	
	if ( ( oldChecked == 0 || oldChecked > maxDatasheet ) && checkedSolutions > 0 && checkedSolutions <= maxDatasheet ) {
    viewDatasheetsEnabled = true;
		//datasheetButtonElement.disabled = false;
	}
	if ( checkedSolutions <= maxDatasheet && oldChecked > maxDatasheet ) datasheetMessageElement.innerHTML = "&nbsp;";
	if ( ( checkedSolutions == 0 || checkedSolutions > maxDatasheet ) && oldChecked <= maxDatasheet && oldChecked > 0 ) {
    viewDatasheetsEnabled = false;
		//datasheetButtonElement.disabled = true;
	}
	if ( checkedSolutions > maxDatasheet && oldChecked <= maxDatasheet ) datasheetMessageElement.innerHTML = "You must reduce the number of suitable solutions to " + maxDatasheet + " or less to view datasheets.";
}

function ssSearchCheckboxChanged( o ) {
	setValidSolutions();
}

function setupGraph() {
	
	// Maximum width a graph bar can be
	maxWidth = 495;
	
	totalGraphs = graphData.length;
	for ( graph = 0; graph < totalGraphs; graph++ ) {
		
		// Determine maximum graph value so as to determine scale
		if ( graphMax[ graph ] == 0 ) {
			maxValue = 0;
			totalSolutions = graphData[ graph ].length;
			for ( solution = 0; solution < totalSolutions; solution++ ) {
				totalSubQuantities = graphData[ graph ][ solution ].length;
				thisValue = 0;
				for ( subQuantity = 0; subQuantity < totalSubQuantities; subQuantity++ ) {
					thisValue += Number(graphData[ graph ][ solution ][ subQuantity ]);
				}
				if ( thisValue >= maxValue ) maxValue = thisValue;
			}
		} else maxValue = graphMax[ graph ];

		// Basic x step is power of ten below largest value
		// (ie 1100 will give 1000, 570 will give 100, 21 will give 10)
		var grad = Math.pow(10, Math.floor(Math.log(maxValue) / Math.log(10)));

		// Calculate number of steps
		var steps = Math.floor(maxValue / grad);

		// If there are more than 7 steps, (eg for a largest total of 80),
		// go to 5 times larger (ie half the next order of magnitude).
		if (steps > 7) {
			grad = grad * 2;
			steps = Math.floor(maxValue / grad);
	
		// If there are less than 4 steps, (eg for a total of 160),
		// go to half the step (ie half the order of magnitude)
		} else if (steps < 4) {
			grad = grad / 2;
			steps = Math.floor(maxValue / grad);

			// If there are still less than 4 steps, go to
			// twice the next lowest order of magnitude, as
			// long as there are not more than 7 of this step
			if (steps < 4 && Math.floor(maxValue / (grad * 2/5)) <= 7) {
				grad = grad * 2/5;
				steps = Math.floor(maxValue / grad);
			}
		}

		steps++;

		graphScaling = maxWidth / maxValue;
		
		tickGrad = grad * ( maxWidth + 2 ) / maxValue;
		
		// Set position of ticks
		for (step = 0; step < steps; step++) {
			document.getElementById("xTick-" + graph + "-" + step ).style.left = (tickGrad * step ) + "px";
			document.getElementById("xTick-" + graph + "-" + step ).style.visibility = "visible";
			document.getElementById("xTick-" + graph + "-" + step ).innerHTML = graphPrefix[ graph ] + ( Math.round( grad * step * 10 ) / 10) + graphSuffix[ graph ];
		}

		// Hide any unused ticks
		if (steps < 7) {
			for (step = steps; step < 7; step++) {
				document.getElementById("xTick-" + graph + "-" + step ).style.visibility = "hidden";
			}
		}
		
		// Set graph bar widths;
		for ( solution = 0; solution < totalSolutions; solution++ ) {
			totalSubQuantities = graphData[ graph ][ solution ].length;
			for ( subQuantity = 0; subQuantity < totalSubQuantities; subQuantity++ ) {
				barId = "bar-" + graph + "-" + solution + "-" + subQuantity;
				document.getElementById( barId ).style.width = ( Number(graphData[ graph ][ solution ][ subQuantity ]) * graphScaling ) + "px";
			}
		}
	}
	
}

function showAdvanced( show ) {
	if ( show ) {
		document.getElementById( "showAdvancedButton" ).style.display = "none";
		document.getElementById( "hideAdvancedButton" ).style.display = "block";
		document.getElementById( "advancedCriteria" ).style.display = "block";
	} else {
		document.getElementById( "showAdvancedButton" ).style.display = "block";
		document.getElementById( "hideAdvancedButton" ).style.display = "none";
		document.getElementById( "advancedCriteria" ).style.display = "none";
	}
}

function selectOrDeselectAll( sectionName, value ) {
  form = document.getElementById( "solutions" );
	changed = 0;
  for ( i = 0; i < form.length; i++ ) {
    if ( form.elements[ i ].id.substr(0,sectionName.length) == sectionName && !form.elements[ i ].disabled ) {
			if ( form.elements[ i ].checked != value ) changed += value ? 1 : -1;
			form.elements[ i ].checked = value;
		}
  }
	return changed;
}

function graphCheckboxClicked( o ) {
	checked = o.checked;
	solutionName = o.id.substr( o.id.indexOf( "-" ) + 1 );
	for ( i = 0; i < graphData.length; i++ ) {
		document.getElementById( i + "-" + solutionName ).checked = checked;
	}
	if ( checked ) graphChangeCount( 1 ); else graphChangeCount( -1 );
}

function graphChangeCount( change ) {
	oldChecked = checkedSolutions;
	checkedSolutions += change;
	
	//buttonElement = document.getElementById( "viewDatasheet" );
	messageElement = document.getElementById( "message" );
	
	if ( ( oldChecked == 0 || oldChecked > maxDatasheet ) && checkedSolutions > 0 && checkedSolutions <= maxDatasheet ) {
    viewDatasheetsEnabled = true;
		//buttonElement.disabled = false;
	}
	if ( checkedSolutions <= maxDatasheet && oldChecked > maxDatasheet ) messageElement.innerHTML = "&nbsp;";
	if ( ( checkedSolutions == 0 || checkedSolutions > maxDatasheet ) && oldChecked <= maxDatasheet && oldChecked > 0 ) {
    viewDatasheetsEnabled = false;
		//buttonElement.disabled = true;
	}
	if ( checkedSolutions > maxDatasheet && oldChecked <= maxDatasheet ) messageElement.innerHTML = "You must reduce the number of suitable solutions to " + maxDatasheet + " or less to view datasheets.";
}

function graphSelectOrDeselectAll( value ) {
	for ( j = 0; j < graphData.length; j++ ) {
		change = selectOrDeselectAll( j + "-", value );
	}
	graphChangeCount( change );
}

function slSelectOrDeselectAll( value ) {
	change = selectOrDeselectAll( "approved", value );
	slChangeCount( change );
}

function slCheckboxClicked( o ) {
	checked = o.checked;
	if ( checked ) slChangeCount( 1 ); else slChangeCount( -1 );
}

function slChangeCount( change ) {
	oldChecked = checkedSolutions;
	checkedSolutions += change;
	
	buttonElement = document.getElementById( "viewDatasheet" );
	messageElement = document.getElementById( "message" );
	
	if ( ( oldChecked == 0 || oldChecked > maxDatasheet ) && checkedSolutions > 0 && checkedSolutions <= maxDatasheet ) {
		buttonElement.disabled = false;
	}
	if ( checkedSolutions <= maxDatasheet && oldChecked > maxDatasheet ) messageElement.innerHTML = "&nbsp;";
	if ( ( checkedSolutions == 0 || checkedSolutions > maxDatasheet ) && oldChecked <= maxDatasheet && oldChecked > 0 ) {
		buttonElement.disabled = true;
	}
	if ( checkedSolutions > maxDatasheet && oldChecked <= maxDatasheet ) messageElement.innerHTML = "You must reduce the number of selected solutions to " + maxDatasheet + " or less to view datasheets.";
}

function graphShowHide( graphNo, value ) {
	graphElement = document.getElementById( "graph-" + graphNo );
	showElement = document.getElementById( "show-" + graphNo );
	hideElement = document.getElementById( "hide-" + graphNo );
	
	if ( value ) {
		graphElement.style.display = "";
		showElement.style.display = "none";
		hideElement.style.display = "";
	} else {
		graphElement.style.display = "none";
		showElement.style.display = "";
		hideElement.style.display = "none";
	}
}

function toolShowHideAdvanced() {
	showAdvanced = !showAdvanced;
	advancedCriteriaElement = document.getElementById( "advancedCriteria" );
	arrowElement = document.getElementById( "advButtonArrow" );
	if ( showAdvanced ) {
		advancedCriteriaElement.style.display = "block";
		arrowElement.src = advButtonUpArrow.src;
	} else {
		advancedCriteriaElement.style.display = "none";
		arrowElement.src = advButtonDownArrow.src;
	}
}

function toolChangeSection( newSection ) {
  
  // If we are on a results page, just jump to the appropriate page, whereas if we are on
  // an input page, we need to take account of any changed inputs
  if ( resultsPage ) {
    newLocation = "/index.php?module=ett&func=toolwizard&solutiontype=" + solutionType + "&jumpto=" + newSection;
  } else {
    newLocation = "/index.php?" + generateGetString( document.getElementById("tool-form") ) + "&jumpto=" + newSection;
  }
	window.location = newLocation;
}

function solutionListShowHide( alpharange ) {
	showhide = document.getElementById( "showhide-" + alpharange);
	rangediv = document.getElementById( "alpharange-" + alpharange);
	if ( showhide.innerHTML == "show" ) {
		rangediv.style.display = "block";
		showhide.innerHTML = "hide";
	} else {
		rangediv.style.display = "none";
		showhide.innerHTML = "show";
	}
}

function viewSolutionsEnabledCheck() {
  return viewSolutionsEnabled;
}

function viewGraphEnabledCheck() {
  if ( currentSection == "toolsteps" ) {
    if ( validSolutions == 0 ) return false; // Nothing selected - button does nothing
    else if ( validSolutions <= maxGraph ) return true; // Less than max selected - view graphs
    else alert('Please limit solutions to '+maxGraph+' before graphing. You can use the View Solutions page and the individual Steps in the Tool to achieve this.');
  } else if ( currentSection == "sliders" ) {
    if ( checkedSolutions == 0 ) return false; // Nothing selected
    else if ( checkedSolutions <= maxGraph ) { // Less than max selected - view graphs
      document.getElementById('func').value='graphsolutions';
      document.getElementById('solutions').submit();
    } else alert('Please limit solutions to '+maxGraph+' before graphing. You can use the View Solutions page and the individual Steps in the Tool to achieve this.');
  } else return true; // For datasheets page (can always go to the graph page because the maximum solutions for the datasheet is lower than that for graphing)
  return false;
}

function viewDatasheetsEnabledCheck() {
  if ( currentSection == "toolsteps" ) {
    if ( validSolutions == 0 ) return false; // Nothing selected - button does nothing
    else if ( validSolutions <= maxDatasheet ) return true; // Less than max selected - view datasheets
    else alert('Please limit solutions to '+maxDatasheet+' before comparing. You can use the View Solutions and Graph Solutions pages and the individual Steps in the Tool to achieve this. We do recommend only comparing 3-5 solutions at one time.');
  } else if ( currentSection == "sliders" || currentSection == "graph" ) {
    if ( checkedSolutions == 0 ) return false; // Nothing selected
    else if ( checkedSolutions <= maxDatasheet ) { // Less than max selected - view datasheets
      document.getElementById('func').value='viewsolutions';
      document.getElementById('solutions').submit();
    } else alert('Please limit solutions to '+maxDatasheet+' before comparing. You can use the View Solutions and Graph Solutions pages and the individual Steps in the Tool to achieve this. We do recommend only comparing 3-5 solutions at one time.');
  } // No other possibilities
  return false;
}

/**
 * Jump to a section when editing solution
 */
function registerSolutionChangeSection(newSection) {
  document.getElementById("jumpto").value = newSection;
  if (processCostFields()) document.getElementById("register-form").submit();
}