// 主人点击回复后显示输入回复的对话框
function zhurenReplay(id) {
	$('#replay_' + id).fadeIn('slow');
}

function delReplay(id) {
	showmessage('确认操作', 'sure:确定要删除此留言吗?:dodelReplay:' + id, 230);

}
// 主人删除评论
function dodelReplay(id) {
	$.ajax( {
		'type' : 'POST',
		'url' : '/',
		'data' : '_do=comment-actionDelReply&plid=' + id,
		success : function(msg) {
			eval('var r=' + msg + ';');
			if (r == 'OK') {
				$("#comment_" + id).fadeOut();
			}
		}
	});
	closewindowdlg();

}
// 删除回复
function delPLreplay(id) {
	showmessage('确认操作', 'sure:确定要删除此留言吗?:dodelPLreplay:' + id, 230);

}
function dodelPLreplay(id) {
	$.ajax( {
		'type' : 'POST',
		'url' : '/',
		'data' : '_do=comment-actionDelPLReply&id=' + id,
		success : function(msg) {
			eval('var r=' + msg + ';');
			if (r == 'OK') {
				// 恢复回复按钮
        		$("#zhurenReplay_" + id).show();
        		$("#reply_" + id).remove();
            }
	   }
	});
	closewindowdlg();
}

// 主人回复
function replyPL(id) {
	var r_val = $('#reply_text_' + id).val();
	if ($.trim(r_val) == '') {
		showmessage('操作失败', 'tips:请输入留言内容');
		return false;
	} else {
		$.ajax( {
			'type' : 'POST',
			'url' : '/',
			'data' : '_do=comment-actionReplyComment&sid=' + id + '&comment='
					+ encodeURIComponent(r_val),
			success : function(msg) {
				$.post('?_do=comment-actionGetReplyInfo', {
					'id' : msg
				}, function(data) {
					$("#reply_tpl_" + id).html(data);
					// 隐藏回复按钮
						$("#zhurenReplay_" + id).hide()
					})

			}
		})
	}
}


// ========================== 删除 留言 =========================================

function delComment(id) {
	showmessage('确认操作', 'sure:确定要删除此留言吗?:dodelComment:' + id, 230);

}
// 主人删除评论
function dodelComment(id) {    
	$.ajax( {
		'type' : 'POST',
		'url' : '/',
		'data' : '_do=comment-actionDelReply&plid=' + id,
		success : function(msg) {
		  try{
			eval('var r=' + msg + ';');
			if (r == 'OK') {
				window.location.reload();
			}
          }catch(ex){
            alert('删除失败请重试.. ');      
          }
		}
	});
	closewindowdlg();

}


//====================== 留言板块加载 JS  =======================

var note_id='';
//argument:appid 模块id, tid 目标id, aimuid 目标对象的uid
function getComment(note_id,appid,tid,aimuid,containerid,type,secret)

{

	var url = '/';

//	if(type=='view'){
//
//		var url = '/';
//
//	}
	if (!secret)
	{
		secret = 0;
	}
	var parameters = '_do=comment-showadd-uid-'+tid+'&noteid='+note_id+'&appid='+appid+'&tid='+tid+'&aimuid='+aimuid+'&secret='+secret+'&j=' + Math.random() ;
    
	$.ajax({
		type:'get',
		url:url,
		data:parameters,
		success:function(msg){
			
			try{
				eval('var res = ' + msg + ';');
		
				if (res['status'] == "succ")
				{
					$('#'+containerid).html(res['data']) ;
		
				}
			}catch(ex){
				showmessage('提示','tips:系统异常,您可以在底部用户反馈中反馈您的信息',320,150) ;
			}
		}
	})
	
}


function doAddComment(noteid,appid,tid,aimuid)
{
    var content = $('#comment_content_'+noteid).val() ;
	if ( $.trim(content)== "")

	{
        showmessage('提示','tips:请输入留言内容');		

		return false;

	}else

	{

		if (content.reallength() > 499)
		{
            showmessage('提示','tips:留言内容的太多了!删除点内容在提交吧');

			return false;
		}

		if ($('#is_secret').attr('checked'))
		{

			var is_secret = 1;

		}else
		{

			var is_secret = 0;

		}
		
        var parameters = '_do=comment-doadd-uid-'+tid+'&content=' + encodeURIComponent(content) + '&appid=' + appid + '&tid=' + tid + '&aimuid=' + aimuid +'&is_secret=' + is_secret +'&j=' + Math.random() ;
        
        $.ajax({
            type:'get',
            url:'/',
            data:parameters,
            success:function(msg){
                try{
               	    eval('var res = ' + msg + ';');
               	    if (res['status'] == 'succ')	// 检验成功
					{	
					   
						$('#comment_content_'+noteid).val('');

						$('#is_secret').attr('checked',false) ;

						var comment_new = $('#comment_new_container_'+noteid).html();

						var comment_new = res['data'] + comment_new;

						$('#comment_new_container_'+noteid).html(comment_new)  ;

					}	else
					{
						alert(res['desc']);

					}
                    
                }catch(ex){
                    alert(msg);
                   showmessage('提示','tips:系统异常,您可以在底部用户反馈中反馈您的信息',320,150) ;
                    
                }
            }
        })
    }
}





function showCommentReply(commentId)

{

	if (!commentId)

	{

		showmessage('提示',"tips:没有评论的ID ,请尝试刷新页面  !");

		return false;

	}else

	{

		
	    var parameters = '_do=message-showreply&commentid=' + commentId + '&j=' + Math.random() ;
		$.ajax({
            type:'post',
            url:'/',
            data:parameters ,
            success:function(msg){
                try{
                    	eval('var res = ' + msg + ';');
    
    					if (res['status'] == 'succ')	// 检验成功
    					{
    
                            $('#reply_container_' + commentId).html( res['data']) ;
    
    						$('#reply_container_' + commentId).show();
    
    						$('#commentReplyInput_' + commentId).focus();
    
    					}
    
    					else
    
    					{
    
    						showmessage('提示',"tips:发生错误, 请重试一遍 !");
    
    					}
                   
                }catch(ex){
                    showmessage('提示','tips:系统异常,您可以在底部用户反馈中反馈您的信息',320,150) ;
                   
                }
            }
            
          
		})

	

	}

}





//提交回复

function doAddReply(commentid)

{    

	var content = $('#commentReplyInput_'+commentid).val();
    
	if ($.trim(content) == "")

	{

		showmessage("提示","tips:回复的内容太少了 ,再多写一些");

		return false;

	}else

	{

        var parameters = '_do=message-doaddreply&content=' + encodeURIComponent(content) + '&commentid=' + commentid + '&j=' + Math.random();
        $.ajax({
          type:'post',
          data:parameters,
          url:'/',
          success:function(msg){
            try{
                	eval('var res = ' + msg + ';');					

					if (res['status'] == 'succ')	// 检验成功

					{
						var replyContent = $('#newreplycontainer_'+commentid).html();

						$('#newreplycontainer_'+commentid).html(replyContent + res['data']) ;

						$('#reply_container_' + commentid).hide();

					}

					else

					{

						alert(res['desc']);

					}
            }catch(ex){
                
                showmessage('提示','tips:系统异常,您可以在底部用户反馈中反馈您的信息') ;
            }
          }
            
        })

	

	}

}

