var tree_flag = false;
function convertToTree(id)
{
    var ul = document.getElementById(id);
    ul.className = "folders";
    var lis = ul.getElementsByTagName("LI");
    for (i = 0; i < lis.length; i++) {
        if (lis[i].getElementsByTagName("UL").length == 0) {
            lis[i].className = "file";
            lis[i].onclick = function()
            {
                tree_flag = true;
                if (typeof action == "function") {
                    var par = this.parentNode;
                    var path = this.innerHTML;
                    while (par.className != "folders") {
                        if (par.tagName == "LI") {
                            path = par.innerHTML.substring(0, par.innerHTML.indexOf("<")) + "\\" + path;
                        }
                        par = par.parentNode;
                    }
                    path = path.replace(/[\n\t\r]/ig, "");
                    action(this, path);
                }
            }
        } else {
            lis[i].className = "folder";
            lis[i].getElementsByTagName("UL")[0].style.display = "none";
            lis[i].onclick = function()
            {
                var ul = this.getElementsByTagName("UL")[0];
                if (ul.style.display == "none") {
                    ul.style.display = "block";
                    this.className = "folder-open";
                    tree_flag = true;
                    if (this.parentNode.className == "folders") tree_flag = false;
                } else {
                    if (!tree_flag) {
                        ul.style.display = "none";
                        this.className = "folder";
                        tree_flag = true;
                    } else {
                        if (this.parentNode.className == "folders") tree_flag = false;
                    }
                }
            }

        }
    }
}


function action(obj, path)
{
    alert(path);
}


