Well, in all honesty, your code is scruffy as hell (tried not to say that) - Using OOP will help you to organise your code in a more structured and understandable way to avoid the messy layout of your code; using cases may also help you to avoid all that elseif/if bumpf.

http://www.koyote.dk/index.php?sid=51

RipX