Topic: Some questions on the form editor javascript?

I have never really put time on coding javascript...
But I kind of need a basic bbcode editor, and since punbb is open source, why not using it's javascript?

so... we have this...

<script type="text/javascript">
                        <!--
                            function insert_text(open, close)
                            {
                                msgfield = (document.all) ? document.all.req_message : document.forms['post']['req_message'];

                                // IE support
                                if (document.selection && document.selection.createRange)
                                {
                                    msgfield.focus();
                                    sel = document.selection.createRange();
                                    sel.text = open + sel.text + close;
                                    msgfield.focus();
                                }

                                // Moz support
                                else if (msgfield.selectionStart || msgfield.selectionStart == '0')
                                {
                                    var startPos = msgfield.selectionStart;
                                    var endPos = msgfield.selectionEnd;

                                    msgfield.value = msgfield.value.substring(0, startPos) + open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
                                    msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length;
                                    msgfield.focus();
                                }

                                // Fallback support for other browsers
                                else
                                {
                                    msgfield.value += open + close;
                                    msgfield.focus();
                                }

                                return;
                            }
                        -->
                        </script>

Now... I am not familiar with browsers DOM implementation, nor with DOM itself, but he above code looks at least tricky, I guess that's how all javascript ends up being.

Here's my questions dump:
-what's the first test for?, in which situation wouldn't  document.all.req_message be defined and what does document.forms['post']['req_message'] represent?
-do the browsers call different things to the form objects? Like... can anybody explain me in detail the browser test conditions?

2

Re: Some questions on the form editor javascript?

Unless I'm mistaken, (which I may well be), the: document.forms['post']['req_message'] is akin to: $_POST['req_message'] in PHP.