﻿var buttunId;
function ToTransferBuy(id, price) {
    if (confirm("确定要购买该商品吗？系统将从您的账户中扣除" + price + "胡豆。")) {
        buttunId = id;
        $("#BtBuy_" + buttunId).attr("disabled", "true");
        UpTransfer(1, new BasicGoods(id, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null));
    }
}

function UpTransfer(id, obj) {
    ajax_json_postV1('Services/UpTransfer.ashx?' + id + '_' + Math.random(), JSON.stringify(obj), 30000, false, UpTransfer_success, UpTransfer_error, UpTransfer_beforeSend);
}

function UpTransfer_beforeSend() {
    xMsgBox.showMsgbox("正在购买，请稍等……", "loading", false, 0);
}

function UpTransfer_error() {
    xMsgBox.showMsgbox("购买失败，请重新提交！", "error", true, 2000);
    $("#BtBuy_" + buttunId).removeAttr("disabled");
}

function UpTransfer_success(data) {
    if (data.InfoStatus == 0) {
        xMsgBox.showMsgbox("购买成功！", "info", true, 2000);
        timer = setTimeout(StringUtility.format("locationhref(\'{0}\')", GlobalHref.MyBuyTransfer()), 2000);
    }
    else if (data.InfoStatus == 1) {
        xMsgBox.showMsgbox("商品信息错误！", "error", true, 2000);
        $("#BtBuy_" + buttunId).removeAttr("disabled");
    }
    else if (data.InfoStatus == 2) {
        xMsgBox.showMsgbox("商品信息错误！", "error", true, 2000);
        $("#BtBuy_" + buttunId).removeAttr("disabled");
    }
    else if (data.InfoStatus == 3) {
        xMsgBox.showMsgbox("您不能购买自己转让的商品！", "error", true, 2000);
        $("#BtBuy_" + buttunId).removeAttr("disabled");
    }
    else if (data.InfoStatus == 4) {
        xMsgBox.showMsgbox("请先登录！", "error", true, 2000);
        $("#BtBuy_" + buttunId).removeAttr("disabled");
    }
    else if (data.InfoStatus == 5) {
        xMsgBox.showMsgbox("您账户中的胡豆数不足，无法购买请充值。<br/><a href='" + GlobalHref.BuyHuDou() + "'>去充值胡豆</a>", "error", true, 2000);
        $("#BtBuy_" + buttunId).removeAttr("disabled");
    }
    else {
        xMsgBox.showMsgbox("未知错误请重新领取！", "error", true, 2000);
    }
}
