document.write is dead - it is only needed for Netscape 4 and earlier.
alert is for debugging only - that's why is displays extra checkboxes in most browsers.
A long series of if statements comparing the same field to different values is better written as a switch statement. Where the statement it runs is the same except for the value being assigned the code would be better rearranged to use a single statement and an array instead of the long series of if statements.
I would recommend completely rewriting that code and testing it a piece at a time making sure each piece works before moving on to the next. To do what you want that script to do only requires about 1/5 to 1/4 the amount of code that you currently have.
Helping others to solve their computer problem at http://www.felgall.com/