

	var loadingImage = 'ajax-loader-big.gif';
	var LoadingBar = '<div style="padding:20px;text-align:center;"><img src="/pic/'+loadingImage+'" /></div>';

	function EditNews(nid) {
		nid = parseInt(nid);
		
		jQuery('#news_text'+nid).empty();
		jQuery('#news_edit_panel'+nid).hide();
		jQuery('#news_text'+nid).html( LoadingBar );
		jQuery.post('/addnews.php',{'do':'edit_news',nid:nid}, 
		function(response) { 
			jQuery('#news_text'+nid).empty();
			jQuery('#news_text'+nid).html(response);
		}, 'html');
	}

	function SaveNews(nid) {
		nid = parseInt(nid);
		
		var body = jQuery('#edit_post').val();
		var subject = jQuery('#edit_post2').val();
		var checker = jQuery('#edit_post3').val();
		
		if(body.length > 0 && body.replace(/ /g, '') != '' && subject.length > 0 && subject.replace(/ /g, '') != '') {
			jQuery('#news_text'+nid).empty();
			jQuery('#news_text'+nid).html( LoadingBar );
			jQuery.post('/addnews.php',{'do':'save_news',nid:nid,body:body,subject:subject,checker:checker},
			function(response) {
				jQuery('#news_text'+nid).empty();
				jQuery('#news_text'+nid).html(response);
				jQuery('#news_edit_panel'+nid).show(); 
			},'html');
		} else {
			alert( 'Поля тема и Сообщение обязательны для заполнения!' );
			jQuery('#edit_post').focus();
			return false;
		}
	}

	function NewsCancel(nid) {
		nid = parseInt(nid);
		
		jQuery('#news_text'+nid).empty();
		jQuery('#news_text'+nid).html( LoadingBar );
		jQuery.post('/addnews.php',{'do':'save_cancel',nid:nid},
		function(response){
			jQuery('#news_text'+nid).empty();
			jQuery('#news_text'+nid).html(response);
			jQuery('#news_edit_panel'+nid).show();
		},'html');
		
	}

	function DeleteNews(nid) {
		nid = parseInt(nid);
		var news = jQuery('#news');
		
		jQuery('#news_text'+nid).html( LoadingBar );
		jQuery.post('/addnews.php',{'do':'delete_news',nid:nid},
		function(response) {
			jQuery('#news_text'+nid).html(response);
			jQuery('#news_edit_panel'+nid).show();
			news.html(response);
		},'html');
	}

	function DeleteNewsGlobal(nid) {
		nid = parseInt(nid);
		var news = jQuery('#news');
		
		jQuery('#news_text'+nid).html( LoadingBar );
		jQuery.post('/addnews.php',{'do':'delete_news_global',nid:nid},
		function(response) {
			jQuery('#news_text'+nid).html(response);
			jQuery('#news_edit_panel'+nid).show();
			news.html(response);
		},'html');
	}

	function SendNews() {
		var comments = jQuery('#news');
		var body     = jQuery('#body').val();
		var subject  = jQuery('#subject').val();
		var checker  = jQuery('#checker').val();
		var bValid   = true;
		
		if(body.length > 0 && body.replace(/ /g, '') != '' && subject.length > 0 && subject.replace(/ /g, '') != '') {
			jQuery('#send_news').get(0).disabled = 'disabled';	
			jQuery.post('/addnews.php',{'do':'add_news',body:body,subject:subject,checker:checker},
			function(response) {
				comments.html(response);
				jQuery('#send_news').get(0).disabled = '';
				jQuery('#body').val('');
				jQuery('#subject').val('');
				jQuery('#checker').val('');
			},'html');
		} else {
			alert( 'Поля тема и Сообщение обязательны для заполнения!' );
			jQuery('#body').focus();
			jQuery('#subject').focus();
			jQuery('#checker').focus();
			return false;
		}

	}
	
	function SE_EditComment(cid,nid) {
		cid = parseInt(cid);
		nid = parseInt(nid);
		
		jQuery('#comment_text'+cid).empty();
		jQuery('#comment_edit_panel'+cid).hide();
		jQuery('#comment_text'+cid).html( LoadingBar );
		jQuery.post('/addnews.php',{'do':'edit_comment',cid:cid,nid:nid}, 
		function(response) { 
			jQuery('#comment_text'+cid).empty();
			jQuery('#comment_text'+cid).html(response);
		}, 'html');
	}

	function SE_SaveComment(cid,nid) {
		cid = parseInt(cid);
		nid = parseInt(nid);
		var text = jQuery('#edit_post').val();
		
		if(text.length > 0 && text.replace(/ /g, '') != '') {
			jQuery('#comment_text'+cid).empty();
			jQuery('#comment_text'+cid).html( LoadingBar );
			jQuery.post('/addnews.php',{'do':'save_comment',cid:cid,nid:nid,text:text},
			function(response) {
				jQuery('#comment_text'+cid).empty();
				jQuery('#comment_text'+cid).html(response);
				jQuery('#comment_edit_panel'+cid).show(); 
			},'html');
		} else {
			alert( 'Поле сообщение обязательно для заполнения!' );
			jQuery('#edit_post').focus();
			return false;
		}
	}

	function SE_CommentCancel(cid,nid) {
		cid = parseInt(cid);
		nid = parseInt(nid);
		
		jQuery('#comment_text'+cid).empty();
		jQuery('#comment_text'+cid).html( LoadingBar );
		jQuery.post('/addnews.php',{'do':'save_cancel_comment',cid:cid,nid:nid},
		function(response){
			jQuery('#comment_text'+cid).empty();
			jQuery('#comment_text'+cid).html(response);
			jQuery('#comment_edit_panel'+cid).show();
		},'html');
		
	}

	function SE_CommentQuote(cid,nid) {
		cid = parseInt(cid);
		nid = parseInt(nid);
		var text = jQuery('#text').val();
		
		jQuery.post('/addnews.php',{'do':'comment_quote',cid:cid,nid:nid,text:text},
		function(response) {
			jQuery('#text').empty(); 
			jQuery('#text').val(response);
		},'html');
		
	}

	function SE_SendComment(nid) {
		nid = parseInt(nid);
		var comments = jQuery('#comments_list');
		var text     = jQuery('#text').val();
		var bValid   = true;
		
		if(text.length > 0 && text.replace(/ /g, '') != '') {
			jQuery('#send_comment').get(0).disabled = 'disabled';	
			jQuery.post('/addnews.php',{'do':'add_comment',nid:nid,text:text},
			function(response) {
				comments.html(response);
				jQuery('#send_comment').get(0).disabled = '';
				jQuery('#text').val('');
			},'html');
		} else {
			alert( 'Поле сообщение обязательно для заполнения!' );
			jQuery('#text').focus();
			return false;
		}
	}

	function SE_DeleteComment(cid,nid) {
		cid = parseInt(cid);
		nid = parseInt(nid);
		var comments = jQuery('#comments_list');
		var cfrm = null;
		
		cfrm = confirm( 'Вы действительно хотите удалить комментарий?' );
		if(cfrm) {
			jQuery.post('/addnews.php',{'do':'delete_comment',cid:cid,nid:nid},
			function(response) {
				comments.html(response);
			},'html');
		} else {
			return false;
		}
	}

	function SE_ViewOriginal(cid,nid) {
		cid = parseInt(cid);
		nid = parseInt(nid);
		
		jQuery('#comment_text'+cid).empty();
		jQuery('#comment_text'+cid).html( LoadingBar );
		jQuery.post('/addnews.php',{'do':'view_original',cid:cid,nid:nid},
		function(response) {
			jQuery('#comment_text'+cid).empty();			   
			jQuery('#comment_text'+cid).html(response);
		},'html');
	}

	function SE_RecoverOriginal(cid,nid) {
		cid = parseInt(cid);
		nid = parseInt(nid);
		
		jQuery('#comment_text'+cid).empty();
		jQuery('#comment_text'+cid).html( LoadingBar );
		jQuery.post('/addnews.php',{'do':'recover_original',cid:cid,nid:nid},
		function(response) {
			jQuery('#comment_text'+cid).empty();
			jQuery('#comment_text'+cid).html(response);
		},'html');
	}
