+ };
+
+ /*
+ * Set initial focus to the first form focusable element.
+ * Try/catch used just to avoid errors in IE 7- which return visibility
+ * 'inherit' when the visibility value is inherited from an ancestor.
+ */
+ try {
+ for ( var i = 0; i < commentForm.elements.length; i++ ) {
+ element = commentForm.elements[i];
+ cssHidden = false;
+
+ // Modern browsers.
+ if ( 'getComputedStyle' in window ) {
+ style = window.getComputedStyle( element );
+ // IE 8.
+ } else if ( document.documentElement.currentStyle ) {
+ style = element.currentStyle;
+ }
+
+ /*
+ * For display none, do the same thing jQuery does. For visibility,
+ * check the element computed style since browsers are already doing
+ * the job for us. In fact, the visibility computed style is the actual
+ * computed value and already takes into account the element ancestors.
+ */
+ if ( ( element.offsetWidth <= 0 && element.offsetHeight <= 0 ) || style.visibility === 'hidden' ) {
+ cssHidden = true;
+ }
+
+ // Skip form elements that are hidden or disabled.
+ if ( 'hidden' === element.type || element.disabled || cssHidden ) {
+ continue;
+ }
+
+ element.focus();
+ // Stop after the first focusable element.
+ break;
+ }