
// Arrays for nodes and icons
var nodes        = new Array();;
var openNodes    = new Array();
var icons        = new Array(6);

// Loads all icons that are used in the tree
function Informacoes() {

 var Tree = new Array;

Tree[0] = '1|0|Manual Finance|conteudo.htm';
Tree[1] = '2|1|Índice Geral|../Manual Finance HTML/Indice/Indice.html';
Tree[2] = '3|1|Instalação|../Manual Finance HTML/Indice_Geral/Html/Instala.html#';
Tree[3] = '4|1|Segurança dos Dados|../Manual Finance HTML/Indice_Geral/Html/seguranca.html#';
Tree[4] = '5|1|Test Drive|../Manual Finance HTML/Arvore/testdrive.html#';
Tree[5] = '6|1|Conciliação Bancária|../Manual Finance HTML/Cadastros/Html/Conciliacao.html#';
Tree[6] = '7|1|Arquivo|../Manual Finance HTML/Arvore/arquivo.html#';
Tree[7] = '8|1|Cadastros|../Manual Finance HTML/Arvore/Cadastros.html#';
Tree[8] = '9|1|Negócios|../Manual Finance HTML/Arvore/Negocios.html#';
Tree[9] = '10|1|Analisar|../Manual Finance HTML/Arvore/Analises.html#';
Tree[10] = '11|1|Indicadores|../Manual Finance HTML/Arvore/Indicadores.html#';
Tree[11] = '12|1|Utilitarios|../Manual Finance HTML/Arvore/Utilitarios.html#';
Tree[12] = '13|1|Dicas|../Manual Finance HTML/Arvore/Dicas.html#';
Tree[13] = '14|1|Problemas|../Manual Finance HTML/Arvore/Problemas_com_Finance.html#';
Tree[14] = '15|1|Sistema de Gestão|../Manual Finance HTML/Arvore/Sistema_de_Gestao.html#';

Tree[15] = '16|0|Manual Business|conteudo.htm';
Tree[16] = '17|16|Índice Geral|../Manual Business HTML/Índice Geral- ok/indice.html#';
Tree[17] = '18|16|Instalação|../Manual Business HTML/Instalação/HTML/instalacao.html#';
Tree[18] = '19|16|Segurança dos Dados|../Manual Business HTML/Arquivo/html/seguranca.html#';
Tree[19] = '20|16|Test Drive|../Manual Business HTML/Arvore/testedrive.html#';
Tree[20] = '21|16|Arquivo|../Manual Business HTML/Arvore/iniciando.html#';
Tree[21] = '22|16|Cadastros|../Manual Business HTML/cadastros/html/cadastro.html#';
Tree[22] = '23|16|Produtos & Serviços|../Manual Business HTML/Produtos & Serviços/HTML/CadastroProdutos&Servicos.html#';
Tree[23] = '24|16|Negócios|../Manual Business HTML/Negócios/html/negocios.html#';
Tree[24] = '25|16|Análise|../Manual Business HTML/Análise/html/analisar.html#';
Tree[25] = '26|16|Utilitários|../Manual Business HTML/Utilitários/html/utilitarios.html#';
Tree[26] = '27|16|Sistema Gestão|../Manual Business HTML/Sistema Gestão/html/sistemagestao.htm#';

Tree[27] = '28|0|Manual Accounting|conteudo.htm';
Tree[28] = '29|28|Índice Geral|../Manual Accounting HTML/indice.html#';
Tree[29] = '30|28|Instalação|../Manual Accounting HTML/instalacao.html#';
Tree[30] = '31|28|Segurança dos Dados|../Manual Accounting HTML/seguranca.html#';
Tree[31] = '32|28|Iniciando|../Manual Accounting HTML/iniciando.html#';
Tree[32] = '33|28|Cadastros|../Manual Accounting HTML/cadastros.html#';
Tree[33] = '34|28|Contabilidade|../Manual Accounting HTML/contabilidade.html#';
Tree[34] = '35|28|Utilitarios|../Manual Accounting HTML/utilitarios.html#';

//Tree[35] = '36|0|Manual Business PDV|conteudo.htm';
//Tree[36] = '37|36|Índice Geral|../Manual Business PDV HTML/indice.html#';
//Tree[37] = '38|36|Introdução|../Manual Business PDV HTML/introducao/index.html#';
//Tree[38] = '39|36|Instalação|../Manual Business PDV HTML/instalacao/index.html#';
//Tree[39] = '40|36|Iniciando|../Manual Business PDV HTML/iniciando/index.html#';
//Tree[40] = '41|36|Controle de Caixa|../Manual Business PDV HTML/contcaixa/index.html#';
//Tree[41] = '42|36|Utilitários|../Manual Business PDV HTML/utilitarios/index.html#';
//Tree[42] = '43|36|Ajuda|../Manual Business PDV HTML/ajuda/index.html#';
//Tree[43] = '44|36|Finalizando|../Manual Business PDV HTML/finalizando/index.html#';

Tree[35] = '36|0|Manual HelpDesk|conteudo.htm';
Tree[36] = '37|36|HelpDesk Client|../Manual HelpDesk HTML/indice.html';
Tree[37] = '38|36|HelpDesk Server|../Manual HelpDesk HTML/indiceserver.htm#';

Tree[38] = '39|0|Manual MarketDesk|conteudo.htm';
Tree[39] = '40|39|Índice Geral|../Manual MarketDesk HTML/indice.html#';

Tree[40] = '41|0|Manual Control|conteudo.htm';
Tree[41] = '42|41|Índice Geral|../Manual Control HTML/indice.html#';
Tree[42] = '43|41|Íntrodução|../Manual Control HTML/introducao/index.html#';
Tree[43] = '44|41|Ínstalação|../Manual Control HTML/instalacao/index.html#';
Tree[44] = '45|41|Iniciando|../Manual Control HTML/iniciando/index.html#';
Tree[45] = '46|41|Cadastros|../Manual Control HTML/cadastros/index.html#';
Tree[46] = '47|41|Peças & Material Cons.|../Manual Control HTML/pecasematerialconsumo/index.html#';
Tree[47] = '48|41|Controles|../Manual Control HTML/controles/index.html#';
Tree[48] = '49|41|Analisar|../Manual Control HTML/analisar/index.html#';
Tree[49] = '50|41|Utilitários|../Manual Control HTML/utilitarios/index.html#';
Tree[50] = '51|41|Ajuda|../Manual Control HTML/ajuda/index.html#';
Tree[51] = '52|41|Dicas|../Manual Control HTML/dicas/index.html#';

Tree[52] = '53|0|Manual Cockpit|conteudo.htm';
Tree[53] = '54|53|Índice Geral|../Manual Cockpit HTML/indice.html#';

Tree[54] = '55|0|Manual iFinance - iPhone|conteudo.htm';
Tree[55] = '56|55|Índice Geral|../Manual iFinance - iPhone HTML/indice.html#';
Tree[56] = '57|55|Introdução|../Manual iFinance - iPhone HTML/introducao.html#';
Tree[57] = '58|55|Instalação|../Manual iFinance - iPhone HTML/instalacao.html#';
Tree[58] = '59|55|Contas|../Manual iFinance - iPhone HTML/contas.html#';
Tree[59] = '60|55|Plano de Contas|../Manual iFinance - iPhone HTML/planodecontas.html#';
Tree[60] = '61|55|Centro de Custos|../Manual iFinance - iPhone HTML/centrocustos.html#';
Tree[61] = '62|55|Transações|../Manual iFinance - iPhone HTML/transacoes.html#';
Tree[62] = '63|55|Análises|../Manual iFinance - iPhone HTML/analises.html#';
Tree[63] = '64|55|Opções|../Manual iFinance - iPhone HTML/opcoes.html#';
Tree[64] = '65|55|Sincronização|../Manual iFinance - iPhone HTML/sincronizacao.html#';

Tree[65] = '66|0|Manual iFinance - iPad|conteudo.htm';
Tree[66] = '67|66|Índice Geral|../Manual iFinance - iPad HTML/indice.html#';
Tree[67] = '68|66|Introdução|../Manual iFinance - iPad HTML/introducao.html#';
Tree[68] = '69|66|Instalação|../Manual iFinance - iPad HTML/instalacao.html#';
Tree[69] = '70|66|Contas|../Manual iFinance - iPad HTML/contas.html#';
Tree[70] = '71|66|Plano de Contas|../Manual iFinance - iPad HTML/planodecontas.html#';
Tree[71] = '72|66|Centro de Custos|../Manual iFinance - iPad HTML/centrocustos.html#';
Tree[72] = '73|66|Transações|../Manual iFinance - iPad HTML/transacoes.html#';
Tree[73] = '74|66|Análises|../Manual iFinance - iPad HTML/analises.html#';
Tree[74] = '75|66|Opções|../Manual iFinance - iPad HTML/opcoes.html#';
Tree[75] = '76|66|Sincronização|../Manual iFinance - iPad HTML/sincronizacao.html#';

Tree[76] = '77|0|Manual Document|conteudo.htm';
Tree[77] = '78|77|Índice Geral|../Manual Document HTML/indice.html#';
Tree[78] = '79|77|Introdução|../Manual Document HTML/introducao.html#';
Tree[79] = '80|77|Instalação|../Manual Document HTML/instalacao.html#';
Tree[80] = '81|77|Configurações|../Manual Document HTML/configuracoes.html#';
Tree[81] = '82|77|Tipos de Documento|../Manual Document HTML/tipos_de_documento.html#';
Tree[82] = '83|77|Documentos|../Manual Document HTML/documentos.html#';
Tree[83] = '84|77|Sincronização|../Manual Document HTML/sincronizacao.html#';

Tree[84] = '85|0|Company|company.html#';
Tree[85] = '86|0|Contrato|contrato.html#';
Tree[86] = '87|0|Garantia|garantia.html#';

 return Tree;

}

function preloadIcons() {
    icons[0] = new Image();
    icons[0].src = "img/plus.gif";
    icons[1] = new Image();
    icons[1].src = "img/plusbottom.gif";
    icons[2] = new Image();
    icons[2].src = "img/minus.gif";
    icons[3] = new Image();
    icons[3].src = "img/minusbottom.gif";
    icons[4] = new Image();
    icons[4].src = "img/folder.gif";
    icons[5] = new Image();
    icons[5].src = "img/folderopen.gif";
}
// Create the tree
function createTree(arrName, startNode, openNode) {
    //nodes = arrName;
      nodes = Informacoes();
    if (nodes.length > 0) {
        preloadIcons();
        if (startNode == null) startNode = 0;
        if (openNode != 0 || openNode != null) setOpenNodes(openNode);
    
        if (startNode !=0) {
            var nodeValues = nodes[getArrayId(startNode)].split("|");
            document.write("<a target='main' href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\"><img src=\"img/folderopen.gif\" align=\"absbottom\" alt=\"\" />" + nodeValues[2] + "</a><br />");
        } else document.write("<img src=\"img/base.gif\" align=\"absbottom\" alt=\"\" />Manuais<br />");
    
        var recursedNodes = new Array();
        addNode(startNode, recursedNodes);
    }
}
// Returns the position of a node in the array
function getArrayId(node) {
    for (i=0; i<nodes.length; i++) {
        var nodeValues = nodes[i].split("|");
        if (nodeValues[0]==node) return i;
    }
}
// Puts in array nodes that will be open
function setOpenNodes(openNode) {
    for (i=0; i<nodes.length; i++) {
        var nodeValues = nodes[i].split("|");
        if (nodeValues[0]==openNode) {
            openNodes.push(nodeValues[0]);
            setOpenNodes(nodeValues[1]);
        }
    } 
}
// Checks if a node is open
function isNodeOpen(node) {
    for (i=0; i<openNodes.length; i++)
        if (openNodes[i]==node) return true;
    return false;
}
// Checks if a node has any children
function hasChildNode(parentNode) {
    for (i=0; i< nodes.length; i++) {
        var nodeValues = nodes[i].split("|");
        if (nodeValues[1] == parentNode) return true;
    }
    return false;
}
// Checks if a node is the last sibling
function lastSibling (node, parentNode) {
    var lastChild = 0;
    for (i=0; i< nodes.length; i++) {
        var nodeValues = nodes[i].split("|");
        if (nodeValues[1] == parentNode)
            lastChild = nodeValues[0];
    }
    if (lastChild==node) return true;
    return false;
}
// Adds a new node in the tree
function addNode(parentNode, recursedNodes) {
    for (var i = 0; i < nodes.length; i++) {

        var nodeValues = nodes[i].split("|");
        if (nodeValues[1] == parentNode) {
            
            var ls    = lastSibling(nodeValues[0], nodeValues[1]);
            var hcn    = hasChildNode(nodeValues[0]);
            var ino = isNodeOpen(nodeValues[0]);

            // Write out line & empty icons
            for (g=0; g<recursedNodes.length; g++) {
                if (recursedNodes[g] == 1) document.write("<img src=\"img/line.gif\" align=\"absbottom\" alt=\"\" />");
                else  document.write("<img src=\"img/empty.gif\" align=\"absbottom\" alt=\"\" />");
            }

            // put in array line & empty icons
            if (ls) recursedNodes.push(0);
            else recursedNodes.push(1);

            // Write out join icons
            if (hcn) {
                if (ls) {
                    document.write("<a  href=\"javascript: oc(" + nodeValues[0] + ", 1);\"><img id=\"join" + nodeValues[0] + "\" src=\"img/");
                         if (ino) document.write("minus");
                        else document.write("plus");
                    document.write("bottom.gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
                } else {
                    document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 0);\"><img id=\"join" + nodeValues[0] + "\" src=\"img/");
                        if (ino) document.write("minus");
                        else document.write("plus");
                    document.write(".gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
                }
            } else {
                if (ls) document.write("<img src=\"img/join.gif\" align=\"absbottom\" alt=\"\" />");
                else document.write("<img src=\"img/joinbottom.gif\" align=\"absbottom\" alt=\"\" />");
            }

            // Start link
            document.write("<a target='main' href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
            
            // Write out folder & page icons
            if (hcn) {
                document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/folder")
                    if (ino) document.write("open");
                document.write(".gif\" align=\"absbottom\" alt=\"Folder\" />");
            } else document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/page.gif\" align=\"absbottom\" alt=\"Page\" />");
            
            // Write out node name
            document.write(nodeValues[2]);

            // End link
            document.write("</a><br />");
            
            // If node has children write out divs and go deeper
            if (hcn) {
                document.write("<div id=\"div" + nodeValues[0] + "\"");
                    if (!ino) document.write(" style=\"display: none;\"");
                document.write(">");
                addNode(nodeValues[0], recursedNodes);
                document.write("</div>");
            }
            
            // remove last line or empty icon 
            recursedNodes.pop();
        }
    }
}
// Opens or closes a node
function oc(node, bottom) {
    var theDiv = document.getElementById("div" + node);
    var theJoin    = document.getElementById("join" + node);
    var theIcon = document.getElementById("icon" + node);
    
    if (theDiv.style.display == 'none') {
        if (bottom==1) theJoin.src = icons[3].src;
        else theJoin.src = icons[2].src;
        theIcon.src = icons[5].src;
        theDiv.style.display = '';
    } else {
        if (bottom==1) theJoin.src = icons[1].src;
        else theJoin.src = icons[0].src;
        theIcon.src = icons[4].src;
        theDiv.style.display = 'none';
    }
}
// Push and pop not implemented in IE(crap!    don´t know about NS though)
if(!Array.prototype.push) {
    function array_push() {
        for(var i=0;i<arguments.length;i++)
            this[this.length]=arguments[i];
        return this.length;
    }
    Array.prototype.push = array_push;
}
if(!Array.prototype.pop) {
    function array_pop(){
        lastElement = this[this.length-1];
        this.length = Math.max(this.length-1,0);
        return lastElement;
    }
    Array.prototype.pop = array_pop;
}

