<?php
require_once("../check.php");
require_once("../../config.php");
$usersql = "select * from dunling_user where username='$username'";
$userery = mysql_query($usersql,$config);
$user = mysql_fetch_array($userery);

$minpaysql = "select rmbvsjinbi from dunling_config where id='1'";
$minpayery = mysql_query($minpaysql,$config);
$pay = mysql_fetch_array($minpayery);
$duihuanbili = $pay['rmbvsjinbi'];

?>
<!DOCTYPE HTML>
<html>
<head>
<title>货币兑换</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="../js/jquery-1.11.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="../style/template.css" />
<style>
input.text{
    width: 150px;height:30px;
    text-align:center;
    border:1px solid #D5D5D5;
}
.form{
    width:150px;
    height:35px;
    
}

</style>
</head>
<body>
<script>
$(function(){
$("#jinbi").keyup(function(){
    var jinbi = $(this).val();
    var jinbiis = isNaN(jinbi);
    var moneyyue = $("#moneyyue").val();
    if(jinbiis){
        $("#jinbi").val('');
        return false;
    }
    if(parseInt((jinbi/<?php echo $duihuanbili;?>)*1000) > parseInt(moneyyue*1000)){
        $("#form").attr("disabled",true);
        $("#ts").html('<span style="color:red;">您的余额不足,请充值！</span>');
        return false;
    }
    $.post("php/duihuan2.php",{
        jinbi:jinbi
    },function(aa,bb){
        $("#form").attr("disabled",false);
        $("#ts").html('共需<span style="color:red;">'+aa+' 元</span>');
        return false;
    });
});
    
$("#form").click(function(){
    var jinbi = $("#jinbi").val();
    if(jinbi==""){
        $("#ts").html('<span style="color:red;">请输入您要兑换的金币数额！</span>');
        return false;
    }
    $.post("php/duihuanok2.php",{
        jinbi:jinbi
    },function(aaa,bbb){
        if(aaa=="usermoneyerror"){
        $("#ts").html('<span style="color:red;">您的余额不足,请充值！</span>');
        return false; 
        }
        if(aaa=="ok"){
        alert('您兑换的金币已入账!');
        location.href='dhjinbi.php';
        return false;
        }
        
    });
    
});



   
});
</script>


<div id="table">
<div class="W100">我的余额:</div><div class="W350 yyxx"><?php echo $user['money'];?> 元</div>
</div>

<div id="table">
<div class="W100">我的金币:</div><div class="W350 yyxx"><?php echo $user['jinbi'];?><input id="moneyyue" type="hidden" value="<?php echo $user['money'];?>"/></div>
</div>

<div id="table">
<div class="W100">兑换比例:</div><div class="W350" >1元人民币 = <?php echo $duihuanbili;?>个金币</div>
</div>

<div id="table">
<div class="W100">兑换金币:</div><div class="W350"><input type="text" class="text" id="jinbi" /></div>
</div>

<div id="table">
<div class="W100"></div><div class="W350" id="ts"><span style="color: #959595;">请输入要兑换的金币</span></div>
</div>

<div id="table">
<div class="W100"> </div><div class="W350"><input class="form" type="button" id="form" value="确认并兑换" /></div>
</div>




</body>
</html>