
var globalOpen = false;

function toggleLayer(whichLayer)
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById(whichLayer);
  else if(document.all) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if(document.layers) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function toggleDiv(currentDiv, previousDiv)
{
  // alert("currentDiv is: " + currentDiv);
  
  // Call toggleLayer to switch hidden and visible divs
  toggleLayer(currentDiv);
  toggleLayer(currentDiv + '2');
  
  // Call to switch previous hidden and visible divs
  if(previousDiv) {
    // alert("previousDiv was: " + previousDiv);
    toggleLayer(previousDiv);
    toggleLayer(previousDiv + '2');
  }
}

function checkDiv(div1, step, div2)
{
  //Uncomment alerts for debugging
  
  // Call toggleLayer to activate tier2 on first click in step 1
  if(!div1) {
  
    // alert("If 1 div1 is: " + div1);
    
    toggleLayer('step2gray');
    toggleLayer('step2active');
  }
  
  // Make sure tier3 is inactive when on step 2, but have not yet made selection
  else if(div2&&step=="step1"){
  
    // alert("Else If 2 div1 is: " + div1 + " and div2 is: " + div2);
    
    toggleLayer('step3gray');
    toggleLayer('step3active');
  }
  
  // Activate tier3 on first click in step 2
  else if(!div2&&step=="step2"){
  
    // alert("Else If 3 div1 is: " + div1 + " and div2 is: " + div2);
    
    toggleLayer('step3gray');
    toggleLayer('step3active');
  }

}

function OpenAllLearnMore(ClassName, FormName, ButtonName)
{

    topButtonName = ButtonName + '_top';
    botButtonName = ButtonName + '_bottom';
    var objTopSubmitButton = document.forms[FormName].elements[topButtonName];
	var objBottomSubmitButton = document.forms[FormName].elements[botButtonName];

    var divList = document.getElementsByTagName('div');
    
    for (var loop = 0; loop < divList.length ; loop++ ) {
    	if (divList[loop].className == ClassName)
    	   divList[loop].style.display=(globalOpen ? 'none' : 'block');
    }
	if (globalOpen) {
	    ButtonValue = 'Expand All \'Learn More\''; }
	else {
	    ButtonValue = 'Close All \'Learn More\''; }
    globalOpen = !globalOpen
    objTopSubmitButton.value = ButtonValue;
    objBottomSubmitButton.value = ButtonValue;
   
}

// This function expands/closes all Learn More divs of a particular class.
// 
// It handles the case of a single button or multiple buttons.  The first
// four parameters are required; ButtonText can be omitted if Expand All
// and Close All are the only text required.
//
// All affected divs are wrapped into a single form:
// 
// <form method="get" action="" name="<form-name>" onsubmit="return false;">
//
// The HTML code for the button itself looks like:
//
// <input value="Expand All 'Learn More'" 
//        name="OpenClose1" class="<button-class>" 
//        onclick="OpenAll('<class-name>','<form-name>','<button-name>', num-buttons, '<optional-button-text>');" 
//     style="float: left;" type="submit">
//
// Input:
//      ClassName: the class of the divs to be opened/closed.
//      FormName: the name of the form that encloses all the divs to be opened/closed
//      ButtonName: the generic name of the "button group".  For instance, if you
//                  have 3 buttons named MyButton1, MyButton2, MyButton3, the ButtonName
//                  will be MyButton.
//      NumButtons: the total number of Open/Close buttons on the page (this is the number of
//                  submit buttons, not the number of divs to be opened/closed onclick.
//      ButtonText: All buttons have the text Expand All or Close All.  You can make the text more
//                  specific (e.g. Expand All Learn More) by defining ButtonText.
        

function OpenAll(ClassName, FormName, ButtonName, NumButtons, ButtonText)
{
    var SubmitButton = [];
    var MaxArgs = 5;  // Maximum number of arguments that the function understands
    
    if (arguments.length < MaxArgs) {
        ButtonText = '';}
    else {
        ButtonText = ' ' + ButtonText;
    }
        
    for (loop=1; loop <= NumButtons; loop++) {
        buttonId = ButtonName + loop;
        SubmitButton[loop-1] = document.forms[FormName].elements[buttonId];
    }
    
    var divList = document.getElementsByTagName('div');
    
    for (var loop = 0; loop < divList.length ; loop++ ) {
    	if (divList[loop].className == ClassName)
    	   divList[loop].style.display=(globalOpen ? 'none' : 'block');
    }
	if (globalOpen) {
	    ButtonValue = 'Expand All' + ButtonText; }
	else {
	    ButtonValue = 'Close All' + ButtonText; }
	    
    globalOpen = !globalOpen
    
    for (var loop = 0; loop < SubmitButton.length; loop++) {
        SubmitButton[loop].value = ButtonValue;
    }
}
