function doRate_files( rate, id ) {
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "go_rate=" + rate;
	ajax.setVar("news_id", id);
	ajax.setVar("skin", dle_skin);
	ajax.requestFile = dle_root + "engine/ajax/files/rating_files.php";
	ajax.method = 'GET';
	ajax.element = 'ratig-layer';
	ajax.sendAJAX(varsString);
};



function MenuCommBuild_files( m_id ){

var menu=new Array();

menu[0]='<a onclick="ajax_comm_edit_files(\'' + m_id + '\'); return false;" href="#">' + menu_short + '</a>';
menu[1]='<a href="' + dle_root + '?do=comments_files&action=comm_edit&id=' + m_id + '">' + menu_full + '</a>';

return menu;
};

function ajax_comm_edit_files( c_id )
{
	if ( ! c_cache[ c_id ] || c_cache[ c_id ] == '' )
	{
		c_cache[ c_id ] = document.getElementById( 'comm-id-'+c_id ).innerHTML;
	}

	var ajax = new dle_ajax();
	comm_id = c_id;
	ajax.onShow ('');
	var varsString = "";
	ajax.setVar("id", c_id);
	ajax.setVar("action", "edit");
	ajax.requestFile = dle_root + "engine/ajax/files/editcomments_files.php";
	ajax.method = 'GET';
	ajax.element = 'comm-id-'+c_id;
	ajax.execute = true;
	ajax.onCompletion = whenCompletedCommentsEdit;
	ajax.sendAJAX(varsString);
	return false;
};

function ajax_save_comm_edit_files( c_id )
{
	var ajax = new dle_ajax();
	comm_edit_id = c_id;
	ajax.onShow ('');
	var comm_txt = ajax.encodeVAR( document.getElementById('dleeditcomments'+c_id).value );
	var varsString = "comm_txt=" + comm_txt;
	ajax.setVar("id", c_id);
	ajax.setVar("action", "save");
	ajax.requestFile = dle_root + "engine/ajax/files/editcomments_files.php";
	ajax.method = 'POST';
	ajax.element = 'comm-id-'+c_id;
	ajax.onCompletion = whenCompletedSaveComments;
	ajax.sendAJAX(varsString);

	return false;
};

function doFavoritesfiles( fav_id, event )
{
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "fav_id=" + fav_id;
	ajax.setVar("action", event);
	ajax.setVar("skin", dle_skin);
	ajax.requestFile = dle_root + "engine/ajax/files/favoritesfiles.php";
	ajax.method = 'GET';
	ajax.element = 'fav-id-'+fav_id;
	ajax.sendAJAX(varsString);

	return false;
};

function doAddCommentsfiles(){

	var form = document.getElementById('dle-comments-form');
    var dle_comments_ajax = new dle_ajax();

	if (dle_wysiwyg == "yes") {
	document.getElementById('comments').value = oEdit1.getXHTMLBody();
	form.submit();
	}
	else {

	closeall();

	if (form.comments.value == '' || form.name.value == '')
	{
		alert ( dle_req_field );
		return false;
	}

	dle_comments_ajax.onShow ('');
	var varsString = "fileid=" + form.fileid.value;
	dle_comments_ajax.setVar("comments", dle_comments_ajax.encodeVAR(form.comments.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/ajax/files/addcomments.php";
	dle_comments_ajax.method = 'POST';
	dle_comments_ajax.execute = true;
	dle_comments_ajax.element = 'dle-ajax-comments';
	dle_comments_ajax.sendAJAX(varsString);

	}
};


function dle_files_delete( m_id ){

    var agree=confirm( dle_del_agree );

    if (agree)
    document.location= dle_root + dle_admin + '?mod=admin_files&action=delete&id=' + m_id + '&user_hash=' + dle_login_hash;
};

function MenufilesBuild( m_id ){

var menu=new Array();

menu[0]='<a onclick="ajax_prep_for_edit_files(\'' + m_id + '\'); return false;" href="#">' + menu_short + '</a>';
menu[1]='<a href="' + dle_root + dle_admin + '?mod=admin_files&action=edit_file&id=' + m_id + '" target="_blank">' + menu_full + '</a>';

if (allow_dle_delete_news) {

menu[2]='<a onclick="dle_files_delete (\'' + m_id + '\'); return false;" href="#">Удалить файл</a>';

}


return menu;
};

function ajax_prep_for_edit_files( file_id )
{
	if ( ! n_cache[ file_id ] || n_cache[ file_id ] == '' )
	{
		n_cache[ file_id ] = document.getElementById( 'file-id-'+file_id ).innerHTML;
	}

	var ajax = new dle_ajax();
	s_id = file_id;
	ajax.onShow ('');
	var varsString = "";
	ajax.setVar("id", file_id);
	ajax.setVar("action", "edit");
	ajax.requestFile = dle_root + "engine/ajax/files/editfile.php";
	ajax.method = 'GET';
	ajax.element = 'file-id-'+file_id;
	ajax.execute = true;
	ajax.onCompletion = whenCompleted_files;
	ajax.sendAJAX(varsString);

	return false;
};


function whenCompleted_files(){

	var post_main_obj = document.getElementById( 'file-id-' + s_id );
	var post_box_top  = _get_obj_toppos( post_main_obj );

			if ( post_box_top )
			{
				scroll( 0, post_box_top - 70 );
			}

};

function ajax_cancel_for_edit_files( file_id )
{
	if ( n_cache[ file_id ] != "" )
	{
		document.getElementById( 'file-id-'+file_id ).innerHTML = n_cache[ file_id ];
	}

	return false;
};

function ajax_save_for_edit_files( file_id )
{
	var ajax = new dle_ajax();
	var allow_br = 0;

	if (document.getElementById('allow_br_'+file_id).checked) { allow_br = 1; }

	e_id = file_id;
	ajax.onShow ('');
	var news_txt = ajax.encodeVAR( document.getElementById('dleeditnews'+file_id).value );
	var news_title = ajax.encodeVAR( document.getElementById('edit-title-'+file_id).value );
	var varsString = "news_txt=" + news_txt;
	ajax.setVar("id", file_id);
	ajax.setVar("title", news_title);
	ajax.setVar("allow_br", allow_br);
	ajax.setVar("action", "save");
	ajax.requestFile = dle_root + "engine/ajax/files/editfile.php";
	ajax.method = 'POST';
	ajax.element = 'file-id-'+file_id;
	ajax.onCompletion = whenCompletedSave;
	ajax.sendAJAX(varsString);

	return false;
};



