[imp] Improve the "Is debug" check for the templates

Rebase of: https://github.com/joomla/joomla-cms/pull/3820

### Tracker

http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33869&start=0

### How to test
1. enable debug
2. make sure that the debug css is load if debug is on for all templates.