add that line (posted by Claus_N) before your "function main()"

I bet your other questions can be answered in the templates forum