﻿function singleVote(pid) {
    for (var i = 0; i < $('#vote_' + pid).find('span[AnswerID]').length; i++) {
        var control = $($('#vote_' + pid).find('span[AnswerID]')[i]);
        var answerID = control.attr('AnswerID');
        $.get('/Ajaxhandle/Ajaxhandler.ashx?CMD=GetVotes&tag=' + new Date() + "&answerID=" + answerID, function (data) {
            var strArray = data.split(',');
            $("#answer_" + strArray[1] + "_votes").html(strArray[0]);
        });
    }
    if (!$.cookie("vote_" + pid)) {
        $('#vote_' + pid).find('span[AnswerID]').click(function () {
            var answerID = $(this).attr('AnswerID');
            var votes = parseInt($('#answer_' + answerID + '_votes').html()) + 1;
            $('#answer_' + answerID + '_votes').html(votes);
            $('#vote_' + pid).find('span[AnswerID]').unbind('click');
            var parma = '&topicid_9999=' + answerID;
            $.get('/Ajaxhandle/Ajaxhandler.ashx?CMD=vote&tag=' + new Date() + parma);
            $('#vote_' + pid).attr("class", "nvt-single-widget nvt-single-bg02 ");
            $.cookie("vote_" + pid, "1",1);
        });
    }
    else {
        $('#vote_' + pid).attr("class", "nvt-single-widget nvt-single-bg02 ");
    }
}
function multiVote(pid) {
    $('#vote_' + pid).find('#vote_submit').click(function () {
        var parma = '';
        for (var i = 0; i < $('#vote_' + pid).find('.topic_item').length; i++) {
            var topicid = $($('#vote_' + pid).find('.topic_item')[i]).attr('topicid');
            var value = '';
            for (var j = 0; j < $($('#vote_' + pid).find('.topic_item')[i]).find('input').length; j++) {
                var control = $($($('#vote_' + pid).find('.topic_item')[i]).find('input')[j]);
                if (control.attr('checked')) {
                    if (value != '') {
                        value += ',';
                    }
                    value += control.val();
                }
            }
            if (value == '' && $($('#vote_1').find('.topic_item')[i]).attr('isRequired')) {
                alert('请填写完整的调查信息');
                return;
            }
            parma += '&topicid_' + topicid + '=' + value;
        }
        $.get('/Ajaxhandle/Ajaxhandler.ashx?CMD=vote&tag=' + new Date() + parma);
        location.href = "/index.php?ct=index&ac=viewvotes&pid=" + pid;
    });
    $('#vote_' + pid).find('#vote_view').click(function () {
        location.href = "/index.php?ct=index&ac=viewvotes&pid=" + pid;
     });
}
