﻿$(document).ready(function () {

    $(".pollResultSection").hide();

    $('.pollForm').submit(function (e) {
        e.preventDefault();
        var data = $(this).serialize();
        var stringID = $(this).attr('id');
        var pollID = stringID.substring(5, stringID.length)

        $.ajax({
            type: "POST",
            url: "/Application/AnswerPoll/" + pollID,
            data: data,
            error: function (msg) {
                alert("error");
            },
            success: function (msg) {
                if (msg.indexOf("Error: ", 0) > -1) {
                    alert(msg);
                }
                else {
                    $("#poll_" + pollID + "_question").hide();
                    $("#poll_" + pollID + "_results").html(msg);
                    $("#poll_" + pollID + "_results").show();
                }
            }
        });

        return false;
    });

});
