
function allsections(action) {
	var open_element = document.getElementById("open_all");
	var close_element = document.getElementById("close_all");
	if (action == "open_all") {
		action = "show";
		open_element.className = "collapsed";
		close_element.className = "expandableDIVsm";
	} else {
		action = "hide";
		open_element.className = "expandableDIVsm";
		close_element.className = "collapsed";
	}
	showhideall(action, "outperforms_", "");
	showhideall(action, "apps_", "");
	showhideall(action, "competition_", "");
	showhideall(action, "dq_", "");
	showhideall(action, "faq_", "");
	showhideall(action, "features_", "");
	showhideall(action, "salesstrategies_", "");
	showhideall(action, "salestools_", "");
}

function showhideall(sh, which, action, path, enableId) {
	var img_element = document.getElementById(which + "_img");
	
	if (sh == "show" || (sh == "toggle" && img_element.className == "show") || action == "expanded") {
		var img = path + "/images/minus.gif";
		var alttext = "Click on the MINUS Sign to DISABLE this section";
		
		if (enableId != null) {
			document.getElementById(enableId).firstChild.nodeValue = 'Disable';
		}
		
		if ((action == null) || (action == 'None')) {
			action = "expanded";
		}
		
		img_element.className = "hide";
		
	} else {
		var img = path + "/images/plus.gif";
		var alttext = "Click on the PLUS Sign to ENABLE this section";
		
		if (enableId != null) {
			document.getElementById(enableId).firstChild.nodeValue = 'Enable';
		}
		
		if ((action == null) || (action == 'None')) {
			action = "collapsed";
		}
		img_element.className = "show";
	}
	
	img_element.src = img;
	img_element.alt = alttext;

	for (var i = 0; i < 20; i++) {
		var div_element = document.getElementById(which + i);
		if (div_element != null) {
			div_element.className = action;
		
			if (action == "collapsed") {
				if (which == "groupdelay_") {
					document.dynaInputForm.groupDelayEnable.value = "false";
				} else if (which == "stepresponse_") {
					document.dynaInputForm.stepResponseEnable.value = "false";
				} else if (which == "flatness_") {
					document.dynaInputForm.flatnessEnable.value = "false"
				}
			} else if (action == "expanded") {
				if (which == "groupdelay_") {
					document.dynaInputForm.groupDelayEnable.value = "true";
				} else if (which == "stepresponse_") {
					document.dynaInputForm.stepResponseEnable.value = "true";
				} else if (which == "flatness_") {
					document.dynaInputForm.flatnessEnable.value = "true"
				}
			}
				
		}
	}
}
function toggle(hidename) {
	var hide_element = document.getElementById(hidename);
	var img_element = document.getElementById(hidename + "_img");
	if (cssjs("check", hide_element, "collapsed")) {
		cssjs("swap", hide_element, "collapsed", "plcourse");
		img_element.src = "../images/minus.gif";
		img_element.alt = "Click on the MINUS Sign to COLLAPSE this section";
	} else {
		cssjs("swap", hide_element, "plcourse", "collapsed");
		img_element.src = "../images/plus.gif";
		img_element.alt = "Click on the PLUS Sign to SHOW this section";
	}
}

function cssjs(a, o, c1, c2) {
	switch (a) {
	  case "swap":
		o.className = !cssjs("check", o, c1) ? o.className.replace(c2, c1) : o.className.replace(c1, c2);
		break;
	  case "add":
		if (!cssjs("check", o, c1)) {
			o.className += o.className ? " " + c1 : c1;
		}
		break;
	  case "remove":
		var rep = o.className.match(" " + c1) ? " " + c1 : c1;
		o.className = o.className.replace(rep, "");
		break;
	  case "check":
		return new RegExp("b" + c1 + "b").test(o.className);
		break;
	}
}

// Updates the test frequencies for change in fref
function updateTestFrequencies(filterType) {

	var frefValue 		= document.dynaInputForm.fref.value;
	var lowerTestFreq;
	var upperTestFreq;
	
	if (filterType == "Lowpass") {
		lowerTestFreq	= frefValue * .1;
		upperTestFreq	= frefValue * .9;
	} else if (filterType == "Highpass") {
		lowerTestFreq	= frefValue * 5;
		upperTestFreq	= frefValue * 100;
	} else if (filterType == "Bandstop") {
		lowerTestFreq	= frefValue * 1.6;
		upperTestFreq	= frefValue * 1.8;
	}
	
	for (var i = 0; i < 20; i++) {
		
		// Flatness test freq
		var div_element = document.getElementById("flatness_" + i);
		if (div_element != null) {
			var className = div_element.className;
			if (className == "collapsed") {
				document.dynaInputForm.f1f.value = lowerTestFreq;
				document.dynaInputForm.f2f.value = upperTestFreq;
			}
		}
		
		// Group Delay test freq
		var div_element = document.getElementById("groupdelay_" + i);
		if (div_element != null) {
			var className = div_element.className;
			if (className == "collapsed") {
				document.dynaInputForm.f1d.value = lowerTestFreq;
				document.dynaInputForm.f2d.value = upperTestFreq;
			}
		}
	}
	
}


