var biddingAlertId = '';
var biddingUrl = "http://www1.360quan.com/bidding/ajax/";

function showBidding(itemid,appMsg)
{
    var url = biddingUrl + "show?id="+ itemid;
    var rnd = new Date().getTime();
    $.get("/broker", { forward: url ,fresh: rnd},
        function(data){
            if(data.error != "200")
            {
                p_alert("Data Loaded Error: " + data.message);
            }else{
                showBiddingAlert(itemid, appMsg, data.result);
            }
        }, 'json');

}

function createBiddingDiv(content)
{
    var html = "";

    html = "<div class=bidAlert><ul><li>竞价项目：" + content.title + "</li>";
        //"<li>出价范围：最低：" + content.min_price + "炫币 最高：" + content.max_price + "炫币</li>" +
        //"<li>出价人条件：等级[" + content.prerequisite_level + "] 财富[" + content.prerequisite_currency_one + "] 炫币[" + content.prerequisite_currency_two + "]</li>" +
        //"<li>项目启动时间：" + content.start_time + "</li>" +
    if(content.currency_one > 0 || content.currency_two > 0)
    {
        //html = html + "<li>目前最高出价：" + content.currency_one + "炫币 + " + content.currency_two + "财富</li>";
    }

    html = html + "<li>出财富：<input type=\"text\" name=\"bid_cf\" id=\"bid_cf\" maxlength=\"8\" onfocus=\"this.value = parseInt(this.value,10) || 0;\" onblur=\"this.value = parseInt(this.value,10) || 0;\" onkeyup=\"this.value = parseInt(this.value,10) || 0;\" size=\"8\" value=\"0\"><input type=\"hidden\" name=\"user_cf\" id=\"user_cf\" value=\""+ content.cf +"\">(你现有财富:" + content.cf +")";

    if(content.cf <= 0) html = html + "财富不足，快去<a href='http://my.360quan.com/' target='_blank'>领财富</a>吧！";

    html = html + "</li>" +
        "<li>出炫币：<input type=\"text\" name=\"bid_xb\" id=\"bid_xb\" maxlength=\"8\" onfocus=\"this.value = parseInt(this.value,10) || 0;\" onblur=\"this.value = parseInt(this.value,10) || 0;\" onkeyup=\"this.value = parseInt(this.value,10) || 0;\" size=\"8\" value=\"0\"><input type=\"hidden\" name=\"user_xb\" id=\"user_xb\" value=\""+ content.xb +"\">(你现有炫币:" + content.xb + ")";

    if(content.xb <= 0) html = html + "炫币不足，点击<a href='http://pay.360quan.com/' target='_blank'>充值</a>";

    html = html + "</li>" +
        "<input type=\"hidden\" name=\"bid_id\" id=\"bid_id\" value=\"" + content.appId + "\">" +
        "<input type=\"hidden\" name=\"bid_auth\" id=\"bid_auth\" value=\"" + content.authCode + "\"></ul></div>";

    return html;
}

function showBiddingAlert(itemid, appMsg, content)
{
    biddingAlertId = "bidding_show_"+itemid;

    content = createBiddingDiv(content);

    var biddingAlert = {};

    biddingAlert = new ph$.alet.build({
             id : biddingAlertId,
             title : "立即竞价购买",
             clos : "关闭",
             head : appMsg,
             cont : content,
             btn : [["确认", "UserBidPrice"], ["取消", ""]],
             width : 500,
             visiby : "visible",
             shadow : 2
	});

}

function UserBidPrice()
{
    var itemid = parseInt($("#bid_id").val());
    var cf = parseInt($("#bid_cf").val());
    var user_cf = parseInt($("#user_cf").val());
    var xb = parseInt($("#bid_xb").val());
    var user_xb = parseInt($("#user_xb").val());
    var auth = $("#bid_auth").val();
    var url = biddingUrl + "bid?id="+ itemid + "&cf=" + cf + "&xb=" + xb + "&auth=" + auth;

    if( cf > user_cf)
    {
        p_alert("你的财富好像不足哦");
        return false;
    }
    if( xb > user_xb)
    {
        p_alert("你的炫币好像不足哦");
        return false;
    }

    var rnd = new Date().getTime();
    $.get("/broker", { forward: url ,fresh: rnd},
            function(data){
                p_alert(data.message);
            if(data.error == "200")
            {
                ph$.alet.hidden(biddingAlertId);
            }
        }, 'json');

}

