My didn't you get up on the wrong side of the bed this morning. I didn't post any code because others had already posted excellent suggestions. I didn't see anyone suggest using strict so I added that to the advice given the OP.
Also I don't feel that personal attacks on me are warranted. If you don't like what I post fine. Why not send your personal attacks top me directly instead of wasting everyone's bandwidth?