<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");
            $("#rowLumpSum").attr("style", "display:block");
            $("#rowAcc").attr("style", "display:none");
             $("#rowPeriode").attr("style", "display:none");
        } else {
            $("#rowSale").attr("style", "display:block");
            $("#rowAcc").attr("style", "display:block");
            $("#rowLumpSum").attr("style", "display:none;");
            $("#rowPeriode").attr("style", "display:block");

        }

    }

    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)
    }
    
    function addNewBene(){
        if (!$("#listCateBene").length) {
    $('' +
            '<tr><td class="span1">' + ($("#trInfos").attr("data-currentRow") * 1 + 1) + '</td>' +
            '<td class="span3" >' +
            '<select class="span12" id="listCateBene""><option></option>' +
<?php
if ($datatbls) {
    foreach ($datatbls as $row) {
        ?>
            '<option value= "<?php echo $row->ID; ?>"' + ' ><?php  echo str_replace("'", " ", $row->name, $count);
        ?></option>' +
        <?php
    }
}
?>
    '</select></td>' +
            '<td class="span4"><input id="beneDesc" name="beneDesc" class="span12 validate[required]" type="text" placeholder="Description"></td>' +
            '<td class="span1"><input id="amtPercentage"  onkeyup="calculamount()" name="amtPercentage" class="span12 validate[required,custom[number]]" type="text" placeholder=""></td>' +
            '<td class="span2"><input class="span12" id="beneAmnt" disabled  name="amtPercentage" type="text"></td>' +
            '<td class="span1">' +
            '<button class="btn btn-mini btn-primary"  type="button"><span class="icon-ok-circle"></span></button>' +
            '<button id="btnCancel" class="btn btn-mini btn-danger" onclick="delRow(this)" type="button"><span class="icon-remove-circle"></span></button>' +
            '</td>' +
            '</tr>'


            ).insertBefore("#trInfos");
            $('#listCateBene').select2();
    } else{
    msg (1, "alert", "Please, do save the current details before addind new one");
    }
    }
function delRow(me){
    var td = me.parentNode;
            var tr = td.parentNode;
            var tBody = tr.parentNode;
            tBody.removeChild(tr);
            getTotal ();
    }
    
    function getSaleAmount(){
      //  alert($('#saleAcctNo').validationEngine('validate'));
      // if( !$('#saleAcctNo').validationEngine('validate') && $('#wYear').validationEngine('validate') && $('#wFrom').validationEngine('validate') && $('#wTo').validationEngine('validate')){
        $.ajax({
                type: "POST",
                data : {
                    year : $("#wYear").val(),
                    from : $("#wFrom").val(),
                    to : $("#wTo").val(),
                    acctno : $("#saleAcctNo").val()
                },
                url: "<?php echo base_url() ?>wakafsetup/getSaleAmount",
                success: function(data) {
                        var resul = eval ("(" + data + ")");
                        var n = resul.records.length;
                        alert (data);
                        
                }
       });
      //  }
     }

</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 style="display:none;" id="rowPeriode" class="controls-row">
                                <div class="span2"></div>
                                <div class="span2">Periode</div>
                                <div class="span2">
                                    <input id="wYear" type="text" class="span12 validate[required, custom[number]]" placeholder="Year EX:2014" />
                                </div>
                                 <div class="span2">
                                    <input id="wFrom" type="text" class="span12 validate[required, custom[number]]" placeholder="From Ex:2" />
                                </div>
                                 <div class="span2">
                                     <input id="wTo" type="text" class="span12 validate[required, custom[number]]" placeholder="To Ex:3" />
                                </div>
                            </div>

                            <div id="rowAcc" style="display:none;" class="controls-row"> <!-- row 3 -->
                                <div class="span2"></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 = ' id="saleAcctNo" class = " span12 validate[required]"';
                                    echo form_dropdown('chargeAccount', $options, $preselcurr, $js);
                                    ?>    
                                </div> 
                                <div class="span3">
                                    <input type="text" readonly class="span12" placeholder="Sale Amount"/>
                                </div>
                                
                                <div class="span1">
                                    <a onclick="getSaleAmount()" class="btn btn-primary"><i class="icon-ok-sign icon-white"></i></a>
                                </div>
                            </div><!-- End Row 3 -->

                            <div style="display:none;" id="rowSale" class="controls-row"> <!-- row 2 -->
                                <div class="span2"></div>              
                                <div class="span2 TAR" >Amount Allocate<?php echo $this->lang->line('amountallocated') ?></div>
                                <div class="span3">
                                        <div class="input-prepend input-append">
                                            <input   class="span10 tar" id="appendedPrependedInput" type="text">
                                            <span class="add-on">&#37;</span>
                                        </div>
                                </div>
                                
                                <div class="span3">
                                    <?php
                                    $data = array(
                                        'placeholder' => 'Amount Aloccated',
                                        'readonly'=> 'true',
                                        'name' => 'contributionPercentageLumpSum',
                                        'id' => 'contributionPercentageLumpSum',
                                        'class' => 'span12',);
                                    echo form_input($data, set_value('contributionPercentageLumpSum'));
                                    ?>      
                                </div> 
                                
                            </div><!-- End Row 2 -->
                              
                        </div>  <!-- content -->
                        </form>
                    </div>  <!-- block -->
                </div>  <!-- span12 -->
            </div>  <!-- row-fluid -->
            
            
            <div class="row-fluid scRow">                            
                                <div class="span12 scCol">
                                    <div class="block" id="grid_block_4">
                                        <div class="head">
                                            <h2><?php echo $this->lang->line('benificiaries') ?></h2>
                                             <ul class="fr buttons">
                                <li><a class="block_toggle collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
                                        <span class="i-arrow-down-3"></span></a></li>
                            </ul>
                            <ul class="buttons fr">
                                <li><a href="#trInfos" onclick="addNewBene()" title="Add New"><span class="i-plus-2"></span></a></li>
                            </ul>                                    
                                        </div><!-- head -->
                                        <div class="content np">
                                            <table id="listDetails" cellpadding="0" cellspacing="0" width="100%">
                                                <thead>
                                                    <tr>
                                                        <th>#</th>
                                                        <th><?php echo $this->lang->line('beneCate') ?></th>
                                                        <th><?php echo $this->lang->line('nameDesc') ?></th>
                                                        <th><?php echo $this->lang->line('percentage') ?></th>
                                                        <th><?php echo $this->lang->line('amount') ?></th>
                                                        <th><?php echo $this->lang->line('action') ?></th>
                                                    </tr>
                                                </thead>
                                                <tbody>

                                                    <tr id="trInfos" data-currentRow="0" >
                                                        <td class="span8" colspan="3" style="text-align:right;">
                                                            Total 
                                                        </td>
                                                        <td class="span1">
                                                            <input class="span12" readonly type="text" placeholder=" 0,00" />
                                                        </td>
                                                        <td class="span2">
                                                            <input class="span12" readonly type="text" placeholder=" 0,00" />
                                                        </td>
                                                        <td></td>
                                                    </tr>
                                                </tbody>
                                            </table>     
                                        </div><!-- content -->
                                    </div><!-- grid block 1-->
                                </div><!-- scCol -->
                            </div><!-- row-fluid scRow-->
                            
                           
                             <div class="row-fluid scRow">  
                    <div class="span8 scCol">
                        <div class="block" id="grid_block_4">
                            <div class="content">
                                <div style="padding:0;" class="controls-row">
                                    <div id="msgDiv" style="min-height: 22px;" class="alert alert-info">  </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="span4 scCol">
                        <div class="block" id="grid_block_4">
                            <div class="content">
                                <div class="controls-row side fr">
                                     <?php
                                        $data = array(
                                            'name' => 'validate',
                                            'style' => 'margin-right:5px;',
                                            '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>
                    
                </div><!-- row-fluid scRow-->
        </div>  <!-- content -->
    </div>  <!-- wrap -->
</div>  <!-- content -->
