<?php $this->block('table'); ?>

<table cellspacing="0" cellpadding="0" id="ctrl_<?php echo $this->strId; ?>" class="tl_tablelookupwizard tl_listing">
    <thead>
        <tr>
            <th class="head_0 col_first tl_folder_tlist">&nbsp;</th>

            <?php foreach($this->columnLabels as $k => $arrColumnLabel): ?>
            <th class="head_<?php echo $k; ?> tl_folder_tlist <?php echo $arrColumnLabel['rowClass']; ?>"><?php echo $arrColumnLabel['label']; ?></th>
            <?php endforeach; ?>
            <?php if ($this->enableSorting): ?>
            <th class="tl_folder_tlist"></th>
            <?php endif; ?>
        </tr>
    </thead>
    <tbody>

        <?php echo $this->body; ?>

        <tr class="jserror">
            <td colspan="<?php echo $this->colspan + 1; ?>">
                <p class="tl_error"><?php echo $GLOBALS['TL_LANG']['MSC']['tlwNoJs']; ?></p>;

                <?php if ($this->fallbackEnabled): ?>
                <a href="<?php echo $this->noAjaxUrl; ?>"><?php echo $GLOBALS['TL_LANG']['MSC']['tlwJsAlternative']; ?></a>
                <?php endif; ?>
             </td>
        </tr>

        <?php if ($this->fieldType == 'radio'): ?>
        <tr class="reset">
            <td><input type="radio" class="radio" name="reset_<?php echo $this->strId; ?>" id="reset_<?php echo $this->strId; ?>" value=""<?php if (!$this->hasValues): ?> checked="checked"<?php endif; ?>></td>
            <td colspan="<?php echo $this->colspan; ?>"><label for="reset_<?php echo $this->strId; ?>" class="tl_change_selected"><?php echo $GLOBALS['TL_LANG']['MSC']['resetSelected']; ?></label></td>
        </tr>
        <?php endif; ?>

        <tr class="search" style="display:none">
            <td colspan="<?php echo $this->colspan + 1; ?>"><label for="ctrl_<?php echo $this->strId; ?>_search"><?php echo $this->searchLabel; ?>:</label>
                <input type="text" id="ctrl_<?php echo $this->strId; ?>_search" name="keywords" class="tl_text" autocomplete="off">
            </td>
        </tr>
    </tbody>
</table>

<?php $this->endblock(); ?>

<?php if (!$this->noAjax): ?>

<?php $this->block('no_ajax'); ?>

<link rel="stylesheet" href="system/modules/tablelookupwizard/assets/tablelookup.min.css">
<script>
window.addEvent('domready', function() {
    function init() {
        new TableLookupWizard('<?php echo $this->strId; ?>', {
            enableSorting: <?php echo $this->enableSorting ? 'true' : 'false'; ?>
        });
    }

    if (!window.TableLookupWizard) {
        var wizard = document.createElement('script');
        wizard.type = 'text/javascript';
        wizard.src = 'system/modules/tablelookupwizard/assets/tablelookup.min.js';
        wizard.onload = init;
        wizard.onreadystatechange = init;

        var script = document.getElementsByTagName('script')[0];
        script.parentNode.insertBefore(wizard, script);
    } else {
        init();
    }
});
</script>

<?php $this->endblock(); ?>

<?php endif; ?>
