function p515_comments_getHTMLForm(parent, idItem, type, isTheFormBottom)
{
	cache = '';
	
	if(isTheFormBottom == 1)
	{
		cache += '';
	}
	
	cache 
	cache += '<form action="#" method="POST" onSubmit="p515_comments_add_form_onSubmit(' + parent + ', ' + idItem + ', ' + type + ', ' + isTheFormBottom + '); return false;" id="p515-comments-form-' + idItem + '" class="comment-form">';
		cache += '<fieldset>';
			cache += '<legend class="blind">Add Comment</legend>';
			
			if(p515_auth == 0)
			{
				cache += '<p>';
					/*cache += '<label for="p515-comments-add-form-name-' + idItem + '"></label><br />';*/
					cache += '<input type="text" id="p515-comments-add-form-name-' + idItem + '" value="Name..." onblur="form__text_onBlur(this, \'Name...\')" onfocus="form__text_onFocus(this, \'Name...\')" />';
				cache += '</p>';
			}
			
			cache += '<p>';
				cache += '<label for="p515-comments-add-form-content-' + idItem + '" class="blind">Message</label>';
				cache += '<textarea id="p515-comments-add-form-content-' + idItem + '" rows="5"></textarea>';
			cache += '</p>';
		cache += '</fieldset>';
		cache += '<p class="submit cf">';
			cache += '<input type="submit" class="button" id="p515-comments-add-form-submit-' + idItem + '" value="Send" />';
		cache += '</p>';
		
	cache += '</form>';
	
	if(isTheFormBottom == 1)
	{
		cache += '';
	}
	
	return cache;
}

function p515_comments_clickedReply(parent, idItem, type)
{	
	if($('#p515-comments-div-form-' + idItem).text() == '')
	{
		$('#p515-comments-div-form-' + idItem).append(p515_comments_getHTMLForm(parent, idItem, type, 0));
		$("#p515-comments-div-form-" + idItem).removeClass('blind');
		$("#p515-comments-div-form-" + idItem).hide();
		$("#p515-comments-div-form-" + idItem).animate( {height: 'toggle', opacity: 'toggle'}, 400 );
	}
	else
	{
		$("#p515-comments-div-form-" + idItem).animate( {height: 'toggle', opacity: 'toggle'}, 400 );
	}
}

function p515_comments_add_form_onSubmit(parent, idItem, type, isTheFormBottom)
{
	data_content = $.trim($("#p515-comments-add-form-content-" + idItem).val());
	data_name = '';
	
	if(p515_auth == 0)
	{
		data_name = $.trim($("#p515-comments-add-form-name-" + idItem).val());
		if(data_name == '' || data_name == 'Name...')
		{
			window.alert('Fill your name, please.');
			return false;
		}
		
		$("#p515-comments-add-form-name-" + idItem).attr('disabled', true);
	}
	
	$("#p515-comments-add-form-content-" + idItem).attr('disabled', true);
	$("#p515-comments-add-form-submit-" + idItem).attr('disabled', true);
	
	
	$.post(pl + URL_p515_comments_add_form_AJAX_DB + '/',
		{
			content: data_content,
			anonymous_name: data_name,
			parent: parent,
			parent_item: idItem,
			type: type,
			
			PL: pl,
			PATH: path
		},
		function(html)
		{
			if(html != '0')
			{
				$("#p515-comments-add-form-content-" + idItem).val("");
				$("#p515-comments-ul-" + idItem).append( html );
				
				if(p515_auth == 0)
				{
					$("#p515-comments-add-form-name-" + idItem).val("");
				}
			}
			
			$("#p515-comments-add-form-content-" + idItem).attr('disabled', false);
			$("#p515-comments-add-form-submit-" + idItem).attr('disabled', false);
			
			if(p515_auth == 0)
			{
				$("#p515-comments-add-form-name-" + idItem).attr('disabled', false);
			}
			
			if(type == 1)
			{
				$("#p515_gallery_photos_commentsCache_comment" + parent).append( html );
			}
			
			if(isTheFormBottom != 1)
			{
				$("#p515-comments-div-form-" + idItem).animate( {height: 'toggle', opacity: 'toggle'}, 400 );
			}
		}
	);
}

