Set all your Javascript functionality between {literal}{/literal} tags.
If you don't, then smarty will try to parse curly brackets. So this:
javascript Code:
function foo(){
var bar = "baz";
}
Will be parsed to {var ... }
And that of course doesn't exist.