
function stopProp() {
    if(event && event.stopPropagation) {
        event.stopPropagation();
        return;
    }
    if(window && window.event) {
        window.event.cancelBubble = true;
    }
}

function removeClassIE(el,remove) {
    var newClassName = "";
    var i;
    var classes = el.className.split(" ");
    for(i = 0; i < classes.length; i++) {
        if(classes[i] !== remove) {
            newClassName += classes[i] + " ";
        }
    }
    el.className = newClassName;
}

function toggleTree(el) {
    //Don't toggle parents
    stopProp();
    
    //Toggle it
    if(el.classList) {
        if(el.classList.contains("collapsed")) {
            el.classList.remove("collapsed");
        } else {
            el.classList.add("collapsed");
        }
    } else {
        //Old IE workaround
        if(el.className) {
            if(el.className.indexOf("collapsed") != -1) {
                removeClassIE(el,"collapsed");
            } else {
                el.className += " collapsed";
            }
        }
    }
}
