
	var ISCHANGE = false;
	function changeComment ()
	{
		if (!ISCHANGE) {
			getObj('viewCommentButs').style.display = 'none';
			// getObj('viewComments').style.display = 'none';
			getObj('insertCommentButs').style.display = 'block';
			getObj('insertComment').style.display = 'block';
			getObj('insertComment').focus();
			document.onkeydown = commentsKeyPress;
		}	else {
			getObj('viewCommentButs').style.display = 'block';
			// getObj('viewComments').style.display = 'block';
			getObj('insertCommentButs').style.display = 'none';
			getObj('insertComment').style.display = 'none';
			document.onkeydown = false;
		}
		ISCHANGE = !ISCHANGE;
	}
	
	
	function commentsKeyPress (e)
	{
		var evt = e || window.event;
		var key = evt.keyCode || evt.which;
		
		if (key == 27) {
			changeComment ();
		} else if ((evt.ctrlKey && key == 13) || key == 10) {
			submitComment ();
		}
	}
	
	
	
	function submitComment ()
	{
		var html = getObj('insertComment').value;
			// html = html.replace(/\n/g, '<br />');

		getByXajax(['users', 'comments_loading'],'page=xa_leftcomments; text=' + encodeURIComponent(html) + ';nick='+nick + ';usertype=' + usertype + ';songid=' + songid);

		changeComment();
	}
	
var pageComment = 1;
var cashCommentPage = [];
	cashCommentPage[1] = getObj('viewComments').innerHTML;
	function showCommentsPage(num)
	{
		pageComment = num;
		if (cashCommentPage[num])
			setHtml(cashCommentPage[num])
		else
			getByXajax(['users', 'comments_loading'],'page=xa_leftcomments; commentspage='+num+'; nick='+nick + ';usertype=' + usertype + ';songid=' + songid);
	}
	
	function say2Comment(num)
	{
		getObj('insertComment').value = getObj('comment_for').innerHTML + '[b]' + getObj('comment_nick_'+num).innerHTML + '[/b]' + '\n';
		changeComment();
	}
	
	function quote2Comment(num)
	{
		var text = quotes();
		if (text&&isFF) {
			re = new RegExp(smiles.join('\\[|'), 'gi');
			text = text.replace(re, '[');
		}
		if (!text) text = getObj('comment_text_'+num).innerHTML;
			text = text.replace(/<code>/gi, '[code]');
			text = text.replace(/<\/code>/gi, '[/code]');
			text = text.replace(/<b>/gi, '[b]');
			text = text.replace(/<\/b>/gi, '[/b]');
			text = text.replace(/<br>/gi, '\n');
			text = text.replace(/<i>.*?<\/i>/gi, '');
		
		text = img2smiles(text);
		
		getObj('insertComment').value = '[code][b]'+getObj('comment_nick_'+num).innerHTML + '[/b]:\n'+text+'\n[/code]\n';
		changeComment();
	}
	
	function setHtml (html)
	{
		cashCommentPage[pageComment] = html;
		getObj('viewComments').innerHTML = html;
	}
	
	function deleteComment (id)
	{
		getByXajax(['users', 'comments_loading'],'page=xa_leftcomments_delete; id=' + id + ';nick='+nick + ';usertype=' + usertype + ';songid=' + songid);
	}