
function ZaznaczBox(idzan)
{
	var all = document.getElementById('all'+idzan).value;

	if (document.getElementById('gl'+idzan).checked == true)
	{
		for (i = 1; i <= all; i++)
		{
			document.getElementById('zaint'+idzan+'_'+i).checked = true;
		}
	}
	else
	{
		for (i = 1; i <= all; i++)
		{
			document.getElementById('zaint'+idzan+'_'+i).checked = false;
		}
	}

}

function DisplayPlatnosci(id)
{
    var div = document.getElementById('DivPlatnosci');

	if (id == 2) div.style.display = "block";
	else div.style.display = "none";
}

function MM_jumpMenu(targ,selObj,restore)
{ //v3.0
	eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function ShowHide(id,ilosc)
{
		var divtemp;
		var div=document.getElementById('podkategorie'+id);
		if(div.style.display == "none") div.style.display = "block";
		//else div.style.display = "none";


		for(i=1; i<=ilosc; i++)
		{
			if(i!=id)
			{
				divtemp=document.getElementById("podkategorie"+i);
				divtemp.style.display = "none";
			}
		}
}

function ShowHide2(nron)
{
	if (nron == 1)
	{
		document.getElementById("p1").style.display = "block";
		document.getElementById("p2").style.display = "none";
	}
	else
	{
		document.getElementById("p2").style.display = "block";
		document.getElementById("p1").style.display = "none";
	}
}

$(document).ready(function() {

	var btnVote = $('.btnVote a');

	btnVote.bind('click', function() {

		var pollAnswers = $(this).parents('.pollAnswers');
		var checkedOption = pollAnswers.find('input:checked');

		if (0 == checkedOption.length) {
			alert('Wybierz jedną odpowiedź.');
		}
		else {

			$.post('vote.php', { idp: checkedOption.attr('name'), ido: checkedOption.val() }, function(data) {

				if ('OK' == data.message) {

					var html = '';

					$.each(data.votes, function(k, v) {
						html += '<div class="voteName">' + v.name + '</div>';
						html += '<div class="voteResult"><div><div class="voteBar" style="width: ' + v.votes_sum + '%;"></div></div>' + v.votes_sum + ' %</div>';
					});

					pollAnswers.find('.replaceMe').html(html);

					alert('Dziękujemy za oddanie głosu.');
				}
				else if ('REPEAT' == data.message) {
					alert('Głosowałeś już w tej sondzie.');
				}
				else {
					alert('Podczas głosowania wystąpił błąd.\n\nSpróbuj ponownie lub skontatkuj się z administratorem serwisu.');
				}
			}, 'json');
		}

		return false;
	});
});
