<!DOCTYPE html>
<html class="no-js" lang="en">
    <head>
        <?php
            $this->load->view('user/common_style');
        ?>
    </head>
    <link id="bsdp-css" href="<?php echo base_url();?>assets/css/bootstrap-datepicker3.min.css" rel="stylesheet">
        <style>
        .project_area figure {
            display: inherit !important; float:left
        }
        
        .modal-dialog {
            width: 300px;
        }
        .modal-content {
            background: rgba(34, 49, 63, 0.9) url("../img/choose_us_area_bg.png") no-repeat scroll 0 0 / cover ;
            border: 1px solid #22313f;
            border-radius: 70px 0;
            box-shadow: 5px 0 14px 1px rgba(0, 0, 0, 0.63) inset;
        }
        .modal-body {
            color: #f5ab35;
        }
        .modal-header {
            color: #fff;
        }
        .dynamic {
            color: #fff;
            font-weight: bold;
        }
        .close span {
            color: #fff;
        }
        input[type="text"] {
            background: rgba(255, 255, 255, 0.9) none repeat scroll 0 0;
            border: 0 none;
            border-radius: 100px;
            color: #22313f;
            font-weight: 600;
            padding: 0 10px;
        }
        </style>
    <style>
        .input-group-addon {background:none !important;border:0px !important}
        small.help-block, .has-error label {text-align: center;color: #EF3328;}
        label.validation-error-label, #bal_error {color: #ef3328; font-size: 14px; font-weight: 100; padding-top: 4px; text-align: center !important;}


    </style>
    <body>
            
        <?php
            $this->load->view('user/header');
        ?>
            
        <?php
            $this->load->view('user/login_header');
            $currency_info = defaultcurrency();
        ?>

        <?php if($user_make_deposit == 'on') { ?>
        
        <form method="post" class="make-deposit" action="<?php echo $action;?>">
            <!-- <section class="dmain">
                <div class="container">
                    <div class="col-lg-12">  
                        <h2 class="section_hedings1"><?php echo $this->lang->line('lbl_our');?> <span><?php echo $this->lang->line('lbl_investment_plans');?></span></h2>
                    </div>
                </div>
            </section> -->
     
<!--             <section class="dmain makeadeposit">
                <div class="container">
                    

                    <?php 
                        $i = 1;
                        foreach ($packages as $package) {
                            $max_rate = $this->packages_model->GetMaxrate($package->packageid);
                        ?>

                        <?php if($i%4 == 0) { ?>
                        <div class="row">
                        <?php } ?>
                        
                            <div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">
                                
                                <div class="panel price panel-white gry1 <?php if($i=='1') { echo 'active';}?>">
                                    <input type="hidden" name="packageid" value="<?php echo $package->packageid;?>">
                                    
                                    <div class="panel-heading arrow_box text-center">
                                        <h3> <span><?php echo ucfirst($package->package_name);?></span></h3>
                                    </div>
                                    <div class="panel-body text-center">
                                        <p class="lead" style="font-size:40px"><strong><?php echo $max_rate->rate;?>% / <br /><?php echo $package->periord_name;?></strong></p>
                                    </div>
                                    <ul class="list-group list-group-flush text-center">
                                    <?php 
                                        $plans = $this->packages_model->GetPlans($package->packageid);
                                        foreach ($plans as $plan) {
                                    ?>
                                            <li class="list-group-item"><i class="icon-ok text-success"></i><?php echo $currency_info->currency_symbol."".number_format($plan->min_amount, $currency_info->deimal_point, '.', '')." - ".$currency_info->currency_symbol."".number_format($plan->max_amount, $currency_info->deimal_point, '.', ''). " - ".$plan->rate." %";?></li>
                                    <?php
                                        } 
                                    ?>
                                    </ul>
                                    <div class="panel-footer">
                                        <a href="#" data-id="<?php echo $package->packageid;?>" class="btn btn-lg btn-block accrodion_top_btn" data-toggle="modal" data-target="#calcModal"><?php echo strtoupper($this->lang->line('lbl_calculate'));?></a>
                                    </div>
                                    <?php if($i=='1') {?>
                                        <input type="hidden" name="select_package" value="<?php echo $package->packageid;?>">
                                    <?php } ?>
                                  
                                </div>
                                
                            </div>

                        <?php if($i%4 == 0) { ?>
                        </div>
                        <?php } ?>

                    <?php 
                            $i++; 
                        } 
                    ?>

                    </div>
                </div>
            </section> -->

            <div class="modal fade" id="calcModal" tabindex="-1" role="dialog" aria-labelledby="calcModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                    
                    </div>
                </div>
            </div>

            <input type="hidden" name="select_package" value="1">
            <section class="dmain  clearfix">
                <div class="container">
                    <h2 class="section_hedings"><?php echo strtoupper($this->lang->line('lbl_deposit'));?><span> <?php echo strtoupper($this->lang->line('lbl_options'));?></span></h2>
                
                    <div class="makeadepositpymnt clearfix">
                        <div class=" col-md-12 col-lg-3 ">
                            <div class="mkdheading">
                              <?php 


                               $condition="icoid = '1'";
                               $coin = $this->common_model->GetRow('icoset',$condition); 
                          

            ?>
                                <!-- <span style="margin-top:20px;"><?php echo strtoupper($this->lang->line('lbl_value_per_token'));?> :</span> $<?php echo $coin->valuetoken; ?> -->
                            </div>
                        </div>
                        <div class="col-md-12 col-lg-7 col-lg-offset-2">
                            <div class="">
                                
                                <div class="dorange" style="margin:0;">
                                    <div class="col-md-6">
                                        <h2><?php echo strtoupper($this->lang->line('lbl_select_currency'));?></h2>
                                        <div class="nren">
                                            <select class="form-control" name="payment" id="payment" style="width:100%;" onchange="currency_change(this.value);">
                                                <!--<option value='1'>USD</option>
                                                <option value='2'>BTC</option>
                                                <option value='3'>ETH</option>-->
                                                <option value="">select</option>
                                                <?php
                                                 $currency_det=$this->db->query("select * from payment_currency where currency_status='1'");
                                                 $currency_dat=$currency_det->result(); 
                                                 foreach($currency_dat as $row)
                                                 {
                                                ?>
                                                <option value="<?php echo $row->currency_id;?>"><?php echo strtoupper($row->currency_unit);?></option>
                                                <?php

                                                 }   
                                                ?>
                                        </select>                   
                                                    
                                                
                                            <div class="messageContainer"></div>
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <h2><?php echo strtoupper($this->lang->line('lbl_payment_amount'));?></h2>
                                        <div class="nren">
                                            <div class="input-group">
                                                    <input style="border-radius:100px;" id="deposit_ammount" name="amount" class="form-control" placeholder="0.00" value="" type="text">
                                                <span class="input-group-addon" id="cur_up"><?php echo strtoupper($currency_info->currency_unit);?></span>
                                            </div>
                                            <div class="messageContainer"></div>
                                        </div>
                                    </div>
                                    <!--<div class="col-md-4" id="compound_rate">
                                        
                                    </div>-->
                                </div>
                                <div id="u_id">
                                <div class="dorange">
                                    <h2><?php echo strtoupper($this->lang->line('lbl_select_payment'));?></h2>
                                    <?php 
                                        $i = '1';
                                        foreach ($payment_list as $payment) 
                                        {
                                            if($payment->payment_id!='2' && $payment->payment_id!='20')
                                            {
                                    ?>
                                            <img src="styles/img/<?php echo $payment->payment_name;?>.png"  alt="<?php echo $payment->payment_id;?>" class=""/>
                                            
                                    <?php 
                                            $i++;
                                            } 
                                    }
                                    ?>
                                    <!-- <div class="messageContainer"></div> -->
                                    </div>
                                    <span id='pay_val'></span>
                                </div>

                                <div id="b_id" style='display:none;'>
                                <div class="dorange">
                                    <h2><?php echo strtoupper($this->lang->line('lbl_select_payment'));?></h2>
                                    <?php 
                                        $i = '1';
                                        foreach ($payment_list as $payment) {
                                            if($payment->payment_id=='2')
                                            {
                                    ?>
                                           
                                            <img src="styles/img/<?php echo $payment->payment_name;?>.png"  alt="<?php echo $payment->payment_id;?>" class=""/>
                                            
                                    <?php 
                                        $i++;
                                        }
                                    } 
                                    ?>
                                    <!-- <div class="messageContainer"></div> -->
                                    </div>
                                </div>
                                <div class="col-md-12">
                                <div id="e_id" style='display:none;'>
                                <div class="dorange">
                                    <h2><?php echo strtoupper($this->lang->line('lbl_select_payment'));?></h2>
                                    <?php 
                                        $i = '1';
                                        foreach ($payment_list as $payment) 
                                        {
                                            if($payment->payment_id=='20')
                                            {

                                    ?>
                                            <img src="styles/img/<?php echo $payment->payment_name;?>.png"  alt="<?php echo $payment->payment_id;?>" class=""/>
                                            
                                    <?php 
                                           $i++;
                                        } 
                                    }
                                    ?>
                                    <!-- <div class="messageContainer"></div> -->
                                    </div>
                                </div>
                                <input type="hidden" id="select_payment" name="select_payment" value=''>
                                <div class="dred">
                                    <input type="hidden" id="uuser_raw_balance" name="user_bal" value="0.00" />
                                    <h2><?php echo strtoupper($this->lang->line('lbl_you_have_selected'));?> : </h2>
                                    <input type="text" style="background:none;font-size:19px;" name="pay_name" id="pay_name" value=''>
                                 
                                    <label id="bal_error"></label>
                                    <button type="submit" style="width:60%;background:#F5AB35" id="submit" name="submit" ><?php echo strtoupper($this->lang->line('lbl_submit'));?></button>
                                    </div>
                                </div>
                                <div>
                                
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </form>
        <?php }  else { ?>

        <section class="dmain">
            <div class="container">
                <div class="row section_padding_50">
                    <div class="col-lg-12"> 
                        <div class="gry clearfix">
                            <div class="profilesub">
                                <h2><?php echo $this->lang->line('warning_msg_lbl'); ?></h2>
                            </div>
                            <div class="col-lg-6" >
                                <p style="color:white;" class="frgtpwd frgtpwd1 frgtpwdred"><i class="fa fa-thumbs-down"></i><?php echo $this->lang->line('makedeposit_option_disabled'); ?> !</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <?php } ?>

        <div class="clearfix"></div>
            
            <?php
                $this->load->view('user/footer');
            ?>
        
            <?php
                $this->load->view('user/common_script');
            ?>
            <!-- Bootsrap form validation JS files 
            <script type="text/javascript" src="<?php echo base_url();?>assets/js/formValidation.js"></script>
            <script type="text/javascript" src="<?php echo base_url();?>assets/js/bootstrap.js"></script>-->

            <script type="text/javascript" src="<?php echo base_url();?>assets/js/plugins/forms/validation/validate.min.js"></script>
            <script src="<?php echo base_url();?>assets/js/bootstrap-datepicker.min.js"></script>
        <script type="text/javascript">

            jQuery.noConflict();
            (function( $ ) {
                $(function() {
                    
                    $('#deposit_ammount').keyup(function() {
                        $('#submit').removeAttr('disabled');
                       

                    })
                    $('#deposit_ammount').change(function() {
                        $('#submit').removeAttr('disabled');
                        var packageid = jQuery('[name="select_package"]').val();
                        
                        $.ajax({
                            method : 'POST',
                            url   : '<?php echo base_url();?>user/deposit/checkearnings',
                            data : {'packageid':packageid,'amount':$('#deposit_ammount').val()},
                            dataType: 'json',
                            success : function(json)
                            {
                                
                                $('.mkdheading').html('<input type="hidden" value="'+json['totalcoinamnt']+'" name="tokenamt">')
                            }
                        })

                    })

                    $.validator.addMethod("price", function(value, element) {
                      return this.optional(element) || /^[0-9.]+$/.test(value);
                    }, "The deposit amount is invalid");

                    $(".make-deposit").validate({
                        ignore: 'input[type=hidden]', // ignore hidden fields
                        errorClass: 'validation-error-label',
                        successClass: 'validation-valid-label',
                        highlight: function(element, errorClass) {
                            $(element).removeClass(errorClass);
                            $(element).parent().addClass('has-error');
                            $(element).parent().removeClass('has-success');
                        },
                        unhighlight: function(element, errorClass) {
                            $(element).removeClass(errorClass);
                            $(element).parent().addClass('has-success');
                            $(element).parent().removeClass('has-error');
                        },
                        // Different components require proper error label placement
                        errorPlacement: function(error, element) {

                            // Styled checkboxes, radios, bootstrap switch
                            if (element.parents('div').hasClass("checker") || element.parents('div').hasClass("choice") || element.parent().hasClass('bootstrap-switch-container') ) {
                                if(element.parents('label').hasClass('checkbox-inline') || element.parents('label').hasClass('radio-inline')) {
                                    error.appendTo( element.parent().parent().parent().parent() );
                                }
                                 else {
                                    error.appendTo( element.parent().parent().parent().parent().parent() );
                                }
                            }

                            // Unstyled checkboxes, radios
                            else if (element.parents('div').hasClass('checkbox') || element.parents('div').hasClass('radio')) {
                                error.appendTo( element.parent().parent().parent() );
                            }

                            // Input with icons and Select2
                            else if (element.parents('div').hasClass('has-feedback') || element.hasClass('select2-hidden-accessible')) {
                                error.appendTo( element.parent() );
                            }

                            // Inline checkboxes, radios
                            else if (element.parents('label').hasClass('checkbox-inline') || element.parents('label').hasClass('radio-inline')) {
                                error.appendTo( element.parent().parent() );
                            }

                            // Input group, styled file input
                            else if (element.parent().hasClass('uploader') || element.parents().hasClass('input-group')) {
                                error.appendTo( element.parent().parent() );
                            }

                            else {
                                error.insertAfter(element);
                            }
                        },
                        validClass: "validation-valid-label",
                        success: function(label) {
                            label.parent().addClass('has-success');
                            // label.addClass("validation-valid-label").text("Success")
                        },
                        rules: {

                            payment: {
                                required: true,
                            },
                            amount: {
                                required: true,
                                price: true
                                
                            },
                            compound_rate: {
                                required: true,
                            },
                            pay_name:{
                                required:true,
                            }
                        },
                        messages: {
                            payment: {
                                 required: "Please Select currency",
                            },
                            amount: {
                                required: "<?php echo strtoupper($this->lang->line('lbl_deposit_amount_required'));?>",
                                price: "<?php echo strtoupper($this->lang->line('lbl_deposit_amtount_invalid'));?>",
                                remote: "<?php echo strtoupper($this->lang->line('lbl_deposit_amount_must'));?>"
                            },
                            compound_rate: {
                                required: "<?php echo strtoupper($this->lang->line('lbl_compound_rate_required'));?>",
                            },
                            pay_name: {
                                required: "Please Select Payment",
                            }
                        }
                        
                        
                    });
                    $("#owl-example").owlCarousel({
                        nav:true,
                        items : 8, 
                        itemsCustom : false,
                        itemsDesktop : [1199,8],
                        itemsDesktopSmall : [980,5],
                        itemsTablet: [768,5],
                        itemsTabletSmall: [768,4],
                        itemsMobile : [479,2],
                        singleItem : false,
                        itemsScaleUp : true,
                        navigation : true,
                        navigationText : ["",""],
                        rewindNav : true,
                        scrollPerPage : false,
                    });
                });

                $(".makeadeposit .gry1 ").click(function () {
                    var isActive = ($(this).hasClass('active')) ? true : false;
                    // console.log("isActive: " + isActive);
                    
                    if (!isActive) {
                        $('.makeadeposit .gry1 ').removeClass('active');
                        $('.makeadeposit').find('[name="select_package"]').remove();
                        var packageid = $(this).children('[name="packageid"]').val();

                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            url:'<?php echo base_url();?>user/deposit/checkpackage/'+packageid,
                            success : function(resp)
                            {
                                $('#compound_rate').html(resp['compound']);
                                if(resp['reinvest']) {
                                    $('.reinvet_status').show();
                                } else {
                                    $('.reinvet_status').hide();
                                }
                            }
                        });

                        
                        
                        $(this).addClass('active'); 
                        $('.makeadeposit').find('.active .panel-footer').after('<input type="hidden" name="select_package" value="'+packageid+'">');
                        if($('[name="amount"]').val()){
                            // checkvalidamt();
                            var amount = $('#deposit_ammount').val();
                            $.ajax({
                                type: 'post',
                                url : '<?php echo base_url();?>user/deposit/validamount',
                                data : {'packageid':packageid,'amount':amount},
                                dataType: 'json',
                                success : function(json)
                                {
                                    // var json = JSON.parse(json);
                                    console.log(json['valid']);
                                    if(json['valid']) {
                                        $('#deposit_ammount').parent().removeClass('has-error');
                                        $('#deposit_ammount').parent().addClass('has-success');
                                        $('#deposit_ammount-error').html('');
                                        $('#submit').removeAttr('disabled');
                                        return true;
                                    } else {
                                        $('#deposit_ammount').parent().removeClass('has-success');
                                        $('#deposit_ammount').parent().addClass('has-error');
                                        $('#deposit_ammount-error').html('This amount must be above selected plan amount');
                                        $('#deposit_ammount').attr('aria-required','true');
                                        $('#deposit_ammount').attr('aria-invalid','true');
                                        $('#submit').attr('disabled','disabled');
                                        return false;
                                    }
                                }
                            });

                           
                        }
                    } 
                });
                if($('.select_payment').val()){
                    // var payment_id = $('.select_payment').val();
                    // var user_id = '3';
                    $.ajax({
                        type: 'post',
                        url : '<?php echo base_url();?>user/deposit/checkbalance',
                        // data : {'user_id':user_id,'payment_id':payment_id},
                        // data : {'user_id':user_id},
                        dataType: 'json',
                        success : function(resp)
                        {
                            if(resp['success']) {
                                $('#pay_name').html(resp['payment']);
                                $('#user_balance').html(resp['balance']);
                                $('#uuser_raw_balance').val(resp['raw_balance']);
                                
                            } else {
                                $('#pay_name').html(resp['payment']);
                                $('#user_balance').html(resp['balance']);
                                $('#uuser_raw_balance').val(resp['raw_balance']);
                                
                            }
                        }
                    });
                }



                $(".dorange img").click(function () {
                    var isActive = ($(this).hasClass('active')) ? true : false; 


                    // console.log("isActive: " + isActive);
                    
                    if (!isActive) {
                        $('.dorange img').removeClass('active');
                        $(this).addClass('active');
                        var payment_id = $(this).attr('alt');
                        var payname = $(this).attr('src');
                        var res = payname.replace("styles/img/","");
                        var res = res.replace(".png","");
                        var res = res.replace(".jpg","");
                        $('#pay_name').val(res);
                        $('#select_payment').val(payment_id);
                        // var user_id = '3';
                        $('.select_payment').val(payment_id);
                        
                    } 
                });

                $(".reinvest").click(function(){
                    if($(".reinvest").is(':checked')) {
                        checkreinvest();

                    } else {
                        console.log('unchecked');
                    }
                })

                

                
                $('#calcModal').on('show.bs.modal', function (event) {
                    var button = $(event.relatedTarget) 
                    var id = button.data('id')
                    var modal = $(this)
                    
                    if(id) {
                        $.ajax({
                            'method': 'POST',
                            'url': '<?php echo base_url();?>user/user/viewcalc/'+id,
                            success:function(resp) {
                                modal.find('.modal-body input').val(id)
                                modal.find('.modal-content').html(resp)
                                modal.find('#to-date').datepicker({startDate: '-0d', autoclose: 'true'}).on('change', function(e) {
                                    CalculatorFunc();
                                })
                                modal.find('#amount').on('change', function(e){
                                    CalculatorFunc();
                                })
                            }
                        })
                    }
                })

                $('#amount').on('change', function(e){
                    CalculatorFunc();
                })

                $('.calcbutton').on('click', function(e){
                    CalculatorFunc();
                })
                    
                

            })(jQuery);

            function checkreinvest() {
                if(jQuery(".reinvest").is(':checked')) {
                    var payment_id = jQuery('.select_payment').val();
                    var user_id = '3';
                    var amount = jQuery('#deposit_ammount').val();
                    var balance = jQuery('#uuser_raw_balance').val();
                    if(parseFloat(amount) > parseFloat(balance)) {
                        jQuery(".reinvest").removeAttr('checked');
                        jQuery('#bal_error').html('Insufficent Balance you can pay through online gateway');
                        console.log('insufficentbalance');
                        
                    } else {
                        jQuery('#bal_error').html('');
                    }
                } else {
                    jQuery('#bal_error').html('');
                    console.log('unchecked');
                }
            }

           
                
            function currency_change(str)
            {
                var cr="USD";
                if(str=='2')
                    cr="BTC";
                else if(str=='3')
                    cr="ETH";

                if(str=='1')
                {
                    document.getElementById("u_id").style.display='block';
                    document.getElementById("b_id").style.display='none';
                    document.getElementById("e_id").style.display='none';
                    

                }

                if(str=='2')
                {
                    document.getElementById("u_id").style.display='none';
                    document.getElementById("b_id").style.display='block';
                    document.getElementById("e_id").style.display='none';
                    
                }


                if(str=='3')
                {
                    document.getElementById("u_id").style.display='none';
                    document.getElementById("b_id").style.display='none';
                    document.getElementById("e_id").style.display='block';
                    
                }    
                document.getElementById("cur_up").innerHTML=cr;
                document.getElementById("pay_name").value="";
                document.getElementById("select_payment").value="";
                

            }
    
        </script>
        
        <script type="text/javascript">
        
        function CalculatorFunc() {
            var to_date = jQuery('#to-date').val();
            var amount = jQuery('#amount').val();
            if(jQuery('#compound').val()) {
                var compound = jQuery('#compound').val();
            } else {
                var compound = '';
            }
            
            if(to_date && amount) {
                jQuery.ajax({
                    method: 'POST',
                    dataType: 'json',
                    // data: jQuery('#calc_form').serialize(),
                    data: {'to_date':jQuery('#to-date').val(),'amount':jQuery('#amount').val(), 'packageid':jQuery('#packageid').val(),'compound':compound},
                    url: '<?php echo base_url();?>user/user/calculator/',
                    success:function(resp) {
                        jQuery('#cal-resp').html(resp)
                        jQuery('#days').html(resp['total_days'])
                        jQuery('#percent').html(resp['percent'])
                        jQuery('#profit').html(resp['profit'])
                        jQuery('#deposit_amt').html(resp['amount'])
                    }
                })
            } else {
                jQuery('#cal-resp').html("<?php echo $this->lang->line('lbl_calc_error');?>");
            }
        }
        // jQuery('#to-date').datepicker();
        </script>
        
       
        
    </body>
</html>