<script>
function showSubAff(sElemId)
{
    if(document.getElementById('level1'+sElemId).style.display=='block')
    {
        document.getElementById('level1'+sElemId).style.display='none';
        document.getElementById('plus'+sElemId).innerHTML='[+]';
    }
    else
    {
        document.getElementById('level1'+sElemId).style.display='block';
        document.getElementById('plus'+sElemId).innerHTML='[-]';
    }
}
</script>
<div id="front_center">
     <div class="constrain">
	<h1>Affilates</h1>	
     <?php
     foreach ($aAffilate as $key=>$affilate)
     {
     ?> 
         <div style="width:100%;padding: 10px; border-bottom: 1px solid gray;">
            <span  onclick="showSubAff('<?=$affilate['id']?>')"><b><?=$affilate['fullname'] ?></b></span> <br/>
            <div style="margin-left:30px;">
            Plan: <?=$affilate['title'] ?><br/>
            Commission: $<?=$affilate['signs_up_referred_by_you'] ?><br/>
             <?php if (isset($affilate['afflevel2'])) { 
                    echo '<a  onclick="showSubAff('.$affilate['id'].')"><span id="plus'.$affilate['id'].'">[+]</span> Refferalls: ('.count($affilate['afflevel2']).')</a>';?> 
                             <?php
                             }
                             ?>
               
            </div>
                <?php if (isset($affilate['afflevel2'])) { ?> 
                       <div style="display:none;" id="level1<?=$affilate['id']?>">
                            <?php
                             foreach ($affilate['afflevel2'] as $key=>$afflevel2)
                             {
                             ?>
                                 <div style="width:30%;padding:10px;margin-left:120px; border-bottom: 1px solid gray;">
                                    <b><?=$afflevel2['fullname'] ?></b>
                                     <div style="margin-left:30px;">
                                        Plan: <?=$afflevel2['title'] ?><br/>
                                        Commission: $ <?= $afflevel2['referred']*$aConf['fee_on_your_2nd_level']/100 ?><br/>
                                    </div>
                                                            
                                 </div>
                             <?php
                             }
                             ?>
                       </div> 
                <?php
                }
                ?>

         </div>
     <?php
     }
     ?>
     
    </div>
</div>
