// 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();

	closeall();
	
	if (form.post_text.value == '' || form.post_text.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_id", dle_comments_ajax.encodeVAR(form.post_id.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);
	form.comments.value = '';
}

// 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, forum_url ){

var menu=new Array();

menu[0]='<a href="' + forum_url + 'act=subscription&code=add&tid=' + tid + '">Подписка на тему</a>';

menu[1]='<a href="' + forum_url + 'act=_topic&code=frend&tid=' + tid + '">Сообщить другу</a>';

menu[2]='<a href="' + forum_url + 'act=_topic&code=print&tid=' + tid + '">Версия для печати</a>';

return menu;
};

// FORUM //
function ForumMenu( fid, moderation, forum_url ){

var menu=new Array();

if (moderation){

menu[0]='<a href="' + forum_url + 'act=_forum&code=02&fid=' + fid + '">Показать все скрытые темы</a>';

menu[1]='<a href="' + forum_url + 'act=_forum&code=01&fid=' + fid + '">Пересчитать все в форуме</a>';

}

menu[3]='<a href="' + forum_url + 'act=_forum&code=today&fid=' + fid + '">Активные темы</a>';

menu[4]='<a href="' + forum_url + 'act=_forum&code=noreply&fid=' + fid + '">Темы без ответов</a>';

return menu;
};

// POST EDIT MENU //
function PostEditMenu( pid, forum_url ){

var menu=new Array();

menu[0]='<a onclick="ajax_post_edit(\'' + pid + '\'); return false;" href="#">' + menu_short + '</a>';
menu[1]='<a href="' + forum_url + 'act=post&code=02&pid=' + pid + '">' + menu_full + '</a>';

return menu;
};

// USER MENU //
function FUserMenu( url, m_id, group, forum_url ){

var menu=new Array();

	menu[0]='<a href="' + dle_root + 'index.php?subaction=userinfo&user=' + url + '">' + menu_profile + '</a>';

	menu[1]='<a href="' + dle_root + 'index.php?do=pm&doaction=newpm&user=' + m_id + '">' + menu_send + '</a>';
	menu[2]='<a href="' + forum_url + 'act=_forum&code=mtopics&mname=' + url + '">Найти темы пользователя</a>';

	if (group == '1') {
		menu[3]='<a onclick="window.open(\'' + dle_root + dle_admin + '?mod=editusers&action=edituser&id=' + m_id + '\', \'User\',\'toolbar=0,location=0,status=0, left=0, top=0, menubar=0,scrollbars=yes,resizable=0,width=540,height=500\'); return false;" href="#">' + menu_uedit + '</a>';
	}

return menu;
};

// WARN //
function FWarn(action, user_id, post_id, forum_id)
{
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "user_id=" + user_id;
	ajax.setVar("skin", dle_skin);
	ajax.setVar("action", action);
	ajax.setVar("forum_id", forum_id);
	ajax.setVar("post_id", post_id);
	ajax.requestFile = dle_root + "engine/forum/ajax/warn.php";
	ajax.method = 'POST';
	ajax.element = 'warn-' + post_id;
	ajax.sendAJAX(varsString);

	return false;
};

// ShowHide by ShVad
function ShowHide( name ){
	
	if (document.getElementById( name ).style.display != "none")
	{
		document.getElementById( name ).style.display = "none";
	}
	else
	{
		document.getElementById( name ).style.display = "";
	}
}