[eluser]Simian Studios[/eluser]
If you just need to have "#advertisement#" or the like replaced with an actual ad code, the easiest way is to just do a str_replace() on the page content when you retrieve it from the DB, and before the content gets rendered in the view.
So you would do something like:
Code:
str_replace('#advertisement#', '<<<your ad invocation code here>>>', $this->data['page_content']);
No JS needed, and you can extend it, for example to have different types of ads, etc.