/*---------------------------------------------------------------------------*/
function extractData(n)
{
    var s = "";

    if (n.hasChildNodes())
    {
        for (var i = 0; i < n.childNodes.length; ++i)
        {
            s += extractData(n.childNodes.item(i));
        }
    }
    else
    {
        s += n.data;
    }

    return s;
}


/*---------------------------------------------------------------------------*/
function mQuestion_anchor()
{
    this.q.setAttribute("id", this.number);
}

function mQuestion_toNode()
{
    var n = document.createElement("li");

    var a = document.createElement("a");
    a.setAttribute("href", "#" + this.number);
    a.innerHTML = extractData(this.q);
    a.className = "jumpto";

    n.appendChild(a);
    this.anchor();

    return n;
}

function Question(node, number)
{
    this.node = node;
    this.number = "faq" + number;
    this.q = null;
    this.a = null;

    var n = null;
    for (var i = 0; i < this.node.childNodes.length; ++i)
    {
        n = this.node.childNodes.item(i);

        if (("DIV" == n.nodeName) && ("question" == n.className))
        {
            this.q = n;
        }
        else if (("DIV" == n.nodeName) && ("answer" == n.className))
        {
            this.a = n;
        }
    }

    this.toNode = mQuestion_toNode;
    this.anchor = mQuestion_anchor;
}


/*---------------------------------------------------------------------------*/
function getQuestions()
{
    var a = new Array();
    var f = document.getElementById("faqs");

    var c = 0;

    var n = null;
    for (var i = 0; i < f.childNodes.length; ++i)
    {
        n = f.childNodes.item(i);

        if (("DIV" == n.nodeName) && ("faq" == n.className))
        {
            a[a.length] = new Question(n, ++c);
        } 
    }

    return a;
}


function generateTOC()
{
    var toc = document.getElementById("toc");
    var qs = getQuestions();

    var list = document.createElement("ul");
    toc.appendChild(list);

    for (var i in qs)
    {
        list.appendChild(qs[i].toNode());
    }
}


generateTOC();

/*---------------------------------------------------------------------------*/
// eof
