function doRate_f( rate, id, modulname ) {
	ShowLoading('');

	$.get(dle_root + "engine/ajax/files/rating.php", { go_rate: rate, news_id: id, skin: dle_skin, modulname: modulname }, function(data){

		HideLoading('');

		$("#ratig-layer").html(data);

	});
};

function dleRate_f( rate, id, modulname ) {
	ShowLoading('');

	$.get(dle_root + "engine/ajax/files/rating.php", { go_rate: rate, news_id: id, skin: dle_skin, mode: "short", modulname: modulname }, function(data){

		HideLoading('');

		$("#ratig-layer-" + id).html(data);

	});

};

function MenuCommBuild_f( m_id, modulname ){

var menu=new Array();

menu[0]='<a onclick="ajax_comm_edit_f(\'' + m_id + '\', \'' + modulname + '\'); return false;" href="#">' + menu_short + '</a>';
menu[1]='<a href="' + dle_root + '?do=' + modulname + '&op=comments_files&action=comm_edit&id=' + m_id + '">' + menu_full + '</a>';

return menu;
};

function ajax_comm_edit_f( c_id, modulname )
{
	if ( ! c_cache[ c_id ] || c_cache[ c_id ] == '' )
	{
		c_cache[ c_id ] = $('#comm-id-'+c_id).html();
	}

	ShowLoading('');

	$.get(dle_root + "engine/ajax/files/editcomments.php", { id: c_id, modulname: modulname, action: "edit" }, function(data){

		HideLoading('');

		RunAjaxJS('comm-id-'+c_id, data);

		setTimeout(function() {
           $("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: $("#comm-id-" + c_id).position().top - 70}, 700);
        }, 100);

	});
	return false;
};

function ajax_save_comm_edit_f ( c_id, modulname )
{
	var comm_txt = '';
	comm_edit_id = c_id;

	if (dle_wysiwyg == "yes") {

		comm_txt = $('#dleeditcomments'+c_id).html();

	} else {

		comm_txt = $('#dleeditcomments'+c_id).val();

	}

	ShowLoading('');

	$.post(dle_root + "engine/ajax/files/editcomments.php", { id: c_id, comm_txt: comm_txt, modulname: modulname, action: "save" }, function(data){

		HideLoading('');
		c_cache[ comm_edit_id ] = '';
		$("#comm-id-"+c_id).html(data);

	});
	return false;
};

function doFavoritesf( fav_id, event, modulname )
{
	ShowLoading('');

	$.get(dle_root + "engine/ajax/files/favorites.php", { fav_id: fav_id, action: event, skin: dle_skin, modulname: modulname }, function(data){

		HideLoading('');

		$("#fav-id-" + fav_id).html(data);

	});

	return false;
};

function MenuBuildf( m_id, modulname, event ){

var menu=new Array();

menu[0]='<a onclick="ajax_prep_for_edit_f(\'' + m_id + '\', \'' + modulname + '\', \'' + event + '\'); return false;" href="#">' + menu_short + '</a>';
menu[1]='<a href="' + dle_root + dle_admin + '?mod=admin_' + modulname + '&action=edit_file&id=' + m_id + '" target="_blank">' + menu_full + '</a>';

if (allow_dle_delete_f) {

menu[2]='<a onclick="dle_delete_f (\'' + m_id + '\', \'' + modulname + '\'); return false;" href="#">Удалить файл</a>';

}


return menu;
};

function dle_delete_f( m_id, modulname ){
    DLEconfirm( dle_del_agree, dle_confirm, function () {
	    document.location= dle_root + 'index.php?do=' + modulname + '&op=delete&id=' + m_id + '&hash=' + dle_login_hash;
	} );
};

function ajax_prep_for_edit_f( news_id, modulname, event )
{
	if ( ! n_cache[ news_id ] || n_cache[ news_id ] == '' )
	{
		n_cache[ news_id ] = $('#file-id-'+news_id).html();
	}

	s_id = news_id;

	ShowLoading('');

	$.get(dle_root + "engine/ajax/files/editfile.php", { id: news_id, field: event, action: "edit", modulname: modulname }, function(data){

		HideLoading('');

		RunAjaxJS('file-id-'+news_id, data);

		setTimeout(function() {
          $("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: $("#file-id-" + s_id).position().top - 70}, 700);
        }, 100);

	});

	return false;
};

function ajax_cancel_for_edit_f( file_id )
{
	if ( n_cache[ news_id ] != "" )
	{
		$("#file-id-"+news_id).html(n_cache[ news_id ]);
	}

	return false;
};

function ajax_save_for_edit_f( news_id, event, modulname )
{
	var allow_br = 0;
	var news_txt = '';
	e_id = news_id;

	if (document.getElementById('allow_br_'+news_id).checked) { allow_br = 1; }

	if (quick_wysiwyg == "1") {

		news_txt = $('#dleeditnews'+news_id).html();

	} else {

		news_txt = $('#dleeditnews'+news_id).val();

	}

	var news_title = $('#edit-title-'+news_id).val();
	var reason = $('#edit-reason-'+news_id).val();

	ShowLoading('');

	$.post(dle_root + "engine/ajax/files/editfile.php", { title: news_title, news_txt: news_txt, id: news_id, allow_br: allow_br, reason: reason, field: event, action: "save", modulname: modulname }, function(data){

		HideLoading('');
		n_cache[ e_id ] = '';
		$("#file-id-"+news_id).html(data);

	});

	return false;
};

function doAddComments_f( modulname ) {
	var form = document.getElementById('dle-comments-form');

	if (dle_wysiwyg == "yes") {
		document.getElementById('comments').value = $('#comments').html();
		var editor_mode = 'wysiwyg';
	} else { var editor_mode = ''; }

	if (form.comments.value == '' || form.name.value == '')
	{
		DLEalert ( dle_req_field, dle_info );
		return false;
	}

	if ( form.sec_code ) {

	   var sec_code = form.sec_code.value;

    } else { var sec_code = ''; }

	if ( form.recaptcha_response_field ) {
	   var recaptcha_response_field= Recaptcha.get_response();
	   var recaptcha_challenge_field= Recaptcha.get_challenge();
    } else {
	   var recaptcha_response_field= '';
	   var recaptcha_challenge_field= '';
	}

	if ( form.allow_subscribe ) {

		if ( form.allow_subscribe.checked == true ) {

		   var allow_subscribe= "1";

		} else {

		   var allow_subscribe= "0";

		}

    } else { var allow_subscribe= "0"; }

	ShowLoading('');

	$.post(dle_root + "engine/ajax/files/addcomments.php", { post_id: form.post_id.value, comments: form.comments.value, name: form.name.value, mail: form.mail.value, editor_mode: editor_mode, skin: dle_skin, sec_code: sec_code, recaptcha_response_field: recaptcha_response_field, recaptcha_challenge_field: recaptcha_challenge_field, allow_subscribe: allow_subscribe, modulname: modulname }, function(data){

		if ( form.sec_code ) {
           form.sec_code.value = '';
           reload();
	    }

		HideLoading('');

		RunAjaxJS('dle-ajax-comments', data);

		if (data != 'error' && document.getElementById('blind-animation')) {

			$("html"+( ! $.browser.opera ? ",body" : "")).animate({scrollTop: $("#dle-ajax-comments").position().top - 70}, 1100);

			setTimeout(function() { $('#blind-animation').show('blind',{},1500)}, 1100);
		}

	});

};

function DeleteComments_f(id, hash, modulname) {

    DLEconfirm( dle_del_agree, dle_confirm, function () {

		ShowLoading('');

		$.get(dle_root + "engine/ajax/files/deletecomments.php", { id: id, dle_allow_hash: hash, modulname: modulname }, function(r){

			HideLoading('');

			r = parseInt(r);

			if (!isNaN(r)) {

				$("html"+( ! $.browser.opera ? ",body" : "")).animate({scrollTop: $("#comment-id-" + r).position().top - 70}, 700);

				setTimeout(function() { $("#comment-id-" + r).hide('blind',{},1400)}, 700);

			}

		});

	} );

};

function newLab(page,w,h){
	window.open(page,'','width='+w+',height='+h+',top=100,scrollbars=yes');
}

function AddThx( id, modulname ){

	ShowLoading('');

	$.get(dle_root + "engine/ajax/files/thanks.php", { post_id: id, do: modulname }, function(data){

		HideLoading('');

		$("#thx-layer").html(data);

	});

	return false;
}
