sub() is undefined due to a syntax error in the function. Try changing:
if !(techlevel==0)
to
if (techlevel!=0)
Incidentally, if you do your HTML programming in a syntax-highlighting IDE like NetBeans or Eclipse, the IDE will spot a lot of errors like this for you.