function expand(a)
      { var ul= a.nextSibling;
        ul.style.display="block";
        a.setAttribute( "onclick", "collapse( this)");
        a.setAttribute( "title",   "Hide this level");
        a.innerHTML= "  ▼" ;
        document.getElementById( "collapse_all").setAttribute( "src", "http://standards.ieee.org/img/minus.png");
        var toc= document.getElementById( "toc");
        if( toc.isAllExpanded())
          { document.getElementById( "expand_all").setAttribute( "src", "http://standards.ieee.org/img/space_32_32.png");   }
        else
          { document.getElementById( "expand_all").setAttribute( "src", "http://standards.ieee.org/img/plus.png"); }
      }

    function collapse(a)
      { var ul= a.nextSibling;
        ul.style.display="none";
        a.setAttribute( "onclick", "expand( this)");
        a.setAttribute( "title",   "Show next level");
        a.innerHTML= "  ▶" ;
        document.getElementById( "expand_all").setAttribute( "src", "http://standards.ieee.org/img/plus.png");
        var toc= document.getElementById( "toc");
        if( toc.isAllCollapsed())
          { document.getElementById( "collapse_all").setAttribute( "src", "http://standards.ieee.org/img/space_32_32.png");   }
        else
          { document.getElementById( "collapse_all").setAttribute( "src", "http://standards.ieee.org/img/minus.png"); }
      }

    function collapseall ()
      { var toc= document.getElementById( "toc");
        var as= toc.getElementsByTagAndClass( "span", "expand");
        for( var i=0; i<as.length; i++)
          { collapse( as[i]); }
        document.getElementById( "expand_all").setAttribute( "src", "http://standards.ieee.org/img/plus.png");
        document.getElementById( "collapse_all").setAttribute( "src", "http://standards.ieee.org/img/space_32_32.png");
      }

    function expandall ()
      { var toc= document.getElementById( "toc");
        var as= toc.getElementsByTagAndClass( "span", "expand");
        for( var i=0; i<as.length; i++)
          { expand( as[i]); }
        document.getElementById( "expand_all").setAttribute( "src", "http://standards.ieee.org/img/space_32_32.png");
        document.getElementById( "collapse_all").setAttribute( "src", "http://standards.ieee.org/img/minus.png");
      }

    
     HTMLElement.prototype.getChildrenByTag= function ( tag)
      { var children= this.childNodes;
        tag= tag.toLowerCase();
        var res=new Array();
        for( var i=0; i<children.length; i++)
          { if( children[i].nodeType == 1 /* Node.ELEMENT_NODE */ && children[i].tagName.toLowerCase() == tag) { res.push( children[i]); } }
        return res;
      }

     HTMLElement.prototype.getElementsByTagAndClass= function ( tag, class)
      { tag= tag.toLowerCase();
        var children= this.getElementsByTagName( tag);
        var res=new Array();
        for( var i=0; i<children.length; i++)
          { if( children[i].getAttribute( "class") == class) { res.push( children[i]);} }
        return res;
      }

    HTMLElement.prototype.isAllExpanded= function ()
      { var uls= this.getElementsByTagAndClass( "ul", "toc");
        for( var i=0; i<uls.length; i++)
          { if( uls[i].style.display == 'none') { return false; } }
        return true;
      }

    HTMLElement.prototype.isAllCollapsed= function ()
      { var lis= this.getChildrenByTag( "li");
        for( var i=0; i<lis.length; i++)
          { var ul= lis[i].getChildrenByTag( "ul");
            if( ul.length && ul[0].style.display == 'block') { return false; }
          }
        return true;
      }

