$(".walletRadio").click(function(){    
    var data = $(this).attr('data-info');	
    if(data.length > 0 ){
        var dataSetValues = data.split("|");
        var currency = dataSetValues[0];
        var address = dataSetValues[1];
        var bar_code = dataSetValues[2];
        var img1 = '<img src="'+bar_code+'" alt="'+address+'" class="" />';
        $("#fund_method").val(currency);
        $(".fund_method").html(currency);
        $(".coin_name").html(currency);
        $(".coin_address").html(address);
        $("#coin_address").val(address);
        $("#dep_qr_code").html(img1);
    }
});
/////////////////////////
$(".step_1_btn").click(function(){    
    var status = '#dep_status';
    var min = parseFloat($("#min_dep").val());
    var val = parseFloat($("#amount").val());
    if($("#amount").val().length == 0){
        Msg("<i class='fa fa-warning'></i>&nbsp; Enter amount...","alert-danger",0,status,12000);
    } else if($("#fund_method").val().length == 0 ){
        Msg("<i class='fa fa-warning'></i>&nbsp; Currency is required...","alert-danger",0,status,12000);
    } else if(val < min){
        Msg("<i class='fa fa-warning'></i>&nbsp; Minimum deposit is $"+min,"alert-danger",0,status,12000);
    } else{
        $(status).html('');
        deposit_funds();
    }
});
/////////////////////////
////////////////////////
function deposit_funds(){
    var method = $("#fund_method").val();
    var status = '#dep_status';
    var min = parseFloat($("#min_dep").val());
	var data = $("#deposite_form").serialize();
    var btn = $('#funds_btn');
    var btn_content = btn.html();
    btn.prop('disabled',true); 
	$.ajax({
		type:'POST',
		url:'../controller/post.php?make_deposit',
		data:data,
		beforeSend: function(){	
            btn.html(spinner);
		},
		success: function(data){
            if(data == 1){
                Msg("<strong><i class='fa fa-check-square'></i>&nbsp;</strong>  Request sent successfuly. An email has been sent to you.","alert-success",0,status,10000);
                setTimeout(function() {
                        $("#deposite_form").trigger('reset');
                },12000);
            } else if (data == 2){
                    Msg("<strong><i class='fa fa-warning'></i>&nbsp;</strong> All fields required","alert-danger",0,status,12000);
            }else if(data == 3){
                Msg("<strong><i class='fa fa-times-circle'></i>&nbsp;</strong> account does not exist","alert-danger",0,status,12000);				
            }else if(data == 33){
                Msg("<strong><i class='fa fa-times-circle'></i></strong>&nbsp; Minimum deposit $"+min,"alert-danger",0,status,12000);				
            }else if(data == 21){
                    Msg("<strong><i class='fa fa-times-circle'></i></strong>&nbsp; Multiple pending transactions on your account, complete them or conatct support.","alert-danger",0,status,12000);				
            }else if(data == 4){
                    Msg("<strong><i class='fa fa-times-circle'></i>&nbsp;</strong> Error!!! Your first deposit can not be below 50 USD.","alert-danger",0,status,12000);				

            }else if(data == 5){
                    Msg("<strong><i class='fa fa-times-circle'></i>&nbsp;</strong> Error! Bank Wire is allowed for only deposits from $50,000 above","alert-danger",0,status,12000);				

            }else{
                var check = data.split("|||")[0];
                if(check == 0){
                    data = data.split("|||")[1];
                    var qr = data.split("||")[0];
                    var addr = data.split("||")[1];
                    var invoice = data.split("||")[2];
                    var amount = data.split("||")[3];
                    var symbol = data.split("||")[4];
                    var payment_Id = data.split("||")[5];
                    var asset_amount = data.split("||")[6];
                    $("#dep_invoice").html('#'+invoice);
                    $(".coin_amount2").html(asset_amount + " "+method);
                    $("#coin_amount2").val(asset_amount);
                    $(".coin_amount").html("$"+amount);
                    $("#coin_amount").val(amount);
                    $(".coin_address").html(addr);
                    $("#coin_address").val(addr);
                    $("#dep_qr_code").html(qr);
                    $("#deposite_form").trigger('reset');                            
                    ///////////////////////
                    $("#deposite_form").addClass("d-none");
                    $("#preview3").removeClass("d-none");
                    startTimer(1,payment_Id);
                }else{
                    Msg("<strong><i class='fa fa-times-circle'></i>&nbsp; </strong> "+data,"alert-danger",0,status,12000);				
                }
            } 
            btn.html(btn_content);
            btn.prop('disabled',false);
		}
	});
}
function copy_text(x) {
    //    $("#"+x+"_btn").html('<i class="fas fa-spinner fa-spin"></i>');
    /* Get the text field */
    var copyText = document.getElementById(x);
    var btn = $("#"+x+"_btn");
    var btn_content = btn.html();
    btn.html('Copied');
    setTimeout(function () {
        btn.html(btn_content);
    }, 2000);
    /* Select the text field */
    copyText.select();
    copyText.setSelectionRange(0, 99999); /* For mobile devices */

    /* Copy the text inside the text field */
    navigator.clipboard.writeText(copyText.value);
    
    
    /* Alert the copied text */
    //    $("#"+x+"_btn").html('<i class="fa fa-copy"></i>');
}
// Update the count down every 10 second
$(".pay_btn").click(function(){
    var value = $(this).data("value");
    if(value.length > 0 ){
        var dataSetValues = value.split("|");
        var wallet = dataSetValues[0];
        var amount = dataSetValues[1];
        var method = dataSetValues[2];
        var qr = '<img src="https://chart.googleapis.com/chart?chs=150x150&amp;cht=qr&amp;chl='+wallet+'&amp;choe=UTF-8" title="'+wallet+'">';
        $(".dp_type").html(method);
        $(".dp_amount").html('$'+amount.toLocaleString('en-US'));
        $("#dp_amount").val(amount);
        $(".dp_address").html(wallet);
        $("#dp_address").val(wallet);
        $("#dep_qr").html(qr);
        /////////////
        // $('#myModal').modal('show');
    }
});