var Polls=Class.create();Polls.prototype={currentValue:0,poll_done:false,poll_id:0,step:1,initialize:function(){if($('poll'))
new Ajax.Request('/?mod2=polls&mod=ajax',{method:'post',parameters:{act:'get_poll',data:''},onLoading:function(){},onLoaded:function(){},onSuccess:function(transport){var data=eval('('+transport.responseText+')');if(data.poll_body){$('poll').show().innerHTML=data.poll_body;polls.updateElement();polls.poll_done=data.poll_done;polls.poll_id=data.poll_id;polls.step=data.step;}
else $('poll').hide().innerHTML='';}});},updateElement:function(){document.observe('click',(function(event){var target=event.findElement('input[id=btn_send_poll]');if(target){event.stop();target.disabled=true;if(this.step==2)this.getResult();else this.postVote();}}).bind(this));document.observe('click',(function(event){var target=event.findElement('div[id=btn_close]');if(target){event.stop();this.pollHide();}}).bind(this));},postVote:function(){var val=this.poll_id+'|'+this.currentValue;new Ajax.Request('/?mod2=polls&mod=ajax',{method:'post',parameters:{act:'post_poll',data:val},onLoading:function(){$('btn_send_poll').value='Отправка...';},onLoaded:function(){},onSuccess:function(transport){var data=eval('('+transport.responseText+')');if(data.poll_body){$('poll').show().innerHTML=data.poll_body;}
else $('poll').hide().innerHTML='';}});},pollHide:function(){var val=this.poll_id
new Ajax.Request('/?mod2=polls&mod=ajax',{method:'post',parameters:{act:'hide_poll',data:val},onLoading:function(){$('poll').hide().innerHTML='';},onLoaded:function(){},});},getResult:function(){var val=this.poll_id+'|'+this.step;new Ajax.Request('/?mod2=polls&mod=ajax',{method:'post',parameters:{act:'get_poll',data:val},onLoading:function(){},onLoaded:function(){},onSuccess:function(transport){var data=eval('('+transport.responseText+')');if(data.poll_body){$('poll').show().innerHTML=data.poll_body;}
else $('poll').hide().innerHTML='';}});},change_v:function(target){this.currentValue=target.value;if(!this.poll_done)$('btn_send_poll').disabled=false;$('btn_send_poll').focus();}}
document.observe('dom:loaded',function(){polls=new Polls();});
