I read that you should define your JavaScript functions in the tag, but how does the location of the
(whether in the
Javascript's scoping rules are similar to perl - you can call any function at the current or any higher scope level. The only restriction is that the function has to be defined at the time you call it. The position in the source is irrelevant - only the position in time matters.
You should avoid putting scripts in the if possible as it slows down page display (see the link Alan posted).