Moved method to jwic_controls.js. Also added comments to method to make then easier to understand(i hope)