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

var supplyObject=new createObject();
supplyObject.prototype.load=function(){
	this.supplyTabDiv=$("supplyTabDiv");
	this.supplyTabBodyDiv=$("supplyTabBodyDiv");
	
	this.page=1;//当前页数
	this.pagesize=5;//每页数据量
	this.pages=0;//数据分页数
	this.pagecount=0;//数据总条数
	this.tab=menuTabSupply;
	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.supplyTabDiv.childNodes.length;i++){
		if(i==0)
			this.selTabObj=this.supplyTabDiv.childNodes[0];
		this.supplyTabDiv.childNodes[i].onclick=function(){
			supplyClass.clickTab(this);	
		}
	}	
	this.loadDate();
}

//点击选项卡加载数据
supplyObject.prototype.clickTab=function(obj){
	this.page=1;
	if(obj.className=="optionCar_1"){
		var parentDiv=obj.parentNode;
		this.selTabObj=obj;
		this.supplyTabBodyDiv.innerHTML="<div class='loadCss'>数据加载中....</div>s";
		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("supplyClass.loadDate()",1000);
	}
}
//加载数据
supplyObject.prototype.loadDate=function(){
	if(parseInt(this.selTabObj.id)==3){
		this.pagesize=20;
	}else{
		this.pagesize=5;
	}
	var objResponse=new JHttpResponse();
	objResponse.write("selMenu",this.selTabObj.id);//选项卡的对象 1 文章 2图片 3音乐
	objResponse.write("pagesize",this.pagesize);
	objResponse.write("page",this.page);
	var out=objAjax.getText("post","./cs/supplyArea.aspx?type=loadDate&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;	
		}	
		if(parseInt(this.selTabObj.id)<3){
			this.loadArticle(out[1]);
		}else{
			this.loadTabArticle(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(){
					supplyClass.page=parseInt(supplyClass.page)+1;
					supplyClass.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(){
					supplyClass.page=parseInt(supplyClass.page)+1;
					supplyClass.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(){
					supplyClass.page=parseInt(supplyClass.page)-1;
					supplyClass.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(){
					supplyClass.page=parseInt(supplyClass.page)-1;
					supplyClass.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(){
				supplyClass.page=parseInt(this.options[this.selectedIndex].value);
				supplyClass.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(){
				supplyClass.page=parseInt(this.options[this.selectedIndex].value);
				supplyClass.loadDate();
			}
			spanPage_1.appendChild(cSel_1);
		}
	}else{
		var spanPage=$("pages");
		var spanPage_1=$("pages_1")
		spanPage.innerHTML="";
		spanPage_1.innerHTML="";
		this.supplyTabBodyDiv.innerHTML=out;	
	}
}
supplyObject.prototype.loadTabArticle=function(out){
		this.supplyTabBodyDiv.innerHTML="";
		//0       1         2         3         4       5    6    7       8   
		//ID,Count_Click,SaveUser,SaveUserID,SaveDate,title,CBS,menuid,Count_Revert
		out=out.split(c2);
		var cTab=document.createElement("table");
		cTab.setAttribute("border",0);
		cTab.setAttribute("cellSpacing",0);
		cTab.setAttribute("cellPadding",0);
		cTab.style.cssText="width:700px;margin-top:5px;"
		this.supplyTabBodyDiv.appendChild(cTab);
		
		var tr=cTab.insertRow(cTab.rows.length);
		var td=tr.insertCell(-1);
		td.className="supplyTitleCss";
		td.innerHTML="标题";
		
		td=tr.insertCell(-1);
		td.className="supplyTitleCss_1";
		td.innerHTML="回复量";

		td=tr.insertCell(-1);
		td.className="supplyTitleCss_1";
		td.innerHTML="发布时间";
		
		td=tr.insertCell(-1);
		td.className="supplyTitleCss_1";
		td.innerHTML="发布者";
		for(var i=0;i<out.length;i++){
			var vp=out[i].split(c1);	
			tr=cTab.insertRow(cTab.rows.length);
			tr.onmouseover=function(){this.style.backgroundColor="#efefef";}
			tr.onmouseout=function(){this.style.backgroundColor="";}
			td=tr.insertCell(-1);
			td.className="supplyBodyCss";
			td.innerHTML="<a href='requestMusicContent.aspx?menuid="+vp[7]+"&tab="+this.tab+"&tabid="+vp[0]+"&user="+vp[2]+"'>"+vp[5]+"</a>";
			
			td=tr.insertCell(-1);
			td.className="supplyBodyCss_1";
			td.innerHTML=vp[8]+"次";
			
			td=tr.insertCell(-1);
			td.className="supplyBodyCss_1";
			var d=new Date(vp[4].replace("-",","));
			var dN=new Date();
			var bT=dN.getTime()-d.getTime();
			if(bT>1000*60*60*24){
				td.innerHTML=vp[4];
			}else{
				var h=bT/(1000*60*60);				
				var m=bT/(1000*60);
				if(h>1){
					td.innerHTML=parseInt(h)+"小时前";
				}else if(m>1){
					td.innerHTML=parseInt(m)+"分前";
				}else{
					td.innerHTML=parseInt(bT/1000)+"秒前";	
				}
			}		
			
			td=tr.insertCell(-1);
			td.className="supplyBodyCss_1";
			td.innerHTML="<a href='index.aspx?user="+vp[2]+"'>"+vp[2]+"</a>";			
		}
}
//生成文章信息页面
supplyObject.prototype.loadArticle=function(out){
		this.supplyTabBodyDiv.innerHTML="";
		//0       1         2         3         4       5    6    7       8   
		//ID,Count_Click,SaveUser,SaveUserID,SaveDate,title,CBS,menuid,Count_Revert
		out=out.split(c2);
		for(var i=0;i<out.length;i++){
			var vp=out[i].split(c1);			
			var cDiv=document.createElement("div");
			this.supplyTabBodyDiv.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[5])
			cDivTitle.innerHTML="<a style='color:#14ADED;font-weight:bold;font-size:14px;' href='requestMusicContent.aspx?menuid="+vp[7]+"&tab="+this.tab+"&tabid="+vp[0]+"&user="+vp[2]+"'>"+vp[5]+"</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[2]+"'>"+vp[2]+"</a>";
			cDivDateTime.appendChild(cSpanUser);
			
			var cSpanUser=document.createElement("span");
			cSpanUser.style.cssText="font-size:12px;margin-left:20px;"
			var d=new Date(vp[4].replace("-",","));
			var dN=new Date();
			var bT=dN.getTime()-d.getTime();
			if(bT>1000*60*60*24){
				cSpanUser.innerHTML=vp[4];
			}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[6];
			
			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="回复量:"+vp[8]+"次";
			cDivBottom.appendChild(cSpanUser);
			var isBool=false;	
			if(parseInt(homeUserID)==parseInt(userID)&&this.selTabObj.id=="1"||parseInt(cUserID)==parseInt(userID)&&this.selTabObj.id=="1"){
				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,supplyClass.tab,supplyClass.user,supplyClass.useType);
						if(out=="ok"){
							alert("删除成功");
							supplyClass.page=1;
							supplyClass.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='publicUpdate.aspx?menuindex=2&pType=modi&menuid="+vp[7]+"&asTab="+this.tab+"&useType="+this.useType+"&typeId=1&id="+vp[0]+"'>编辑</a>";
				cDivBottom.appendChild(cSpanUser);
			}
		}	
}
