Improved the escaping of variables used in JS code

Some of these variables where not being escaped, or only partially.
Merge pull request #43 from stof/value_escaping

Improved the escaping of variables used in JS code