If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

If you wrote that code then you can't be that new to JavaScript.
It would be easy to spoon-feed you the answer, but you need to learn to debug, which means checking that what you think is happenng, is happening. The easiest method to explain is to use the alert() function to display the value of variables in a failing function, which is all I did to find the immediate problem.

Where used, return should be executed unconditionally and always as the last statement in the function.