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

//初始化执行
indexObject.prototype.load=function(){
	this.isBunch=isBunch;//是否是全空间
	this.isMy=isMy;//是否是自己的空间	
	this.indexTabDiv=$("indexTabDiv");//当前选项卡所在的div容器
	this.indexTabBodyDiv=$("indexTabBodyDiv");//当前选项卡内容所在的div容器
	this.useType=urlPar("useType");//当前所访问的博客角色 0 自己空间 大于0则为群
	this.user=urlPar("user");
	if(this.user==null){		
		this.user=userName;
	}	
	if(this.useType==null){
		this.useType=0;	
	}	
	for(var i=0;i<this.indexTabDiv.childNodes.length;i++){
		if(i==0)
			this.selTabObj=this.indexTabDiv.childNodes[0];
		this.indexTabDiv.childNodes[i].onclick=function(){
			indexClass.clickTab(this);	
		}
	}		
	if(this.isBunch=="0"){
		this.tab=menuTabBlog;
		this.indexTabDiv.childNodes[0].innerHTML="日志";	
		this.indexTabDiv.childNodes[1].innerHTML="相册";	
		this.indexTabDiv.childNodes[2].innerHTML="音乐";	
	}else{
		this.tab=menuTabBunBlog;
		this.indexTabDiv.childNodes[0].innerHTML="群日志";	
		this.indexTabDiv.childNodes[1].innerHTML="群相册";	
		this.indexTabDiv.childNodes[2].innerHTML="群音乐";	
	}
	this.loadDate();
}

//点击选项卡加载数据
indexObject.prototype.clickTab=function(obj){
	if(obj.className=="optionCar_1"){
		var parentDiv=obj.parentNode;
		this.selTabObj=obj;
		this.indexTabBodyDiv.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";	
			}
		}
		setTimeout("indexClass.loadDate()",1000);
	}
}

//加载数据信息
indexObject.prototype.loadDate=function(){
	var objResponse=new JHttpResponse();
	objResponse.write("selMenu",this.selTabObj.id);//选项卡的对象 1 文章 2图片 3音乐
	objResponse.write("typeMenuID","0");
	var out=objAjax.getText("post","./cs/indexServer.aspx?type=loadDate&useType="+this.useType+"&user="+this.user,objResponse,null); 
	if(out.indexOf(c1)>-1){
		this.indexTabBodyDiv.innerHTML="";
		if(this.selTabObj.id=="1"){
			this.loadArticle(out);	
		}else if(this.selTabObj.id=="2"){
			this.loadPhoto(out);
		}else{
			this.loadMusic(out);
		}
	}else{
		this.indexTabBodyDiv.innerHTML=out;
	}
}

//生成音乐信息
indexObject.prototype.loadMusic=function(out){
	// 0     1         2     3       4    5    6
	//id,groupname,userid,username,photo,num,ClusterID
	out=out.split(c2);
	for(var i=0;i<out.length;i++){
		var vp=out[i].split(c1);
		var cDiv=document.createElement("div");
		var isBool=false;		
		if(parseInt(vp[2])==parseInt(userID)||parseInt(cUserID)==parseInt(userID)){
			isBool=true;	
		}		
		if(isBool){
			cDiv.style.cssText="float:left;margin-left:6px;position:relative;overflow:hidden;width:168px;height:200px;margin-top:7px;border:solid 2px #e0e0e0;";
		}else{
			cDiv.style.cssText="float:left;margin-left:6px;position:relative;overflow:hidden;width:168px;height:185px;margin-top:7px;border:solid 2px #e0e0e0;"			
		}
		cDiv.onmouseover=function(){this.style.border="solid 2px #cccccc";}
		cDiv.onmouseout=function(){this.style.border="solid 2px #efefef";}
		this.indexTabBodyDiv.appendChild(cDiv);
		
		var cDivImg=document.createElement("div");
		cDivImg.className="photoalignCss";
		cDiv.appendChild(cDivImg);
		
		var cA=document.createElement("a");
		cA.href="../../home/musics.aspx?user=admin&typeMenuID="+vp[0]+"&userid="+vp[2];
		cDivImg.appendChild(cA);
		
		var cCaDiv=document.createElement("div");
		cCaDiv.style.cssText="height:88px;width:136px;overflow:hidden;";
		cCaDiv.innerHTML="<img  onload='setImgWH(this)'  src='"+vp[4]+"'/>";
		cA.appendChild(cCaDiv);	
		
		var cBodyDiv=document.createElement("div");
		cDiv.appendChild(cBodyDiv);
		var cDivTitle=document.createElement("div");
		cDivTitle.className="photoTitleCss";
		cDivTitle.style.cssText="text-align:left;padding-left:10px;";
		cDivTitle.innerHTML="<a href='./musics.aspx?user="+this.user+"&typeMenuID="+vp[0]+"&userid="+vp[2]+"&useType="+this.useType+"'>"+vp[1]+"</a>";
		cBodyDiv.appendChild(cDivTitle);
		
		var cDivUser=document.createElement("div");
		cDivUser.className="photoUserCss";
		cDivUser.style.cssText="text-align:left;padding-left:10px;";
		cDivUser.innerHTML="共"+vp[5]+"首";
		cBodyDiv.appendChild(cDivUser);	
		if(isBool){
			cSpanUser=document.createElement("span");
			cSpanUser.className="delMessageCss"
			cSpanUser.innerHTML="删除";
			cSpanUser.title="删除";
			cSpanUser.onmouseover=function(){this.style.color="red";}
			cSpanUser.onmouseout=function(){this.style.color="#000000";}
			cSpanUser.setAttribute("id",vp[0])
			cSpanUser.onclick=function(){
				if(confirm("数据删除后将无法恢复,确认要执行该操作吗?")){	
					var out=delUserMenuClass("3",this.id,indexClass.user,indexClass.useType);
					if(out=="ok"){
						alert("删除成功");
						indexClass.loadDate();
					}else{
						alert(out);	
					}
				}
			}
			cDivUser.appendChild(cSpanUser);
			
			cSpanUser=document.createElement("span");
			cSpanUser.onmouseover=function(){this.firstChild.style.color="red";}
			cSpanUser.onmouseout=function(){this.firstChild.style.color="#000000";}
			cSpanUser.className="editorMessageCss";
			cSpanUser.innerHTML="<a href='Management.aspx?typeid=3&useType="+this.useType+"'>编辑</a>";
			cDivUser.appendChild(cSpanUser);
			
			var cDivUser=document.createElement("div");
			cDivUser.className="photoUserCss";
			cDivUser.style.cssText="text-align:left;padding-left:10px;";
			cDivUser.innerHTML="创建者:<a href='./index.aspx?user="+vp[3]+"'>"+vp[3]+"</a>"
			cBodyDiv.appendChild(cDivUser);	
		}
	}		
}

//生成相册信息
indexObject.prototype.loadPhoto=function(out){
	// 0     1         2     3       4    5     6
	//id,groupname,userid,username,photo,num,ClusterID
	out=out.split(c2);
	for(var i=0;i<out.length;i++){
		var vp=out[i].split(c1);
		var cDiv=document.createElement("div");
		var isBool=false;
		if(parseInt(vp[2])==parseInt(userID)||parseInt(cUserID)==parseInt(userID)){
			isBool=true;	
		}
		if(isBool){
			cDiv.style.cssText="float:left;margin-left:6px;position:relative;overflow:hidden;width:168px;height:200px;margin-top:7px;border:solid 2px #e0e0e0;";
		}else{
			cDiv.style.cssText="float:left;margin-left:6px;position:relative;overflow:hidden;width:168px;height:185px;margin-top:7px;border:solid 2px #e0e0e0;"			
		}
		cDiv.onmouseover=function(){this.style.border="solid 2px #cccccc";}
		cDiv.onmouseout=function(){this.style.border="solid 2px #efefef";}
		
		this.indexTabBodyDiv.appendChild(cDiv);
		
		var cDivImg=document.createElement("div");
		cDivImg.className="photoalignCss";
		cDiv.appendChild(cDivImg);
		
		var cA=document.createElement("a");
		cA.href="../../home/photos.aspx?user=admin&typeMenuID="+vp[0]+"&userid="+vp[2];
		cDivImg.appendChild(cA);
		
		var cCaDiv=document.createElement("div");
		cCaDiv.style.cssText="height:88px;width:136px;overflow:hidden;";
		cCaDiv.innerHTML="<img  onload='setImgWH(this)'  src='"+vp[4]+"'/>";
		cA.appendChild(cCaDiv);	
		
		var cBodyDiv=document.createElement("div");
		cDiv.appendChild(cBodyDiv);
		
		var cDivTitle=document.createElement("div");
		cDivTitle.className="photoTitleCss";
		cDivTitle.style.cssText="text-align:left;padding-left:10px;";
		cDivTitle.innerHTML="<a href='./photos.aspx?user="+this.user+"&typeMenuID="+vp[0]+"&userid="+vp[2]+"&useType="+this.useType+"'>"+vp[1]+"</a>";
		cBodyDiv.appendChild(cDivTitle);
		
		var cDivUser=document.createElement("div");
		cDivUser.className="photoUserCss";
		cDivUser.style.cssText="text-align:left;padding-left:10px;";
		cDivUser.innerHTML="共"+vp[5]+"张";
		cBodyDiv.appendChild(cDivUser);	
		if(isBool){
			cSpanUser=document.createElement("span");
			cSpanUser.className="delMessageCss"
			cSpanUser.innerHTML="删除";
			cSpanUser.title="删除";
			cSpanUser.onmouseover=function(){this.style.color="red";}
			cSpanUser.onmouseout=function(){this.style.color="#000000";}
			cSpanUser.setAttribute("id",vp[0]);
			cSpanUser.onclick=function(){
				if(confirm("数据删除后将无法恢复,确认要执行该操作吗?")){	
					var out=delUserMenuClass("2",this.id,indexClass.user,indexClass.useType);
					if(out=="ok"){
						alert("删除成功");
						indexClass.loadDate();
					}else{
						alert(out);	
					}
				}
			}
			cDivUser.appendChild(cSpanUser);

			cSpanUser=document.createElement("span");
			cSpanUser.onmouseover=function(){this.firstChild.style.color="red";}
			cSpanUser.onmouseout=function(){this.firstChild.style.color="#000000";}
			cSpanUser.className="editorMessageCss";
			cSpanUser.innerHTML="<a href='Management.aspx?typeid=2&useType="+this.useType+"'>编辑</a>";
			cDivUser.appendChild(cSpanUser);
		}
		
		var cDivUser=document.createElement("div");
		cDivUser.className="photoUserCss";
		cDivUser.style.cssText="text-align:left;padding-left:10px;";
		cDivUser.innerHTML="创建者:<a href='./index.aspx?user="+vp[3]+"'>"+vp[3]+"</a>"
		cBodyDiv.appendChild(cDivUser);
	}		
}

//生成文章信息页面
indexObject.prototype.loadArticle=function(out){
		//0    1    2     3          4          5          6         7         8        9      10         11    12
		//id,title,CBS,SaveDate,Count_Click,Point_Good,SaveUserID,SaveUser,typeMenuID,menuid,groupname,bunchid,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.indexTabBodyDiv.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(parseInt(vp[6])==parseInt(userID)||parseInt(cUserID)==parseInt(userID)){
				isBool=true;	
			}
			if(isBool){
				cSpanUser=document.createElement("span");
				cSpanUser.className="delMessageCss"
				cSpanUser.innerHTML="删除";
				cSpanUser.title="删除";
				cSpanUser.onmouseover=function(){this.style.color="red";}
				cSpanUser.onmouseout=function(){this.style.color="#000000";}
				cSpanUser.setAttribute("id",vp[0])
				cSpanUser.onclick=function(){
					if(confirm("数据删除后将无法恢复,确认要执行该操作吗?")){	
						var out=delUserBolgContent(this.id,indexClass.tab,indexClass.user,indexClass.useType);
						if(out=="ok"){
							alert("删除成功");
							indexClass.loadDate();
						}else{
							alert(out);	
						}
					}
				}
				cDivBottom.appendChild(cSpanUser);
				cSpanUser=document.createElement("span");
				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);
			}
		}	
}



