﻿Type.registerNamespace('Fansite.Poll');

Fansite.Poll.submitAnswer = function (evt, context) 
{
    if(context.contactId <= 0) {
        window.location.href = '../Public/Signup.aspx';
        return Relational.Utility.eventCancel(evt);
    }
    else {
        var pollSelectedValue = Website.Behavior.getRadioSelectedValue(context.pollAnswersId);
        if(typeof(pollSelectedValue) != 'undefined') {            
            var controlPath =  '~/ViewControls/Poll.ascx';
            var command = 'Vote';
            var arguments = { selectedValue : pollSelectedValue }; 
            Relational.ViewControls.refresh(context.element, controlPath, command, arguments);
            return Relational.Utility.eventCancel(evt);
        }
    }
}

Fansite.Poll.initControl = function (submitButtonId,pollAnswersId,contactId) 
{
    var submitAnswerButton = $get(submitButtonId);
    if(typeof(submitAnswerButton) != 'undefined' && submitAnswerButton != null) {
        $clearHandlers(submitAnswerButton);
        $addHandler(submitAnswerButton, 'click', Function.createCallback(Fansite.Poll.submitAnswer, { element : submitAnswerButton, pollAnswersId : pollAnswersId, contactId : contactId }));
    }
}

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
