﻿function $(eId) { return document.getElementById(eId); }

var mMPoll = function() {
    var _pollId = '', _piIds = '', _extraData = '';
    //Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
return {
    init: function(pollId, viewMode) {
        _pollId = pollId;
		if (viewMode == 'form' || (viewMode != 'results' && g_Cookies.get('AtpPoll_pid' + _pollId) == null )) 
		    { this.showForm(); } else { this.showResults(); }
    },
    
    showForm: function() { $('MPoll_f'+_pollId).style.display = ''; $('MPoll_r'+_pollId).style.display = 'none'; },
    showResults: function() { $('MPoll_f'+_pollId).style.display = 'none'; $('MPoll_r'+_pollId).style.display = ''; },
    
    setVote: function(piIds, extraData) { _piIds = piIds; _extraData = extraData; },
    
    sendVote: function(url) {
        if (_piIds == '') { Ext.MessageBox.alert('סקר', 'יש לסמן תשובה רצוייה'); return; }
        
        var delegateShowResults = this.showResults;
        
        Atp.Poll.WS_MPoll.SendVote(_pollId, _piIds, function(r) {
            if (r.isSuccess) {
                g_Cookies.set('AtpPoll_pid' + _pollId, _piIds, 365);
		        if (url) location.href = url; else delegateShowResults();
            }
        });
    }
}};
