function p505_board_form_onSubmit()
{
	msg = $.trim($("#p505-form-board-content").val());
	msgParent = $.trim($("#p505-form-board-parent").val());
	
	if(msg == TEXT_p505_board_form_content || msg == '')
	{
		return false;
	}
	
	$("#p505-form-board-content").attr('disabled', true);
	$("#p505-form-board-submit").attr('disabled', true);
	
	$.post(path + language + '/' + URL_p505_board_form_AJAX_DB + '/',
		{
			content: msg,
			parent: msgParent
		},
		function(xml)
		{
			if($(xml).find('error').text() == '')
			{
				xml_user_id = $(xml).find('user_id').text();
				xml_user_name = $(xml).find('user_name').text();
				xml_user_surname = $(xml).find('user_surname').text();
				xml_datetime = $(xml).find('datetime').text();
				xml_content = $(xml).find('content').text();
				xml_image = $(xml).find('image').text();
				
				$("#p505-form-board-content").val("");
				
				$("#p505-board-content").prepend( p505_board_form_TEMPLATE_item(xml_user_id, xml_user_name, xml_user_surname, xml_datetime,xml_content, xml_image) );
				
				$("#p505-board-content div:first").hide();
				$("#p505-board-content div:first").animate( {opacity: 'toggle'}, 400 );
				
				$("#p505-form-board-content_remaining").text("600");
			}
			
			$("#p505-form-board-content").attr('disabled', false);
			$("#p505-form-board-submit").attr('disabled', false);
		}
	);
}

function p505_board_form_TEMPLATE_item(id, name, surname, datetime, content, image)
{
	html = '';
	
	html += '<div class="item cf">';
		if(id != 0) { html += '<a href="' + URL_p507_userProfile + id + '/">'; }
			html += '<span class="small-avatar"><img src="' + path + image + '" alt="' + name + ' '  + surname + '" /></span>';
		if(id != 0) { html += '</a>'; }
		html += '<p><strong>'
		if(id != 0) { html += '<a href="' + URL_p507_userProfile + id + '/">'; }
			html += name + ' '  + surname;
		if(id != 0) { html += '</a>'; }
		html += '&nbsp;<span class="dn">-</span>&nbsp;';
		html += '<small>' + datetime + '</small></strong><br />';
		html += content + '</p>';
	html += '</div>';
	
	return html;
}

function p505_board_showMore()
{	
	$('#p505-board-content-more').removeClass('dn');
	$('#p505-board-content-more').hide();
	$('#p505-board-content-more').animate( {opacity: 'toggle'}, 400 );
	/*$('#p505-board-content-more-p').prepend( $('#p505-board-content-more-p a').text());*/
	$('#p505-board-content-more-p a').remove();
}

function p505_board_loadNewPage(page)
{
	$.ajax({
		type: "GET",
		url: path + language + '/' + URL_p505_board_getData_AJAX_DB + '/page:' + page + '/group:' + p505_groupID + '/',
		dataType: "xml",
		success: function(xml)
		{			
			if($(xml).find('error').text() == '')
			{
				$("#p505-board-content").empty();
				
				$(xml).find('item').each(function()
				{
					$("#p505-board-content").append( p505_board_form_TEMPLATE_item($(this).find('user_id').text(), $(this).find('user_name').text(), $(this).find('user_surname').text(), $(this).find('datetime').text(), $(this).find('content').text(), $(this).find('image').text()) );
				});
			}
		},
		error: function() { }
	});
}

function p505_board_delete(id, element_id)
{	
	$.post(path + language + '/' + p505_board_delete_URL,
		{
			id: id
		},
		function(xml)
		{
			if($(xml).find('error').text() == '0')
			{
				$("#" + element_id).show();
				$("#" + element_id).animate( {height: 'toggle', opacity: 'toggle'}, 400 );
			}
		}
	);
}