[eluser]bigtony[/eluser]
You should not be defining functions within a view. Views are just for presenting data, so the only PHP code in them should be stuff directly concerned with how it looks (htmlentities(), number_format(), foreach loops through recordsets, that kind of thing).
Instead, move your variable setup & functions to your controller and then pass that data into the view, then just echo it from there.