// the function shows or hides the chosen section in products; make sure to update function if sections are added
var stateArray = new Array(0,0);			/* since everything at "first" (after style tag in script tag above) is hidden, the first time the link is clicked (note increment of []switch) will turn off the display */
var nameArray = new Array("EAS","fibers");

function showHide(Name)
{
 var stateInfo = "";						/* shows both categories */
 var toggle = -1;							/* prevents anything from happening if sectionName is empty (because called by body onload, for instance) */

 if (Name=="EAS++")
 {
  var sectionName = Name.slice(0,-2);		/* from before first position to before penultimate (before ++) */	
  stateArray[0]++;
  stateArray[0]%=2;							/* modulo two because two states possible! */
  toggle = stateArray[0];
 }
 
 if (Name=="fibers++")
 {
  var sectionName = Name.slice(0,-2);
  stateArray[1]++;
  stateArray[1]%=2;
  toggle = stateArray[1];
 }

 if (toggle==0)
 {
  document.getElementById(sectionName).style.display="none";	/*hide firstly, then show */
  document.getElementById(sectionName+"Replacement").style.display="block";
 }
 
 if (toggle==1)
 {
  document.getElementById(sectionName+"Replacement").style.display="none";
  document.getElementById(sectionName).style.display="block";
 }

 
 /* The four following sectionNames are called only from onload, with location.search read */
 if (Name == "none")			
 {
  for (i in nameArray)
  {
   document.getElementById(nameArray[i]).style.display="none";
   document.getElementById(nameArray[i]+"Replacement").style.display="block";
  }
  document.getElementById("BottomBar").style.display="block";	/* display lastly to avoid jumping in Firefox */
 }

 if (Name == "EAS")
 { 
  document.getElementById(Name).style.display="block";
  document.getElementById("fibersReplacement").style.display="block";
  document.getElementById("BottomBar").style.display="block";
  stateArray[0]++;		/* increment because starting values (upon loading) are zero; also, no need for modulo */
 }

 if (Name == "fibers")
 { 
  document.getElementById(Name).style.display="block";
  document.getElementById("EASReplacement").style.display="block";
  document.getElementById("BottomBar").style.display="block";
  stateArray[1]++;
 }

 if (Name == "")
 {
  for (i in nameArray)
  {
   document.getElementById(nameArray[i]).style.display="block";
   stateArray[i]++;
  }
  document.getElementById("BottomBar").style.display="block";
 }


 switch (stateArray.toString())				/* toString() converts the states array into a string; is used because states==[0,0] did not work (why? good question) */
 {											/* read states before "bothHidden" and "" cases, which increment */
  case "0,0":
   stateInfo="?none";
   break;
   
  case "0,1":
   stateInfo="?fibers";
   break;
  
  case "1,0":
   stateInfo="?EAS";
   break;									/* case 1,1: stateInfo is already ="" */
 }
 createMenu(stateInfo);
}

