function initAnkieta(ankieta_id){
	initAnkietaGfx();
	$('#ankieta_'+ankieta_id+' label').click(function(){
		$('#ankieta_'+ankieta_id+' label.on').removeClass().addClass('off');
		$(this).removeClass().addClass('on');
		$('#ankieta_'+ankieta_id).attr('selected',$(this).attr('pytanie_id'));
	})
}
function initAnkietaGfx(){
	$("<img>").attr("src", '/public/item/ankieta/checkbox_on.gif');
}
function getAnkieta(ankieta_id,typ){
	getAnkietaBox('POST','view',ankieta_id,0,'typ='+parseInt(typ));
}
function glosujAnkieta(ankieta_id,typ){
	var selected=$('#ankieta_'+ankieta_id).attr('selected');
	if(selected>0){
		var post='pytanie_id='+parseInt(selected)+'&typ='+parseInt(typ);
		getAnkietaBox('POST','glosuj',ankieta_id,0,post);
	}else{
		alert('Nie zaznaczono odpowiedzi w ankiecie');
	}
}
function getAnkietaBox(method,action,ankieta_id,info_id,post){
	var box = '#ankieta_'+ankieta_id;
	var message = '#ankietaMessage_'+ankieta_id;
	$(box).html(getMessageBox(ankieta_id));
		$.ajax({
			url: '/item/'+ankieta_id+','+info_id+','+action+',ankieta.html',
			data: post,
			type: method,
			dataType: 'json',
			cache: false,
			timeout: 10000,
			error: function(){
				alert('Wystąpił problem z połączeniem.')				
			},
		 success: function(data){
				$(box).html(data.html);
				switch(data.view){
					case 1:initAnkieta(data.ankieta_id);break;
				}
			}
		});
}
function getMessageBox(id){
	return '<div id="ankietaMessage_'+id+'" class="ankietaMessage"></div>';
}
