﻿//判断用户登录了没
function JudgeUserLogin(type, typeID) {
    $.post("UserHasLogined.ashx", { none: "ee" }, function(data) {
        if (data.state == "yes") {
            ChooseFunction(type, typeID);
        } else {
            //登录
            ShowLoginDiv();
            $("#UserLoginDiv").data({ "type": type, "typeID": typeID, state: "sendParameter" });
        }
    }, "json");
}
//
function SendParameterToChooseFunction() {
    var tempParameter = $("#UserLoginDiv");
    if (tempParameter.data("state") == "sendParameter") {
        ChooseFunction(tempParameter.data("type"), tempParameter.data("typeID"));
        ClearSendData();
    }
}
function ClearSendData() {
    var tempParameter = $("#UserLoginDiv");
    tempParameter.removeData("state");
    tempParameter.removeData("type");
    tempParameter.removeData("typeID");
}
//选择函数
function ChooseFunction(type, typeID) {
    switch (type) {
        case "FavEcoupon":
            CollectionEcoupon(typeID);
            break;
        case "FavEnterprise":
            CollecitonEnterprise(typeID);
            break;
        case "DownEcoupon":
            Down(typeID);
            break;
    }

}
//收藏优惠券函数
function CollectionEcoupon(typeID) {
    if (confirm("您确定收藏此优惠券？")) {
        $.post(
                    "CollectEcoupons.ashx",
                   { ID: typeID },
                    function(data) { CollectionSuccess(data); },
                    "json");
    }
}
//收藏商家函数
function CollecitonEnterprise(typeID) {
    if (confirm("您确定收藏此商家？")) {
        $.post(
                    "CollectionEnterprise.ashx",
                   { ID: typeID },
                    function(data) { CollectionSuccess(data); },
                    "json");
    }
}
//收藏成功函数
function CollectionSuccess(data) {
    if (data.state == "success") {
        alert(data.msg);
    } else {
        alert(data.msg);
    }
}
//下载函数
function Down(typeID) {
    $('#ex2').jqm({ ajax: 'ReadyDownLoad.ashx?EcouponID=' + typeID, trigger: 'a.ex2trigger' + typeID });
    $('#ex2').jqmShow();
}