var artCommentLoad=0  // храним идентификатор загруженной статьи

function testart(){	alert('test_art')}

//получаем комментарии  к статье

function getComment(){	retval=''	JsHttpRequest.query(
 	'/BEX_art_comment/getComment.php',
 	{
	 	artID: Article_id,
	 	SID: sid
 	},
 	function (result, error){
 	  debug(error)
 //	  debug(result.rval)
      document.getElementById('ControlComment').innerHTML=result.CommentControl
 	  document.getElementById('Comment').innerHTML=result.rval
 	},
 	true );
}


function CommentOnOff(){
    if (document.getElementById('Comment').innerHTML.length==0) getComment()
    state = document.getElementById('Comment').style.visibility

    if (state=='visible') {    	document.getElementById('Comment').style.visibility='hidden'
    	document.getElementById('SwitchComment').value='Показать комментарии'
    }
    else {    	document.getElementById('Comment').style.visibility='visible'
    	document.getElementById('SwitchComment').value='Скрыть комментарии'
    }
}

function EditCom(){ // строим cписок сообщений пользователя
JsHttpRequest.query(
	'/BEX_art_comment/EditCom.php',
	{
	user_ID: user_id,
	art_ID: Article_id
	},
	function (result, error){
	    debug(error)

// debug('всего комментариев'+result.cntrec)

	    if (result.cntrec == 0 ) close_RR_wndw()
	    else {
	    	RR_wndw(400,300)
			document.getElementById('RR_wndw_header').innerHTML=user_name+'. Комментарии к статье...'
        	document.getElementById('RR_wndw_body').innerHTML=result.rval
        }
	},
	true );}

// редактирование комментария

function EditComment(mid){	   JsHttpRequest.query(
    	'/BEX_art_comment/getCom.php',
    	{
    	MID: mid
    	},
    	function (result, error){
    	   debug(error)
    	   CommentForm();
    	   document.CommentForm.CommentID.value=mid
    	   document.CommentForm.Comment.value=result.rval
    	},
    	true );
}
// удаление
function DelComment(mid){	JsHttpRequest.query(
 	'/BEX_art_comment/DelComment.php',
 	{
 	MID: mid
 	},
 	function (result, error){
		debug(error)
		close_RR_wndw()
 		EditCom()
 		getComment()
 	},
 	true );
}

function ACom()
{  CommentForm()}


function CommentForm()
{
  try{ if (CommentID!=0){}
  }catch(e){  	CommentID=0  }	RR_wndw(430,250)
	document.getElementById('RR_wndw_header').innerHTML='Комментарий к статье...'
	str='<form name="CommentForm" action="" method="post" enctype="multipart/form-data">'
	str+='<input name="CommentID" type="hidden" value="'+CommentID+'">'
	str+='<input name="artID" type="hidden" value="'+Article_id+'">'
	str+='<input name="user_id" type="hidden" value="'+user_id+'">'
	str+='<textarea name="Comment" id="Comment" rows=14 cols=46 wrap="on"></textarea>'
	str+='<br><input type="button" value="Отправить" onclick="save_comment(this.form); return false"</form>'
	document.getElementById('RR_wndw_body').innerHTML=str

	var oFCKE = new FCKeditor( 'Comment' ) ;
	oFCKE.BasePath = '/netcat/FCKeditor/'; ;
    oFCKE.ToolbarSet = 'Basic';
	oFCKE.Width = '420px';
	oFCKE.Height = '200px';
	oFCKE.Config['DefaultLanguage'] = 'ru';
	oFCKE.Config['ForcePasteAsPlainText'] = true;
    oFCKE.ReplaceTextarea() ;

//	var cmnt=document.getElementById("Comment");
//    var fck = new FCKeditor("myFCK");
//     cmnt.innerHTML = fck.CreateHtml();
}

function save_comment(FORM)
{
	JsHttpRequest.query(
 	'/BEX_art_comment/save_comment.php',
 	{
      form: FORM
 	},
 	function (result, error){ 		debug(error)
 		if (FORM.CommentID.value!=0) EditCom() // список редактирования
        else close_RR_wndw()                   // вводили новый
        getComment()                           // обновили список комментариев на странице
 	},
 	true );
}





