Following @adeneo's remark, you might be mixing up PHP and javascript variables. It's a bit nasty but try this:
<script>
window.onload=function(){
if(<?php echo $tokens; ?> == '0'){
var ntoken= document.getElementById("token");
ntoken.style.opacity='0.4';
ntoken.style.filter='alpha(opacity=40)';
}
}
</script>
c.f. How to access PHP variables in JavaScript or jQuery rather than <?php echo $variable ?>