/* These commands are for expanding/collapsing elements (<div> tagged)
   in a page.  The id(s) of the <div> tag(s) is/are passed to the function. */

var toggle = 1;  // this allows elements to expand/collapse uniformly

// Expand an element
function expand(){
  var i, j, args;
  args=expand.arguments;
  for (j = 0; j < args.length; j++) {
    i=document.getElementById(args[j]);
    i.style.display ='block';
  }
}

// Collapse an element
function collapse(){
  var i, j, args;
  args=collapse.arguments;
  for (j = 0; j < args.length; j++) {
    i=document.getElementById(args[j]);
    i.style.display ='none';
  }
}

// Expand/Collapse (toggle) an element
function expandCollapse(){
  var i, j, args;
  args=expandCollapse.arguments;
  for (j = 0; j < args.length; j++) {
    i=document.getElementById(args[j]);
    if( i.style.display != 'none' ) { i.style.display = 'none'; }
    else { i.style.display = 'block'; }
  }
}

// Expand/Collapse (toggle) an element with a button
function expandCollapseButton(){
  var i, j, args;
  args=expandCollapseButton.arguments;
  for (j = 0; j < args.length; j++) {
    i=document.getElementById(args[j]);
    var image = document.images[args[j]+"_img"];
    if (i != null) {
      if( i.style.display != 'none' ) { 
        i.style.display = 'none'; 
        image.src = '/images/closedArrow.png';
      }
      else { 
        i.style.display = 'block'; 
        image.src = '/images/openedArrow.png';
      }
    }
  }
}
// Expand/Collapse (toggle) a set of elements uniformly, 
function expandCollapseDiv(){

// restricted to limited set of class names
  var args = expandCollapseDiv.arguments;

// get all <div> elements
  var x = document.getElementsByTagName('div');

  for (var j = 0; j < args.length; j++) { 
    for (var i = 0; i < x.length; i++) {
// only chosen class of <div> will be modified
      if (x[i].className == args[j]) {
        if( toggle == -1 ) { x[i].style.display = 'block'; }
        else { x[i].style.display = 'none'; }
      }
    }
  }
  toggle = toggle * -1;
}

// Expand/Collapse (toggle) a set of elements uniformly
function expandCollapseAll(){

// get all <div> elements
  var x = document.getElementsByTagName('div');
  for (var i = 0; i < x.length; i++) {
// only expandable class of <div> will be modified
//    if (x[i].className == 'expandable') {
    var myRegExp = /expandable/;
    var doesItMatch = x[i].className.search(myRegExp);
    if (doesItMatch != -1) {
      if( toggle == -1 ) { x[i].style.display = 'block'; }
      else { x[i].style.display = 'none'; }
    }
  }
  toggle = toggle * -1;
}

// Expand/Collapse (toggle) a set of elements uniformly with buttons
function collapseAllButton(){

  var x = document.getElementsByTagName('*');
  for (var i = 0; i < x.length; i++) {
    
// only expandable class of <div> will be modified
//    if (x[i].className == 'expandable') {
    var myRegExp = /expandable/;
    var doesItMatch = x[i].className.search(myRegExp);
    if (doesItMatch != -1) {
      x[i].style.display = 'none'; 
      var imageId = x[i].id + "_img";
      var image = document.images[imageId];
      image.src = '/images/closedArrow.png';
    }
  }
  toggle = -1
}

// Expand/Collapse (toggle) a set of elements uniformly with buttons
function expandCollapseAllButton(){

// don't collapse if a named anchor tag is given
  var pattern = /#[^#]*$/g;
  var text = document.URL;
  var result;
  if ((result = pattern.exec(text)) != null) {
    var name = result[0].toLowerCase();
    expandCollapseButton(name);
  }

  else {

// get all <div> elements
    var x = document.getElementsByTagName('*');
    for (var i = 0; i < x.length; i++) {
    
// only expandable class of <div> will be modified
    //  if (x[i].className == 'expandable') {
    var myRegExp = /expandable/;
    var doesItMatch = x[i].className.search(myRegExp);
    if (doesItMatch != -1) {
        if( toggle == -1 ) { 
          x[i].style.display = 'block'; 
        }
        else { 
          x[i].style.display = 'none'; 
        }
        var imageId = x[i].id + "_img";
        var image = document.images[imageId];
        if( toggle == -1 ) { 
          image.src = '/images/openedArrow.png';
        }
        else {
          image.src = '/images/closedArrow.png';
        }
      }
    }
    toggle = toggle * -1;
  }
}




