Element.addMethods({
    // This function converts multiple <br>'s to a single one
    // (thus collapsing blank lines).
    collapseBlankLines: function(element){
        var element = $(element);
        var html = element.innerHTML;
        var re = /<br[^>]*>\s*<br[^>]*>/g;
        while (html.match(re)) {
            html = html.replace(re, '<br');
        }
        element.innerHTML = html;
    },
    // Return the larger of the styled height or prototype's computed height.
    // Under quirky circumstances, they don't always match.
    getComputedHeight: function(element) {
        var element = $(element);
        var styleHeight = parseInt(element.style.height);
        var protoHeight = element.getHeight();
        return ( styleHeight > protoHeight ? styleHeight : protoHeight );
    },
	
    // Return the height of the element plus the offset.
    // This will represent the "bottom" value of this element,
    // which is useful for deriving the actual height of the parent object.
    getOffsetHeight: function(element) {
        var element = $(element);
        var ht = element.getComputedHeight();
        var off = element.positionedOffset();
        return ht + off["top"];
	},
	
    // Set the height of the current element to the cumulative offset of all children.
    // This is to simplify fixing divs containing positioned content (e.g. from CMS...)
    fixContentHeight: function(element) {
        var element = $(element);
        var h = 0;

        element.descendants().each( function(elem) {
            var el = $(elem);
            // Apparently script tags have a height in IE....
            if ( el.tagName != 'SCRIPT' ) {
                var ch = el.getOffsetHeight();
                if ( ch > h ) {
                    h = ch;
                }
            }
        });
        
        element.style.height = h+'px';
    }
});
