function switchCommentsVisibility() {
	var comment_body = document.getElementById('comment_body');
	var comment_switch_text = document.getElementById('comment_switch_text');
	var comments_showall = document.getElementById('comment_showall');
	if (comments_showall.childNodes.length != 0) {
		xajax_run('xcomments','hideCommentsBody');
	} else {
		xajax_run('xcomments','showCommentsBody');
	}
	return true;
}

function checkFillContent(value)
{
	if (value == '') {
		alert("Заполните все поля, отмеченные символом '*'");
		return false;
	}
	return true;
}


function saveComment(pid, type)
{
	var content = document.getElementById('comment_content_' + pid).value;
	if (document.getElementById('comment_login_' + pid)) {
		var login = document.getElementById('comment_login_' + pid).value;
	}
	var code = document.getElementById('comment_code_' + pid).value;

	if (document.getElementById('comment_mess_pass_'+pid)) {
		var mes_pass = document.getElementById('comment_mess_pass_'+pid).value;
	} else {
		var mes_pass = false;
	}
	
	if (document.getElementById('comment_pass_'+pid)) {
		var com_pass = document.getElementById('comment_pass_'+pid).value;
	} else {
		var com_pass = false;
	}
	
	if (checkFillContent(content)  && checkFillContent(code)) {

		xajax_run(
			'xcomments',
			'saveComment',
			pid,
			document.getElementById('comment_content_'+pid).value,
			type,
			login,
			com_pass,
			code,
			1,
			mes_pass
		);

	}

}


function saveBoardMessage(aUID,table,aType)
{
	var content = document.getElementById('message_content').value;
	
	if (content != '') {
		xajax_run(
			'xprofiles',
			'saveComment',
			aUID,
			table,
			aType,
			content
		);
	} 
}



function changeCommentNode(id)
{
	if (document.getElementById('comment_child_' + id).style.display == 'none') {
		openSubComments(id);
	} else {
		closeSubComments(id);
	}
}



function openSubComments(id)
{
	if (document.getElementById('comment_child_' + id).innerHTML == '') {
		xajax_run('xcomments','showSubComments', id);
		document.getElementById('comment_child_' + id).style.display = 'block';
	} else {
		document.getElementById('comment_child_' + id).style.display = 'block';
	}
	document.getElementById('comment_img_' + id).src = "images/xcomments/minus.gif";
}



function closeSubComments(id)
{
	document.getElementById('comment_child_' + id).style.display = 'none';
    document.getElementById('comment_img_' + id).src = "images/xcomments/plus.gif";
}
