How can I capture JavaScript value for use on tpl.php
What you can do in this particular case is add the HTML for both the images inside tpl file.
On the js file, you can display/hide the images according to your IF condition.

To capture JS value for use in tpl, you can use javascript/ajax to send the information through a url / xmlhttp and then use hook menu to grab the information inside module file, then send the variable to the tpl