// POST EDIT //

var c_cache  = Array;
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 netchat_ajax();
	comm_id = с_id;
	ajax.onShow ('');
	var varsString = "";
	ajax.setVar("id", с_id);
	ajax.setVar("action", "edit");
	ajax.requestFile = "http://netchat.ru/system/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 ( c_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 netchat_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 = "http://netchat.ru/system/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('REPLIER');
    var dle_comments_ajax = new netchat_ajax();

	closeall();

	if (form.POST_MESSAGE.value == '' || form.POST_MESSAGE.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_MESSAGE", dle_comments_ajax.encodeVAR(form.POST_MESSAGE.value));
	dle_comments_ajax.setVar("MOOD_ID", dle_comments_ajax.encodeVAR(form.MOOD_ID.value));
	dle_comments_ajax.setVar("TITLE", dle_comments_ajax.encodeVAR(form.TITLE.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 = "http://netchat.ru/system/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.POST_MESSAGE.value = '';
	form.MOOD_ID.value = '';

}

// DEL POST //
function postDelete(сc_id){

    var agree=confirm( 'Вы действительно хотите удалить это сообщение?' );

    if (agree){

	var ajax = new netchat_ajax();
	var commv_id = сc_id;
	ajax.onShow ('');
	var varsString = "pid=" + сc_id;
	ajax.requestFile = "http://netchat.ru/system/forum/ajax/dellpost.php";
	ajax.method = 'GET';
	ajax.element = 'idpost-' + commv_id;
//	ajax.onCompletion = whenCompletedCommentsEdit;
	ajax.sendAJAX(varsString);
    }
};

// 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 + 'userlogin/' + 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(\'/admin.php?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>';
	menu[4]='<a href="' + forum_url + 'act=_nullpoint&uname=' + url + '">Обнулить у.е.</a>';

	}

return menu;
};

// WARN //
function FWarn(action, user_id, post_id, forum_id)
{
	var ajax = new netchat_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 + "system/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 = "";
	}
}

function anti_flood( time ){

    alert( 'Зафиксирован флуд, повторите попытку через ' + time+' секунд.');
    
    return false;

};

function IPMenu( m_ip, l1, l2, l3 ){

var menu=new Array();

menu[0]='<a href="http://www.nic.ru/whois/?ip=' + m_ip + '" target="_blank">Информация о IP адресе</a>';
menu[1]='<a href="/admin.php?mod=iptools&ip=' + m_ip + '" target="_blank">Поиск других пользователей</a>';
menu[2]='<a href="/admin.php?mod=blockip&ip=' + m_ip + '" target="_blank">Забанить адрес</a>';

return menu;
};