var act;

function create(nid) {
	dark('dark');
	if ($('adToolbar'))
		$('adToolbar').hide()
	$('sendMsg').action += 'create/';
	$('post').show();
	align_height('post');
}

function reply(tid) {
	dark('dark');
	if ($('adToolbar'))
		$('adToolbar').hide()
	$('topic_id').value=tid;
	$('sendMsg').action += 'reply/';
	$('title_div').hide();
	$('post').show();
	align_height('post');
}

function edit(tid, topic) {
	act = $('sendMsg').action;
	dark('dark');
	$('topic_id').value=tid;
	$('sendMsg').action += 'edit/';
	if ($('title'+tid)) {
		$('title').value = $('title'+tid).innerHTML;
		$('title_div').show();
	}
	else {
		$('title_div').hide();
	}

	$('message').value = $('msg'+tid).innerHTML;
	$('post').show();
	align_height('post');

	if (topic) {
		$('edit_theme').show();
	}
	else {
		$('edit_theme').hide();
	}

	if ($('adToolbar')) {
		$('adToolbar').show();
	}

}

function delete_post() {
	$('sendMsg').action = act+'delete/';
	$('sendMsg').submit();
}
function block() {
	$('sendMsg').action = act+'block/';
	$('sendMsg').submit();
}
function delete_theme() {
	$('sendMsg').action = act+'delete_theme/';
	$('sendMsg').submit();
}
function move_to() {
	$('movePost').show();
	$('movePost').style.top = $('post').offsetTop + 'px';
}
function move(tid) {
	$('sendMsg').action = act+'move/'+tid+'/';
	$('sendMsg').submit();
}

function send() {
	$('sendMsg').submit();
}

function reset() {
	$('sendMsg').reset();
	$('post').hide();
	$('dark').hide();
	$('movePost').hide();
}

function find_by_topic(tid) {
	$('topic').value=tid;
	$('topic_href').style.textDecoration = 'none';
	$('forum_href').style.textDecoration = 'underline';
}

function find_by_forum() {
	$('topic').value='';
	$('topic_href').style.textDecoration = 'underline';
	$('forum_href').style.textDecoration = 'none';
}

function align_height(id){
	  var post = document.getElementById(id);
	  var height = document.documentElement.clientHeight;
	  var post_height = post.offsetHeight;
	  post.style.top = (height - post_height)/2 + document.documentElement.scrollTop + 'px';
}

function hide_it(){
	$('movePost').hide();
}

function show_children(mas_id, class_name){
	if(class_name == 'topicText'){
		var mas = $$('div#commTopic'+mas_id+' .topicText');
		for(var i=1; i<mas.length; ++i){
			mas[i].className = 'topicText_new';
		}
		chtext('href'+mas_id, 'Показать ветвь дискуссии');
		$('href'+mas_id).setAttribute('href',"javascript:show_children("+mas_id+", 'topicText_new');");
	}
	else {
		var mas = $$('div#commTopic'+mas_id+' .topicText_new');
		for(var i=0; i<mas.length; ++i){
			mas[i].className = 'topicText';
		}
		chtext('href'+mas_id, 'Скрыть ветвь дискуссии');
		$('href'+mas_id).setAttribute('href',"javascript:show_children("+mas_id+", 'topicText');");
	}
	
}
function change_className(id, class_name){
	$(id).className = class_name;
}
function ch_class(id, class_name1, class_name2){
        if ($(id).className == class_name1) {
            $(id).className = class_name2;
        }
        else {
            $(id).className = class_name1;
        }
}

