﻿
function Vote(pollGUID) {

    var radiobuttonOptions = Form.getInputs('aspnetForm', 'radio', 'radioAnswerSelection' + pollGUID);

    var answerID = 0;
    var length = radiobuttonOptions.length;

    for (i = 0; i < length; i++) 
    {
        if (radiobuttonOptions[i].checked) 
        {
            answerID = radiobuttonOptions[i].value;
        }
    }

    if (answerID == 0) {
        MM.showMessage("You must select an answer before voting in a poll.", "Choose an answer!");
    }
    else {
        ret = Avenue7_Presentation.PollService.PollVote(pollGUID, answerID, PollVoteOC, PollVoteOE);
    }
}

function PollVoteOC(arg) {
    if (arg == "error") {
        PollVoteOE(arg);
    }
    else if (arg == "login") {
        MW.showBoxP('/ModalContent/loginSml.aspx');
    }
    else{ // success!
        new Ajax.Updater('divAnswers' + arg, '/PollResults.aspx?pollGUID=' + arg + '&rand=' + Math.random(), { method: 'get', evalScripts: true});
    }
}

function PollVoteOE(arg) 
{
    MM.showMessage("There was an error voting on your poll. Send us feedback if this happens regularly.", "Error Voting");
}

function ButtonReport_Onclick(pollGUID) {
    ret = Avenue7_Presentation.UserService.ReportItem('Poll.aspx?PollGUID=' + pollGUID, ReportOC, ReportOE);
    MM.showWaiting("This item is being reported, please wait", "Reporting item...");
}

function ReportOC(arg) {
    MM.showMessage("This item has been reported to the administrators. Thank you for reporting inappropriate content. If you have any further questions please email info@avenue7.com.", "Item Reported.");
}

function ReportOE(arg) {
    MM.showMessage("There was a problem reporting the item, we will try and solve this problem as soon as possible. In the mean time please email us at info@avenue7.com to tell us of this inappropriate item and we will take action immediately.", "Reporting item failed.");
}

