/** modul ankieta */
var timeLeft=0, pollTimerS=0;

function formatTimeFromSec(){
	var m,s;
	if(timeLeft>1){--timeLeft;}else{return '-:--';}
	m=parseInt(timeLeft/60);
	s=timeLeft%60;
	s=(s<10)?'0'+s:s;
	return m+':'+s;
}

function pollTimerBar(v){
	var w=Math.round((100 / v.time) * (v.time - timeLeft));
	var o=dojo.byId('pollBarCurrent');
	if(typeof o == 'object'){
		o.style.width=w+'%';
	}
}

function pollTimerF(){
	var tdiv=dojo.byId('pollTimerBox');
	var val=dojo.fromJson('{'+tdiv.title+'}');
	if(!timeLeft){timeLeft=parseInt(val.left);}
	document.title=tdiv.title+' | '+val.left+' | '+timeLeft;
	tdiv.innerHTML='Czas: '+formatTimeFromSec();
	pollTimerBar(val);
}

var submitPollForm = function(){
	var hdiv=dojo.byId('ax-poll');
	if(pollTimerS){window.clearInterval(pollTimerS); pollTimerS=false;}
	timeLeft=0;
	var bind={
		url:'/pub/sess/poll',
		form:'pollForm',
		handle: function(request, ioArgs){
			hdiv.innerHTML='';
			hdiv.innerHTML=request+'';
			pollTimerS=window.setInterval('pollTimerF()',1000);
		},
		error: function(data){
			console.error('Wystapil blad: ', request);
		}
	};
	dojo.xhrGet(bind);
	return false;
}

