// POST EDIT //
function whenCompletedCommentsEdit(){

	var post_main_obj = document.getElementById( 'post-id-' + comm_id );
	var post_box_top  = _get_obj_toppos( post_main_obj );

			if ( post_box_top )
			{
				scroll( 0, post_box_top - 70 );
			}

};

function ajax_post_edit( с_id )
{
	if ( ! c_cache[ с_id ] || c_cache[ с_id ] == '' )
	{
		c_cache[ с_id ] = document.getElementById( 'post-id-'+с_id ).innerHTML;
	}

	var ajax = new dle_ajax();
	comm_id = с_id;
	ajax.onShow ('');
	var varsString = "";
	ajax.setVar("id", с_id);
	ajax.setVar("action", "edit");
	ajax.requestFile = dle_root + "engine/forum/ajax/editpost.php";
	ajax.method = 'GET';
	ajax.element = 'post-id-'+с_id;
	ajax.onCompletion = whenCompletedCommentsEdit;
	ajax.sendAJAX(varsString);
	return false;
}

function ajax_cancel_post_edit( c_id )
{
	if ( n_cache[ c_id ] != "" )
	{
		document.getElementById( 'post-id-'+c_id ).innerHTML = c_cache[ c_id ];
	}
	
	return false;
};

// POST SAVE //
function whenCompletedSavePost(){
c_cache[ comm_edit_id ] = '';
}

function ajax_save_post_edit( c_id )
{
	var ajax = new dle_ajax();
	comm_edit_id = c_id;
	ajax.onShow ('');
	var comm_txt = ajax.encodeVAR( document.getElementById('edit-post-'+c_id).value );
	var varsString = "post_text=" + comm_txt;
	ajax.setVar("id", c_id);
	ajax.setVar("action", "save");
	ajax.requestFile = dle_root + "engine/forum/ajax/editpost.php";
	ajax.method = 'POST';
	ajax.element = 'post-id-'+c_id;
	ajax.onCompletion = whenCompletedSavePost;
	ajax.sendAJAX(varsString);

	return false;
};

// ADD POST //
function doAddPost(){

	var form = document.getElementById('dle-comments-form');
    var dle_comments_ajax = new dle_ajax();

	if (dle_wysiwyg == "yes") {
	document.getElementById('post_text').value = oEdit1.getXHTMLBody();
	form.submit();
	}
	else {

	closeall();

	if (form.post_text.value == '' || form.name.value == '')
	{
		alert ( dle_req_field );
		return false;
	}

	dle_comments_ajax.onShow ('');
	var varsString = "topic_id=" + form.topic_id.value;
	
	dle_comments_ajax.setVar("forum_id", dle_comments_ajax.encodeVAR(form.forum_id.value));
	dle_comments_ajax.setVar("topic_ti", dle_comments_ajax.encodeVAR(form.topic_ti.value));
	
	dle_comments_ajax.setVar("post_text", dle_comments_ajax.encodeVAR(form.post_text.value));
	dle_comments_ajax.setVar("name", dle_comments_ajax.encodeVAR(form.name.value));
	dle_comments_ajax.setVar("mail", dle_comments_ajax.encodeVAR(form.mail.value));
	dle_comments_ajax.setVar("skin", dle_skin);

	if ( form.sec_code ) {

	   dle_comments_ajax.setVar("sec_code", form.sec_code.value);

    }

	dle_comments_ajax.requestFile = dle_root + "engine/forum/ajax/addpost.php";
	dle_comments_ajax.method = 'POST';
	dle_comments_ajax.add_html = true;
	dle_comments_ajax.execute = true;
	dle_comments_ajax.element = 'ajax-post';
	dle_comments_ajax.sendAJAX(varsString);

	}
}

// DEL POST //
function postDelete(url){

    var agree=confirm( 'Вы действительно хотите удалить это сообщение?' );

    if (agree)
    document.location=url;
};
// DEL TOPIC //
function topicDelete(url){

    var agree=confirm( 'Вы действительно хотите удалить эту тему?' );

    if (agree)
    document.location=url;
};

// TOPIC //
function TopicMenu( tid ){

var menu=new Array();

menu[0]='<a href="' + dle_root + '?do=forum&act=subscription&code=add&tid=' + tid + '">Подписка на тему</a>';

menu[1]='<a href="' + dle_root + '?do=forum&act=_topic&code=frend&tid=' + tid + '">Сообщить другу</a>';

menu[2]='<a href="' + dle_root + '?do=forum&act=_topic&code=print&tid=' + tid + '">Версия для печати</a>';

return menu;
};

// FORUM //
function ForumMenu( fid, moderation ){

var menu=new Array();

if (moderation){

menu[0]='<a href="' + dle_root + '?do=forum&act=_forum&code=02&fid=' + fid + '">Показать все скрытые темы</a>';

menu[1]='<a href="' + dle_root + '?do=forum&act=_forum&code=01&fid=' + fid + '">Пересчитать все в форуме</a>';

}

menu[3]='<a href="' + dle_root + '?do=forum&act=_forum&code=today&fid=' + fid + '">Активные темы</a>';

menu[4]='<a href="' + dle_root + '?do=forum&act=_forum&code=noreply&fid=' + fid + '">Темы без ответов</a>';

return menu;
};

// POST EDIT MENU //
function PostEditMenu( pid ){

var menu=new Array();

menu[0]='<a onclick="ajax_post_edit(\'' + pid + '\'); return false;" href="#">' + menu_short + '</a>';
menu[1]='<a href="' + dle_root + '?do=forum&act=post&code=02&pid=' + pid + '">' + menu_full + '</a>';

return menu;
};