<?php
error_reporting(0);
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);

$pmsql = "select * from dunling_web where smoney>'0' order by danjia desc limit 1";
$pmery = mysql_query($pmsql,$config);
$pm = mysql_fetch_array($pmery);
isset($pm['danjia'])?$pm1 = $pm['danjia']:$pm1="0";

$rwsql = "select * from dunling_renwu where smoney>'0' order by danjia desc limit 1";
$rwery = mysql_query($rwsql,$config);
$rw = mysql_fetch_array($rwery);
isset($rw['danjia'])?$rw1 = $rw['danjia']:$rw1="0";
?>
<!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: 300px;height:30px;
    border:1px solid #D5D5D5;
}

input.danjia{
    width:150px;height:30px;
    text-align:center;
    border:1px solid #D5D5D5;
}
.form{
    width:300px;
    height:35px;
    
}
#renwu{
    margin:0;
    padding:0;
    list-style:none;
    border:1px solid #D5D5D5;
    width:305px;
    height:35px;
    line-height:35px;
    font-family: 微软雅黑;
    font-size:16px;
    color:#FF0000;
}
.vb{
    display:none;
}
#a4,#a5{
    width:150px;
    height:35px;
    line-height:35px;
    font-family: 微软雅黑;
    font-size:16px;
    color:#FF0000;
    margin:0;
    padding:0;
    list-style:none;
    border:1px solid #D5D5D5;
}
textarea{
    width:600px;
    height:200px;
    resize:none;
    border:1px solid #D5D5D5;
    line-height:30px;
    font-size:16px;
    color: #535353;
    font-family: 微软雅黑;
    letter-spacing: 1px;
}
input.radio{
    width:15px;
    height:15px;
}
</style>
</head>
<body>
<script>
$(function(){
    $("#a1").keyup(function(){
        var danjia = $(this).val();
        var yy = $("#yy").val();
        var xhs = parseInt(yy/danjia);
        if(xhs<"1"){
        $(".tis").html('<span style="color:red;">单价过高,您的金币不足！</span>');
        $("#a1").val('');
        return false;
        }else{
        var cis = $("#a4").val();
        var danjia = $(this).val();
        var zje = ((cis*danjia)*10000)/10000;
        if(zje>yy){
        $(".tis").html('<span style="color:red;">您的金币不足！</span>');
        }else{
        $(".tis").html('共需支付 <span style="color:red;">'+ zje + '</span> 个金币');
        }

        return false;
        }
  
    });
    
    $("#a4").change(function(){
        var yy = $("#yy").val();
        var cis = $(this).val();
        var danjia = $("#a1").val();
        var zje = ((cis*danjia)*10000)/10000;
        if(zje>yy){
        $(".tis").html('<span style="color:red;">您的金币不足！</span>');
        }else{
        $(".tis").html('共需支付 <span style="color:red;">'+ zje + '</span> 个金币');
        }
        return false;
        
    });
    

    
    $("#renwu").change(function(){
        var z = $(this).val();
        if(z=="1"){
            $(".va").show();
            $(".vb").hide();
        }
        if(z=="2"){
            $(".vb").show();
            $(".va").hide();
        }
        
        
    });
    
    
    $("#form").click(function(){
        var z = $("#renwu").val();
        var a1 = $("#a1").val();
        var a2 = $("#a2").val();
        var a3 = $("#a3").val();
        var a4 = $("#a4").val();
        var a5 = $("#a5").val();
        var b1 = $("#b1").val();
        var b2 = $("#b2").val();
        var b3 = $("input[type='radio']:checked").val();
        if(z=="1"){

            if(a1==""){
                $(".txt").text('请输入推广价格!');
                return false;
            }
            if(a1 < "1"){
                $(".txt").text('悬赏单价不能少于1个金币!');
                return false;
            }
            if(a2==""){
                $(".txt").text('请输入网站名称!');
                return false;
            }
            if(a3==""){
                $(".txt").text('请输入阅览网址!');
                return false;
            }
            if(a4==null){
                $(".txt").text('请选择阅览任务次数!');
                return false;
            }
            if(a4=="0"){
                $(".txt").text('请选择阅览任务次数!');
                return false;
            }
            
            if(a5==""){
                $(".txt").text('请输入阅览时间(以秒为单位)!');
                return false;
            }
        }
            if(z=="2"){
            if(b1==""){
                $(".txt").text('请输入任务单价!');
                return false;
            }
            if(b2==""){
                $(".txt").text('请输入任务名称!');
                return false;
            }
            if(b3==""){
                $(".txt").text('请输入任务说明!');
                return false;
            }
        }
        $.post("fabu_1.php",{
            z:z,
            a1:a1,
            a2:a2,
            a3:a3,
            a4:a4,
            a5:a5,
            b1:b1,
            b2:b2,
            b3:b3
        },function(a,b){
           if(a=="ok"){
            alert('添加成功！');
            location.href='fabu.php';
           }
           if(a=="moneyerror"){
            alert('您的金币不足！');
            return false;
           }
           if(a=="urlerror"){
            $(".txt").text('网址输入有误！');
            alert('网址输入有误！');
            return false;
           }
        });


        });
        

   
});
</script>

<div id="table"><input id="yy" type="hidden" value="<?php echo $user['jinbi'];?>"/>
<div class="W100">可用金币:</div><div class="W350"><?php echo $user['jinbi'];?></div>
</div>

<div id="table">
<div class="W100">任务类型:</div><div class="W350"><select id="renwu"><option value="1">浏览任务</option><option value="2">综合任务</option></select></div>
</div>

<div id="table">
<div class="W100">悬赏单价:</div><div class="W350"><input type="text" class="danjia" id="a1" onkeyup='this.value=this.value.replace(/\D/gi,"")' /> 单位:金币</div>
</div>

<div id="table">
<div class="W100">需求稿件:</div><div class="W150" style="text-align: left;"><select id="a4">
<option value="0">请选择</option>
<?php
for($i="10";$i<="100";$i++){
if(floor($i/10)==($i/10)){
echo '<option value="'.$i.'">'.$i.'</option>';
}
}
for($i="200";$i<="10000";$i++){
        if(floor($i/100)==($i/100)){
echo '<option value="'.$i.'">'.$i.'</option>';
}
}
?></select></div>
<div class="W350 tis" style="color: #B0B0B0;margin-left:20px;"></div>
</div>

<div class="va">
<div id="table">
<div class="W100">阅览时间:</div><div class="W350"><select id="a5">
<?php
for($i="5";$i<="180";$i++){
    if(floor($i/5)==($i/5)){
    echo '<option value="'.$i.'">'.$i.'秒</option>';
    }
    }
?>

</select></div>
</div>

<div id="table">
<div class="W100">网站名称:</div><div class="W350"><input type="text" class="text" id="a2" /></div>
</div>

<div id="table">
<div class="W100">阅览网址:</div><div class="W350"><input type="text" value="http://" class="text" id="a3" /></div>
</div>
</div>

<div class="vb">
<div id="table">
<div class="W100">任务名称:</div><div class="W350"><input type="text" class="text" style="width: 602px;" id="b1" maxlength="32" /></div>
</div>

<div id="table">
<div class="W100">任务说明:</div>
<div class="W350_AUTO"><textarea id="b2" maxlength="300"></textarea></div>
</div>

<div id="table">
<div class="W100">上传截图:</div><div class="W100"><input type="radio" class="radio" value="1" name="imgfile"/>是 <input type="radio" class="radio" value="0"  name="imgfile" checked=""/>否</div><div class="W200"><span style="color: #868686;font-size:12px;">是否需将稿件截图上传审核</span></div>
</div>

</div>

<div id="table">
<div class="W100"></div>
<div class="W450_AUTO txt" style="color: red;"><span style="color: #797979;">提示:单价越高,推广排名就会越靠前！<br />当前最高价:&nbsp;浏览任务:<?php echo $pm1;?>金币&nbsp;综合任务:<?php echo $rw1;?>金币</span></div>
</div>

<div id="table">
<div class="W100"> </div><div class="W350"><input class="form" type="button" id="form" value="发布新任务" /></div>
</div>
<div id="table">
<div class="W100"> </div><div class="W350 ts"></div>
</div>




</body>
</html>