var prize_word=[
    '家和万事兴',
    '和谐美满',
    '和和美美',
    '和和睦睦 ',
    '和气生财',
    '和蔼可亲'
];
var prize_lock=1;
$(document).ready(function () {

    try {
        window.Origami.fastclick(document.body);
    } catch (e) {
    }
    document.addEventListener("touchmove", function (e) {
        e.preventDefault();
    }, false);
    var clickEvent = $.isFunction($.fn.tap) ? 'tap' : 'click';
    window['max_zindex'] = 100;
    $.fn.show_dialog = function () {
        window['max_zindex'] += 1;
        this.css('z-index', window['max_zindex']);
        this.show();
    };
    if(window.type==1){
        $('.prize-type').show();
    }else {
        $('.btn-prize').show();
    }
    $('.btn-prize').on('click',function () {
        if(prize_lock==2){
            return;
        }
        btnPrize();
    });
});
function btnPrize() {
    prize_lock=2;
    $('.btn-prize').text('抽奖中...');
    $.ajax({
        url: '/index/tryPrize',
        type: 'post',
        data:{'channel':GetQueryString('channel')},
        success: function (resp) {
           var rank=RandomNumBoth(0,5);
            if (resp.errcode != 0) {
                my_notify(prize_word[rank]);
            }else{
                $('.btn-prize').hide();
                $('.prize-type').show();
            }
            $('.btn-prize').text(prize_word[rank]);

        },
        error: function () {
            my_notify('网络异常，请稍后重试');
        }
    });

}
function RandomNumBoth(Min, Max) {
    var Range = Max - Min;
    var Rand = Math.random();
    var num = Min + Math.round(Rand * Range); //四舍五入
    return num;
}
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null)return unescape(r[2]);
    return null;
}
window.wx && wx.ready(function () {
    // wx.hideMenuItems({
    //     menuList: ['menuItem:share:appMessage','menuItem:share:timeline','menuItem:share:qq','menuItem:share:facebook','menuItem:share:QZone','menuItem:copyUrl','menuItem:openWithQQBrowser',''] // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
    // });
    wx.hideAllNonBaseMenuItem();
});