<?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="Trading Calculator";
    $page_desc="Know the current value of BTC, ETH to USD, know your return on Trade and many more...";
    $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."calculator/";
    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-fluid">
                        <div class="row">
                            <div class="col-md-2"></div>
                            <div class="col-md-8">
                                <div class="page-header">
									<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>
                     
                     <?php //require('../j_incs/balance.php'); ?>
                    
                    <div class="container-fluid">
                    <div class="row">
						<div class="col-md-2"></div>
                        <div class="col-md-8">
							<div class="tab-content m-t-15">
								<div class="tab-pane fade show active" id="tab-account">
								
										
									<div class="card">
										
										<div class="card-header">
											<h4><?php echo $page_name; ?></h4>
											<h6 class="text_sm_gray">
												 <?php echo $page_desc; ?>
											</h6>
										</div>
										<div class="card-body">
										
											
											
											<form method="POST" action="" id="form">
												
												
												<div class="form-group">
													<label class="font-weight-semibold">Select Cryptocurrency</label>
													<select type="text" class="form-control rMe" name="wallet_type">
														<option value="BTC"><i class="fab fa-btc"></i>BTC</option>
														<option value="ETH"><i class="fab fa-ethereum">ETH</option>
													</select>
												</div>
												
												<div class="form-group">
													<label class="font-weight-semibold">Amount in USD </label>
													<input autocomplete="off" type="tel" class="form-control rMe" name="amount_usd" placeholder="Amount"/>
												</div>
												
												
												<div class="form-group">
													<label class="font-weight-semibold">Amount in <span class="addressInfo">BTC</span> </label>
													<input autocomplete="off" type="tel" class="form-control rMe" name="amount" placeholder="Amount"/>
												</div>
												
                                            
												
												<div class="form-group">
													<label class="font-weight-semibold">Select Plan</label>
													 <select type="text" class="form-control rMe" name="duration">
														<option value="">*Choose*</option>
														<?php $TRADING_array_count = count($TRADING_array); $num=0; for($i=0; $i<$TRADING_array_count; $i++){ ?>
														<option value="<?php echo $i; ?>"><?php echo $TRADING_array[$i][7]; ?> - <?php echo $TRADING_array[$i][0]; ?> (<?php echo $TRADING_array[$i][3]; ?>%)</option> 
														<?php } ?>
													</select>
													<div class="">
														<h4> 
															Total Earning: <b><span id="lt">0.00 </span></b>
														</h4>
													</div>
													
												</div>
												
											</form>
										</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=amount_usd]").keyup(function(){
            var a = $("[name=amount_usd]").val();
            var d = $("[name=duration]").val();
            var c = $("[name=wallet_type]").val();
            if(a!=="" && d!=="" && c!==""){
              $.ajax({
                url: '<?php echo $dir;  ?>invest-now/calculator.php?a='+a+'&d='+d+'&c='+c+'',
                method: 'post',
                success: function (data) {
                     $("#lt").html(data);
                 }
              });
            }
          });
			
		
        $("[name=duration]").change(function(){
            var a = $("[name=amount_usd]").val();
            var d = $("[name=duration]").val();
            var c = $("[name=wallet_type]").val();
            if(a!=="" && d!=="" && c!==""){
              $.ajax({
                url: '<?php echo $dir;  ?>invest-now/calculator.php?a='+a+'&d='+d+'&c='+c+'',
                method: 'post',
                success: function (data) {
                     $("#lt").html(data);
                 }
              });
            }
          });
		  
		$("[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'); 
					}
				});
			}
		});
		
		
       
        
        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>