//博客首页 2011-7-15
var objAjax = new JAjax();
function createObject(){
	return function(){
		this.load.apply(this,arguments);	
	}
}

var blogClass=null;
//博客首页 2011-7-18
setTimeout("loadPageBlog()",500);
function loadPageBlog(){
	blogClass=new blogObject();	
}

var blogObject=new createObject();
//初始化执行
blogObject.prototype.load=function(){
	this.blogTabDiv=$("blogTabDiv");
	this.blogTabBodyDiv=$("blogTabBodyDiv");
	this.typeMenuID=urlPar("typeMenuID");//当前要查看的文章分类信息
	this.useType=urlPar("useType");//获取当前的群信息
	this.user=urlPar("user");
	this.pagesize=5;//每页数量
	this.page=1;//当前页数
	this.pages=0;//总页数
	this.pagecount=0;//数据总条数
	if(this.typeMenuID==null){
		this.typeMenuID=0;	
	}
	if(this.useType==null){
		this.useType=0;
	}
	if(this.user==null){
		this.user=userName;
	}	
	this.isBunch=isBunch;
	for(var i=0;i<this.blogTabDiv.childNodes.length;i++){
		if(i==0)
			this.selTabObj=this.blogTabDiv.childNodes[0];
		this.blogTabDiv.childNodes[i].onclick=function(){
			blogClass.clickTab(this);
		}
	}	
	if(this.isBunch=="0"){
		this.tab=menuTabBlog;
		this.blogTabDiv.childNodes[0].innerHTML="用户日志";	
		this.blogTabDiv.childNodes[1].innerHTML="大家日志";	
		this.blogTabDiv.childNodes[2].innerHTML="用户好友日志";	
	}else{
		this.tab=menuTabBunBlog;
		this.blogTabDiv.childNodes[0].innerHTML="群公开日志";	
		this.blogTabDiv.childNodes[1].innerHTML="群内日志";	
		this.blogTabDiv.childNodes[2].style.display="none";
	}
	if(this.readBolgClass()){
		this.loadDate();
	}
}

//读取日志的所有分类信息
blogObject.prototype.readBolgClass=function(){
	var selLoadDate=$("selLoadDate");
	var selLoadDate_1=$("selLoadDate_1");
	selLoadDate.innerHTML="";
	selLoadDate_1.innerHTML="";
	selLoadDate.options.add(new Option("请选择","0"));
	selLoadDate_1.options.add(new Option("请选择","0"));
	var objResponse=new JHttpResponse();
	objResponse.write("typeMenuID","1");
	objResponse.write("selTabIndex",this.selTabObj.id);//当前获取数据的格式信息
	var out=objAjax.getText("post","./cs/indexServer.aspx?type=loadClass&useType="+this.useType+"&user="+this.user,objResponse,null); 
	if(out.indexOf(c1)>-1){
		out=out.split(c2);		
		for(var i=0;i<out.length;i++){
			var sp=out[i].split(c1);
			selLoadDate.options.add(new Option(sp[1],sp[0]));
			selLoadDate_1.options.add(new Option(sp[1],sp[0]));
			if(parseInt(this.typeMenuID)==parseInt(sp[0])){
				selLoadDate_1.options[i+1].selected=true;
				selLoadDate.options[i+1].selected=true;
			}
		}
		return true;
	}else{
		this.blogTabBodyDiv.innerHTML=out;	
		return false;
	}
}

//加载选择分类
blogObject.prototype.rLoadDate=function(obj){
	this.typeMenuID=obj.options[obj.selectedIndex].value;
	$("selLoadDate").options[obj.selectedIndex].selected=true;
	$("selLoadDate_1").options[obj.selectedIndex].selected=true;
	this.page=1;
	this.loadDate();
}

//点击选项卡加载数据
blogObject.prototype.clickTab=function(obj){
	if(obj.className=="optionCar_1"){
		var parentDiv=obj.parentNode;
		this.selTabObj=obj;
		this.blogTabBodyDiv.innerHTML="<div class='loadCss'>努力加载中....</div>";
		for(var i=0;i<parentDiv.childNodes.length;i++){
			if(parentDiv.childNodes[i]!=obj){
				parentDiv.childNodes[i].className="optionCar_1";	
			}else{
				parentDiv.childNodes[i].className="optionCar";	
			}
		}
		this.page=1;
		this.typeMenuID=0
		if(this.readBolgClass()){
			setTimeout("blogClass.loadDate()",1000);
		}
	}
}
//加载数据信息
blogObject.prototype.loadDate=function(){	
	var objResponse=new JHttpResponse();
	objResponse.write("selTabIndex",this.selTabObj.id);//当前获取数据的格式信息
	objResponse.write("typeMenuID",this.typeMenuID);	
	objResponse.write("page",this.page);	
	objResponse.write("pagesize",this.pagesize);	
	objResponse.write("serValue",$("serValue").value);	
	var out=objAjax.getText("post","./cs/indexServer.aspx?type=loadBlogDate&useType="+this.useType+"&user="+this.user,objResponse,null); 
	if(out.indexOf(c3)>-1){
		out=out.split(c3);
		this.pagecount=out[0];
		this.pages=parseInt(this.pagecount)/parseInt(this.pagesize);
		if(parseInt(this.pages)<parseFloat(this.pages)){
			this.pages=parseInt(this.pages)+1;	
		}		
		this.loadArticle(out[1]);
		var spanPage=$("pages");
		var spanPage_1=$("pages_1")
		spanPage.innerHTML="";
		spanPage_1.innerHTML="";
		if(parseInt(this.pages)>1){	
			spanPage.innerHTML="<span style='font-size:13px; height:24px;'>"+this.page+"/"+this.pages+"页</span>";
			spanPage_1.innerHTML="<span style='font-size:13px; height:24px;'>"+this.page+"/"+this.pages+"页</span>";

			if(this.page=="1"||parseInt(this.pages)>parseInt(this.page)){
				var nSpan=document.createElement("span");
				nSpan.style.cssText="cursor:pointer;color:blue;"
				nSpan.innerHTML="下一页";
				nSpan.onclick=function(){
					blogClass.page=parseInt(blogClass.page)+1;
					blogClass.loadDate();
				}
				spanPage.firstChild.appendChild(nSpan);
				var nSpan_1=document.createElement("span");
				nSpan_1.style.cssText="cursor:pointer;color:blue;"
				nSpan_1.innerHTML="下一页";
				nSpan_1.onclick=function(){
					blogClass.page=parseInt(blogClass.page)+1;
					blogClass.loadDate();
				}
				spanPage_1.firstChild.appendChild(nSpan_1);
			}
			if(parseInt(this.page)>1){
				var nSpan=document.createElement("span");
				nSpan.style.cssText="cursor:pointer;color:blue;"
				nSpan.innerHTML="上一页";
				nSpan.onclick=function(){
					blogClass.page=parseInt(blogClass.page)-1;
					blogClass.loadDate();
				}
				spanPage.firstChild.appendChild(nSpan);
				var nSpan_1=document.createElement("span");
				nSpan_1.style.cssText="cursor:pointer;color:blue;"
				nSpan_1.innerHTML="上一页";
				nSpan_1.onclick=function(){
					blogClass.page=parseInt(blogClass.page)-1;
					blogClass.loadDate();
				}
				spanPage_1.firstChild.appendChild(nSpan_1);
			}
			
			var cSel=document.createElement("select");	
			cSel.style.cssText="margin:5px;"
			for(var i=1;i<=parseInt(this.pages);i++){
				cSel.options.add(new Option("跳转到第"+i+"页",i));
				if(i==parseInt(this.page)){
					cSel.options[i-1].selected=true;	
				}
			}
			cSel.onchange=function(){
				blogClass.page=parseInt(this.options[this.selectedIndex].value);
				blogClass.loadDate();
			}
			spanPage.appendChild(cSel);
			var cSel_1=document.createElement("select");
			cSel_1.style.cssText="margin:5px;"
			for(var i=1;i<=parseInt(this.pages);i++){
				cSel_1.options.add(new Option("跳转到第"+i+"页",i));
				if(i==parseInt(this.page)){
					cSel_1.options[i-1].selected=true;	
				}
			}
			cSel_1.onchange=function(){
				blogClass.page=parseInt(this.options[this.selectedIndex].value);
				blogClass.loadDate();
			}
			spanPage_1.appendChild(cSel_1);
		}
		
	}else{
		var spanPage=$("pages");
		var spanPage_1=$("pages_1")
		spanPage.innerHTML="";
		spanPage_1.innerHTML="";
		this.blogTabBodyDiv.innerHTML=out;		
	}
}

//生成文章信息页面
blogObject.prototype.loadArticle=function(out){
		this.blogTabBodyDiv.innerHTML="";
		//0    1    2     3          4          5          6         7         8        9      10         11
		//id,title,CBS,SaveDate,Count_Click,Point_Good,SaveUserID,SaveUser,typeMenuID,menuid,groupname,competenceID
		out=out.split(c2);
		for(var i=0;i<out.length;i++){
			var vp=out[i].split(c1);			
			var cDiv=document.createElement("div");
			this.blogTabBodyDiv.appendChild(cDiv);
			if(i==out.length-1){
				cDiv.style.cssText="margin:5px;"
			}else{
				cDiv.style.cssText="margin:5px;border-bottom:dotted 1px #cccccc;"
			}			
			
			var cDivTitle=document.createElement("div");
			cDiv.appendChild(cDivTitle);
			cDivTitle.style.cssText="text-align:left;width:100%;height:25px;cursor:pointer;"
			cDivTitle.setAttribute("title",vp[1])
			cDivTitle.innerHTML="<a style='color:#14ADED;font-weight:bold;font-size:14px;' href='blogContent.aspx?menuid="+vp[9]+"&tab="+this.tab+"&tabid="+vp[0]+"&user="+vp[7]+"'>"+vp[1]+"</a>";
			
			var cDivDateTime=document.createElement("div");
			cDiv.appendChild(cDivDateTime);
			cDivDateTime.style.cssText="text-align:left;width:100%;height:22px;";
			var cSpanUser=document.createElement("span");
			cSpanUser.innerHTML="<a style='font-size:12px;color:#14ADED;' href='index.aspx?user="+vp[7]+"'>"+vp[7]+"</a>";
			cDivDateTime.appendChild(cSpanUser);
			
			var cSpanUser=document.createElement("span");
			cSpanUser.style.cssText="font-size:12px;margin-left:20px;"
			var d=new Date(vp[3].replace("-",","));
			var dN=new Date();
			var bT=dN.getTime()-d.getTime();
			if(bT>1000*60*60*24){
				cSpanUser.innerHTML=vp[3];
			}else{
				var h=bT/(1000*60*60);				
				var m=bT/(1000*60);
				if(h>1){
					cSpanUser.innerHTML=parseInt(h)+"小时前";
				}else if(m>1){
					cSpanUser.innerHTML=parseInt(m)+"分前";
				}else{
					cSpanUser.innerHTML=parseInt(bT/1000)+"秒前";	
				}
			}
			cDivDateTime.appendChild(cSpanUser);			
			var cDivCbs=document.createElement("div");
			cDiv.appendChild(cDivCbs);
			cDivCbs.style.cssText="text-align:left;width:100%;height:40px;text-indent:2em;"
			cDivCbs.innerHTML=vp[2];
			
			var cDivBottom=document.createElement("div");
			cDivBottom.style.cssText="width:100%;padding-bottom:10px;padding-top:10px;"

			cDiv.appendChild(cDivBottom);
			cSpanUser=document.createElement("span");
			cSpanUser.style.cssText="padding-right:10px;"			
			cSpanUser.innerHTML="分类:<a href='userbloglist.aspx?typeMenuID="+vp[8]+"&selUserID="+vp[6]+"&user="+vp[7]+"'>"+vp[10]+"</a>";
			cDivBottom.appendChild(cSpanUser);
			
			cSpanUser=document.createElement("span");
			cSpanUser.style.cssText="padding-left:10px;padding-right:10px;border-left:solid 1px #cccccc;";
			if(isBunch=="1"){
				cSpanUser.innerHTML="状态:"+(vp[12]=="0"?"全部可见":"群内可见");
			}else{
				cSpanUser.innerHTML="状态:"+(vp[12]=="0"?"全部可见":vp[12]=="1"?"好友可见":"自己可见");
			}
			cDivBottom.appendChild(cSpanUser);


			cSpanUser=document.createElement("span");
			cSpanUser.style.cssText="padding-left:10px;padding-right:10px;border-left:solid 1px #cccccc;"
			cSpanUser.innerHTML="阅读数:"+vp[4];
			cDivBottom.appendChild(cSpanUser);
			
			cSpanUser=document.createElement("span");
			cSpanUser.style.cssText="padding-left:10px;padding-right:10px;border-left:solid 1px #cccccc;"
			cSpanUser.innerHTML="好评数:"+vp[5];
			cDivBottom.appendChild(cSpanUser);
			
			var isBool=false;		
			if(isBunch=="0"){
				if(parseInt(homeUserID)==parseInt(userID)&&this.selTabObj.id=="1"||parseInt(cUserID)==parseInt(userID)&&this.selTabObj.id=="1"){
					isBool=true;	
				}
			}else{
				if(parseInt(homeUserID)==parseInt(userID)&&this.selTabObj.id=="2"||parseInt(cUserID)==parseInt(userID)&&this.selTabObj.id=="2"){
					isBool=true;	
				}
			}
			if(isBool){
				cSpanUser=document.createElement("span");
				cSpanUser.className="delMessageCss"
				cSpanUser.title="删除";
				cSpanUser.innerHTML="删除";
				cSpanUser.setAttribute("id",vp[0])
				cSpanUser.onmouseover=function(){this.style.color="red";}
				cSpanUser.onmouseout=function(){this.style.color="#000000";}
				cSpanUser.onclick=function(){
					if(confirm("数据删除后将无法恢复,确认要执行该操作吗?")){
						var out=delUserBolgContent(this.id,blogClass.tab,blogClass.user,blogClass.useType);
						if(out=="ok"){
							alert("删除成功");
							blogClass.page=1;
							blogClass.loadDate();
						}else{
							alert(out);	
						}
					}
				}
				cDivBottom.appendChild(cSpanUser);
				cSpanUser=document.createElement("span");
				cSpanUser.title="编辑";
				cSpanUser.onmouseover=function(){this.firstChild.style.color="red";}
				cSpanUser.onmouseout=function(){this.firstChild.style.color="#000000";}
				cSpanUser.className="editorMessageCss"
				cSpanUser.innerHTML="<a href='updataArticles.aspx?menuindex=2&pType=modi&menuid="+vp[9]+"&asTab="+this.tab+"&useType="+this.useType+"&typeId=1&id="+vp[0]+"'>编辑</a>";
				cDivBottom.appendChild(cSpanUser);
			}
		}	
}
