function clickElement(SuperMemoElement, ID, Type) {
    if (SuperMemoElement.open == "false") {
        expand(SuperMemoElement, ID, Type);
    }
    else {
        collapse(SuperMemoElement, ID, Type);
    }
    window.event.cancelBubble = true;
}

function expand(SuperMemoElement, ID, Type) {
    var i;

    if (Type == 'Topic') {
        PicName = 'Pic' + ID;

        document.images[PicName].src = "http://www.supermemo.com/beta/xml/img/collapse.gif";
        document.images[PicName].alt = "Collapse";
    }


    for (i = 0; i < SuperMemoElement.childNodes.length; i++) {
        if (SuperMemoElement.childNodes(i).tagName == "DIV") {
            SuperMemoElement.childNodes(i).style.display = "block";
        }
    }
    SuperMemoElement.open = "true";
}

function collapse(SuperMemoElement, ID, Type) {
    var i;

    if (Type == 'Topic') {
        PicName = 'Pic' + ID;

        document.images[PicName].src = "http://www.supermemo.com/beta/xml/img/expand.gif";
        document.images[PicName].alt = "Expand";
    }

    for (i = 0; i < SuperMemoElement.childNodes.length; i++) {
        if (SuperMemoElement.childNodes(i).tagName == "DIV") {
            SuperMemoElement.childNodes(i).style.display = "none";
        }
    }
    SuperMemoElement.open = "false";
}

function viewItem(ID) {
    var CurLocation = document.location.href;
    var Slash = '/';

    if (CurLocation.match(/\\/)) { 
        Slash = '\\';
    }

    TargetItem = CurLocation.substring(CurLocation.lastIndexOf(Slash) + 1, CurLocation.lastIndexOf('-tree.')) + '.xml#' + ID;

    document.location.href = TargetItem;
}