Refactoring display (TE)

Added a few refactorings and rebased https://github.com/elkarte/Elkarte/pull/531
Added countMessagesBefore() for https://github.com/eurich/Elkarte/commit/1038aa98e2095f04105e2da4afeb68c9533ef985, should be working - I hope!