Not very complicated.
I broke down the output variable into several steps, itīs easier to read that way, but you can always change to one big string, if you like. I chose to simply do document.write(output) but you can send tha variable to wherever you would want it to appear. I didnīt bother with design, but it works fine.
the .htm file is included in the .zip
Enjoy!