﻿$(document).ready(function($){
						   
	_initBlogdel();	
	
	_initDel();	
	
	_initFont();
		
	if(comment==1)
	{
	_initShowComent(1);
	
	_initLogin();
	
	_initSendComent();	
	
	}
	_initFavorite();
	
	_initCope();
})


function _initCope()
{
	
	document.body.oncopy=function(){ 
	
		event.returnValue=false; 
		
		var txt_cr=document.selection.createRange().text; 
		
		var copy_cr="\r \r本文来源：为傲网 www.willproud.com"; 
		
		clipboardData.setData('Text',txt_cr+copy_cr); 

     } 

	
}




function _initDel(){
	
     $("a[@actid]").click(function(){
								   
		     if (confirm("此操作将删除掉专辑以及专辑里的所有日志 \n \n        您确定要删除吗？"))
			 {
			  var sortid = $(this).attr("actid");
			  <!-- start -->
			   $.post(
			   "/"+domain+"/blog/blogsortdel",
				{sortid:sortid},
				 function(msg)
					{
						if(msg=="ok")
						{
						     $("a[@actid="+sortid+"]").parent().parent().slideUp();
						} 
					});
			   <!-- end -->		
			 }
	 })	
}

function _initBlogdel(){
	
     $("#blogdel").click(function(){
								   
		  if (confirm("温馨提示：确定要把它放进回收站吗？"))
		  {
		         <!-- start -->
				   $.post(
				   "/"+domain+"/manage/blogdelsing",
					{id:id,type:"list"},
					 function(msg)
						{
						 if(msg=="login")
						  {
							   alert("请你先登录");
						  }
						  else
						  {
							   window.location.href  = '/'+domain+'/blog';
                          }
					});
			    <!-- end --> 
		  }
	 })	
}

function _initFont(){
	
       $(".operate a[@type=font]").toggle(
		function(){
			
			$(this).attr("title","将日志内容显示为小字体");
			
			$(this).html("小字显示");
			
			$(".blogcontent").css("font-size","16px")
				
			$(".blogcontent").css("line-height","30px")
		
		}, 
		function(){ 
		
		    $(this).attr("title","将日志内容显示为大字体");
			
			$(this).html("大字显示");
		
			$(".blogcontent").css("font-size","12px")
				
			$(".blogcontent").css("line-height","20px")
			
		});  
}



//日志评论


function _initLogin()
{
     $(".commentlogin a:first").click(function(){
											   
		var username = $("#user").val();
		
		var passwd   = $("#pw").val();
		
		if(username==""||passwd=="")
		{
			alert("请输入完整的用户名和密码");
		}
		else
		{
			
		 <!-- start -->
				$.post(
			   "/login/login",
				{name:username,pass:passwd},
				 function(msg)
					{
					   if(msg=="nouser")
					   {
						  $("#user").val("");
						 
						  $("#pw").val("");
						 
					 	   alert("此用户不存在");
					   }
					   else if(msg=="nopasswd")
					   {
						   alert("密码错误,请重新输入密码");
						  
						   $("#pw").val("");
					  }
					  else
					  { 
					      $(".commentlogin").html("登录成功，请发表评论：");
					  }
				});
		 <!-- end -->
		}									   
	 })
}


function _initSendComent(){

	$(".send img").click(function(){
			
		var sum     = $(".commentlogin input").size();
		
		var content = KE.util.getData("content");

		var html;
			
		if(sum!=0)
		{
			 alert("登录后才能发表评论，请您先登录或注册。");
			 
			 $("#user").focus();
	    }
		else if(content=="")
		{
		     alert("请输入评论内容");
			 
			 $(".sendcoment textarea").focus();
		}
		else
		{
	          <!-- start -->
				$.ajax({
					  url: "/"+domain+"/blog/commentadd",
					  type: 'post',
					  dataType: 'post',
					  data: 'id='+id+'&content='+content,
					  success: function(data){
						 if(data=="login")
						 {
							alert("请你先登录");	 
						 }
						 else
						 {
							 _initShowComent(data);
							
						     clearEditor('content'); 
						 }
					  }
				});
	         <!-- end -->  
		}							
   })	
}


/* 清空内容 */  

function clearEditor(id) {
	
    KE.g[id].iframeDoc.open();
	
    KE.g[id].iframeDoc.write(KE.util.getFullHtml(id));
	
    KE.g[id].iframeDoc.close();
	
    KE.g[id].newTextarea.value = '';
	
}


//显示评论

function _initShowComent(page){

	var html="";
	 <!-- start -->
	      	 $.getJSON(
				    "/"+domain+"/blog/comment/id/"+id+"/page/"+page,
					 function(msg)
						{
						  if(msg!="")
						  {
							 var len   = msg.coment.length;
							 if(len>0)
							 {
								 for(var i=0;i<len;i++)
								 {				
					 if(msg.coment[i].nickname=="")
					 {
						msg.coment[i].nickname  = msg.coment[i].username; 
					 }
					 if(msg.coment[i].svisualize=="")
					 {
					   msg.coment[i].svisualize	= '/images/default/head.jpg';
					 }
					 				 
	    html+='<div class="comment" id="'+msg.coment[i].id+'"><div class="head"><p><a href="/'+msg.coment[i].domain+'" target="_blank">';
					
		html+='<img src="'+msg.coment[i].svisualize+'" /></a></p><p class="username">';

		if(msg.coment[i].line!=0)
		{
		html+='<img title="在线" src="/images/friend/line.gif"/>';
		}
		
		html+='<a href="/'+msg.coment[i].domain+'" target="_blank">'+msg.coment[i].nickname+'</a></p></div>';

	    html+='<div class="commentbody"><ul><li class="time"><b>评论时间：</b>'+msg.coment[i].timestamp;
				  
				  if(loginStatus=="host")
				  {
				     if(msg.coment[i].replay!="")
				     {
						var temp ="编辑回复"
					 }
					 else
					 {
						var temp ="回复"
				     }
					    html+='<span><a href="javascript:void(0);" type="edit">'+temp+'</a> | <a href="javascript:void(0);" type="del">删除</a></span>'  
				  }
					    html+='</li><li class="content">'+msg.coment[i].content+'</li></ul>';	 
				  
				  if(msg.coment[i].replay!="")
				  {
html+='<ul class="replay"><li class="replaytime"><b>主人回复：</b>('+msg.coment[i].replaytime+')</li> <li class="replaycontent">'+msg.coment[i].replay+'</li></ul>';
				  }
	    html+='</div><div class="clear"></div></div>';		
				 }
							        $(".comment").remove();
								   
									$(".comment-top").after(html);
								   
								    _initcomedit();
		                    }
							        setpage(msg.page);
					    }
				  });
     <!-- end -->
}



function setpage(page){
	
	    var curpage    = page.page;
							
		var totalpage  = page.totalpage;
							
		var totalcount = page.totalcount;
		
		var html;
		
		var count; 
		
		var uppage;
		
		var nextpage;
		
		$(".comment-top font").html(totalcount);
		
	    if(totalpage>1)
		{
                html = "第 <span class='cur'>"+curpage+"</span> 页/共 <span>"+totalpage+"</span> 页 &nbsp;&nbsp;";

			if(curpage==1)
			{
				html+= ' 首页 上一页';
			}
			else
			{
				uppage = curpage-1;
				
			    html+= ' <a page="1">首页</a> <a  page="'+uppage+'">上一页</a>'
		    }

			if(curpage==totalpage)
			{
				html+= ' 下一页  末页';
			}
			else
			{
				nextpage = curpage+1;
				
			    html+= ' <a  page="'+nextpage+'">下一页</a> <a page="'+totalpage+'">末页</a>'
			}
		}
        if(html!="")
        {
			   $(".page").html(html);
				 
			   $(".page a").click(function(){
													
				  var page = $(this).attr("page");	
	
				  _initShowComent(page);
				  
				  window.location.hash="se";
			   
			   })	 
		}
}


//评论的操作

function _initcomedit(){
	
           $(".comment a[@type]").click(function(){
																	 
                var type = $(this).attr("type");
				
				var id   = $(this).parent().parent().parent().parent().parent().attr("id");
	
				if(type=="del")
				{
					comdel(id);
				}
				else
				{
				    comedit(id);
				}
		   })    
}

// 评论删除

function comdel(id){
	
      if (confirm("删除后不可恢复，你确定要删除吗？"))
	  {
				 <!-- start -->
						$.post(
					   "/"+domain+"/blog/comentdel",
						{id:id},
						 function(msg)
							{
							  if(msg=="nologin")
							  {
								  alert("请您先登录再进行操作");  
							  }
							  else
							  {
								 $(".comment[@id="+id+"]").slideUp();
							  }
							  
					  });
			     <!-- end -->
	  }
}

//回复
function comedit(id){
	
	var sum = $(".comment[@id="+id+"] .replay").size();
	
	var replay = "";
	
	var relpaysum = $(".comment[@id="+id+"] .replays").size();

   if(relpaysum==0)
   {
		if(sum!=0)
		{
					   replay =  $(".comment[@id="+id+"] .replaycontent").html();
			 
					   $(".comment[@id="+id+"] .replay").hide();
		}	
		
	   var html ='<ul class="replays"><li><b>主人回复：</b></li>'
		
		   html+='<li><input type="text" value="'+replay+'" /> <a replay="'+id+'">保存</a> <a canel="'+id+'">取消</a></li></ul>';
		
		   $(".comment[@id="+id+"] .commentbody").append(html);
		   	   
		   $("a[@replay="+id+"]").click(function(){
														
					 var replay = $(this).parent().find("input").val();
	
					 if(replay=="")
					 {
						alert("请您输入内容");	 
					 }
					 else
					 {
						 <!-- start -->
						  $.post(
						    "/"+domain+"/blog/replay",
							{id:id,replay:replay},
							 function(msg)
								{
								  if(msg=="1")
								  {
										$(".comment[@id="+id+"] .replays").remove();
										
										var sum = $(".comment[@id="+id+"] .replay").size();
										
										if(sum!=0)
										{
											$(".comment[@id="+id+"] .replaycontent").html(replay);
											
											$(".comment[@id="+id+"] .replay").show();
										}else
										{
											var  html='<ul class="replay"><li class="replaytime"><b>主人回复：</b></li><li class="replaycontent">'+replay+'</li></ul>';	
			 
											$(".comment[@id="+id+"] .commentbody").append(html);
										}
								  }
						  });
						  <!-- end --> 
					  }
		  })

          $("a[@canel="+id+"]").click(function(){
																
			    $(this).parent().parent().remove();
				
				$(".comment[@id="+id+"] .replay").show();
		  })	  		 
   }
}





function _initFavorite()
{

    $("a[@type=favorite]").click(function(){
								
								
	     if(loginStatus=="guest")
		 {
			 alert("请您登录后，再进行此操作");
		 }
		 else
		 {
			 		     <!-- start -->
						  $.post(
						    "/"+domain+"/action/favorite",
							{id:id,type:"blog"},
							 function(msg)
								{
								  if(msg=="ok")
								  {
									 var sum = $("#favorite").text();
									 
									 sum = parseInt(sum);

								     sum = sum+1;
									 
									 $("#favorite").text(sum);
									  
									 alert("恭喜，已将本文收藏到您的灵光一闪 ^_^");
								  }
								  else if(msg=="login")
								  {
									 alert("请您登录后，再进行此操作");
								  }
								  else if(msg=="exist")
								  {
									 alert("温馨提示：您已收藏过本文，不能重复收藏");
								  }
						  });
						  <!-- end --> 
		 }
	 
	 
	 })
}





