control.js: hush some js2-mode warnings

Add 'var' for some variables defined outside the file: shouldn't hurt,
and hushes the warnings. Also added some 'var' that were actually
needed.
control.js: rearrange code, no functional changes