  <br>
  
  <table border=1 cellspacing=1 cellpadding=2 width=928 style="border: 1px inset;">

  <? //$trade_list1 = $mytradeModel->getlist_tradesbylevel(1,"","tradecode"); ?>

  <? $catindex=0; ?>
  <? foreach ($trade_list1 as $mytrade) { ?>

    <tr valign=top>
    <td valign=top width=928 class=newscontent style="border-bottom: 1px solid;">

      <table border=0 cellspacing=0 cellpadding=0 width=918>
      <tr valign=top>
      <td valign=top class=newscontent width=858>
      <img id="open<?=$mytrade['tradepkey'];?>" src="gfx/tree/open2.png" border=0 width=16 height=16 title="Open" alt="Open" align=left style="display: none; cursor: pointer;" onClick="javascript:trade_tree_open('<?=$mytrade['tradepkey'];?>');">
      <img id="close<?=$mytrade['tradepkey'];?>" src="gfx/tree/close.png" border=0 width=16 height=16 title="Open" alt="Close" align=left style="display: block; cursor: pointer;" onClick="javascript:trade_tree_close('<?=$mytrade['tradepkey'];?>');">
      &nbsp;&nbsp;<b><?=$mytrade['tradecode']." - ".$mytrade['tradedescription'];?></b>&nbsp;&nbsp;
      </td>
      <td valign=top class=newscontent width=60>
      <img src="gfx/tree/b_view.png" border=0 width=16 height=16 title="View" alt="View" style="display: inline; cursor: pointer;" onClick="location.href='index.php?module=trade&task=view&itemid=<?=$mytrade['tradepkey'];?>';">&nbsp;<img src="gfx/tree/b_edit.png" border=0 width=16 height=16 title="Edit" alt="Edit" style="display: inline; cursor: pointer;" onClick="location.href='index.php?module=trade&task=edit&itemid=<?=$mytrade['tradepkey'];?>';">&nbsp;<img src="gfx/tree/b_drop.png" border=0 width=16 height=16 title="Delete" alt="Delete" style="display: inline; cursor: pointer;" onClick="javascript:trade_tree_delete('<?=$mytrade['tradepkey'];?>');"><br>
      </td>
      </tr>
      </table>

    </td>
    </tr>

    <tr valign=top>
    <td valign=top width=928 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">

    <? //$trade_list2 = $mytradeModel->getlist_tradesbylevel(2,"","tradecode"); ?>
    <? $trade_list2 = $mytradeModel->getlist_tradesbyparent($mytrade['tradepkey'],"","tradecode"); ?>

    <div id="<?=$mytrade['tradepkey'];?>" style="display: block; border-bottom: 1px solid; line-height: 18px;">
    <table border=0 cellspacing=1 cellpadding=2 width=918>

    <? $trade2index=0; ?>
    <? foreach ($trade_list2 as $mytrade2) { ?>

      <? if ($mytrade2['tradeparentpkey']==$mytrade['tradepkey']) { ?>

        <tr valign=top>
        <td valign=top width=908 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">

          <table border=0 cellspacing=0 cellpadding=0 width=908>
          <tr valign=top>
          <td valign=top class=newscontent width=20>&nbsp;</td>
          <td valign=top class=newscontent width=828>
          <img id="open<?=$mytrade2['tradepkey'];?>" src="gfx/tree/open2.png" border=0 width=16 height=16 title="Open" alt="Open" align=left style="display: block; cursor: pointer;" onClick="javascript:trade_tree_open('<?=$mytrade2['tradepkey'];?>');">
          <img id="close<?=$mytrade2['tradepkey'];?>" src="gfx/tree/close.png" border=0 width=16 height=16 title="Close" alt="Close" align=left style="display: none; cursor: pointer;" onClick="javascript:trade_tree_close('<?=$mytrade2['tradepkey'];?>');">
          &nbsp;&nbsp;<?=unescape($mytrade2['tradecode'])." - ".unescape($mytrade2['tradedescription']);?>&nbsp;&nbsp;
		  <!-- test -->
		  <?=$mytrade2['tradetype'];?> | <?=$mytrade2['tradeunit'];?>
          </td>
          <td valign=top class=newscontent width=60>
          <img src="gfx/tree/b_view.png" border=0 width=16 height=16 title="View" alt="View" style="display: inline; cursor: pointer;" onClick="location.href='index.php?module=trade&task=view&itemid=<?=$mytrade2['tradepkey'];?>';">&nbsp;<img src="gfx/tree/b_edit.png" border=0 width=16 height=16 title="Edit" alt="Edit" style="display: inline; cursor: pointer;" onClick="location.href='index.php?module=trade&task=edit&itemid=<?=$mytrade2['tradepkey'];?>';">&nbsp;<img src="gfx/tree/b_drop.png" border=0 width=16 height=16 title="Delete" alt="Delete" style="display: inline; cursor: hand;" onClick="javascript:trade_tree_delete('<?=$mytrade2['tradepkey'];?>');"><br>
          </td>
          </tr>
          </table>

        </td>
        </tr>

        <tr valign=top>
        <td valign=top width=908 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">

        <? //$trade_list3 = $mytradeModel->getlist_tradesbylevel(3,"","tradecode"); ?>
        <? $trade_list3 = $mytradeModel->getlist_tradesbyparent($mytrade2['tradepkey'],"","tradecode"); ?>

        <div id="<?=$mytrade2['tradepkey'];?>" style="display: none; border-bottom: 1px solid; line-height: 18px;">
        <table border=0 cellspacing=1 cellpadding=2 width=898>

        <? $trade3index=0; ?>
        <? foreach ($trade_list3 as $mytrade3) { ?>

          <? if ($mytrade3['tradeparentpkey']==$mytrade2['tradepkey']) { ?>

            <tr valign=top>
            <td valign=top width=898 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">

              <table border=0 cellspacing=0 cellpadding=0 width=888>
              <tr valign=top>
              <td valign=top class=newscontent width=40>&nbsp;</td>
              <td valign=top class=newscontent width=788>
              <img id="open<?=$mytrade3['tradepkey'];?>" src="gfx/tree/open2.png" border=0 width=16 height=16 title="Open" alt="Open" align=left style="display: block; cursor: pointer;" onClick="javascript:trade_tree_open('<?=$mytrade3['tradepkey'];?>');">
              <img id="close<?=$mytrade3['tradepkey'];?>" src="gfx/tree/close.png" border=0 width=16 height=16 title="Close" alt="Close" align=left style="display: none; cursor: pointer;" onClick="javascript:trade_tree_close('<?=$mytrade3['tradepkey'];?>');">
              &nbsp;&nbsp;<?=unescape($mytrade3['tradecode'])." - ".unescape($mytrade3['tradedescription']);?>&nbsp;&nbsp;
              <!-- test -->
		      <?=$mytrade3['tradetype'];?> | <?=$mytrade3['tradeunit'];?>
			  </td>
              <td valign=top class=newscontent width=60>
              <img src="gfx/tree/b_view.png" border=0 width=16 height=16 title="View" alt="View" style="display: inline; cursor: pointer;" onClick="location.href='index.php?module=trade&task=view&itemid=<?=$mytrade3['tradepkey'];?>';">&nbsp;<img src="gfx/tree/b_edit.png" border=0 width=16 height=16 title="Edit" alt="Edit" style="display: inline; cursor: pointer;" onClick="location.href='index.php?module=trade&task=edit&itemid=<?=$mytrade3['tradepkey'];?>';">&nbsp;<img src="gfx/tree/b_drop.png" border=0 width=16 height=16 title="Delete" alt="Delete" style="display: inline; cursor: hand;" onClick="javascript:trade_tree_delete('<?=$mytrade3['tradepkey'];?>');"><br>
              </td>
              </tr>
              </table>

            </td>
            </tr>

            <tr valign=top>
            <td valign=top width=888 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">

            <? //$trade_list4 = $mytradeModel->getlist_tradesbylevel(4,"","tradecode"); ?>
            <? $trade_list4 = $mytradeModel->getlist_tradesbyparent($mytrade3['tradepkey'],"","tradecode"); ?>

            <div id="<?=$mytrade3['tradepkey'];?>" style="display: none; border-bottom: 1px solid; line-height: 18px;">
            <table border=0 cellspacing=1 cellpadding=2 width=878>

            <? $trade4index=0; ?>
            <? foreach ($trade_list4 as $mytrade4) { ?>

              <? if ($mytrade4['tradeparentpkey']==$mytrade3['tradepkey']) { ?>

                <tr valign=top>
                <td valign=top width=878 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">

                  <table border=0 cellspacing=0 cellpadding=0 width=868>
                  <tr valign=top>
                  <td valign=top class=newscontent width=60>&nbsp;</td>
                  <td valign=top class=newscontent width=748>
                  <img id="open<?=$mytrade4['tradepkey'];?>" src="gfx/tree/open2.png" border=0 width=16 height=16 title="Open" alt="Open" align=left style="display: block; cursor: pointer;" onClick="javascript:trade_tree_open('<?=$mytrade4['tradepkey'];?>');">
                  <img id="close<?=$mytrade4['tradepkey'];?>" src="gfx/tree/close.png" border=0 width=16 height=16 title="Close" alt="Close" align=left style="display: none; cursor: pointer;" onClick="javascript:trade_tree_close('<?=$mytrade4['tradepkey'];?>');">
                  &nbsp;&nbsp;<?=unescape($mytrade4['tradecode'])." - ".unescape($mytrade4['tradedescription']);?>&nbsp;&nbsp;
                  <!-- test -->
					<?=$mytrade4['tradetype'];?> | <?=$mytrade4['tradeunit'];?>
				  </td>
                  <td valign=top class=newscontent width=60>
                  <img src="gfx/tree/b_view.png" border=0 width=16 height=16 title="View" alt="View" style="display: inline; cursor: pointer;" onClick="location.href='index.php?module=trade&task=view&itemid=<?=$mytrade4['tradepkey'];?>';">&nbsp;<img src="gfx/tree/b_edit.png" border=0 width=16 height=16 title="Edit" alt="Edit" style="display: inline; cursor: pointer;" onClick="location.href='index.php?module=trade&task=edit&itemid=<?=$mytrade4['tradepkey'];?>';">&nbsp;<img src="gfx/tree/b_drop.png" border=0 width=16 height=16 title="Delete" alt="Delete" style="display: inline; cursor: hand;" onClick="javascript:trade_tree_delete('<?=$mytrade4['tradepkey'];?>');"><br>
                  </td>
                  </tr>
                  </table>

                </td>
                </tr>

                <tr valign=top>
                <td valign=top width=868 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">

                <? //$trade_list5 = $mytradeModel->getlist_tradesbylevel(5,"","tradecode"); ?>
                <? $trade_list5 = $mytradeModel->getlist_tradesbyparent($mytrade4['tradepkey'],"","tradecode"); ?>

                <div id="<?=$mytrade4['tradepkey'];?>" style="display: none; border-bottom: 1px solid; line-height: 18px;">
                <table border=0 cellspacing=1 cellpadding=2 width=858>

                <? $trade5index=0; ?>
                <? foreach ($trade_list5 as $mytrade5) { ?>

                  <? if ($mytrade5['tradeparentpkey']==$mytrade4['tradepkey']) { ?>

                    <tr valign=top>
                    <td valign=top width=858 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">

                      <table border=0 cellspacing=0 cellpadding=0 width=848>
                      <tr valign=top>
                      <td valign=top class=newscontent width=80>&nbsp;</td>
                      <td valign=top class=newscontent width=708>
                      <img id="open<?=$mytrade5['tradepkey'];?>" src="gfx/tree/open2.png" border=0 width=16 height=16 title="Open" alt="Open" align=left style="display: block; cursor: pointer;" onClick="javascript:trade_tree_open('<?=$mytrade5['tradepkey'];?>');">
                      <img id="close<?=$mytrade5['tradepkey'];?>" src="gfx/tree/close.png" border=0 width=16 height=16 title="Close" alt="Close" align=left style="display: none; cursor: pointer;" onClick="javascript:trade_tree_close('<?=$mytrade5['tradepkey'];?>');">
                      &nbsp;&nbsp;<?=unescape($mytrade5['tradecode'])." - ".unescape($mytrade5['tradedescription']);?>&nbsp;&nbsp;
                      <!-- test -->
						<?=$mytrade5['tradetype'];?> | <?=$mytrade5['tradeunit'];?>
					  </td>
                      <td valign=top class=newscontent width=60>
                      <img src="gfx/tree/b_view.png" border=0 width=16 height=16 title="View" alt="View" style="display: inline; cursor: pointer;" onClick="location.href='index.php?module=trade&task=view&itemid=<?=$mytrade5['tradepkey'];?>';">&nbsp;<img src="gfx/tree/b_edit.png" border=0 width=16 height=16 title="Edit" alt="Edit" style="display: inline; cursor: pointer;" onClick="location.href='index.php?module=trade&task=edit&itemid=<?=$mytrade5['tradepkey'];?>';">&nbsp;<img src="gfx/tree/b_drop.png" border=0 width=16 height=16 title="Delete" alt="Delete" style="display: inline; cursor: hand;" onClick="javascript:trade_tree_delete('<?=$mytrade5['tradepkey'];?>');"><br>
                      </td>
                      </tr>
                      </table>

                    </td>
                    </tr>

                  <? } ?>

                <? } ?>
                <? reset($trade_list5); ?>

                <tr valign=top>
                <td valign=top width=868 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button name="add5<?=$mytrade4['tradepkey'];?>" id="add5<?=$mytrade4['tradepkey'];?>" onClick="trade_button_add('<?=$mytrade4['tradepkey'];?>',5);">Add Level 5 Category..</button><br>
                </td>
                </tr>
                </table>
                </div>

                </td>
                </tr>

              <? } ?>

            <? } ?>
            <? reset($trade_list4); ?>

            <tr valign=top>
            <td valign=top width=888 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button name="add4<?=$mytrade3['tradepkey'];?>" id="add4<?=$mytrade3['tradepkey'];?>" onClick="trade_button_add('<?=$mytrade3['tradepkey'];?>',4);">Add Level 4 Category..</button><br>
            </td>
            </tr>
            </table>
            </div>

            </td>
            </tr>

          <? } ?>

        <? } ?>
        <? reset($trade_list3); ?>

        <tr valign=top>
        <td valign=top width=908 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button name="add3<?=$mytrade2['tradepkey'];?>" id="add3<?=$mytrade2['tradepkey'];?>" onClick="trade_button_add('<?=$mytrade2['tradepkey'];?>',3);">Add Level 3 Category..</button><br>
        </td>
        </tr>
        </table>
        </div>

        </td>
        </tr>

      <? } ?>

    <? } ?>
    <? reset($trade_list2); ?>

    <tr valign=top>
    <td valign=top width=928 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button name="add2<?=$mytrade['tradepkey'];?>" id="add2<?=$mytrade['tradepkey'];?>" onClick="trade_button_add('<?=$mytrade['tradepkey'];?>',2);">Add Level 2 Category..</button><br>
    </td>
    </tr>
    </table>
    </div>

    </td>
    </tr>

    <? $catindex++; ?>

  <? } ?>
  <tr valign=top>
  <td valign=top width=928 class=newscontent style="border-bottom: 1px solid; line-height: 18px;">
  <button name="add1" id="add1" onClick="trade_button_add('',1);">Add Level 1 Category..</button><br>
  </td>
  </tr>

  </table>
