/*
	Chppppj
*/

function p507_frontend_chppppjItemAdd(type, parenttype, parent, id)
{
	
	$.post(path + language + '/' + p507_frontend_chppppjItemAdd_URL + '/',
		{
			type: type,
			parenttype: parenttype,
			parent: parent
		},
		function(xml)
		{			
			if($(xml).find('error').text() == '')
			{
				message = $(xml).find('message').text();
				
				$("#" + id + "_message").prepend("<br />" + message);
			}
			else
			{
				error = $(xml).find('error').text();
				message = $(xml).find('error_message').text();
				
				if(error == "3")
				{					
					$("#" + id + "_message").prepend("<br />" + '<span style="color: red">' + message + '</span>');
				}
				if(error == "4")
				{					
					$("#" + id + "_message").prepend("<br />" + message);
				}
			}
		}
	);
}

/*
	Favourite items
*/

function p507_frontend_actionbuttons_favouriteItemsAdd(parenttype, parent, id)
{
	$.post(path + language + '/' + p507_frontend_actionbuttons_favouriteItemsAdd_URL + '/',
		{
			parenttype: parenttype,
			parent: parent
		},
		function(xml)
		{
			if($(xml).find('error').text() == '')
			{
				message = $(xml).find('message').text();
				
				$("#" + id + "_message").prepend("<br />" + message);
			}
			else
			{
				error = $(xml).find('error').text();
				
				if(error == "3")
				{
					message = $(xml).find('error_message').text();
					
					$("#" + id + "_message").prepend("<br />" + '<span style="color: red">' + message + '</span>');
				}
			}
		}
	);
}

/*
	Comments
*/

function p504_frontend_commentsMakeForm(idElement, parent, type, notSetMaximalWidth, makeAnAnimation)
{
	if(makeAnAnimation == 1) makeAnAnimation = 1; else makeAnAnimation = 0;
	
	if($("#" + idElement + "_commentsForm").text() == '')
	{
		cache = '';
		
		form_CSSClass = ' class="default"';
		if(notSetMaximalWidth == 1) form_CSSClass = '';
		
		cache += '<form action="#" method="POST" onSubmit="p504_frontend_commentsOnSubmit(\'' + idElement + '\', \'' + parent + '\', \'' + type + '\'); return false;" id="' + idElement + '_form" ' + form_CSSClass + '>';
			cache += '<fieldset>';
			cache += '<table cellspacing="0" class="wide">';
			cache += '<tr><td><textarea name="content" class="wide" id="' + idElement + '_form_textarea"></textarea></td></tr>';
			cache += '<tr><td><input class="submit" type="submit" value="Komentovat" /></td></tr>';
			cache += '</table>';
			cache += '</fieldset>';
		cache += '</form>';
			
		$("#" + idElement + "_commentsForm").hide();
		$("#" + idElement + "_commentsForm").text('');
		$("#" + idElement + "_commentsForm").append(cache);
	}
	
	if(makeAnAnimation == 1)
	{
		$("#" + idElement + "_commentsForm").slideToggle();	
	}
	else
	{
		$("#" + idElement + "_commentsForm").toggle();
	}
}

function p504_frontend_commentsOnSubmit(idElement, parent, type)
{
	data_text = $.trim($("#" + idElement + "_form_textarea").val());
	
	if(data_text == '')
	{
		return false;
	}
	
	$("#" + idElement + "_form_textarea").attr('disabled', true);
	
	$.post(path + language + '/' + p504_frontend_commentsOnSubmit_URL + '/',
		{
			parent: parent,
			path: path,
			type: type,
			content: data_text
		},
		function(text)
		{
			if(text != '0')
			{
				$("#" + idElement + "_comments").removeClass( 'dn' );
				$("#" + idElement + "_comments").show();
				$("#" + idElement + "_comments").prepend( text );
				
				$("#" + idElement + "_comments div:first").hide();
				$("#" + idElement + "_comments div:first").animate( {opacity: 'toggle'}, 400 );
				
				if(type == 5)
				{
					$("#p015_photo_DATA_comments" + parent).prepend( text );
				}
			}
			
			$("#" + idElement + "_form_textarea").val('');
			$("#" + idElement + "_form_textarea").attr('disabled', false);
		}
	);
}