
function Expand_Menu(menu_item,force_display) {

  var i, nptr, dmode, newdmode, lnparts, conheight, lnheight; 

//  document.write("In Expand_Menu");
  if (document.getElementById) {
    if (menu_item.parentNode) {
      if (menu_item.parentNode.childNodes) {
      nptr = menu_item.parentNode.childNodes; 
      }
    else { return; };
      }


//    document.write("Before for loop. <BR>");
//    document.write("Menu item tag:"+menu_item.tagName+"=<BR>");
//    document.write("Menu item classname:"+menu_item.className+"=<BR>");
//    document.write("Value of length = <BR>" + nptr.length);
//    document.write("Value of force_display = " + force_display);
    for (i = 0;  i < nptr.length;  i++) {
//    document.write("In loop. "+i+" "+nptr[i].tagName+" <BR>");
//    document.write("The data "+nptr[i].data+" <BR>");
      if (nptr[i].tagName == "DIV") {
//    document.write("In set d part. "+i+" <BR>");
        dmode = nptr[i].style.display; 
//    document.write("Value of d ="+dmode+"= <BR>");
        newdmode = (dmode == "block") ? "none" : "block";  
        if (force_display == 1) { newdmode = "block"; };
        nptr[i].style.display = newdmode;
        };
      };
//    document.write("Out of loop. "+i+" <BR>");
    if (menu_item.className == 'ECEPlus') {
      menu_item.className = 'ECEMinus';
      }
    else if (menu_item.className == 'ECEMinus') {
      menu_item.className = 'ECEPlus';
      }
    }
    conheight = document.getElementById("content").offsetHeight;
    lnparts = document.getElementById("leftsidebar");
    lnheight = lnparts.offsetHeight;
    if (conheight > lnheight) {
      lnparts.style.height = conheight;
      }
    else {
      document.getElementById("content").style.height = lnheight;
     };
//    document.write("At end of function. <BR>");

  }

// This is needed to deal with opera display problems. 
// It is called when the page is loaded.

function ECE_SetDType() {

  var i, d = '', h = '<style type = \"text/css\">'; 
  var agent = navigator.userAgent.toLowerCase(); 
 
//  document.write("In ECE_Set_DType");
  if (document.getElementById) {
    if (window.opera) {
      if ((agent.indexOf("opera 5") > -1) || (agent.indexOf("opera 6") > -1)) {
	return;
        }
      }
    for (i = 1;  i < 5; i++) {
      d += 'div '; 
      h += "\n#localnav div "+d+"{ display:none; }"; 
      }
    document.write(h+"\n</style>"); 
    }
  }

function ECEInit() { // Initialize Menu types.

  var i, currenturl, Aparts, nptr, amethod;
  var lnparts; 
  var conheight, lnheight;
  var web_home = "http://ecee.colorado.edu/";
  var size, j;

  size = web_home.length + 4;  // Add 4 to get the first four unique
                               // characters of the subdirectory name.
//    document.write("Size "+size+"X <BR>");

 //  document.write("In ECE_Init_Menu <BR>\n");
  ECE_Set_Class();
 //  document.write("After ECE_Set_Class <BR>\n");
  if (document.getElementById) {
    lnparts = document.getElementById("localnav");
    if (lnparts) { /* Found a localnav div */
//      currenturl = window.location.href;
      if (window.location.href.length >= size) {
        currenturl = window.location.href.substr(0,size);
	}
      else { currenturl = window.location.href + "index.html"; };
//    document.write("Current URL substring "+currenturl+"X <BR>\n");
      Aparts = lnparts.getElementsByTagName("A");
      if (Aparts && Aparts.length) {
    j = Aparts.length + 100;
//    document.write("Aparts length "+ j +"X <BR>\n");
        for (i = 0; i < Aparts.length; i++) {
//    document.write("Aparts href "+ Aparts[i].href +"X <BR>\n");
          if (Aparts[i].href) {
//  	    if (currenturl.indexOf(Aparts[i].href) > -1) {
  	    if (Aparts[i].href.indexOf(currenturl) > -1) {
//    document.write("Current A part URL substring "+ Aparts[i].href +"X <BR>\n");
              if (window.location.href.indexOf(Aparts[i].href) > -1) {
		Aparts[i].className = "ECECurrentPage";
		};
              nptr = Aparts[i].parentNode.parentNode;
//              nptr = Aparts[i].parentNode;
              while (nptr) {
                if (nptr.firstChild && nptr.firstChild.tagName == "A"
		    && (nptr.firstChild.href.indexOf(currenturl) > -1)) {
  	          if (nptr.firstChild.onclick) {
                    amethod = nptr.firstChild.onclick.toString();
                    if (amethod && amethod.indexOf("Expand_Menu") > -1) {
                      Expand_Menu(nptr.firstChild,1);
                      }
                    }
                  }
  	        nptr = nptr.parentNode;
                }
              }
  	    }
  	  }
        }
      }
    }
  conheight = document.getElementById("content").offsetHeight;
  lnparts = document.getElementById("leftsidebar");
  lnheight = lnparts.offsetHeight;
  if (conheight > lnheight) {
    lnparts.style.height = conheight;
      }
  else {
    document.getElementById("content").style.height = lnheight;
   };
  }

function Expand_All(a) {

  var i, j, aptr, ag, dmode, nptr;
  var conheight, lnparts, lnheight;

  if (document.getElementById) {
    aptr = document.getElementsByTagName("A");
    for (i = 0; i < aptr.length; i++) {
      if (aptr[i].onclick) {
        astg = aptr[i].onclick.toString();
        if (astg && (astg.indexOf("Expand_Menu") > -1)) {
          if (aptr[i].parentNode && aptr[i].parentNode.childNodes) {
            nptr = aptr[i].parentNode.childNodes;
            }
          else{
            break;
            }
          for (j = 0; j < nptr.length; j++) {
            if (nptr[j].tagName == "DIV") {
              dmode = nptr[j].style.display;
              if ((a == 0) && (dmode != 'block')) {
                Expand_Menu(aptr[i]);
                }
              else if ((a == 1) && (dmode == 'block')) {
                Expand_Menu(aptr[i]);
                }
              break;
              }
            }
          }
        }
      }
    }
  conheight = document.getElementById("content").offsetHeight;
  lnparts = document.getElementById("leftsidebar");
  lnheight = lnparts.offsetHeight;
  if (conheight > lnheight) {
    lnparts.style.height = conheight;
      }
  else {
    document.getElementById("content").style.height = lnheight;
   };

  }

function ECE_Set_Class() {  // Set menu classes

  var i, lnparts, Aparts, nptr; 

//  document.write("In ECE_Set_Class <BR>");
  if (document.getElementById) {
    lnparts = document.getElementById('localnav'); 
    if (lnparts) {
      Aparts = lnparts.getElementsByTagName("A");
      if (Aparts && Aparts.length) {
        for (i = 0; i < Aparts.length; i++) {
          nptr = (Aparts[i].onclick) ? Aparts[i].onclick.toString() : false;
          if (nptr && nptr.indexOf("Expand_Menu") > -1) {
            Aparts[i].className = 'ECEPlus'; }
          else {
            Aparts[i].className = 'ECENoChar'; }
          }
        }
      }
    }
  return true;
  }


ECE_SetDType();


