function PollVoting(id)
{
	var type = $('#poll_type_'+ id).val();
	var check = 0;
	var answer = 0;
	
	if (type == 1)
	{
		$('#formp_'+ id +' input').each(function(i){
			if (this.type == 'radio' && this.checked == true)
			{
				answer+= parseInt(this.value);
				check++;
			}
		});
		if (check < 1)
		{
			alert('Вы не выбрали ни вариант ответа.');
			return;
		}
	}
	else if (type == 2)
	{
		$('#formp_'+ id +' input').each(function(i){
			if (this.type == 'checkbox' && this.checked == true)
			{
				if (answer != '')
					answer += ',';
				answer+= parseInt(this.value);
				check++;
			}
		});
		var cnt = parseInt($('#poll_cnt_'+ id).val());
		
		if (check < 1)
		{
			alert('Вы не выбрали ни одного варианта ответа.');
			return;
		}
		else if (check > cnt)
		{
			alert('Вы выбрали слишком много вариантов ответа.\nВ данном голосовании можно выбрать '+ cnt +' вариантов ответа.');
			return;
		}
	}
	
	var options = {
		dataType: 'json',
		url: '/poll/',
		type: 'POST',
		data: {
			action: 'PollVoting',
			id: id
		},
		success: function(data)	{
			if (data.status == 'error')
			{
				$('#poll_' + id +' .poll_content .poll_button').show();
				$('#poll_' + id +' .poll_content .poll_loader').hide();
				alert(data.msg);
				return;
			}
			else if (data.status == 'ok')
			{
				$('#poll_'+ id +' .poll_content').html(data.msg);
			}
		}
	};
	$('#poll_' + id +' .poll_content .poll_button').hide();
	$('#poll_' + id +' .poll_content .poll_loader').show();
	$('#formp_'+ id).ajaxSubmit(options);
}
function PollGetResults(id)
{
	var options = {
		dataType: 'json',
		url: '/poll/',
		type: 'POST',
		data: {
			action: 'PollGetResults',
			id: id
		},
		success: function(data)	{
			if (data.status == 'error')
			{
				alert('Ошибочка вышла');
				return;
			}
			else if (data.status == 'ok')
			{
				$('#poll_'+ id +' .poll_content').html(data.msg);
			}
		}
	};
	$('#poll_' + id +' .poll_content .poll_button').hide();
	$('#poll_' + id +' .poll_content .poll_loader').show();
	$('#formp_'+ id).ajaxSubmit(options);
}
function PollInit()
{
	$.ajax({
		url: '/poll/',
		dataType: 'json',
		type: 'POST',
		data: {
			action: 'GetPollsRight'
		},
		success: function(data){
			if (data.status == 'ok')
			{
				$('#rbl_poll_cont').html(data.data);
			}
			else if (data.status == 'error')
			{
				$('#right_poll').remove();
			}
		}
	});	
}
