﻿
$(document).ready(function() {
    getAcivedate();
});

//获取团购时间
function getAcivedate() {
    var id = Geturl();
    $.ajax({
        url: "../Zx/ZxHandler.ashx",
        type: "post",
        data: { aID: id },
        //error: function() { alert("请求页面错误！") },
        success: function(date) {
            var msg = DateDiff(date);
            $("#timenum").html(msg);
        }
    });
}



//获取感兴趣内容
function getThing() {
    var thingStr = "";
    for (var i = 1; i < 7; i++) {
        var thing = document.getElementById("cbF" + i);
        if (thing.checked) {
            thingStr += thing.value + ",";
        }
    }
    return thingStr;
}

//报名
function activeBm() {
    var nameStr = $("#txtName").val();
    var phoneStr = $("#txtPhone").val();

    if (nameStr == "") {
        alert("名字不能为空！");
    }
    else {
        if (phoneStr == "") {
            alert("联系电话不能为空！");
        }
        else {

            //报名列表
            var bmtable = $("#activeTable").html();

            //感兴趣内容
            var thingStr = getThing();

            //活动编号
            var aidStr = Geturl();

            //获取会员信息
            var userinfo = GetCookie("userinfot");
            var uidStr = "0";

            if (userinfo != null) {
                var id = userinfo.split('&');
                id = id[0].split('=');
                if (id != "") {
                    uidStr = id[1];
                }
            }
            //alert(nameStr + "," + phoneStr + "," + uidStr + "," + aidStr + "," + $("#txtAddress").html() + "," + thingStr);

            //处理报名信息
            $.ajax({
            url: "http://www.wootg.com/active/Bmlogon.ashx",
                type: "post",
                data: { uid: uidStr, aid: aidStr, name: nameStr, phone: phoneStr, address: $("#txtAddress").html(), thing: thingStr },
                beforeSend: function() {
                    $("#activeTable").hide().next("#loadding").show().html("<span style='color:#fff;padding:10px;padding-top:20px;float:left;font-size:14px'>系统正在受理您提交的报名信息，请耐心等待......</span>");
                },
                error: function() { alert("请求页面错误！") },
                complete: function() { $("#activeTable").show().next("#loadding").hide(); },
                success: function(data) {
                    var msg = decodeURI(data);

                    //返回处理信息
                    switch (msg) {
                        case "0":
                            alert("报名成功，我们会尽快与您联系，请密切关注！请注意查收短信！");
                            break;
                        case "-4":
                            alert("报名成功，我们会尽快与您联系，请密切关注！您输入的是无效手机号码，未接受到信息！");
                            break;
                        case "10":
                            alert("该活动已结束报名，您可以参加其他的活动！");
                            break;
                        default:
                            alert("报名成功，我们会尽快与您联系，请密切关注！");
                            break;
                    }
                    window.location.href("../huodong/success.html");
                }
            });
        }
    }
}