function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        };
    }
}

function getElementsByClass(searchClass, node, tag) {
    if (!(searchClass instanceof RegExp))
        searchClass = new RegExp("\\b" + searchClass + "\\b");
        var classElements = new Array();
    if (node == null)
        node = document;
    if (tag == null)
        tag = '*';
        var els = node.getElementsByTagName(tag);
        for (i = 0, j = 0; i < els.length; i++) {
            if (searchClass.test(els[i].className)) {
                classElements[j] = els[i];
                j++;
            }
        }
    return classElements;
}

function setHeights() {
    if ( document.getElementById('promo') != null ) {
        var promo_height = document.getElementById('promo').offsetHeight;
    }
    if ( document.getElementById('editorial') != null ) {
        var editorial_height = document.getElementById('editorial').offsetHeight; 
    }
    if ( promo_height > editorial_height ) {
        var difference = promo_height - editorial_height;
    	
        // set the editorial height to the promo height
        var elm_promo = document.getElementById('promo');
    	elm_promo.style.height = promo_height - 1 + "px";
    	document.getElementById('editorial').style.height = promo_height - 1 + "px";
    	document.getElementById('nav_vertical').style.height = promo_height + 1 + "px";
    	
    	// add the difference to news_article_fixed div if it exists on page
    	if ( document.getElementById('news_article_fixed') != null ) {
    		var article_height = document.getElementById('news_article_fixed').offsetHeight; 
    		document.getElementById('news_article_fixed').style.height = article_height + difference - 1 + "px";
    	}
    }
    
    if ( editorial_height > promo_height ) {
        // set the promo height and vertical nav height to the height of editorial contents
        var elm_editorial = document.getElementById('editorial');
        // if the editorial height is below a min of 360px, set it that value
        if ( editorial_height < 360 )
            editorial_height = 360;	
        else
            editorial_height = editorial_height - 1;
    	
    	elm_editorial.style.height = editorial_height + "px";
    	document.getElementById('promo').style.height = editorial_height + "px";
    	document.getElementById('nav_vertical').style.height = editorial_height + 1 + "px";
    }
    
    if ( document.getElementById('maincontent') != null ) {
        var maincontent_height = document.getElementById('maincontent').offsetHeight;
    }
    
    if ( document.getElementById('rightrail') != null ) {
        var rightrail_height = document.getElementById('rightrail').offsetHeight;
    }
      
    if ( maincontent_height > rightrail_height ) {
        // set the rightrail divs to the height of the main content
        var elm_maincontent = document.getElementById('maincontent');
        elm_maincontent.style.height = maincontent_height + "px";
        document.getElementById('rightrail').style.height = elm_maincontent.style.height;
        document.getElementById('rightrail_whitecol').style.height = elm_maincontent.style.height;
    }
    
    if ( rightrail_height > maincontent_height ) {
        // set the maincontent div to the height of the rightrail
    	var elm_rightrail = document.getElementById('rightrail');
    	elm_rightrail.style.height = rightrail_height + "px";
    	document.getElementById('maincontent').style.height = elm_rightrail.style.height;
    	document.getElementById('rightrail_whitecol').style.height = elm_rightrail.style.height;
    }
    
    if ( document.getElementById('rightrail') != null ) {
        document.getElementById('rightrail').style.height = document.getElementById('rightrail').offsetHeight + 2 + "px";
    }
    
    if ( document.getElementById('rightrail_whitecol') != null ) {
        document.getElementById('rightrail_whitecol').style.height = document.getElementById('rightrail_whitecol').offsetHeight + 2 + "px";
    }
} // close function

addLoadEvent(setHeights);