function saveEntry()
{
	if ($('#title').val() =='')
	{
		alert(N_JS_ENTER_TITLE);
		return;
	}

	if ($('textarea[@id=content]').val() =='')
	{
		alert(N_JS_ENTER_TEXT);
		return;
	}

	document.entryform.submit();
};

function addVoteOption()
{
	var voteCounter = $('#voteCounter').val();

	if (voteCounter == 20) 
	{
		return;
	}
	
	var elem = $('#voteItem').clone();

	var elemA = $('a', elem);
	elemA.attr('href', 'javascript:removeVoteOption('+voteCounter+');');
	elem.attr('id', 'voteItem'+voteCounter);
	elem.css('display', '');

	$('#votelist').append(elem);

	$('#voteCounter').val(parseInt(voteCounter)+1);
};

function removeVoteOption(id)
{
	$('#voteItem'+id).remove();
};

function vote(entryId)
{
	var optionId = 0;
	$('input:radio[@name=voteoption]').each(function(el){
		if ($(this).attr('checked'))
		{
			optionId = $(this).val();
		}
	});

	if (optionId > 0)
	{
		$.post('ajax.php?page=blogs&action=vote&entryId='+entryId+'&optionId='+optionId, '', function(response) {
			eval( "var reply = "+response+";");
			if (reply.result) 
			{
				location.href = 'entry' + entryId;
			}
		});
		
	}
};

function showVoteResults(poll_id)
{
	$('#voteResults'+poll_id).show();
	$('#voteQuestion'+poll_id).hide();
};

function showVoteQuestion(poll_id)
{
	$('#voteQuestion'+poll_id).show();
	$('#voteResults'+poll_id).hide();
	
};

function checkPoll()
{
		var badoptions = false;
		var badquestion = false;

		if ($('#question').val() == '')
		{
			badquestion = true;
		}

		$('#votelist input').each(function(el){
			if ($(this).val() == '')
			{
				badoptions = true;
			}
		});

		if (badquestion) alert(N_JS_ENTER_QUESTION);
		else
			if (badoptions) alert(N_JS_ENTER_ALL_ANSWERS);
		else
			document.entryform.submit();
};

function removeFromBest(entryId)
{
	$('#mem'+entryId).hide();
	$.post('ajax.php?page=blogs&action=removeFromBest&entryId='+entryId, '', function(response) {

		eval( "var reply = "+response+";");
		if (reply.result) {
			$('#entryItem'+entryId).fadeOut(300);
			showNotification(reply.message);
		}
	});

};

function addToBest(entryId)
{
	$('#mem'+entryId).hide();

	$.post('ajax.php?page=blogs&action=addToBest&entryId='+entryId, '', function(response) {

		eval( "var reply = "+response+";");
		if (reply.result) {
			showNotification(reply.message);
		}
	});
};
