<script type="text/javascript">
    $(document).ready(function() {
        $('#selecctall').click(function(event) {  //on click
            if (this.checked) { // check select status
                $('.checkbox1').each(function() { //loop through each checkbox
                    this.checked = true;  //select all checkboxes with class "checkbox1"              
                });
            } else {
                $('.checkbox1').each(function() { //loop through each checkbox
                    this.checked = false; //deselect all checkboxes with class "checkbox1"                      
                });
            }
        });

    });

</script>

<script>
     $(document).ready(function() {
        $('select').select2();
    	  $.each($(".select2-container"), function (i, n) {
                    $(n).next().show().fadeTo(0, 0).height("0px").css("left", "auto"); // make the original select visible for validation engine and hidden for us
                    $(n).prepend($(n).next());
                    $(n).delay(500).queue(function () {
                        $(this).removeClass("validate[required]"); //remove the class name from select2 container(div), so that validation engine dose not validate it
                        $(this).dequeue();
                    });
                });	
    });
    
    function enable_lumpsum(id) {
        if (document.getElementById(id).disabled == true) {
            document.getElementById(id).disabled = false;
        } else {
            document.getElementById(id).disabled = true;
        }
        return true;
    }
    function checkOption(opt) {
        if (opt == 1) {
            $("#rowSale").attr("style", "display:none");
            $("#rowAmount").attr("style", "display:none");
            $("#rowLumpSum").attr("style", "display:block");
            $("#rowAcc").attr("style", "display:none");
        } else {
            $("#rowSale").attr("style", "display:block");
            $("#rowAmount").attr("style", "display:block");
            $("#rowAcc").attr("style", "display:block");
            $("#rowLumpSum").attr("style", "display:none;");
            
           	
        }
        
    }

    function checkCategory(opt) {
        if (opt == 1) {
            $("#specifikDetails").attr("style", "display:none");
        } else {
            $("#specifikDetails").attr("style", "display:block");
        }
    }
    
    function updateTotal(){
        var som = 0;
       $("#specifikDetailslist > tbody > tr").each(function(){
           var tr = $(this);
           som += 1* accounting.unformat($(tr).find("td").eq(3).children("input:last-child").val());
           //alert($(tr).find("td").eq(1).text());
        });
        $("#sequence").val(som)
    }
    
   
</script>

<div id="content">                        
    <div class="wrap">

        <div class="head">
            <div class="info">
                <h1><?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
                    <?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]</h1>
                <ul class="breadcrumb">
                    <li><a href="<?php echo base_url() ?>home"><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                    <li><a href="zakat/home"><?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                    <li class="active"><?php echo $this->lang->line('title') ?></li>
                </ul>
            </div>

            <div class="search">
                <form action="<?php echo base_url() ?>admin/search" method="post">
                    <input name="search_text" type="text" placeholder="search..."/>                                
                    <button type="submit"><span class="i-magnifier"></span></button>
                </form>
            </div>                        
        </div>  <!-- Head -->
        <div class="content">
            <div class="row-fluid">
                <div class="span12">
                    <?php
                    $hidden = array('order_time' => date('Y-m-d H-i-s'));
                    $attrib = array('id' => 'validate');
                    echo form_open('', $attrib, $hidden);
                    ?>
                    <div class="block">
                        <div class="head">
                            <h2><?php echo $this->lang->line('title') ?></h2>
                            <div class="side fr">
                                <button class="btn" onClick="clear_form('#validate');" type="button">Clear form</button>
                            </div>
                        </div>
                        <div class="content np">    
                            <div class="controls-row">
                                <div class="span2"><?php echo $this->lang->line('waqif') ?></div>
                                <div class="span10">
                                    <?php
                                    $preselcurr = '0';
							$options = '';
							$options[NULL] = '--Please Select--';
                                                        $options['founder'] ="Founder(s)";
                                                        $options['owner'] ="Owner(s)/Shareholder(s)";
                                                        $options['director'] ="Director(s)";
                                                        $options['other'] ="Other(s)";
							$js='class = "span7 validate[required]" id= "waqif"';
							echo form_dropdown('waqif', $options, $preselcurr, $js);
				
                                    ?>                       
                                </div>                            
                            </div>
                            <div class="controls-row"> <!-- row 1 -->
                                <div class="span2"><?php echo $this->lang->line('allocation') ?></div>
                                <div class="span3">
                                    <input checked="checked" type='radio' onclick='checkOption(1)' name='alocationOpt' value='1'> Lump Sum       
                                </div>   
                                <div class="span3">
                                      <?php
                                    echo"<input onclick='checkOption(2)' type='radio' name='alocationOpt' id='percentage' value='2'> Percentage";
                                    ?>  
                                     
                                </div>                
                            </div><!-- End Row 1 -->
                            
                              <div id="rowLumpSum" class="controls-row"> <!-- row 2 -->
                                <div class="span2"></div>              
                                <div class="span2 TAR" > <div class="span1 TAR" ><?php echo $this->lang->line('amount') ?></div></div>
                                <div class="span4">
                                    <input class="validate[required]" type='text' name='amountLumpSum' id='amountLumpSum'>    
                                </div>                
                            </div><!-- End Row 2 -->
                            
                            <div class="controls-row"></div>
                            
                              <div id="rowAcc" style="display:none;" class="controls-row"> <!-- row 3 -->
                                <div class="span5"></div>              
                                <div class="span2" ><?php echo $this->lang->line('saleaccountno') ?></div>
                                <div class="span3">
                                    <?php 								
							$preselcurr = '0';
							$options = '';
							$options[NULL] = '--Please Select--';
							foreach($chargeAccount as $row){
							$options[$row->ID] = '['.$row->acctCode.'] '.$row->acctName;
							}
							$js='class = "span12 validate[required]"';
							echo form_dropdown('chargeAccount', $options, $preselcurr, $js);
						?>    
                                </div>                
                            </div><!-- End Row 3 -->
                            
                            <div style="display:none;" id="rowSale" class="controls-row"> <!-- row 2 -->
                                <div class="span5"></div>              
                                <div class="span2" TAR><?php echo $this->lang->line('sales') ?></div>
                                <div class="span4">
                                    <?php
                                    $data = array(
                                        'name' => 'contributionPercentageLumpSum',
                                        'id' => 'contributionPercentageLumpSum',
                                        'class' => 'span9 validate[required]',);
                                    echo form_input($data, set_value('contributionPercentageLumpSum'));
                                    echo "%";
                                    ?>      
                                </div>                
                            </div><!-- End Row 2 -->
                            <div id="rowAmount" style="display:none;" class="controls-row"> <!-- row 3 -->
                                <div class="span5"></div>              
                                <div class="span2" TAR><?php echo $this->lang->line('amount') ?></div>
                                <div class="span4">
                                    <?php
                                    $data = array(
                                        'name' => 'amountLumpSum',
                                        'id' => 'amountLumpSum',
                                        'class' => 'span9 validate[required]',);
                                    echo form_input($data, set_value('amountLumpSum'));
                                    echo "%";
                                    ?>      
                                </div>                
                            </div><!-- End Row 3 -->
                            
                            
                            
                            <div class="controls-row"> <!-- row 4 -->
                                <div class="span2"><?php echo $this->lang->line('category') ?></div>
                                <div class="span4">
<?php echo"<input checked='checked' onclick='checkCategory(1)' type='radio' id='general' name='category' value='general'> General"; ?>     
                                </div> 
                                <div class="span4">
                                    <?php echo"<input onclick='checkCategory(2)' type='radio' id='specific' name='category' value='specific'> Specific"; ?>     
                                </div>
                            </div><!-- End Row 4 -->
                            <div class="controls-row">               
                            </div><!-- End Row 5 -->
                            <div style="display:none;" id="specifikDetails" class="table-sorting">
                                <table cellpadding="0" cellspacing="0" width="100%" id="specifikDetailslist" class="editable">
                                    <thead>
                                        <tr>
                                            <th style="display:none"></th>
                                            <th class="tac">#</th>
                                            <th><?php echo $this->lang->line('benificiaries'); ?></th>
                                            <th style="max-width:60px;"><?php echo $this->lang->line('percentage'); ?></th>
                                            <th><?php echo $this->lang->line('description'); ?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $bil = 0;
                                        //echo var_dump($datatbls); 
                                        if ($datatbls) {
                                            foreach ($datatbls as $datatbl):
                                                $bil++
                                                ?>
                                                <tr>
                                                    <td style="display:none" ><?php echo $datatbl->ID; ?></td>
                                                    <td class="tac"><?php echo $bil; ?></td>
                                                    <td><?php echo $datatbl->name ?></td>
                                                    <td><?php
                                                        $data = array(
                                                            'onkeyup' => 'updateTotal()',
                                                            'name' => 'contribution[' . $datatbl->ID . ']',
                                                            'id' => 'contribution[' . $datatbl->ID . ']',
                                                            'class' => 'span3',);
                                                        echo form_input($data);
                                                        echo "%";
                                                        ?>
                                                    </td>
                                                    <td><?php
                                                        if (($datatbl->ID) == 6) {  //others
                                                            $data = array(
                                                                'name' => 'descriptionDistribution',
                                                                'id' => 'descriptionDistribution',
                                                                'class' => 'span12',);
                                                            echo form_input($data);
                                                        }
                                                        ?>
                                                    </td>
                                                </tr>
                                                <?php endforeach;
                                            } ?>
                                    </tbody>
                                    <tr>
                                        <td class="tac"><?php echo $bil + 1; ?></td>
                                        <td><?php echo "Total"; ?></td>
                                        <td><?php
                                            $data = array(
                                                'name' => 'sequence',
                                                'id' => 'sequence',
                                                'class' => 'span3 validate[required, min[100], max[100]]',);
                                            $js = 'readonly';
                                            echo form_input($data, set_value('sequence'), $js);
                                            echo "%";
                                            ?></td>
                                        <td></td>
                                    </tr>
                                </table>                                         
                            </div>
                            <div class="footer">
                                <div class="side fr">
                                    <div class="btn-group">
                                        <?php
                                        $data = array(
                                            'name' => 'validat',
                                            'class' => 'btn',
                                            'onClick' => "$('#validate').validationEngine('hide');");
                                        echo form_button($data, 'Hide prompts');
                                        $data = array(
                                            'name' => 'mysubmit',
                                            'class' => 'btn btn-primary');
                                        $js = 'onclick="return confirm(\'' . $this->lang->line('message3') . '\')"';
                                        echo form_submit($data, 'Submit', $js);
                                        ?>
                                    </div>
                                </div>
                            </div>                                    
                        </div>  <!-- content -->
                        </form>
                    </div>  <!-- block -->
                </div>  <!-- span12 -->
            </div>  <!-- row-fluid -->
        </div>  <!-- content -->
    </div>  <!-- wrap -->
</div>  <!-- content -->
