
/***************************************************************
*  Copyright notice
*
*  (c) 2003-2004 Jean-Michel Garnier (garnierjm@yahoo.fr)
*  All rights reserved
*
*  This script is part of the phpXplorer project. The phpXplorer 
project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt distributed with these 
scripts.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

// ---------------------------------------------------------------------------

// --- Name:    Easy DHTML Treeview                                         --

// --- Original idea by : D.D. de Kerf                  --

// --- Updated by Jean-Michel Garnier, garnierjm@yahoo.fr                   --

// ---------------------------------------------------------------------------

/*****************************************************************************

Name : toggle

Parameters :  node , DOM element (<a> tag)

Description :     Description, collapse or unfold a branch

Author : Jean-Michel Garnier /  D.D. de Kerf

*****************************************************************************/

function changeImage (node, imagefile) {

		if (node.childNodes.length > 0) {

			if (node.childNodes.item(0).nodeName == "IMG") {

				node.childNodes.item(0).src = getImgDirectory(node.childNodes.item(0).src) + imagefile;

			}

		}
}


function toggle(node) {

    // Get the next tag (read the HTML source)

	var nextDIV = node.nextSibling;



	// find the next DIV

	while(nextDIV.nodeName != "DIV") {

		nextDIV = nextDIV.nextSibling;
 
	}
	
	// Unfold the branch if it isn't visible
	
	var dispstat = nextDIV.style.display;
	
	switch(dispstat) {
		
		case 'none':
			changeImage(node,"tvminus.gif");
			nextDIV.style.display = 'block';
			break;
		case '':
			changeImage(node,"tvminus.gif");
			nextDIV.style.display = 'block';
			break;
		case 'block':
			changeImage(node,"tvplus.gif");
			nextDIV.style.display = 'none';
			break;
	}



/* 
	if (dispstat == 'none' || dispstat == '') {

		// Change the image (if there is an image)

		if (node.childNodes.length > 0) {

			if (node.childNodes.item(0).nodeName == "IMG") {

				node.childNodes.item(0).src = getImgDirectory(node.childNodes.item(0).src) + "tvminus.gif";

			}

		}

		nextDIV.style.display = 'block'; 

	// Collapse the branch if it IS visible

	} else {

		// Change the image (if there is an image)

		if (node.childNodes.length > 0) {

			if (node.childNodes.item(0).nodeName == "IMG") {

				node.childNodes.item(0).src = getImgDirectory(node.childNodes.item(0).src) + "tvplus.gif";

			}

		}

		nextDIV.style.display = 'none';

	}
*/

} // end function toggle(node)



/*****************************************************************************

Name : getImgDirectory

Parameters : Image source path

Return : Image source Directory

Author : Jean-Michel Garnier

*****************************************************************************/



function getImgDirectory(source) {

    return source.substring(0, source.lastIndexOf('/') + 1);

}