﻿$(function() {
    daRen.load();
    lifeState.load();
    lifeState.buttonPages();
    $(".button01").bind(
    {
        click: function() {
            daRen.isLogin();
        }
    });
    $("#button02").bind(
	{
	    click: function() {
	        lifeState.getDiv();
	    }
	});
	$("#getawards").bind(
	{
		click:function(){
			lifeState.getAwards();
			clickNum ++;
		}
	});
});
var clickNum =0;
var cur_index = 0;
var cur_page = 0;
var ques_num = 0;
var yidaTi = [];
var lifeArr = [false, false, false];
var flag_lifeState = true;
var flag_left = true;
var flag_right = true;
var str_sts = '<div class="float2010" style="height:150px">'
			  + '<div class="bd-float floatnew-content">'
			  + '<div class="float-close" onclick="daRen.divClose()">关闭窗口</div>'
			  + '<h2>系统出错：</h2>'
			  + '<div class="float-wrap">'
			  + '<h3 class="errorbig"></h3>'
			  + '<p class="alertpart">请联系客服，客服电话：400-889-9646</p>'
			  + '</div>'
			  + '</div>'
			  + '</div>';
var str_img = '<img src="http://pics.yoho.cn/yohobuy/floatlayer/errorbig.gif" />';
var centerkh = '<div class="float2010" id="Slogan" style="height:150px">'
                  + '<div class="bd-float floatnew-content">'
	              + '<div class="float-close" onclick="divShowClose();">关闭窗口</div>'
	              + '<h2>提示：</h2>'
	              + '<div class="float-wrap">'
	              + '<h4 class="center"><img src="http://pics.yoho.cn/yohobuy/floatlayer/alertsmall.gif">本期乐活口号：来有货 做YOHO!最潮的HOT GUY</h4>'
	              + '<hr />'
	              + '<p class="center"><label id="yes" class="btn2010 btn-redsmall"><input type="button" value="确定" onclick="divShowClose();" /></label></p>'
	              + '</div>'
	              + '</div>'
	              + '</div>';
var daRen = {
    load: function() {
        var ret = "";
        var str = "";
		var ret_01 = "";
        $.get("AjaxJson.ashx?type=0", function(data) {
            var type = "";
            if (data.code) {
                $("#button01").hide();
                $("#input01")[0].value = "今日无活动";
                flag_left = false;
            } else {
                $("#input01")[0].value = "输入活动口号";
                switch (data.gift.gifttype) {
                    case '0':
                        type = 'YOHO币';
                        break;
                    case '1':
                        type = '品牌抵扣券';
                        break;
                    default:
                        type = '全场抵扣券';
                        break;
                }
                var giftvalue = Number(data.gift.giftvalue);
                ret += data.starttime + '起参与“LOHAS答题赠' + type + '活动”你只需回答' + data.questioncount + '道超简单问题，就能获得<strong>';
                if (data.gift.gifttype == 0) {
                    ret += giftvalue + '个<a href="http://old.buy.yoho.cn/help0905/help_biz02.html#help_b02yohocoin" target="_blank">' + type + '</a></strong>大礼。';
                } else {
                    ret += '<a href="http://old.buy.yoho.cn/help0905/help_biz02.html#help_b02offset" target="_blank">' + type + '</a></strong>大礼。';
                }
				ret_01 = ret+'<strong><span onclick="divShow(centerkh);" style="cursor:pointer;text-decoration:underline; font-weight:bold; color:#FF3133 !important">查看活动口号&gt;&gt;</span></strong>';
                str += '获得';
                if (data.gift.gifttype == 0) {
                    str += '￥' + giftvalue + ' <a href="http://old.buy.yoho.cn/help0905/help_biz02.html#help_b02yohocoin" target="_blank">' + type + '</a>,<a href="http://i.yoho.cn/manage/biz/account.aspx?page=1" target="_blank">点此查看</a>';
                } else {
                    str += '1张 ' + '<a href="http://old.buy.yoho.cn/help0905/help_biz02.html#help_b02offset" target="_blank">' + type + '</a>' + ',<a href="http://i.yoho.cn/manage/biz/Ticket.aspx?page=1">点此查看</a>';
                }
                $("#submit_info").html(str);
                $(".issue01").html(data.centerissue);
                $("#intro01").html(ret_01);
				$("#intro01_r").html(ret);
            }
            lifeState.buttonGray();
        }, "json");
    },
	SelectAll: function(){
		$("#input01").focus();
		$("#input01").select();
		//$("#input01").text()="";
	},
    isLogin: function() {
        if (!buy_islgoin.islgoin()) {
            login.open();
        } else {
            daRen.getDivData();
        }
    },
    getDivData: function() {
        if ($("#input01")[0].value != "来有货 做YOHO!最潮的HOT GUY") {
            divShow(centerkh);
            return;
        }
        $.get("AjaxJson.ashx?type=1", function(data) {
            if (data.code) {
                switch (data.code) {
                    case "000":
                        divShow(str_sts);
                        $(".errorbig").html(str_img + "系统出错");
                        break;
                    case "001":
                        login.open();
                        break;
                    case "007":
                        active.open();
                        break;
                    case "008":
                        $(".lohas-cnt-01").hide();
                        $("#darenFour").show();
                        break;
                    default:
                        break;
                }
            } else {
                $(".lohas-cnt-01").hide();
                daRen.genQuestions(data);
            }
        }, "json");
    },
    genQuestions: function(data) {
        $("#darenTwo").show();
        var type = "";
        switch (data.gift.gifttype) {
            case '0':
                type = 'YOHO币';
                break;
            case '1':
                type = '品牌抵扣券';
                break;
            default:
                type = '全场抵扣券';
                break;
        }
        ques_num = data.questionlist.length;
        for (var i = 0; i < ques_num; i++) {
            yidaTi.push(false);
        }
        var giftvalue = Number(data.gift.giftvalue);
        var str = "";
        var ret = '<div class="pager01">'
				   + '<div class="pagerprev" id="pagerprev_id" style="display:none">上一题</div>'
				   + '<div class="pagernext" id="pagernext_id">下一题</div></div>'
				   + '<p id="queserror" class="queserror" style="display:none;">*你还没有选择答案哦！</p></div></div>'
				   + '<div class="questions01-bot"></div></div>'
				   + '<input type="button" class="button03" id="button_send" value="提交问卷，获取好礼"  /></div>'
				   + '<div class="lohas-float-bot"></div></div>';
        str += '<div class="lohas-cnt-02 lohas-float">'
			       + '<div class="lohas-float-top"></div>'
				   + '<div class="lohas-float-cnt">'
				   + '<div class="lohas-close" onclick="daRen.twoClose()">关闭</div>'
				   + '<h2 class="hidden">lohas网购达人集中营</h2>'
				   + '<small class="issue01">' + data.centerissue + '</small>'
                   + '<p class="intro01">' + data.starttime + '起参与“LOHAS答题赠' + type + '活动”你只需回答' + data.questionlist.length + '道超简单问题，就能获得<strong>';
        if (data.gift.gifttype == 0) {
            str += giftvalue + '个<a href="http://old.buy.yoho.cn/help0905/help_biz02.html#help_b02yohocoin" target="_blank">' + type + '</a></strong>大礼。';
        } else {
            str += '<a href="http://old.buy.yoho.cn/help0905/help_biz02.html#help_b02offset" target="_blank">' + type + '</a></strong>大礼。';
        }
        str += '<div class="questions01">'
			   + '<div class="questions01-top"></div><div class="questions01-cnt"><p class="quesnum">当前题目：<span id="cur"></span>/' + data.questionlist.length + '</p><div class="quesdetail" id="quesdetail">';
        for (var i = 0; i < data.questionlist.length; i++) {
            str += '<span' + (i > 0 ? ' style="display:none;"' : '') + '><h3 id="qus_' + i + '" qusid="' +
				data.questionlist[i].qusid + '" qustype="' +
				data.questionlist[i].qustype + '" anwnum="' +
				data.questionlist[i].optionlist.length + '">' +
				data.questionlist[i].quscontent + '</h3>';
            switch (data.questionlist[i].qustype) {
                case "0":
                    str += '<ul>';
                    for (var j = 0; j < data.questionlist[i].optionlist.length; j++) {
                        str += '<li><label><input type="radio" class="quesradio" id="anw_' + i + '_' + j + '" title="' +
							data.questionlist[i].optionlist[j].optioncontent + '"   " anwid="' +
							data.questionlist[i].optionlist[j].optionid + '" name="' +
							data.questionlist[i].qusid + '"/>' +
							data.questionlist[i].optionlist[j].optioncontent + '</label></li>';
                    }
                    str += '</ul>';
                    if (data.questionlist[i].additional == "True") {
                        str += data.questionlist[i].additionaltext + '<input type="text" id="additional_' + i + '" size="50" />';
                    }
                    str += '</span>';
                    break;
                case "1":
                case "2":
                    str += '<ul>';
                    for (var j = 0; j < data.questionlist[i].optionlist.length; j++) {
                        str += '<li><label><input type="checkbox" id="anw_' + i + '_' + j + '" title="'
							+ data.questionlist[i].optionlist[j].optioncontent
							+ '" anwid="' + data.questionlist[i].optionlist[j].optionid
							+ '" name="' + data.questionlist[i].qusid + '"/>'
							+ data.questionlist[i].optionlist[j].optioncontent + '</label></li>';
                    }
                    str += '</ul>';
                    if (data.questionlist[i].additional == "True") {
                        str += data.questionlist[i].additionaltext + '<input type="text" class="text" id="additional_' + i + '" size="50" />';
                    }
                    str += '</span>';
                    break;
                case "3":
                    str += '<ul><li><input id="anw_' + i + '" type="text" class="text" anwid="'
					    + data.questionlist[i].optionlist[0].optionid
					    + '" class="text" size="50" /></li></ul>';
                    if (data.questionlist[i].additional == "True") {
                        str += data.questionlist[i].additionaltext + '<input type="text" class="text" id="additional_' + i + '" size="50" />';
                    }
                    str += '</span>';
                    break;
                case "4":
                    str += '<ul>';
                    var last_index = data.questionlist[i].optionlist.length - 1;
                    for (var j = 0; j < last_index; j++) {
                        str += '<li><label><input type="radio" id="anw_' + i + '_' + j + '" title="'
							+ data.questionlist[i].optionlist[j].optioncontent
							+ '" anwid="' + data.questionlist[i].optionlist[j].optionid
							+ '" name="' + data.questionlist[i].qusid + '"/>'
							+ data.questionlist[i].optionlist[j].optioncontent + '</label></li>';
                    }
                    str += '<li><input type="radio" id="anw_' + i + '_' + last_index + '" title="'
						+ data.questionlist[i].optionlist[last_index].optioncontent
						+ '" anwid="' + data.questionlist[i].optionlist[last_index].optionid
						+ '" name="' + data.questionlist[i].qusid + '"/>'
						+ data.questionlist[i].optionlist[last_index].optioncontent
						+ '<input type="text" class="option text" size="50" id="option_' + i + '" /></li></ul>';
                    if (data.questionlist[i].additional == "True") {
                        str += data.questionlist[i].additionaltext
							+ '<input type="text" class="text" id="additional_' + i + '" size="50" />';
                    }
                    str += '</span>';
                    break;
                default:
                    str += '<ul><input type="text" id="'
					    + data.questionlist[i].optionlist[0].optionid + '" class="text" size="50" /></ul>';
                    if (data.questionlist[i].additional == "True") {
                        str += data.questionlist[i].additionaltext + '<input type="text" class="text" id="additional_' + i + '" size="50" />';
                    }
                    str += '</span>';
                    break;
            }
        }
        str += ret;
        $("#darenTwo").html(str);
        $("input").change(function() {
            if (!daRen.promptAnswer(true)) {
                yidaTi[cur_index - 1] = false;
            }
            else {
                yidaTi[cur_index - 1] = true;
            }
            daRen.isSubmit();
        });
        $("input").keyup(function() {
            if (!daRen.promptAnswer(true)) {
                yidaTi[cur_index - 1] = false;
            }
            else {
                yidaTi[cur_index - 1] = true;
            }
            daRen.isSubmit();
        });
        daRen.pageButton(data);
        $("#cur").html(++cur_index);
        $("#button_send").addClass("button03-grey");
    },
    twoClose: function() {
        var str = '<div class="float2010" style="height:150px">'
          + '<div class="bd-float floatnew-content">'
	      + '<div class="float-close" onclick="divShowClose();">关闭窗口</div>'
	      + '<h2>提示：</h2>'
	      + '<div class="float-wrap">'
	      + '<h4 class="center">点击关闭要重新开始答题，确定要关闭吗？</h4>'
	      + '<hr />'
	      + '<p class="center"><label class="btn2010 btn-redsmall"><input type="button" value="确定" onclick="window.location.reload();" /></label>&nbsp;&nbsp;'
	      + '<label class="btn2010 btn-greysmall"><input type="button" value="取消" onclick="divShowClose();" /></label></p>'
	      + '</div>'
	      + '</div>'
	      + '</div>';
        divShow(str);
    },
	returnAnswer: function(){
		//window.location.reload();
		$("#darenFive").hide();
		$("#button_send").removeClass("button03-grey");
		var cur_length = $("#cur").text();
		for (var i=0;i<cur_length ;i++ )
		{
			$("#pagerprev_id").click();
		}
        $("#darenTwo").show();
	},
    threeClose: function() {
        window.location.reload();
    },
    fourClose: function() {
        $("#darenFour").hide();
        $(".lohas-cnt-01").show();
    },
    fiveClose: function() {
        /*$("#darenFive").hide();
        $("#darenTwo").show();*/
		window.location.reload();
    },
    divClose: function() {
        window.location.reload();
        //divShowClose();
        //$(".lohas-cnt-01").show();
    },
    isSubmit: function() {
        for (var i = 0; i < yidaTi.length; i++) {
            if (!yidaTi[i]) {
                $("#button_send").addClass("button03-grey");
                return;
            }
        }
        $("#button_send").removeClass("button03-grey");
    },
    pageButton: function(data) {
        $(".pagernext").bind("click", function() {
			/*if ($("#queserror").css("display")=="none")
			{
				$("#pagerprev_id").show();
			}*/
			//$("#pagerprev_id").show();
            if (daRen.promptAnswer()) {
                if (cur_index == data.questionlist.length) {
                    return;
                }
                if (cur_index == data.questionlist.length - 1) {
                    $("#pagernext_id").hide();
                }
                cur_index++;
                yidaTi[cur_index - 1] = true;
                $("#quesdetail span").hide();
                $("#quesdetail span:eq(" + (cur_index - 1) + ")").show();
                $("#cur").html(cur_index);
            }
			if ($("#queserror").css("display")=="none")
			{
				$("#pagerprev_id").show();
			}
        });
        $(".pagerprev").bind("click", function() {
            $("#pagernext_id").show();
            if (cur_index == 1) {
				//$("#pagerprev_id").hide();
                return;
            }
			if (cur_index ==2)
			{
				$("#pagerprev_id").hide();
			}
            cur_index--;
            $("#quesdetail span").hide();
            $("#quesdetail span:eq(" + (cur_index - 1) + ")").show();
            $("#cur").html(cur_index);
            $("#queserror").hide();
        });
        $("#button_send").bind({
            click: function() {
                if ($(this).hasClass("button03-grey")) {
                    return;
                }
                daRen.sendQuestion();
            }
        });
    },
    promptAnswer: function(isShow) {
        var quesindex = cur_index - 1;
        var ques = $("#qus_" + quesindex);
        if (ques) {
            var type = $(ques).attr("qustype");
            var anwnum = $(ques).attr("anwnum");
            var flag = false;
            switch (type) {
                case "0":
                case "1":
                case "2":
                    for (var i = 0, j = anwnum; i < j; i++) {
                        if ($("#anw_" + quesindex + "_" + i + ":checked").length > 0) {
                            flag = true;
                            break;
                        }
                    }
                    break;
                case "3":
                    if ($("#anw_" + quesindex).val() != "") {
                        flag = true;
                    }
                    break;
                case "4":
                    for (var i = 0, j = anwnum - 1; i < j; i++) {
                        if ($("#anw_" + quesindex + "_" + i + ":checked").length > 0) {
                            flag = true;
                            break;
                        }
                    }
                    if (($("#anw_" + quesindex + "_" + (anwnum - 1) + ":checked").length > 0) && ($("#option_" + quesindex).val() != "")) {
                        flag = true;
                    }
                    break;
                default:
                    flag = true;
                    break;
            }
            if (flag) {
                $("#queserror").hide();
            }
            else {
                if (!isShow) {
                    $("#queserror").show();
                }
            }
            return flag;
        }
    },
    sendQuestion: function() {
		$("#button_send").addClass("button03-grey");
        var AnswerRecord = '{"answerrecordlist":[';
        for (var i = 0, j = ques_num; i < j; i++) {
            var qus = $("#qus_" + i);
            var qusid = $(qus).attr("qusid");
            var type = $(qus).attr("qustype");
            var anwnum = $(qus).attr("anwnum");

            AnswerRecord += '{"qusid":"' + qusid + '","qustype":"' + type + '","answerlist":[';
            switch (type) {
                case "0":
                case "1":
                case "2":
                    for (var x = 0, y = anwnum; x < y; x++) {
                        if ($("#anw_" + i + "_" + x + ":checked").length > 0) {
                            AnswerRecord += '{"answerid":"' + $("#anw_" + i + "_" + x).attr("anwid") + '"';
                            AnswerRecord += ',"answervalue":"' + encodeURIComponent($("#anw_" + i + "_" + x).attr("title")) + '"},';
                        }
                    }
                    var length = AnswerRecord.length;
                    AnswerRecord = AnswerRecord.substr(0, length - 1);
                    break;
                case "3":
                    AnswerRecord += '{"answerid":"' + $("#anw_" + i).attr("anwid") + '"';
                    AnswerRecord += ',"answervalue":"' + encodeURIComponent($("#anw_" + i).val()) + '"}';
                    break;
                case "4":
                    for (var x = 0, y = anwnum; x < y; x++) {
                        if ($("#anw_" + i + "_" + x + ":checked").length > 0) {
                            AnswerRecord += '{"answerid":"' + $("#anw_" + i + "_" + x).attr("anwid") + '"';
                            AnswerRecord += ',"answervalue":"' + encodeURIComponent($("#anw_" + i + "_" + x).attr("title")) + '"},';
                        }
                    }
                    var length = AnswerRecord.length;
                    if ($("#anw_" + i + "_" + (anwnum - 1) + ":checked").length > 0) {
                        AnswerRecord = AnswerRecord.substr(0, length - 3);
                        if ($("#option_" + i).length > 0) {
                            AnswerRecord += ',' + encodeURIComponent($("#option_" + i).val());
                        }
                        AnswerRecord += '"}';
                    } else {
                        AnswerRecord = AnswerRecord.substr(0, length - 1);
                    }
                    break;
                default:
                    break;
            }
            AnswerRecord += ']';
            if ($("#additional_" + i).length > 0) {
                AnswerRecord += ',"additional":"' + encodeURIComponent($("#additional_" + i).val()) + '"';
            }
            else {
                AnswerRecord += ',"additional":""'
            }
            AnswerRecord += '},';
        }
        var length = AnswerRecord.length;
        AnswerRecord = AnswerRecord.substr(0, length - 1);
        AnswerRecord += "]}";
        $.post("AjaxVerify.ashx?type=3", { data: AnswerRecord }, function(data) {
            if (data.code) {
                switch (data.code) {
                    case "000":
                        divShow(str_sts);
                        $(".errorbig").html(str_img + "系统出错");
                        break;
                    case "001":
                        login.open();
                        break;
                    case "007":
                        active.open();
                        break;
                    case "008":
                        $("#darenTwo").hide();
                        $("#darenFour").show();
                        break;
                    case "009":
                        $("#darenFive").show();
                        $("#darenTwo").hide();
                        break;
                    case "010":
                        $("#darenThree").show();
                        $("#darenTwo").hide();
                        break;
                    case "011":
                        divShow(str_sts);
                        $(".errorbig").html(str_img + "抱歉，您的赠品发送失败");
                        break;
                    case "012":
                        divShow(str_sts);
                        $(".errorbig").html(str_img + "抱歉，系统数据错误");
                        break;
                    default:
                        break;
                }
            }
        }, "json");
    }
}
var lifeState =
{
    load: function() {
        $.get("AjaxJson.ashx?type=3", function(data) {
            if (data.code) {
				$(".button02").hide();
				$(".button04").hide();
				flag_right = false;
            } else {
                var str = "";
                var ret = "";
                $(".issue02").html(data.currentstateissue);
                for (var i = 0; i < data.stateawards.length; i++) {
                    str += '<li><a href="http://i.yoho.cn/' + data.stateawards[i].userid + '" target="_blank">' + data.stateawards[i].nickname + '</a>获' + data.stateawards[i].prizename + '</li>';
                }
                for (var i = 0; i < data.prizelist.length; i++) {
                    //ret += '<li><img src="' + data.prizelist[i].prizepicurl + '" alt="' + data.prizelist[i].prizename + '" /><p>' + data.prizelist[i].prizename + '</p></li>';
                    ret += '<li style="float:left;"><img src="' + data.prizelist[i].prizepicurl + '" alt="' + data.prizelist[i].prizename + '" /></li>';
                }
                $("#winnersli").html("<span>" + str + "</span>");
                $("#prizesli").html("<table cellpadding='0' cellspacing='0'><tr><td><div style='width:"+(data.prizelist.length*100)+"px'>" + ret + "</div></td></tr></table>");
                $("#winnersli").kxbdMarquee();
				startmarquee(100,1,1500); 

            }
			lifeState.buttonGray();
        }, "json");
    },
    getDiv: function() {
        if (!buy_islgoin.islgoin()) {
            login.open();
            return;
        }
        $.get("AjaxJson.ashx?type=2", function(data) {
            if (data.code) {
                switch (data.code) {
                    case "000":
                        divShow(str_sts);
						$(".errorbig").html(str_img+"系统出错");
                        break;
                    case "001":
                        login.open();
                        break;
                    case "008":
                        $(".lohas-cnt-01").hide();
                        $("#lifeState05").show();
                        break;
                    default:
                        break;
                }
            } else {
                $(".lohas-cnt-01").hide();
                lifeState.genDiv_01(data);
                var sttrr = "本期结果将于" + data.endtime + "公布";
                $("#lifeState04_p").html(sttrr);
                $("#lifeState05_p").html(sttrr);
            }
        }, "json");
        $.get("AjaxJson.ashx?type=4", function(data) {
            if (data.code) {
                return;
            } else {
                lifeState.genDiv_03(data);
            }
        }, "json");
    },
    genDiv_01: function(data) {
        var str = "";
        $("#lifeState01").show();
        if (data.prizelist.length > 6) {
            data.prizelist = data.prizelist.slice(0, 5);
        }
        for (var i = 0; i < data.prizelist.length; i++) {
            str += '<div class="ansdetail01"><img src="'
					+ data.prizelist[i].prizepicurl
					+ '" alt="'
					+ data.prizelist[i].prizename
					+ '"/><label><input type="radio" class="answer01_life"  name="answer01" id="'
					+ data.prizelist[i].prizeid
					+ '"/>'
					+ data.prizelist[i].prizename
					+ '</label><p>还剩'
					+ data.prizelist[i].prizeamount
					+ '件</p><small>共有'
					+ data.prizelist[i].prizeattention
					+ '人申领</small></div>';
        }
        str += '<div class="clear"></div>';
        $("#answerwrap01").html(str);
    },
    genDiv_03: function(data) {
        $("#tleid")[0].value = data.phonenum;
        $("#lifeState03_text").html(data.address);
        $("#ad_p")[0].value = data.province;
        ADInput.selectAD_c();
        $("#ad_c")[0].value = data.city;
        ADInput.selectAD_a();
        $("#ad_a")[0].value = data.area;
    },
    buttonPages: function() {
        $("#pager01_next").bind(
		{
		    click: function() {
		        lifeState.validate();
		        if (!flag_lifeState) {
		            return;
		        }
		        cur_page = 1;
		        $("#lifeState01").hide();
		        $("#lifeState02").show();
		    }
		});
        $("#pager02_prev").bind(
		{
		    click: function() {
		        cur_page = 0;
		        $("#lifeState02").hide();
		        $("#lifeState01").show();
		    }
		});
        $("#pager02_next").bind(
		{
		    click: function() {
		        lifeState.validate();
		        if (!flag_lifeState) {
		            return;
		        }
		        cur_page = 2;
		        $("#lifeState02").hide();
		        $("#lifeState03").show();
		    }
		});
        $("#pager03_prev").bind(
		{
		    click: function() {
		        cur_page = 1;
		        $("#lifeState03").hide();
		        $("#lifeState02").show();
		    }
		});
        $(".lohas-cnt-03 input,textarea").change(function() {
            lifeState.validate();
            for (var i = 0; i < 3; i++) {
                if (!lifeArr[i]) {
                    $(".button03_life").addClass("button03-grey");
                    return;
                }
                $(".button03_life").removeClass("button03-grey");
            }
        });
        $(".lohas-cnt-03 input,textarea").keyup(function() {
            lifeState.validate();
            for (var i = 0; i < 3; i++) {
                if (!lifeArr[i]) {
                    $(".button03_life").addClass("button03-grey");
                    return;
                }
                $(".button03_life").removeClass("button03-grey");
            }
        });
        $(".button03_life").bind({
            click: function() {
                if ($(this).hasClass("button03-grey")) {
                    return;
                }
				$(this).addClass("button03-grey");
                lifeState.sendForm();
            }
        });
    },
    lifeState01_che: function() {
        if ($(".answer01_life:checked").length > 0) {
            flag_lifeState = true;
            lifeArr[0] = true;
            $("#lifeState01_sug").hide();
        } else {
            flag_lifeState = false;
            lifeArr[0] = false;
            $("#lifeState01_sug").show();
        }
    },
    lifeState02_che: function() {
        if ($("#lifeState02_text").val() != "") {
            flag_lifeState = true;
            lifeArr[1] = true;
            $("#lifeState02_sug").hide();
        } else {
            flag_lifeState = false;
            lifeArr[1] = false;
            $("#lifeState02_sug").show();
        }
    },
    lifeState03_che: function() {
        $("#lifeState03_sug").html("");
        $("#lifeState03_sug").append("*你填写的");
        if ($("#lifeState03_name").val() == "") {
            $("#lifeState03_sug").append("姓名 ");
        }
        if ($("#sex_man:checked").length < 1 && $("#sex_woman:checked").length < 1) {
            $("#lifeState03_sug").append("性别 ");
        }
        if ($("#tleid").val() == "" || !/^[\d\s-]+$/.test($("#tleid").val())) {
            $("#lifeState03_sug").append("电话号码 ");
        }
        if ($("#lifeState03_text").val() == "") {
            $("#lifeState03_sug").append("详细地址 ");
        }
        if ($("#lifeState03_name").val() != "" && ($("#sex_man:checked").length > 0 || $("#sex_woman:checked").length > 0) && $("#tleid").val() != "" &&
			/^\d+$/.test($("#tleid").val()) && $("#lifeState03_text").val() != "") {
            flag_lifeState = true;
            lifeArr[2] = true;
        } else {
            flag_lifeState = false;
            lifeArr[2] = false;
        }
        if (!flag_lifeState) {
            $("#lifeState03_sug").append("有误哦！");
            $("#lifeState03_sug").show();
        } else {
            $("#lifeState03_sug").hide();
            flag_lifeState = true;
            lifeArr[2] = true;
        }
    },
    validate: function() {
        switch (cur_page + "") {
            case "0":
                lifeState.lifeState01_che();
                break;
            case "1":
                lifeState.lifeState02_che();
                break;
            case "2":
                lifeState.lifeState03_che();
                break;
        }
    },
    lifeState_Close: function() {
        var str = '<div class="float2010" style="height:150px">'
              + '<div class="bd-float floatnew-content">'
	          + '<div class="float-close" onclick="divShowClose();">关闭窗口</div>'
	          + '<h2>提示：</h2>'
	          + '<div class="float-wrap">'
	          + '<h4 class="center">点击关闭要重新填写，确定要关闭吗？</h4>'
	          + '<hr />'
	          + '<p class="center"><label class="btn2010 btn-redsmall"><input type="button" value="确定" onclick="window.location.reload();" /></label>&nbsp;&nbsp;'
	          + '<label class="btn2010 btn-greysmall"><input type="button" value="取消" onclick="divShowClose();" /></label></p>'
	          + '</div>'
	          + '</div>'
	          + '</div>';
        divShow(str);
    },
    lifeClose: function() {
        window.location.reload();
    },
    noawardsClose: function() {
        $("#lifeState08").hide();
		$("#lohas-cnt-01").show();
    },
    awardsClose: function() {
        $("#lifeState06").hide();
		$("#lohas-cnt-01").show();
    },
    prizeClose: function() {
        $("#lifeState07").hide();
		$("#lohas-cnt-01").show();
    },
    /*noprizeClose: function() {
        $("#lifeState06").hide();
    },*/
    nojoinClick: function() {
        lifeState.getDiv();
        $("#lifeState08").hide();
    },
	fiveClose: function(){
		$("#lifeState05").hide();
		$("#lohas-cnt-01").show();
	},
    sendForm: function() {
        var data_life = '{"prizeid":"'
		                + $("#answerwrap01 input:checked").attr("id")
			            + '","useradvice":"'
						+ encodeURIComponent($("#lifeState02_text").val())
						+ '","userdetail":{"usertruename":"'
						+ encodeURIComponent($("#lifeState03_name").val())
						+ '","usersex":"'
						+ $("#p_sex input:checked").attr("value");
        if ($("#tleid").val().length == 11) {
            data_life += '","userphonenum":"'
						+ $("#tleid").val()
						+ '","usermobilephonenum":"","province":"'
						+ $("#ad_p").val()
						+ '","city":"'
						+ $("#ad_c").val()
						+ '","area":"'
						+ $("#ad_a").val()
						+ '","useraddress":"'
						+ encodeURIComponent($("#lifeState03_text").val())
						+ '"}}';
        } else {
            data_life += '","userphonenum":"","usermobilephonenum":"'
						+ $("#tleid").val()
						+ '","province":"'
						+ $("#ad_p").val()
						+ '","city":"'
						+ $("#ad_c").val()
						+ '","area":"'
						+ $("#ad_a").val()
						+ '","useraddress":"'
						+ encodeURIComponent($("#lifeState03_text").val())
						+ '"}}';
        }
        $.post("AjaxVerify.ashx?type=5", { statedata: data_life }, function(data) {
            if (data.code) {
                switch (data.code) {
                    case "001":
                        divShow(str_sts);
						$(".errorbig").html(str_img+"获取用户信息失败");
                        break;
                    case "001":
                        login.open();
                        break;
                    case "008":
                        $("#lifeState01").hide();
                        $("#lifeState02").hide();
                        $("#lifeState03").hide();
                        $("#lifeState05").show();
                        break;
					case "012":
						divShow(str_sts);
						$(".errorbig").html(str_img+"抱歉，系统数据错误");
						break;
                    case "016":
                        $("#lifeState01").hide();
                        $("#lifeState02").hide();
                        $("#lifeState03").hide();
                        $("#lifeState04").show();
                        break;
                    case "017":
                        divShow(str_sts);
						$(".errorbig").html(str_img+"系统出错，记录失败");
                        break;
                    default:
                        break;
                }
            }
        }, "json");
    },
    getAwards: function() {
        if (!newToolbar.islgoin()) {
            login.open();
            return;
        }
        $.get("AjaxVerify.ashx?type=4", function(data) {
            if (data.code) {
                switch (data.code) {
                    case "001":
                        login.open();
                        break;
                    case "018":
                        $("#lohas-cnt-01").hide();
                        $("#lifeState08").show();
                        $("#lifeState07").hide();
                        $("#lifeState06").hide();
                        break;
                    default:
                        break;
                }
            } else {
				if (clickNum > 0)
				{
					$("#lifeState06").show();
					$("#lohas-cnt-01").hide();
				}else {
					if (!data.currentstate.code) {
                    $("#prizedata_yes").html(data.currentstate.stateissue + "中奖情况");
                    var rett = '<img src="'
					           + data.currentstate.prizepicurl
							   + '" /><p>恭喜你，你获得了奖品：<br /><strong>'
							   + data.currentstate.prizename
							   + '</strong></p><small>奖品已寄到“'
							   + data.currentstate.address
							   + '”，请注意查收，感谢你参与我们的活动。</small>';
                    $("#prize-cong").html(rett);
                    var sst = "";
                    for (var i = 0; i < data.paststate.length; i++) {
                        if (!data.paststate[i].code) {
                            sst += '<li>' + data.paststate[i].stateissue + '&nbsp;&nbsp;获' + data.paststate[i].prizename + '</li>';
                        } else {
                            sst += '<li>' + data.paststate[i].stateissue + '&nbsp;&nbsp;未中奖<li>';
                        }
                    }
                    $("#prize-history-yes").html(sst);
                    $("#lifeState07").show();
                    $("#lohas-cnt-01").hide();
                    $("#lifeState06").hide();
					} else {
						$("#prizedata_no").html(data.currentstate.stateissue + "中奖情况");
						$("#prize-pity").html('<span class="hidden">很抱歉，你没有在本期活动中中奖！</span>');
						var sst = "";
						for (var i = 0; i < data.paststate.length; i++) {
							if (!data.paststate[i].code) {
								sst += '<li>' + data.paststate[i].stateissue + '&nbsp;&nbsp;获' + data.paststate[i].prizename + '</li>';
							} else {
								sst += '<li>' + data.paststate[i].stateissue + '&nbsp;&nbsp;未中奖<li>';
							}
						}
						$("#prize-history-no").html(sst);
						$("#lifeState06").show();
						$("#lohas-cnt-01").hide();
						$("#lifeState07").hide();
					}
			    }    
            }
        }, "json");
    },
	buttonGray:function(){
		if(flag_left == true && flag_right == true)
		{
			return;
		}
		if (flag_left == false && flag_right == true)
		{
			$("#lohas-cnt-01").addClass("lohas-nopre-01");
			return;
		}
		if (flag_left == true && flag_right == false)
		{
			$("#lohas-cnt-01").addClass("lohas-nopre-02");
			return;
		}
		if (flag_left == false && flag_right == false)
		{
			$("#lohas-cnt-01").addClass("lohas-nopre-03");
			return;
		}
	}
}
