function advert_edit(&$row, &$lists, $option)
    {
        $app = JFactory::getApplication();
        JFilterOutput::objectHTMLSafe($row, ENT_QUOTES, 'custombannercode');
        JHTML::_('behavior.tooltip');
        JHTML::_('behavior.calendar');
        $db =& JFactory::getDBO();
        $wbAdvert = new wbAdvert_advert($db);
        ?>
    <script>
      var dimRatio = '<?php 
        echo $row->width ? $row->height / $row->width : 0;
        ?>
';
      function dimCheck( myObj ){
        if( !dimRatio )return;
        var form = document.adminForm;
        if( form.constrain.checked == true ){
          if( myObj.name == 'height' )
            form.width.value = Math.round(myObj.value / dimRatio);
          else
            form.height.value = Math.round(myObj.value * dimRatio);
        }
      }
      function getSelectedValue(formName,fieldName){
        var form = document[formName];
        if( form[fieldName].selectedIndex >= 0 )
          return form[fieldName].options[form[fieldName].selectedIndex].value;
        return 0;
      }
      Joomla.submitbutton = function(pressbutton) {
        var form = document.adminForm;
        if (pressbutton == 'advert.cancel') {
          submitform( pressbutton );
          return;
        }
        // do field validation
        if (form.name.value == "") {
          alert( "<?php 
        echo JText::_('FLD_VAL_ADVERTNAME');
        ?>
" );
        }
        else if (getSelectedValue('adminForm','client_id') < 1) {
          alert( "<?php 
        echo JText::_('FLD_VAL_ADVERTCLIENT');
        ?>
" );
        }
        else if (getSelectedValue('adminForm','idx_group') < 1) {
          alert( "<?php 
        echo JText::_('FLD_VAL_ADVERTGROUP');
        ?>
" );
        }
        else if (form.id.value == '' && form.code.value == '' && form.advert_file.value == ''){
          alert( "<?php 
        echo JText::_('FLD_VAL_ADVERTADMEDIA');
        ?>
" );
        }
        else {
          submitform( pressbutton );
        }
      }
      function toggleAllDays(el){
        var isAll = el.checked;
        var fields = document.adminForm['weekdays[]'];
        for(var i=1;i<fields.length;i++){
          fields[i].checked = isAll?false:true;
          fields[i].disabled = isAll?true:false;
        }
      }
    </script>
    <style>
      .adminform select.idx_menu { width:400px; height:190px; }
      .adminform select.idx_category { width:400px; height:190px; }
      .adminform textarea.idx_content { width:400px;height:80px; }
      .adminform textarea.code { width:360px;height:140px; }
    </style>
    <form action="<?php 
        echo JRoute::_('index.php?option=com_wbadvert&task=advert.edit');
        ?>
" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">
      <table class="adminHeading" width="100%">
        <tr><th class="icon-48-advert">
          <?php 
        echo $row->id ? JText::sprintf('HEAD_ADVERTEDIT', $row->name) : JText::_('HEAD_ADVERTNEW');
        ?>
<br/>
          <font size="-1"><?php 
        echo $row->id ? JText::_('LBL_ADVERTLINK') . ': <a href="' . JURI::root() . 'index.php?option=' . $option . '&task=load&id=' . $row->id . '" target="_blank">index.php?option=' . $option . '&task=load&id=' . $row->id . '</a>' : '&nbsp;';
        ?>
</font>
        </th></tr>
      </table>
      <div class="col100">
        <table class="adminTable" width="100%">
          <tr><td valign="top" width="50%">
            <fieldset class="adminForm">
              <legend><?php 
        echo JText::_('SET_ADVERTDETAIL');
        ?>
</legend>
              <table class="adminTable" width="100%">
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_ADVERTNAME'), JText::_('FLD_ADVERTNAME_TIP'));
        ?>
</td>
                  <td><input class="inputbox" type="text" name="name" size="30" value="<?php 
        echo $row->name;
        ?>
" required="true"></td>
                </tr>
                <tr>
                  <td valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_ADVERTGROUPIDX'), JText::_('FLD_ADVERTGROUPIDX_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['idx_group'];
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_ADVERTCLIENT'), JText::_('FLD_ADVERTCLIENT_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['client_id'];
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_PUBLISHED'), JText::_('FLD_PUBLISHED_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['published'];
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_IMPTOTAL'), JText::_('FLD_IMPTOTAL_TIP'));
        ?>
</td>
                  <td><input class="inputbox" type="text" name="imptotal" size="12" maxlength="11" value="<?php 
        echo $row->imptotal ? $row->imptotal : null;
        ?>
">
                    <span><?php 
        echo JText::_('FLD_IMPTOTAL_NOTE');
        ?>
</span></td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_IMPMADE'), JText::_('FLD_IMPMADE_TIP'));
        ?>
</td>
                  <td>
                    <?php 
        echo '<b> ' . (int) $row->impmade . ' </b>';
        if ($row->id) {
            echo '&nbsp;&nbsp;&nbsp;<input type="button" onClick="submitbutton(\'advert.reset\');" value="' . JText::_('BTN_RESETCOUNTER') . '" />';
        }
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_DATESTART'), JText::_('FLD_DATESTART_TIP'));
        ?>
</td>
                  <td><?php 
        echo JHTML::_('calendar', $row->date_start, 'date_start', 'date_start_cal', '%Y-%m-%d', array('class' => 'inputbox'));
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_DATESTOP'), JText::_('FLD_DATESTOP_TIP'));
        ?>
</td>
                  <td><?php 
        echo JHTML::_('calendar', $row->date_stop == 'Never' ? null : $row->date_stop, 'date_stop', 'date_stop_cal', '%Y-%m-%d', array('class' => 'inputbox'));
        ?>
</td>
                </tr>
              </table>
            </fieldset>
            <fieldset class="adminForm">
              <legend><?php 
        echo JText::_('SET_ADVERTMEDIA');
        ?>
</legend>
              <table class="adminTable" width="100%">
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_URL'), JText::_('FLD_URL_TIP'));
        ?>
</td>
                  <td><input class="inputbox" type="text" name="url" size="30" maxlength="200" value="<?php 
        echo $row->url;
        ?>
"></td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_TARGET'), JText::_('FLD_TARGET_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['target'];
        ?>
</td>
                </tr>
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_CAPTION'), JText::_('FLD_CAPTION_TIP'));
        ?>
</td>
                  <td><input class="inputbox" type="text" name="caption" size="30" maxlength="200" value="<?php 
        echo $row->caption;
        ?>
"></td>
                </tr>
                <tr>
                  <td nowrap valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_UPLOADFILE'), JText::_('FLD_UPLOADFILE_TIP'));
        ?>
</td>
                  <td>
                    <input class="inputbox" type="file" name="advert_file" size="30" /><br/>
                    <span><?php 
        echo JText::_('FLD_UPLOADFILE_NOTE');
        ?>
</span>
                  </td>
                </tr>
                <tr>
                  <td nowrap valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_DIMENSIONS'), JText::_('FLD_DIMENSIONS_TIP'));
        ?>
</td>
                  <td>
                    <input class="inputbox" type="text" name="width" size="5" value="<?php 
        echo $row->width;
        ?>
" onkeypress="dimCheck(this);" onchange="dimCheck(this);" /> x
                    <input class="inputbox" type="text" name="height" size="5" value="<?php 
        echo $row->height;
        ?>
" onkeypress="dimCheck(this);" onchange="dimCheck(this);" /><br/>
                    <input type="checkbox" id="constrain" name="constrain" <?php 
        echo $row->height && $row->width ? 'checked' : '';
        ?>
> <label for="constrain"><?php 
        echo JText::_('CHK_CONSTRAIN');
        ?>
</label>
                  </td>
                </tr>
                <tr><th colspan="2"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_CODE'), JText::_('FLD_CODE_TIP'));
        ?>
</th></tr>
                <tr><td colspan="2"><textarea class="inputbox code" name="code"><?php 
        echo $row->code;
        ?>
</textarea></td></tr>
              </table>
            </fieldset>
          </td>
          <td valign="top" width="50%">
            <fieldset class="adminForm">
              <legend><?php 
        echo JText::_('SET_ADVERTFILTERS');
        ?>
</legend>
              <table class="adminTable" width="100%">
                <tr>
                  <td><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_WEEKDAYS'), JText::_('FLD_WEEKDAYS_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['weekdays'];
        ?>
</td>
                </tr>
                <tr>
                  <td>
                    <?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_TIMESTART'), JText::_('FLD_TIMESTART_TIP'));
        ?>
 /
                    <?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_TIMESTOP'), JText::_('FLD_TIMESTOP_TIP'));
        ?>
                    </td>
                  <td>
                    <?php 
        echo $lists['time_start'];
        ?>
 /
                    <?php 
        echo $lists['time_stop'];
        ?>
                    </td>
                </tr>
                <tr>
                  <td valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_IDXMENU'), JText::_('FLD_IDXMENU_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['idx_menu'];
        ?>
</td>
                </tr>
                <tr>
                  <td valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_IDXCATEGORY'), JText::_('FLD_IDXCATEGORY_TIP'));
        ?>
</td>
                  <td><?php 
        echo $lists['idx_category'];
        ?>
</td>
                </tr>
                <tr>
                  <td valign="top"><?php 
        echo wbAdvert_Common::getFormLabel(JText::_('FLD_IDXCONTENT'), JText::_('FLD_IDXCONTENT_TIP'));
        ?>
</td>
                  <td><textarea class="inputbox idx_content" name="idx_content"><?php 
        echo $row->idx_content;
        ?>
</textarea></td>
                </tr>
              </table>
            </fieldset>
          </td></tr>
        </table>
      </div>
      <input type="hidden" name="option" value="<?php 
        echo $option;
        ?>
">
      <input type="hidden" name="id" value="<?php 
        echo $row->id;
        ?>
">
      <input type="hidden" name="task" value="advert.apply">
      <?php 
        echo JHTML::_('form.token');
        ?>
    </form>
    <?php 
        if ($row->id) {
            ?>
    <fieldset class="adminForm">
      <legend><?php 
            echo JText::_('SET_ADVERTMEDIA');
            ?>
</legend>
      <table class="adminTable report" width="100%">
        <tbody>
          <tr>
            <td><label><?php 
            echo JText::_('SET_ADVERTSAMPLE');
            ?>
 - <?php 
            echo $row->file_type;
            ?>
</label></td>
            <td><?php 
            echo $wbAdvert->getAdvertCode($row->id);
            ?>
</td>
          </tr>
          <?php 
            if (!$row->code) {
                ?>
          <tr>
            <td><label><?php 
                echo JText::_('SET_ADVERTCODE');
                ?>
</label></td>
            <td><textarea class="inputbox" style="width:100%;height:100px;"><?php 
                echo $wbAdvert->getAdvertCode($row->id);
                ?>
</textarea></td>
          </tr>
          <?php 
            }
            ?>
        </tbody>
      </table>
    </fieldset>
    <?php 
        }
        ?>
    <?php 
    }
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
// ************************************************************************************************
//
// Public Kernel
//
// ************************************************************************************************
$_inc = JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_wbadvert' . DS . 'load.php';
if (!is_readable($_inc)) {
    $msg = '<h1 alert="alert">' . JText::_('ERR_LOADFAILED') . '</h1>';
    die($msg);
} else {
    // Include Classes
    require_once $_inc;
    // Load DB Class
    $db =& JFactory::getDBO();
    $wbAdvert = new wbAdvert_advert($db);
    $_id = JRequest::getInt('id', 0);
    $_task = JRequest::getCmd('task', 'click');
    $_func = array_shift(explode('\\.', $_task));
    switch ($_func) {
        case 'system':
            $control = new wbAdvert_System();
            $control->process($_task);
            break;
        case 'code':
            // Override SWF Loader Option
            $wbAdvert_config->set('swf_jsloader', 0);
            // Load & Return Code
            $code = $wbAdvert->getAdvertCode((int) $_id);
            if (!strlen($code)) {
                die('<h1 alert="alert">' . JText::_('ERR_NOTFOUND') . '</h1>');
  ----------------------------------------------------------------------------------------
*/
// Block Direct Access
defined('_JEXEC') or die('Access Denied');
// Block Direct Access
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
// Application
$app = JFactory::getApplication();
// Pull Parameters
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
$params->def('debug', 0);
// Get DBO
$db =& JFactory::getDBO();
// Include Classes
require_once JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_wbadvert' . DS . 'load.php';
$wbAdvert = new wbAdvert_advert($db);
// Include Component Langyuage
$jLang = JFactory::getLanguage();
$jLang->load('com_wbadvert', JPATH_SITE, 'en-GB', true);
// Pull Shown Advertisements
$wbAdvert_config = wbAdvert_config::getInstance();
if (!count($wbAdvert_config->shown)) {
    $wbAdvert_config->shown = array();
}
// Configuration
$cat_strict = $params->get('cat_strict', $wbAdvert_config->get('cat_strict', 1));
$wrap_module = $params->get('wrap_module', $wbAdvert_config->get('wrap_module', 0));
$wrap_advert = $params->get('wrap_advert', $wbAdvert_config->get('wrap_advert', 0));
$show_alert = $params->get('show_alert', $wbAdvert_config->get('show_alert', 1));
$minSize = explode(',', $params->get('min_size', 2));
$maxSize = explode(',', $params->get('max_size', 2));