function Joom_ShowCommentsArea_HTML($allowcomment)
    {
        $config = Joom_getConfig();
        $database =& JFactory::getDBO();
        $user =& JFactory::getUser();
        $linecolor = 0;
        ?>
      <a name="joomcomments"></a>
<?php 
        if ($user->get('username') || !$user->get('username') && $config->jg_showcommentsunreg == 0) {
            if ($config->jg_showcommentsarea == 1) {
                $order = 'DESC';
            } else {
                $order = 'ASC';
            }
            $database->setQuery(" SELECT\n                              cm.*\n                            FROM\n                              #__joomgallery_comments AS cm\n                            WHERE\n                                  cm.cmtpic    = " . $this->id . "\n                              AND cm.published = '1'\n                              AND cm.approved  = '1'\n                            ORDER BY\n                              cmtid {$order}\n                          ");
            $result1 = $database->LoadObjectList();
            $count = count($result1);
            if ($count > 0) {
                ?>
      <tr class="sectiontableheader">
        <td class="jg_cmtl">
          <?php 
                echo JText::_('JGS_AUTHOR');
                ?>
&nbsp;
        </td>
        <td class="jg_cmtr">
          <?php 
                echo JText::_('JGS_COMMENT');
                ?>
&nbsp;
        </td>
      </tr>
<?php 
                foreach ($result1 as $row1) {
                    $linecolor = $linecolor % 2 + 1;
                    ?>
      <tr class="<?php 
                    echo "sectiontableentry" . $linecolor;
                    ?>
">
        <td class="jg_cmtl">
<?php 
                    if ($row1->userid > 0) {
                        ?>
          <?php 
                        echo Joom_GetDisplayName($row1->userid, false);
                        ?>
&nbsp;
<?php 
                    } elseif ($row1->cmtname == JText::_('JGS_GUEST')) {
                        ?>
          <?php 
                        echo $row1->cmtname;
                        ?>
&nbsp;
<?php 
                    } else {
                        ?>
      <?php 
                        echo $row1->cmtname . ' (' . JText::_('JGS_GUEST') . ') ';
                        ?>
&nbsp;
<?php 
                    }
                    // Editor logged?
                    if ($user->get('gid') == 20 || $user->get('gid') == 24 || $user->get('gid') == 25) {
                        ?>
          <div class="jg_cmticons">
            <a href="http://www.db.ripe.net/whois?form_type=simple&full_query_string=&searchtext=<?php 
                        echo $row1->cmtip;
                        ?>
&do_search=Search" target="_blank">
              <img src="<?php 
                        echo _JOOM_LIVE_SITE . $this->joom_assetspath;
                        ?>
images/ip.gif" alt="<?php 
                        echo $row1->cmtip;
                        ?>
" title="<?php 
                        echo $row1->cmtip;
                        ?>
" hspace="3" border="0" /></a>
            <a href="<?php 
                        echo JRoute::_($this->joom_componenturl . '&func=deletecomment&cmtid=' . $row1->cmtid . _JOOM_ITEMID);
                        ?>
">
              <img src="<?php 
                        echo _JOOM_LIVE_SITE . $this->joom_assetspath;
                        ?>
images/del.gif" alt="<?php 
                        echo JText::_('JGS_DELETE_COMMENT');
                        ?>
" hspace="3" border="0" /></a>
          </div>
<?php 
                    }
                    ?>
        </td>
<?php 
                    $signtime = strftime($config->jg_dateformat, $row1->cmtdate);
                    $origtext = $row1->cmttext;
                    $origtext = Joom_ProcessText($origtext);
                    if ($config->jg_bbcodesupport) {
                        $origtext = Joom_BBDecode($origtext);
                    }
                    if ($config->jg_smiliesupport) {
                        $smileys = Joom_GetSmileys();
                        foreach ($smileys as $i => $sm) {
                            $origtext = str_replace($i, '<img src="' . $sm . '" border="0" alt="' . $i . '" title="' . $i . '" />', $origtext);
                        }
                    }
                    ?>
        <td class="jg_cmtr">
          <span class="small">
            <?php 
                    echo JText::_('JGS_COMMENT_ADDED');
                    ?>
: <?php 
                    echo $signtime;
                    ?>
&nbsp;
            <hr />
          </span>
          <?php 
                    echo stripslashes($origtext);
                    ?>
&nbsp;
        </td>
      </tr>
<?php 
                }
            } else {
                ?>
      <tr class="<?php 
                echo "sectiontableentry" . $linecolor;
                ?>
">
        <td colspan="2" class="jg_cmtf">
          <p>
          <?php 
                echo JText::_('JGS_NO_EXISTING_COMMENTS');
                ?>
&nbsp;
<?php 
                if ($allowcomment == 1) {
                    ?>
          <?php 
                    echo ' ' . JText::_('JGS_WRITE_FIRST_COMMENT');
                    ?>
&nbsp;
<?php 
                }
                ?>
          </p>
        </td>
      </tr>
<?php 
            }
        } else {
            ?>
      <tr class="<?php 
            echo "sectiontableentry" . $linecolor;
            ?>
">
        <td colspan="2" class="jg_cmtf">
          <p>
          <?php 
            echo JText::_('JGS_NO_COMMENTS_FOR_UNREG');
            ?>
&nbsp;
          </p>
        </td>
      </tr>
<?php 
        }
    }
function Joom_FixForJS($text, $bbcode = 0)
{
    $config = Joom_getConfig();
    if ($bbcode == 1 && $config->jg_bbcodesupport == 1) {
        if (!function_exists('Joom_BBDecode')) {
            include JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomgallery' . DS . 'common.joomgallery.php';
        }
        $text = Joom_BBDecode($text);
    }
    $text = str_replace("\"", "\\'", $text);
    $text = preg_replace("/[\n\t\r]*/", "", $text);
    return $text;
}
 function decodetext($text, $newlength = 0, $wrap = 0, $more = 0)
 {
     //Remove whitespace at start and end of the text
     $text = trim($text);
     $newlength = $newlength != 0 ? $newlength - 1 : 0;
     //Smilies if smilies are supported
     $smiley = array();
     $smiley[':smile:'] = "sm_smile.gif";
     $smiley[':cool:'] = "sm_cool.gif";
     $smiley[':grin:'] = "sm_biggrin.gif";
     $smiley[':wink:'] = "sm_wink.gif";
     $smiley[':none:'] = "sm_none.gif";
     $smiley[':mad:'] = "sm_mad.gif";
     $smiley[':sad:'] = "sm_sad.gif";
     $smiley[':dead:'] = "sm_dead.gif";
     if ($this->_config['anismilie']) {
         $smiley[':yes:'] = "sm_yes.gif";
         $smiley[':lol:'] = "sm_laugh.gif";
         $smiley[':smilewinkgrin:'] = "sm_smilewinkgrin.gif";
         $smiley[':razz:'] = "sm_bigrazz.gif";
         $smiley[':roll:'] = "sm_rolleyes.gif";
         $smiley[':eek:'] = "sm_bigeek.gif";
         $smiley[':no:'] = "sm_no.gif";
         $smiley[':cry:'] = "sm_cry.gif";
     }
     //Define replace tags
     $replace1 = array("[url]", "[/url]", "[email]", "[/email]");
     $replace21 = array("[b]", "[i]", "[u]");
     $replace22 = array("[/b]", "[/i]", "[/u]");
     $replace2 = array_merge($replace21, $replace22);
     $replace3 = array("<b>", "<i>", "<u>", "</b>", "</i>", "</u>");
     //replace url and emailtags because we do not show them in our modules
     foreach ($replace1 as $replace) {
         $text = str_replace($replace, '', $text);
     }
     $textlength = strlen($text);
     //if text has to be in a range we abridge him
     if ($newlength > 0 && $newlength < $textlength) {
         $add = '';
         //replace simple html-tags with bb_code
         for ($i = 0; $i < count($replace3); $i++) {
             $text = str_replace($replace3[$i], $replace2[$i], $text);
         }
         //replace smilies with shorttags or remove them
         if ($this->_config['smiliesupport'] == 1) {
             $count = 0;
             $smileshort = array();
             foreach ($smiley as $i => $sm) {
                 $text = str_replace($i, "{" . $count . "}", $text);
                 $smileshort[$count]["short"] = $i;
                 $smileshort[$count]["long"] = $sm;
                 $count++;
             }
         } else {
             foreach ($smiley as $i => $sm) {
                 $text = str_replace($i, '', $text);
             }
         }
         $textlength = strlen($text);
     }
     //remove any html because it is too complicated to handle them
     //except the <br /> coming from an former allowed wordwrap
     if ($wrap > 0) {
         $text = strip_tags($text, "<br>");
     } else {
         $text = strip_tags($text);
     }
     //if wrap is activated count the containing <br />
     // and add their length to $newlength
     if ($wrap > 0) {
         $countbrstr = substr($text, 0, $newlength);
         //count the <br />
         $countbr = substr_count($countbrstr, '<br />');
         if ($countbr > 0) {
             $newlength = $newlength + $countbr * 6;
         }
     }
     $textlength = strlen($text);
     // slice if needful
     if ($newlength != 0 && $textlength > $newlength + 1) {
         //Check a sliced <br />
         if ($textlength - 6 > 0 && $newlength - 6 > 0) {
             $strposfound = strpos($text, '<br />', $newlength - 6);
         } else {
             $strposfound = 0;
         }
         if ($strposfound > 0 && $strposfound < $newlength) {
             $newlength = $strposfound;
             //slice before the begin of the <br />
         } else {
             //check a sliced bbcode tag and shorten newlength
             foreach ($replace2 as $replace) {
                 $replacelength = strlen($replace);
                 if ($textlength > $newlength - $replacelength && $newlength - $replacelength > 0) {
                     $strposfound = strpos($text, $replace, $newlength - $replacelength);
                 } else {
                     $strposfound = 0;
                 }
                 if ($strposfound > 0 && $strposfound < $newlength) {
                     $newlength = $strposfound;
                     break;
                 }
             }
             //check a sliced smilie tag and shorten newlength
             if (isset($smileshort)) {
                 for ($i = 0; $i < count($smileshort); $i++) {
                     $replacelength = strlen($i) + 2;
                     if ($textlength > $newlength - $replacelength && $newlength - $replacelength > 0) {
                         $strposfound = strpos($text, "{" . $i . "}", $newlength - $replacelength);
                     } else {
                         $strposfound = 0;
                     }
                     if ($strposfound > 0 && $strposfound < $newlength) {
                         $newlength = $strposfound;
                         break;
                     }
                 }
             }
         }
         //slice the text
         $text = substr($text, 0, $newlength);
     }
     //Adding mising tags at the end of the text
     if ($this->_config['bbcodesupport'] == 1) {
         $prioarr = array();
         //builds an array for the priority in replacing
         $countreplace = count($replace21);
         for ($i = 0; $i < $countreplace; $i++) {
             //check if there is an unbalance
             //of opening and closing tags
             $countopen = substr_count($text, $replace21[$i]);
             $countclose = substr_count($text, $replace22[$i]);
             $diff = $countopen - $countclose;
             $found = -1;
             while ($diff > 0) {
                 $found = strpos($text, $replace21[$i], $found + 1);
                 $prioarr[$found] = $replace22[$i];
                 //add the closing tag
                 $diff--;
             }
         }
         if (count($prioarr)) {
             //reverse the array to begin with the last element
             arsort($prioarr);
             foreach ($prioarr as $key => $value) {
                 $add .= $value;
             }
         }
     }
     //abridge text and add missing tags
     if (!empty($add)) {
         $text = $text . $add;
     }
     //If text was sliced add the ellipsis
     if ($newlength > 0 && $textlength > $newlength && $more == 0) {
         $text .= "...";
     }
     //decoding bb_code or remove tags
     if ($this->_config['bbcodesupport'] == 1) {
         //including common.joomgallery.php for decoding bb_code function
         if (!function_exists('Joom_BBDecode')) {
             include JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomgallery' . DS . 'common.joomgallery.php';
         }
         $text = Joom_BBDecode($text);
     } else {
         foreach ($replace2 as $replace) {
             $text = str_replace($replace, '', $text);
         }
     }
     //decoding smilies or remove them
     if ($this->_config['smiliesupport'] == 1) {
         foreach ($smiley as $i => $sm) {
             $text = str_replace($i, "<img src=\"" . JURI::base() . "components/com_joomgallery/assets/images/smilies/" . $this->_config['smiliescolor'] . "/" . $sm . "\" border=\"0\" alt=\"" . $i . "\" title=\"" . $i . "\" />", $text);
         }
         if (isset($smileshort)) {
             for ($i = 0; $i < count($smileshort); $i++) {
                 $text = str_replace("{" . $i . "}", "<img src=\"" . JURI::base() . "components/com_joomgallery/assets/images/smilies/" . $this->_config['smiliescolor'] . "/" . $smileshort[$i]['long'] . "\" border=\"0\" alt=\"" . $smileshort[$i]['short'] . "\" title=\"" . $smileshort[$i]['short'] . "\" />", $text);
             }
         }
     } else {
         foreach ($smiley as $i => $sm) {
             $text = str_replace($i, '', $text);
         }
         if (isset($smileshort)) {
             for ($i = 0; $i < count($smileshort); $i++) {
                 $text = str_replace("{" . $i . "}", '', $text);
             }
         }
     }
     return $text;
 }