<?php  session_start(); error_reporting(0); ?>
<?php if(!isset($_SESSION['j_admin'])){ 
    $url = urlencode("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); header('location:../login/?url='.$url.'');  
} ?>
<!doctype html>
<html lang="en"> 
<head>
	<?php
    require_once("../j_conn/url.php");
    require_once("../j_conn/dbc.php");
    require_once("../j_incs/functions.php");
    $page_name="Edit User Wallet";
    $page_desc="$page_name";
    $page_img="".$dir."j_files/j_img/logo/logo-meta.png";
    $page_author="$company";
    $page_keywords="".$company.", $page_name, $page_desc, ".$company_motto.", $company_desc";
    $page_url="".$dir."wallet-edit/";
    require_once("../j_incs/metas.php");
    require_once("../j_incs/scripts-top.php");
    ?>
</head>
<body>
    
    <div class="app">
        <div class="layout">
            <?php 
            require_once("../j_incs/header.php");
            require_once("../j_incs/nav.php");
            ?>
            <!-- Page Container START -->
            <div class="page-container">
                

                <!-- Content Wrapper START -->
                <div class="main-content">
                    <div class="container">
                        <div class="row">
                            <div class="col-md-1"></div>
                            <div class="col-md-10">
                                <div class="page-header">
									<?php /*<h2 class="header-title"><?php echo $page_name; ?></h2>*/ ?>
									<div class="header-sub-title">
										<nav class="breadcrumb breadcrumb-dash">
											<a href="<?php echo $dir; ?>" class="breadcrumb-item"><i class="anticon anticon-dashboard m-r-5"></i>Dashboard</a>
											<!--<a class="breadcrumb-item" href="#"> </a>-->
											<span class="breadcrumb-item active"><?php echo $page_name; ?></span>
										</nav>
									</div>
								</div>
                            </div>
                        </div>
                    </div>
                     
                     
                    <div class="container">
						<div class="row">
                            <div class="col-md-1"></div>
                            <div class="col-md-10">
						
						
						
								<div class="tab-content m-t-15">
									<div class="tab-pane fade show active" id="tab-account">
										
										
										<div class="card">

											<div class="card-body">
												
												<div class="row">
													<div class="col-md-1"></div>
													<div class="col-md-10">
														
														<form method="POST" action="" id="form">
															<div class="row">
																<div class="col-md-2"></div>
																<div class="col-md-8">

																	<div class="form-group">
																		<label class="font-weight-semibold">Recipient's Username </label>
																		<input autocomplete="off" type="text" class="form-control rMe" name="re_username" placeholder="Username"/>
																	</div>


																	<div class="form-group">
																		<label class="font-weight-semibold">Name: <b id="re_name"></b>
																		</label>
																	</div>
																	
																	
																	<div class="form-group">
																		<label class="font-weight-semibold">BTC Wallet (Amount in USD) </label>
																		<input autocomplete="off" type="tel" class="form-control rMe" name="amount_btc" placeholder="Amount BTC"/>
																	</div>
																	
																	
																	<div class="form-group">
																		<label class="font-weight-semibold">ETH Wallet (Amount in USD) </label>
																		<input autocomplete="off" type="tel" class="form-control rMe" name="amount_eth" placeholder="Amount ETH"/>
																	</div>
																	
																	

																	<div class="form-group">
																		<button id="submit"  name="submit" class="btn btn-primary btn-block">Continue</button>
																	</div>





																</div>
															</div>

														</form>
														<div id="formresult"></div>
														
													</div>
												</div>
											</div>
										</div>

									</div>

								</div>
							</div>
						</div>
						
						
						
						
						
						
						
                    </div>
                </div>
                <!-- Content Wrapper END -->
				
		
				

                <?php
                require_once("../j_incs/footer.php");
                ?>

            </div>
            <!-- Page Container END -->
        </div>
    </div>
    
    
    <?php
    require_once("../j_incs/scripts-bottom.php");
    ?>
	<script>
	
	$("[name=wallet_type]").change(function () {
			$("[name=amount]").val('');
			$("[name=amount_usd]").val('');
			var  wallet_type_id = $("[name=wallet_type]");
			var  addressInfo_id = $(".addressInfo");
			var wallet_type_val = wallet_type_id.val();
			if(wallet_type_val !==''){
				addressInfo_id.html(wallet_type_val);
			}
		});
		$("[name=amount_usd]").keyup(function () {
			var  amount_crypto = $("[name=amount]");
			var  amount_usd = $("[name=amount_usd]");
			var  currency = $("[name=wallet_type]").val();
			var  amount_crypto_val = amount_crypto.val();
			var  amount_usd_val = amount_usd.val();
			var  rateResult = $("[name=amount]");
			if(currency !=='' && amount_usd !==''){
				amount_crypto.val('***');
				amount_crypto.attr('disabled','');
				$.post('<?php echo $dir; ?>wallet-topup/rate-usd.php', 
				{
					currency:currency,
					amount_crypto_val:amount_crypto_val,
					amount_usd_val:amount_usd_val,
				},function(data){
					if(data){
						rateResult.html(data);
						//amount_crypto.removeAttr('disabled'); 
					}else{
						amount_crypto.val('');
						//amount_crypto.removeAttr('disabled'); 
					}
				});
			}
		});
		
		
		
		$("[name=amount]").keyup(function () {
			var  amount_crypto = $("[name=amount]");
			var  amount_usd = $("[name=amount_usd]");
			var  currency = $("[name=wallet_type]").val();
			var  amount_crypto_val = amount_crypto.val();
			var  amount_usd_val = amount_usd.val();
			var  rateResult = $("[name=amount]");
			if(currency !=='' && amount_crypto !==''){
				amount_usd.val('***');
				amount_usd.attr('disabled','');
				$.post('<?php echo $dir; ?>wallet-topup/rate-crypto.php', 
				{
					currency:currency,
					amount_crypto_val:amount_crypto_val,
					amount_usd_val:amount_usd_val,
				},function(data){
					if(data){
					   rateResult.html(data);
						amount_usd.removeAttr('disabled'); 
					}else{
						amount_usd.val('');
						amount_usd.removeAttr('disabled'); 
					}
				});
			}
		});
		
		
    $("[name=re_username]").keyup(function () {
        var  re_username_id = $("[name=re_username]");
        var  re_username = re_username_id.val();
        var  re_name_id = $("#re_name");
        var  re_wallet_id = $("[name=wallet_type]");
        if(re_username !==''){
            re_name_id.html('***');
            re_wallet_id.html('<option value="">*Select*</option>');
            $.post('re-name.php', 
            {
                re_username:re_username
            },function(data){
                if(data){
                   re_name_id.html(data);
                }else{
                    re_name_id.html('');
                }
            });
        }else{
			re_name_id.html('');
		}
    });
        
    var form = "#form";
    var button = "#submit";
    var button_val = $(button).html();
    var result = "#formresult";
    $(form).on('submit',(function(e) {
    e.preventDefault();
    $(button).attr('disabled', '');
    $(button).html("<i class='anticon anticon-loading'></i> Processing");
    $(result).html("<div class='alert alert-warning'> Taking too long? <a href=''>Reload </a></div>");
     $.ajax({
    url: "save.php",
    type: "POST",
    data: new FormData(this),
    contentType: false,
    cache: false,
    processData:false,
    success: function(data)
    {
    if(data){
     $(button).removeAttr('disabled');
    $(button).html(button_val);
    $(result).html(data);
    }else{
    $(result).html("Error occurred.");
    $(button).removeAttr('disabled');
    $(button).html(button_val);
    }
    }
    });
    }));
    </script>

   
</body>
</html>