function collapseEmptyAreas() {
    // for each homemedium box, loop through it's children to find left and right divs
    var mediumDivs = getElementsByClass("homemedium", "div");
    for (var j = 0; j < mediumDivs.length; j++) {
        var mediumDiv = mediumDivs[j];
        var mediumChildren = mediumDiv.childNodes;
        var leftIsEmpty = false;
        var rightIsEmpty = false;
        var rightChild;
        for (var k = 0; k < mediumChildren.length; k++) {
            var mediumChild = mediumChildren[k];
            if (mediumChild.className == "editLeft" && isDivEmpty(mediumChild)) {
                leftIsEmpty = true;
            } else if (mediumChild.className == "editRight") {
                rightChild = mediumChild;
                if (isDivEmpty(rightChild)) {
                    rightIsEmpty = true;
                }
            }
        }
        // if the left is empty but the right isn't, move the right one over to the left
        if (leftIsEmpty && !rightIsEmpty) {
            var rightNodes = rightChild.childNodes;
            for (var i = 0; i < rightNodes.length; i++) {
                var node = rightNodes[i];
                if (node.nodeName == "DIV" && node.className.indexOf("right") >= 0) {
                    node.className = node.className.replace(/right/, "left");
                }
            }
        }
        // if both left and right are empty, hide the homemedium div
        else if (leftIsEmpty && rightIsEmpty) {
            mediumDiv.style.display = "none";
        }
    }
    // collapse the right hand area
    var rightDivs = getElementsByClass("col cthr noprint", "div");

    for (var r = 0; r < rightDivs.length; r++) {
        var rightDiv = rightDivs[r];
        if (isDivEmpty(rightDiv)) {
            rightDiv.style.display = "none";
            document.body.className = document.body.className + " nocallout";
        }
    }
}

// determine whether a div has no children or only empty children
function isDivEmpty(div) {
    var i = div.childNodes.length - 1;
    while (div.hasChildNodes()) {
        var child = div.childNodes[i];
        if (child.hasChildNodes()) break;
        var trimmed = ((child.nodeValue == null) ? "" : child.nodeValue.replace(/^\s*|\s*$/g, ''));
        if (trimmed.length == 0) {
            div.removeChild(child);
        } else {
            break;
        }
        i--;
    }
    return (!div.hasChildNodes());
}
