function Joom_BuildCommentsForm_HTML($allowcomment)
    {
        $config = Joom_getConfig();
        $database =& JFactory::getDBO();
        $user =& JFactory::getUser();
        $linecolor = 0;
        if (!$allowcomment) {
            ?>
        <tr class="sectiontableentry1">
          <td class="jg_cmtf" colspan="2">
            <?php 
            echo JText::_('JGS_NO_COMMENTS_BY_GUEST');
            ?>
&nbsp;
          </td>
        </tr>
<?php 
            return;
        }
        if ($config->jg_secimages == 2 || $config->jg_secimages == 1 && $user->get('aid') < 1) {
            if (file_exists(JPATH_ROOT . DS . 'components' . DS . 'com_easycaptcha' . DS . 'class.easycaptcha.php')) {
                include_once JPATH_ROOT . DS . 'components' . DS . 'com_easycaptcha' . DS . 'class.easycaptcha.php';
                $captcha = new easyCaptcha();
            } else {
                $config->jg_secimages = 0;
            }
        }
        ?>
      <a name="joomcommentform"></a>
<?php 
        $bbcodestatus = array(JText::_('JGS_BBCODE_OFF'), JText::_('JGS_BBCODE_ON'));
        if (isset($_COOKIE['sessioncookie']) && $_COOKIE['sessioncookie'] != '') {
            $cryptSessionID = md5($_COOKIE['sessioncookie']);
            $database->setQuery(" SELECT\n                              username\n                            FROM\n                              #__session\n                            WHERE\n                              session_ID = " . $cryptSessionID . "\n                          ");
            $cmtname = $database->LoadResult();
            //$cmtname = $result2->cmtname;
        }
        ?>
        <form name="commentform" action="<?php 
        echo JRoute::_($this->joom_componenturl . '&func=commentpic&id=' . $this->id . _JOOM_ITEMID);
        ?>
" target="_top" method="post">
<?php 
        if ($config->jg_secimages == 2 || $config->jg_secimages == 1 && $user->get('aid') < 1) {
            ?>
          <input type="hidden" name="jg_captcha_id" value="<?php 
            echo $captcha->getCaptchaId();
            ?>
" />
<?php 
        }
        if (!$user->get('username')) {
            $ip = $_SERVER['REMOTE_ADDR'];
            ?>
          <input type="hidden" name="cmtip" value="<?php 
            echo $ip;
            ?>
" />
<?php 
        }
        $linecolor = $linecolor % 2 + 1;
        ?>
        <tr class="sectiontableentry1">
          <td class="jg_cmtl">
            <?php 
        echo $user->get('username');
        ?>
&nbsp;
<?php 
        if ($user->get('aid') < 1) {
            if ($config->jg_namedanoncomment) {
                ?>
            <input type="text" class="inputbox" name="cmtname" value="<?php 
                echo JText::_('JGS_GUEST');
                ?>
" />
<?php 
            } else {
                ?>
            <input type="hidden" class="inputbox" name="cmtname" value="<?php 
                echo JText::_('JGS_GUEST');
                ?>
" />
<?php 
            }
        } else {
            ?>
            <input type="hidden" class="inputbox" name="cmtname" value="<?php 
            echo $user->get('username');
            ?>
" />
<?php 
        }
        if ($config->jg_smiliesupport) {
            ?>
            <div style="padding:0.4em 0;">
<?php 
            $count = 1;
            $smileys = Joom_GetSmileys();
            foreach ($smileys as $i => $sm) {
                ?>
              <a href="javascript:joom_smilie('<?php 
                echo $i;
                ?>
')" title="<?php 
                echo $i;
                ?>
">
                <img src="<?php 
                echo $sm;
                ?>
" border="0" alt="<?php 
                echo $sm;
                ?>
" /></a><?php 
                if ($count % 4 == 0) {
                    ?>
              <br />
<?php 
                }
                $count++;
            }
            ?>
            </div>
<?php 
        }
        ?>
            <p class="small">
              <?php 
        echo JText::_('JGS_BBCODE_IS');
        ?>
              <b><?php 
        echo $bbcodestatus[$config->jg_bbcodesupport];
        ?>
</b>.
            </p>
          </td>
          <td class="jg_cmtr">
<?php 
        if ($config->jg_smiliesupport) {
            $rows = 8;
        } else {
            $rows = 4;
        }
        ?>
            <p>
              <textarea cols="40" rows="<?php 
        echo $rows;
        ?>
" name="cmttext" class="inputbox" onfocus="jg_comment_active=1" onchange="jg_comment_active=0" onblur="jg_comment_active=0"></textarea>
            </p>
          </td>
        </tr>
<?php 
        if ($config->jg_secimages == 2 || $config->jg_secimages == 1 && $user->get('aid') < 1) {
            ?>
        <tr class="<?php 
            echo "sectiontableentry" . $linecolor;
            ?>
">
          <td class="jg_cmtl">
            &nbsp;
          </td>
          <td class="jg_cmtr">
            <img src="<?php 
            echo $captcha->getImageUrl();
            ?>
" alt="<?php 
            echo $captcha->getAltText();
            ?>
" border="0" id="jg_captcha_image" />
          </td>
        </tr>
<?php 
            $linecolor = $linecolor % 2 + 1;
            ?>
        <tr class="sectiontableentry1">
          <td class="jg_cmtl">
            <?php 
            echo JText::_('JGS_ENTER_CODE');
            ?>
&nbsp;
          </td>
          <td class="jg_cmtr">
            <input class="inputbox" type='text' value="" name='jg_code' />
            <?php 
            echo $captcha->getReloadButton("jg_captcha_image");
            ?>
            <?php 
            echo $captcha->getReloadCode();
            ?>
          </td>
        </tr>
<?php 
        }
        ?>
        <tr class="sectiontableentry1">
          <td class="jg_cmtl">
          </td>
          <td class="jg_cmtr">
            <p>
              <input type="button" name="send" value="<?php 
        echo JText::_('JGS_COMMENT_SEND');
        ?>
" class="button" onclick="joom_validatecomment()" />
              &nbsp;
              <input type="reset" value="<?php 
        echo JText::_('JGS_DELETE');
        ?>
" name="reset" class="button" />
            </p>
          </td>
        </tr>
        </form>
<?php 
    }
    function Joom_CommentPic($id)
    {
        $config = Joom_getConfig();
        $mainframe =& JFactory::getApplication('site');
        $database =& JFactory::getDBO();
        $user =& JFactory::getUser();
        //Check for hacking attempt
        $database->setQuery(" SELECT\n                            COUNT(id)\n                          FROM \n                            #__joomgallery AS a\n                          LEFT JOIN \n                            #__joomgallery_catg AS c ON c.cid=a.catid\n                          WHERE \n                                a.published = '1' \n                            AND a.approved  = '1'\n                            AND a.id        = '" . $id . "' \n                            AND c.access   <= '" . $user->get('aid') . "'\n                       ");
        $result = $database->loadResult();
        if ($result != 1 || $config->jg_showcomment == 0 || $config->jg_anoncomment == 0 && $user->get('aid') < 1) {
            die('Hacking attempt, aborted!');
        }
        $codeisright = 1;
        if ($config->jg_secimages == 2 || $config->jg_secimages == 1 && $user->get('aid') < 1) {
            if (file_exists(JPATH_ROOT . DS . 'components' . DS . 'com_easycaptcha' . DS . 'class.easycaptcha.php')) {
                include_once JPATH_ROOT . DS . 'components' . DS . 'com_easycaptcha' . DS . 'class.easycaptcha.php';
                $captcha = new easyCaptcha($this->jg_captcha_id);
                $codeisright = $captcha->checkEnteredCode($this->jg_code) ? 1 : 0;
            }
        }
        if ($codeisright == 1) {
            // Save new values
            $cmtip = $_SERVER['REMOTE_ADDR'];
            $cmtdate = time();
            if ($config->jg_approvecom == 0 || $config->jg_approvecom == 1 && $user->get('aid') > 0) {
                $approve = 1;
            } elseif ($config->jg_approvecom == 1 && $user->get('aid') < 1 || $config->jg_approvecom == 2) {
                $approve = 0;
                // message about new comment TODO
                $cmtsenderid = $user->get('aid') < 1 ? "62" : $user->get('id');
                require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_messages' . DS . 'tables' . DS . 'message.php';
                $database->setQuery(" SELECT \n                                id \n                              FROM \n                                #__users \n                              WHERE \n                                sendEmail = '1'\n                            ");
                $users = $database->loadResultArray();
                foreach ($users as $user_id) {
                    $msg = new TableMessage($database);
                    $msg->send($cmtsenderid, $user_id, JText::_('JGS_ALERT_NEW_COMMENT'), JText::_('JGS_ALERT_NEW_COMMENT_MESSAGE_PARTONE') . $this->cmtname . JText::_('JGS_ALERT_NEW_COMMENT_MESSAGE_PARTTWO'));
                }
            }
            //change \r\n or \n to <br />
            $this->cmttext = nl2br(stripslashes($this->cmttext));
            $database->setQuery(" INSERT INTO \n                              #__joomgallery_comments\n                            VALUES(\n                                    '', \n                                    '{$id}', \n                                    '{$cmtip}',\n                                    '{$this->userid}', \n                                    '{$this->cmtname}', \n                                    '{$this->cmttext}', \n                                    '{$cmtdate}', \n                                    '1', \n                                    '{$approve}'\n                                   )\n                         ");
            $database->query();
            # Get back to details page
            if ($config->jg_approvecom == 0 || $config->jg_approvecom == 1 && $user->get('aid') > 0) {
                $mosmsg = JText::_('JGS_ALERT_COMMENT_SAVED');
            } else {
                $mosmsg = JText::_('JGS_ALERT_COMMENT_SAVED_BUT_NEEDS_ARROVAL');
            }
            $mainframe->redirect(JRoute::_('index.php?option=com_joomgallery&func=detail&id=' . $id . _JOOM_ITEMID, false), $mosmsg);
        } else {
            ?>
          <form id="send_form" name="commentform" action="<?php 
            echo JRoute::_('index.php?option=com_joomgallery&func=detail&id=' . $id . _JOOM_ITEMID . '#joomcommentform');
            ?>
" method="post" class="jg_displaynone">
            <textarea cols="40" rows="8" name="cmttext" class="inputbox" wrap="virtual">
              <?php 
            echo $this->cmttext;
            ?>
            </textarea>
          </form>
         <script type="text/javascript">
           alert("<?php 
            echo JText::_('JGS_ALERT_SECURITY_CODE_WRONG', true);
            ?>
");
           document.getElementById('send_form').submit();
         </script>
<?php 
        }
    }