
var openedForm = 0;

function showReplyForm(id)
{
	if (openedForm != 0)
	{
		var oldCommentDiv = document.getElementById('comment-' + openedForm);
		
		while(oldCommentDiv.childNodes.length > 0)
		{
			oldCommentDiv.removeChild(oldCommentDiv.childNodes[0]);
		}
	}

	openedForm = id;
	
	var commentDiv = document.getElementById('comment-' + id);
	
	// create div
	
	var div = document.createElement('div');
	div.setAttribute('style', 'margin: 5px 0px 5px 0px;');
	
	// form
	
	var form = document.createElement('form');
	
	form.setAttribute('action', '/comments/');
	form.setAttribute('method', 'post');
	
	// hidden
	
	var hidden = document.createElement('input');
	
	hidden.setAttribute('type', 'hidden');
	hidden.setAttribute('name', 'parent');
	hidden.setAttribute('value', id);
	
	form.appendChild(hidden);
	
	// textarea
	
	var textarea = document.createElement('textarea');
	
	textarea.setAttribute('name', 'text');
	textarea.setAttribute('rows', '10');
	
	form.appendChild(textarea);
	
	// submit button
	
	var submit = document.createElement('input');
	
	submit.setAttribute('type', 'submit');
	submit.setAttribute('style', 'margin-top: 5px;');
	submit.setAttribute('value', 'ответить');
	submit.setAttribute('class', 'button');
	
	form.appendChild(submit);
	
	div.appendChild(form);
	
	// add to parent
	
	commentDiv.appendChild(div);
}
