// show or hide the entire tree except for the root node
function websn_showhideAll() {
  if (document.getElementById('treecontainer').style.display == "block") {
    document.getElementById('treecontainer').style.display = "none";
  }
  else {
    document.getElementById('treecontainer').style.display = "block";
  }
}

// toggle folder images open / closed
function websn_toggleImgs(el) {
  var allImg = document.body.getElementsByTagName("IMG"); // get all images in the tree page
  for (i=0; i<allImg.length; i++) {
     if (allImg[i].className == "fldricon") { // if it is a folder icon
	   allImg[i].src = "images/fldr_closed.gif"; // change it to the closed version
	}
  }
  el.src = "images/fldr_open.gif"; // set the newly selected folder image to the open version
}

// show and hide sub folders
function showhidesub(targetEl, srcEl) {
  var chk = srcEl.src;
  if (document.getElementById(targetEl).style.display == 'none') { // if the current sub is hidden
    document.getElementById(targetEl).style.display = 'block'; // show it
	
	if (chk.indexOf('middle') == -1) {
       srcEl.src = "images/bottom_minus.gif";  // change to bottom minus icon
	}
	else {
       srcEl.src = "images/middle_minus.gif"; // change to middle minus icon
	}
  }
  else {
    document.getElementById(targetEl).style.display = 'none'; //  hide it
	
	if (chk.indexOf('middle') == -1) {
       srcEl.src = "images/bottom_plus.gif"; // change to bottom plus icon
	}
	else {
       srcEl.src = "images/middle_plus.gif"; // change to middle plus icon
	}
  }
}

// hide the folder tree frame and show the folders button in control.asp
function hidefrm() {
  parent.main.cols = "0,*";
  parent.control.document.all['flders'].style.visibility = "visible"
}

// align the tree container so that scrollbars appear in the right place if needed
function alignScroll() {
  var ht = parseInt(document.body.clientHeight) - 25 ;
  document.getElementById('treeholder').style.height = ht;
}

// synchronise the tree with the file list after an update or folder change
function websn_sync(path, opt) {
  // sync with +/- signs
  pre = "plus"
  pre2 = "join"
  if (path != "" && path != null && path != "undefined") { // we have a path to set
    arrPath = path.split("/");
    id = "";
    for (i=0;i<arrPath.length;i++) {
      id += arrPath[i]; // build id string (path without slashes)
    }
  }
  else {
    document.getElementById('link0').focus(); // set focus to the root node
	return;
  }
  if (document.getElementById(pre + id)) { // if the item exists and is a has a plusicon
       var el = pre + id;
       el = document.getElementById(el); // get the item
	   var isPlus = el.src.indexOf('_plus') != -1
	   var isMinus = el.src.indexOf('_minus') != -1
        
	    if (opt == 1 && isPlus) { // called from loadsync where the current icon is a plus
	      el.click(); // simulate a click
		  el  = el.parentElement.parentElement.lastChild;
		  el.focus(); // send focus to the link associated with the current folder
	    }
		
	    if (opt == 2 && isMinus) { // called from control.asp when the 'up' button is pressed
	      el = el.parentElement.parentElement.lastChild;
		  el.focus(); // send focus to the link associated with the current folder
	    }
  }
  else if (document.getElementById(pre2 + id)) { // if the item exists and has a join icon
       var el = pre2 + id;
       el = document.getElementById(el); // get the element
	   el  = el.parentElement.parentElement.lastChild;
	   el.focus(); // send focus to the link associated with the current folder
  }
}

// sync with the file list onload
function websn_loadsync(path) {
  var arrloc = path.split("/");
  str = "";
  for (i=0;i<arrloc.length-1;i++) {
    str += arrloc[i]; // build current string
	setTimeout("websn_sync('" + str + "',1)", 200); // call the synchronisation routine.
  } 
}