﻿var alldata;
var REPLY = 1, FANGLE=2, ALL=0, GROUP=3, SCHOOLCLASS=6;
var NUMBER_PER_PAGE = 30;
var showtype = 0, bAtHome = false, gCurPage;
var myDate = new Date();
var feedUserId = 0;
var fdCount = 0;
function getFeedHome(){
	var feedUrl = '/feedhome_ajax.do';
	var pars = 't=home&time='+myDate.getTime();
	var myAjax = new Ajax.Request(
					feedUrl,
					{
						method:'post',
						parameters:pars,
						onComplete:showFeedHome,
						onFailure:showError
						});
}

function getMiniFeed(){
	var feedUrl = '/feedmini_ajax.do';
	var pars = 't=minifeed&u='+feedUserId+'&time='+myDate.getTime();
	var myAjax = new Ajax.Request(
					feedUrl,
					{
						method:'post',
						parameters:pars,
						onComplete:showFeedHome,
						onFailure:showError
						});
}

function showFeedHome(r){
	var feedHome = r.responseText.split("@JL@D");
	if($('feedCountDiv')){
		$('feedCountDiv').innerHTML = '('+feedHome[0]+')';
	}
	if($('feedHome')){
		$('feedHome').innerHTML = feedHome[1];
	}
}

function setNewsFeedRead(feedId){
	var feedUrl = '/feedhome_ajax.do';
	var pars = 't=read&id='+feedId+'&ran='+Math.random();
		var myAjax = new Ajax.Request(
					feedUrl,
					{
						method:'post',
						parameters:pars,
						onComplete:showFeedHome,
						onFailure:showError
						});
}

function setMiniFeedRead(feedId,userId){
	var feedUrl = '/feedmini_ajax.do';
	var pars = 't=miniread&u='+userId+'&id='+feedId+'&ran='+Math.random();
	feedUserId = userId;
	var myAjax = new Ajax.Request(
				feedUrl,
				{
					method:'post',
					parameters:pars,
					onComplete:showFeedHome,
					onFailure:showError
					});
}

function readThisFeed(feedId,userId,fType){
	if(fType=='newsfeed'){
		setNewsFeedRead(feedId);
	}else if(fType=='minifeed'){		
		setMiniFeedRead(feedId,userId);
	}	
}

function readHomeFeed(feedId){
	var feedUrl = '/feedhome_ajax.do';
	fdCount++;
	if(fdCount==10){
		fdCount = 0;
		var pars = 't=read&id='+feedId+'&ran='+Math.random();
			var myAjax = new Ajax.Request(
						feedUrl,
						{
							method:'post',
							parameters:pars,
							onComplete:showFeedHome,
							onFailure:showError
							});
	}else{
		hideNewsFeedItem(feedId);
		var pars = 't=readone&id='+feedId+'&ran='+Math.random();
		var myAjax = new Ajax.Request(
					feedUrl,
					{
					method:'post',
					parameters:pars,
					onFailure:showError
					});		
	}
}

function hideNewsFeedItem(disid){
	try{
	document.getElementById(disid).style.display="none";
	}catch(E){}
//标记阅读部分
}

function confirmReadAll(){
	if(confirm("确定将全部新鲜事设置为已读吗?")){
		readFeedAll();
		return true;
	}else
		return false;
}

function readFeedAll(){
	var feedUrl = '/feedhome_ajax.do';
	var pars = 't=readall&ran='+Math.random();
		var myAjax = new Ajax.Request(
					feedUrl,
					{
						method:'post',
						parameters:pars,
						onComplete:getFeedHome,
						onFailure:showError
						});
}

function fnFeed(actionType,curpage,isfirst) {	
	showtype = actionType;
	bAtHome = isfirst;
	gCurPage = curpage;
 	if(getEl("fangle_curpage_hid")) {getEl("fangle_curpage_hid").value=curpage;}
	if(getEl("fangle_first_hid")) {getEl("fangle_first_hid").value=isfirst;}
	var url = '/dispatchview.do';
 	var pars = 'type='+ actionType 
		 + '&curpage='+curpage 
		 + '&isfirst='+isfirst
		 + '&t=' + myDate.getTime();
	//debugOut(pars);	
	var myAjax = new Ajax.Request(
				url, 
				{
							method: 'post', 
							parameters: pars, 
							onComplete: showResponseHome,
							onFailure: showError
				});
}

function showResponseHome(r) {
	
	//return_result = r.responseText;
	//alert(rturn_result) ;
	//var dataStr =null ;// "alldata = " + return_result;			
	eval("alldata="+r.responseText);
	//var tempEl = findElement(document.body,'floatphoto','div');	
	//tempEl.style.position = "absolute";
	//tempEl.style.display = "none";
	switch(showtype) {
		case REPLY: 		  
			CampusInfo.buildRepInfo(1);
			break;
		case FANGLE: 
			CampusInfo.buildPnlInfo(2);
			break;
		case GROUP: 		  		  		  
			CampusInfo.buildGplInfo(3);
			break;			
		case SCHOOLCLASS: 		  			  
			CampusInfo.buildClsInfo(6);
			break;						
		default:				  
			CampusInfo.buildRepInfo(1);	
			CampusInfo.buildPnlInfo(2);
			CampusInfo.buildGplInfo(3);
			CampusInfo.buildClsInfo(6);
	}
	if($('friendsNewsFeedDiv') && $('clsNewsFeedDiv') && $('TribeNewsFeedDiv')) {
 		if(($('friendsNewsFeedDiv').style.display == "none") && ($('clsNewsFeedDiv').style.display == "none") && ($('TribeNewsFeedDiv').style.display == "none")) {
 			if($('freshDiv')) $('freshDiv').style.display = "none";
 		}
 	}
}
function showError(t) {
	var errmsg = t.status + ' -- ' + t.statusText; 
	alert("抱歉，出错了；错误信息：" + errmsg + " 麻烦点页面底部的 “给管理员留言”报告错误");
}

function getReplyList(){	
	showtype = 1;
	bAtHome = 2;
	gCurPage = 0;
 	//if(getEl("fangle_curpage_hid")) {getEl("fangle_curpage_hid").value=0;}
	//if(getEl("fangle_first_hid")) {getEl("fangle_first_hid").value=2;}
	var url = '/dispatchview.do';
	var pars = "type=1&curpage=0&isfirst=2&t="+myDate.getTime();
	var myAjax = new Ajax.Request(
				url, 
				{
							method: 'post', 
							parameters: pars, 
							onComplete: showResponseHomeReply,
							onFailure: showError
				});
}
function showResponseHomeReply(r) {	
	eval("alldatanew="+r.responseText);
	CampusInfo.buildNewRepInfo(1);
}

var CampusInfo = new Object();
CampusInfo.NewsIsEmpty = 0;
//新留言以及回复提示
CampusInfo.buildNewRepInfo=function(type){
try{	
	var gossipReplyCount;
	var total;	
	if ((!alldatanew.replys) && (!alldatanew.fangles)){	

		if(showtype==0) {
	 		gossipReplyCount= alldatanew.count.replyc;
		} else {
	 		gossipReplyCount= alldatanew.count;
		}		
		if(gossipReplyCount == 0) {			
			CampusInfo.NewsIsEmpty++;	
			if($("gossipReplyFeed")) 
			{		
			  $('opilist').innerHTML = "当有人回复了你发表的内容或者给你留言，这里会有提示" ;
			  $('opilist').style.display="";
			}
			if(bAtHome && (alldatanew.count.replytc > 0) ) {
				//更多		
				if($("replyMoreDiv")) $("replyMoreDiv").innerHTML = '<a href="/myreplylist.do">更多</a>' ;
			}
			if($('replyDiv')) $('replyDiv').style.display="none";
			return;
 		}else{
 			if($('replyDiv')&&$('replyDiv').style.display=="none") $('replyDiv').style.display="";
 		}
	}			
	var data;
	if(alldatanew.replys) {
		data = alldatanew.replys;
	}else {
		data = alldatanew.fangles;
	}	
	var pages = 0;
	//显示数量
	
	var rep = "";
		
	for(var i=0; i<data.length; i++) {
		// bell(2009-7-13): 据说状态回复的状态会乱，考察一番，未发现乱状态，如以后发现了就再注释这里吧
		if(data[i].type!=65549){ // 状态回复过滤 xieweibo
		rep +="<div class=\"opi\"><div class=\"opi-icon\"><img src=\"http://img.hi.mop.com/img/newsfeed/wall_post.gif\"/></div>"
					+"<div class=\"opi-content\"><div class=\"headline\"><span class=\"title\"><div class=\"share-n-hide\">"
					+"<a class=\"x-2-hide\" href=\"javascript:void(0)\" onclick=\"CampusInfo.readOneNew("+type+","+data[i].recordNo+","+data[i].type+","+data[i].sourceNo+",'"+data[i].link+"',"+type+","+type+","+data[i].unread+" )\">&nbsp</a></div>";
		if (data[i].type==65540) {
			if(data[i].fromUserName=="某人") {
				rep +=CampusUtils.resizeName(data[i].fromUserName)+data[i].prefix+" <a href='"+data[i].link+"'  onclick=\"CampusInfo.readOneNew("+type+","+data[i].recordNo+","+data[i].type+","+data[i].sourceNo+",'"+data[i].link+"',"+type+","+type+","+data[i].unread+" )\">"+CampusUtils.resizeTitle(data[i].title)+"</a> "+data[i].sufix+" <span class='date'>"+today(data[i].createTime)+"</span>";
			}
		} else {
		// 2
			rep +="<a href='"+myDomain+"/profile.do?id="+data[i].fromUserNo+"'>"+CampusUtils.resizeName(data[i].fromUserName)+"</a> "+data[i].prefix+
				" <a href=\""+data[i].link+"\"  onclick=\"CampusInfo.readOneNew("+type+","+data[i].recordNo+","+data[i].type+","+data[i].sourceNo+",'"+data[i].link+"',"+type+","+type+","+data[i].unread+" )\">"+CampusUtils.resizeTitle(data[i].title)+"</a> "+data[i].sufix+" <span class=\"date\">"+today(data[i].createTime)+"</span>";
		}
		rep +="</span></div></div></div>";
		}
	}
	if(showtype==0) {
 		gossipReplyCount= alldatanew.count.replyc;
	} else {
 		gossipReplyCount= alldatanew.count;
	}	
	
	if($("gossipReplyCount")) 
	    $("gossipReplyCount").innerHTML = "(" + gossipReplyCount + ")";
	
	if(bAtHome) {
		total = alldatanew.count.replytc;
	}
	if(bAtHome && (total > 0) ) {
		//更多		
		if($("replyMoreDiv")) $("replyMoreDiv").innerHTML = '<a href="/myreplylist.do">更多</a>' ;
	}	
	
 	if((!bAtHome) && gossipReplyCount > NUMBER_PER_PAGE) {
		rep +='<div id="pNav">';
		if(alldatanew.page>0) {
 			rep +='<a href="javascript:fnFeed('+showtype+',' + (alldatanew.page - 1) + ',0)">上一页</a>';  
		}else if (bAtHome==0){
			rep += '<span  style="color: #999999; text-decoration:none">上一页</span>';
		}
 		if(alldatanew.page < ((gossipReplyCount- (gossipReplyCount % NUMBER_PER_PAGE) )/NUMBER_PER_PAGE)){
			if(alldatanew.page>0) rep +="<span class='separator'> </span>";
			rep += '<a href="javascript:fnFeed('+showtype+',' + (alldatanew.page + 1) + ',0)">下一页</a>';
		}else if (bAtHome==0){
			if(alldatanew.page>0) rep +="<span class='separator'> </span>";
			rep += '<span style="color:#999999;text-decoration:none">下一页</span>';
		}
		
		rep +='</div>';
	}
	if($('replyDiv')) $('replyDiv').style.display="";
  if($("opilist")) 
	  $("opilist").innerHTML = rep;
	}catch(E){
	    $('opilist').innerHTML = "当有人回复了你发表的内容或者给你留言，这里会有提示" ;
			if($('replyDiv')) 
				$('replyDiv').style.display="";
			if($('opilist'))
				$('opilist').style.display="";			 
  }
}
CampusInfo.buildRepInfo=function(type){
try{	
	var gossipReplyCount;
	var total;	
	if ((!alldata.replys) && (!alldata.fangles)){	

		if(showtype==0) {
	 		gossipReplyCount= alldata.count.replyc;
		} else {
	 		gossipReplyCount= alldata.count;
		}		
		if(gossipReplyCount == 0) {			
			CampusInfo.NewsIsEmpty++;	
			if($("gossipReplyFeed")) 
			{		
			  $('gossipReplyFeed').innerHTML = "当有人回复了你发表的内容或者给你留言，这里会有提示" ;
			  $('gossipReplyFeed').style.display="";
			}
			if(bAtHome && (alldata.count.replytc > 0) ) {
				//更多		
				if($("gossipReplyMore")) $("gossipReplyMore").innerHTML = '<a href="/myreplylist.do">更多</a>' ;
			}
			if($('gossipReplyFeedDiv')) $('gossipReplyFeedDiv').style.display="none";
			return;
 		}
	}			
	var data;
	if(alldata.replys) {
		data = alldata.replys;
	}else {
		data = alldata.fangles;
	}	
	var pages = 0;
	//显示数量
	var rep = "<table class=\"rapidlist\">";	
	for(var i = 0 ;i<data.length;i++){
		if(data[i].unread){
			rep +="<tr class=\"unread\">" ;
		}else{
		 	rep +="<tr class=\"read\">" ;
		}
		//类型图标暂时不显示
		//rep +="<img src='"+CampusUtils.getIcon(type, data[i].type)+"'>" ;
		if (data[i].type==65540){
			if(data[i].fromUserName=="某人")
				rep +="<td class='title'><p>"+CampusUtils.resizeName(data[i].fromUserName)+"	<span class='prefix'>"+data[i].prefix +"</span> ";
			else
				rep +="<td class='title'><p><a class='author' href='"+myDomain+"/profile.do?id="+data[i].fromUserNo+"' >"+CampusUtils.resizeName(data[i].fromUserName)+"</a>	<span class='prefix'>"+data[i].prefix +"</span>";
		}else
			rep +="<td class='title'><p><a class='author' href='"+myDomain+"/profile.do?id="+data[i].fromUserNo+"' >"+CampusUtils.resizeName(data[i].fromUserName)+"</a>	<span class='prefix'>"+data[i].prefix +"</span>";
		if (data[i].type==2048){ //社团 回复和引用某用户留言，给他分发。
			rep += data[i].title;
		}else{
		 	rep +=" <a href=\""+data[i].link+"\" onclick=\"CampusInfo.readOne("+type+","+data[i].recordNo+","+data[i].type+","+data[i].sourceNo+",'"+data[i].link+"',"+type+","+type+","+data[i].unread+" )\" >"+CampusUtils.resizeTitle(data[i].title)+"</a>" ;
		}
		if(data[i].type==8||data[i].type==256){
			rep +="	-	<a href='"+domainGroup+"/GetTribe.do?id="+data[i].ownerNo+"' >"+data[i].ownerName+"</a>" ;
		}
		if (data[i].type!=1024){ //社团不需要 
			rep +="	<span class='sufix'>"+data[i].sufix +"</span>" ;
		}
		rep +="</p></td><td class=\"meta\"><p><span class=\"time\">" + today(data[i].createTime) + "</span><a href=\"javascript:void(0)\" onclick=\"CampusInfo.readOne("+type+","+data[i].recordNo+","+data[i].type+","+data[i].sourceNo+",'"+data[i].link+"',"+type+","+type+","+data[i].unread+" )\" class=\"remove\">删除</a></p></td>";
		rep +="</tr>" ;
	}
	rep += "</table>";	
	
	if(showtype==0) {
 		gossipReplyCount= alldata.count.replyc;
	} else {
 		gossipReplyCount= alldata.count;
	}	
	 
	if($("gossipReplyCount")) 
	    $("gossipReplyCount").innerHTML = "(" + gossipReplyCount + ")";
	
	if(bAtHome) {
		total = alldata.count.replytc;
	}
	if(bAtHome && (total > 0) ) {
		//更多		
		if($("gossipReplyMore")) $("gossipReplyMore").innerHTML = '<a href="/myreplylist.do">更多</a>' ;
	}	
	
 	if((!bAtHome) && gossipReplyCount > NUMBER_PER_PAGE) {
		rep +='<div id="pNav">';
		if(alldata.page>0) {
 			rep +='<a href="javascript:fnFeed('+showtype+',' + (alldata.page - 1) + ',0)">上一页</a>';  
		}else if (bAtHome==0){
			rep += '<span  style="color: #999999; text-decoration:none">上一页</span>';
		}
 		if(alldata.page < ((gossipReplyCount- (gossipReplyCount % NUMBER_PER_PAGE) )/NUMBER_PER_PAGE)){
			if(alldata.page>0) rep +="<span class='separator'> </span>";
			rep += '<a href="javascript:fnFeed('+showtype+',' + (alldata.page + 1) + ',0)">下一页</a>';
		}else if (bAtHome==0){
			if(alldata.page>0) rep +="<span class='separator'> </span>";
			rep += '<span style="color:#999999;text-decoration:none">下一页</span>';
		}
		
		rep +='</div>';
	}
  if($("gossipReplyFeed")) 
	  $("gossipReplyFeed").innerHTML = rep;
	}catch(E){
	    $('gossipReplyFeed').innerHTML = "当有人回复了你发表的内容或者给你留言，这里会有提示" ;
			  $('gossipReplyFeed').style.display="";	
        }
}

//好友新鲜事
CampusInfo.buildPnlInfo=function(type){
try{
	if ((!alldata.diarys)&&(!alldata.fangles)){
		CampusInfo.NewsIsEmpty++;
		if($('friendsNewsFeed')) 
		{
			if($('fresherpage'))
				$('friendsNewsFeed').innerHTML ="当你加了朋友后，朋友发的<strong>照片</strong>和<strong>日志</strong>都会在这里显示";
			else
				$('friendsNewsFeed').innerHTML ="当你的朋友发表日记、照片或者帖子，这里会有提示";
		}
		if( bAtHome && (alldata.count.diarytc > 0)) {
			//更多		
			if($("friendsNewsMore")) { 
				$("friendsNewsMore").innerHTML = '<a href="/myfanglelist.do">更多</a>' 
			}
		}
		if($('friendsNewsFeedDiv')) $('friendsNewsFeedDiv').style.display="none";
		return;
	}	
	if(alldata.diarys) {
		data = alldata.diarys;
	}else {
		data = alldata.fangles;
	}
	var pages = 0;
	if(showtype!=0) {pages=alldata.page;}
	var rep = "" ;
	rep += "<table class=\"rapidlist\">";
	for(var i = 0 ;i<data.length;i++){
		if(data[i].unread)
			rep +="<tr class=\"unread\">" ;
		else
		 	rep +="<tr class=\"read\">" ;
		if(data[i].type==1049154)
			rep +="<td class='name'><p><a class='author' href='"+myDomain+"/profile.do?id="+data[i].fromUserNo+"' target='_blank'>"+CampusUtils.resizeName(data[i].fromUserName)+"</a>	<span class='prefix'>"+data[i].prefix +"</span> "
			+"</td><td class='title'><p> <a class='author' href='"+myDomain+"/profile.do?id="+data[i].ownerNo+"' target='_blank'>"+CampusUtils.resizeName(data[i].ownerName)+"</a>" ;
		else if(data[i].type==1049156)
			rep +="<td class='name'><p><a class='author' href='"+myDomain+"/profile.do?id="+data[i].fromUserNo+"' target='_blank'>"+CampusUtils.resizeName(data[i].fromUserName)+"</a>	<span class='prefix'>"+data[i].prefix +"</span> "
			+ "</td><td class='title'><p>"+CampusUtils.resizeName(data[i].ownerName);
		else
			rep +="<td class='name'><p><a class='author' href='"+myDomain+"/profile.do?id="+data[i].fromUserNo+"' target='_blank'>"+CampusUtils.resizeName(data[i].fromUserName)+"</a>	<span class='prefix'>"+data[i].prefix +"</span></td><td class='title'><p>" ;
		if(data[i].type==64){
		 	if(data[i].fromUserNo==data[i].ownerNo)
		 		rep +=" 回复 " ;
		 	else
				rep +="给 "
		}
		if(data[i].type==64){
		 	if(data[i].fromUserNo==data[i].ownerNo)
		 		rep +="自己的" ;
		 	else
				rep +=data[i].ownerName ;
		}

		rep +=" <a href=\""+data[i].link+"\" " ;
		rep +="onclick=\"CampusInfo.readOne("+type+","+data[i].recordNo+","+data[i].type+","+data[i].sourceNo+",'"+data[i].link+"',"+type+","+data[i].unread+")\" " ;
		rep +="target=\"_blank\"" ;
		rep += (data[i].type!=16? (" title=\""+data[i].title+"\" "):"");

		if(data[i].type==64){
		 	if(data[i].fromUserNo==data[i].ownerNo)
		 		rep +=">留言</a>" ;
		 	else
				rep +="><span class='leaveWord'>留言</span></a>" ;
		}else if (data[i].type==16){//只显示图片图标
		 	rep +=" onmouseover='javascript:FloatPhoto.overImage(event,\""+data[i].imageUrl+"\",this,500);' onmouseout='javascript:FloatPhoto.outImage();'	>"+CampusUtils.resizeTitle(data[i].title)+"</a>" ;
		 	rep +=" <img src='"+CampusUtils.getIcon(type,data[i].type)+"'	align='absmiddle' onmouseover='javascript:FloatPhoto.overImage(event,\""+data[i].imageUrl+"\",this,200);' onmouseout='javascript:FloatPhoto.outImage();' >" ;
		} else if(data[i].type==2) {
			rep += ">"+CampusUtils.resizeTitle(data[i].title)+"</a> <img src='http://img.hi.mop.com/img/ico_blog.gif' />";
		}else{			
		 	rep += " >"+CampusUtils.resizeTitle(data[i].title)+"</a>";
		}

		rep +="	"+data[i].sufix ;
		rep +="</p></td><td class=\"meta\"><p><span class=\"time\">" + today(data[i].createTime) + "</span><a href=\"javascript:void(0)\" onclick=\"CampusInfo.readOne("+type+","+data[i].recordNo+","+data[i].type+","+data[i].sourceNo+",'"+data[i].link+"',"+type+","+data[i].unread+")\" class=\"remove\">删除</a></p></td>" ;
		rep +="</tr>";

	}
	rep += "</table>";
	var friendsNewsCount;
	var total;
	var tcount = alldata.tcount;
 	if(showtype==0) {
 		friendsNewsCount= alldata.count.diaryc;
	} else {
 		friendsNewsCount= alldata.count;
	}
 	if($("friendsNewsCount")) $("friendsNewsCount").innerHTML = "(" + friendsNewsCount + ")";
	if(bAtHome) {
		total = alldata.count.diarytc;	
	}
	if( bAtHome && (total > 0)) {
		//更多		
		if($("friendsNewsMore")) { 
			$("friendsNewsMore").innerHTML = '<a href="/myfanglelist.do">更多</a>' 
		}
	}	
	if((!bAtHome) && (friendsNewsCount > NUMBER_PER_PAGE)) {
		rep +='<div id="pNav">';
		if(alldata.page>0) {
 			rep +='<a href="javascript:fnFeed('+showtype+',' + (alldata.page - 1) + ',0)">上一页</a>';  
		}else if (bAtHome==0){
			rep +='<span  style="color: #999999; text-decoration:none">上一页</span>';
		}
		var totalPage = (tcount - tcount % NUMBER_PER_PAGE) / NUMBER_PER_PAGE;
		if(tcount % NUMBER_PER_PAGE>0)
			totalPage = totalPage + 1;
		if(alldata.page < totalPage - 1 ){		
 			if(alldata.page>0) rep +="<span class='separator'> </span>";
			rep += '<a href="javascript:fnFeed('+showtype+',' + (alldata.page + 1) + ',0)">下一页</a></div>';
		}else if (bAtHome==0){
 			if(alldata.page>0) rep +="<span class='separator'> </span>";
			rep += '<span  style="color: #999999; text-decoration:none">下一页</span></div>';			
		}
		rep +='</div>';
	}
	$("friendsNewsFeed").innerHTML = rep ;
	$("friendsNewsFeed").style.display="";
  }catch(E){
  	$('friendsNewsFeed').innerHTML ="当你的朋友发表日记、照片或者帖子，这里会有提示";
  	$("friendsNewsFeed").style.display="";
  	}	
}

//　小圈子新鲜事
CampusInfo.buildGplInfo=function(type){	
try{
	if (!alldata.groups){		
		CampusInfo.NewsIsEmpty++;
		if($("TribeNewsFeed"))
			$('TribeNewsFeed').innerHTML =  "当你加入的群有新的帖子，这里会有提示";				
	  if( bAtHome && alldata.count.grouptc > 0 ) {
			//更多		
			if($("TribeNewsMore")) { 
				$("TribeNewsMore").innerHTML = '<a href="/mytribefanglelist.do">更多</a>' 
			}
		}
		if($('TribeNewsFeedDiv')) $('TribeNewsFeedDiv').style.display="none";
		return;
	}
	if($("TribeNewsCount")){
	 	if(showtype==0)
	  	$("TribeNewsCount").innerHTML = "("+alldata.count.groupc+")";
	  else
	  	$("TribeNewsCount").innerHTML = "("+alldata.count+")";
	}

	var data = alldata.groups;	

	var pages = 0;
	if(showtype!=0) {pages=alldata.page;}

	var rep = "" ;
	var rep = "<table class=\"rapidlist\">";	
	for(var i = 0 ;i<data.length;i++){
	   if(data[i].unread)
	   	   rep +="<tr class=\"unread\">" ;
	   else
	   	   rep +="<tr class=\"read\">" ;

	   rep +="<td class='title'><p>" ;
	   rep +="<a class='author' href='http://group.xiaonei.com/GetTribe.do?id="+data[i].ownerNo+"' target='_blank'>"+data[i].ownerName+"</a>" + " - "
	   rep +="<a target='_blank' href='http://group.xiaonei.com/" + data[i].link + "' onclick=CampusInfo.readOne("+type+","+data[i].recordNo+","+data[i].type+","+data[i].sourceNo+",'"+data[i].link+"',"+type+","+data[i].unread+") title='"+data[i].title+"'>"+CampusUtils.resizeTitle(data[i].title)+"</a>" ;
	   //rep +="<span> by " + data[i].fromUserName + "</span>"
		rep +="</p></td><td class=\"meta\"><p><span class=\"time\">" + today(data[i].createTime) + "</span><a href=\"javascript:void(0)\" onclick=CampusInfo.readOne("+type+","+data[i].recordNo+","+data[i].type+","+data[i].sourceNo+",'"+data[i].link+"',"+type+","+data[i].unread+") class=\"remove\">删除</a></p></td>" ;
		rep +="</tr>";
	}
	rep += "</table>";
  if( bAtHome && alldata.count.grouptc > 0 ) {
		//更多		
		if($("TribeNewsMore")) { 
			$("TribeNewsMore").innerHTML = '<a href="/mytribefanglelist.do">更多</a>' 
		}
	}	
	if($("TribeNewsFeed"))
    $("TribeNewsFeed").innerHTML = rep ;   
	var tribeNewsCount;
	var total;
 	if(showtype==0) {
 		tribeNewsCount = alldata.count.groupc;
	} else {
 		tribeNewsCount = alldata.count;
	}
  
	if((!bAtHome) && (alldata.count.groupc > NUMBER_PER_PAGE)) {
		rep +='<div id="pNav">';
		if(alldata.page>0) {
 			rep +='<a href="javascript:fnFeed('+showtype+',' + (alldata.page - 1) + ',0)">上一页</a>';  
		}else if (bAtHome==0){
			rep +='<span  style="color: #999999; text-decoration:none">上一页</span>';
		}
		if(alldata.page < ((tribeNewsCount - tribeNewsCount % NUMBER_PER_PAGE) / NUMBER_PER_PAGE) ){		
 			if(alldata.page>0) rep +="<span class='separator'> </span>";
			rep += '<a href="javascript:fnFeed('+showtype+',' + (alldata.page + 1) + ',0)">下一页</a></div>';
		}else if (bAtHome==0){
 			if(alldata.page>0) rep +="<span class='separator'> </span>";
			rep += '<span  style="color: #999999; text-decoration:none">下一页</span></div>';			
		}
		rep +='</div>';
	}	
	if($("TribeNewsAllFeed"))
	  $("TribeNewsAllFeed").innerHTML = rep ;  
}catch(E){
	$('TribeNewsFeed').innerHTML =  "当你加入的群有新的帖子，这里会有提示";	
	}
}


//班级新鲜事
CampusInfo.buildClsInfo=function(type){	
try{
	if (!alldata.schoolclass){    		
		CampusInfo.NewsIsEmpty++;
		if($('clsNewsFeed')) $('clsNewsFeed').innerHTML ="当你的班级有新鲜事，这里会有提示";
		if( bAtHome && (alldata.count.classtc > 0)) {
			//更多		
			if($("clsNewsMore")) { 
				$("clsNewsMore").innerHTML = '<a href="/moreclsfanglelist.do">更多</a>' 
			}
		}
		if($('clsNewsFeedDiv')) $('clsNewsFeedDiv').style.display="none";
		return;
	}	
	if(alldata.schoolclass) {
		data = alldata.schoolclass;
	}	
	var pages = 0;
	if(showtype!=0) {pages=alldata.page;}
	var rep = "" ;
	rep += "<table class=\"rapidlist\">";
	for(var i = 0 ;i<data.length;i++){
		rep +="<tr class=\"unread\">" ;		
		if(data[i].type==2){
			rep +="<td class='name'><p><a class='author' href='"+myDomain+"/profile.do?id="+data[i].fromUserNo+"' target='_blank'>"+CampusUtils.resizeName(data[i].fromUserName)+"</a>	<span class='prefix'>"+data[i].prefix +"</span>" ;
			rep +=" </td><td class='title'><p><a href=\"http://class.xiaonei.com"+data[i].link+"\" " ;		
    } else if(data[i].type==8) {
			rep +="<td class='name'><p><a href=\"http://class.xiaonei.com" + data[i].link + "\"" + "target=\"_blank\">" + data[i].ownerName + "</a><span class='prefix'>"+data[i].prefix +"</span>" ;
			rep +=" </td><td class='title'><p><a href=\""+data[i].link+"\" " ;		
    } else {
			rep +="<td class='name'><p><a class='author' href='"+myDomain+"/profile.do?id="+data[i].fromUserNo+"' target='_blank'>"+CampusUtils.resizeName(data[i].fromUserName)+"</a>	<span class='prefix'>"+data[i].prefix +"</span>" ;
			rep +=" </td><td class='title'><p><a href=\""+data[i].link+"\" " ;		
    }
		rep +="target=\"_blank\">";
	 	rep += CampusUtils.resizeTitle(data[i].title)+"</a> ";
		if(data[i].type == 16) {
    	rep += "<img src='http://img.hi.mop.com/img/ico_blog.gif' />";
    } else if(data[i].type == 32) {
    	rep += "<img src='http://img.hi.mop.com/img/dispatch/xiangji.gif' />";
    }
		rep +="	"+data[i].sufix ;
		rep +="</p></td><td class=\"meta\"><p><span class=\"time\">" + today(data[i].createTime) + "</span></p></td>" ;
		rep +="</tr>";
	}
	rep += "</table>";
	var clsNewsCount;
	var total;
	
 	if(showtype==0) {
 		clsNewsCount= alldata.count.classc;
	} else {
 		clsNewsCount= alldata.count;
	}
 	if($("clsNewsCount")) $("clsNewsCount").innerHTML = "(" + clsNewsCount + ")";
	if(bAtHome) {
		total = alldata.count.classtc;	
	}
	if( bAtHome && (total > 0)) {
		//更多		
		if($("clsNewsMore")) { 
			$("clsNewsMore").innerHTML = '<a href="/moreclsfanglelist.do">更多</a>' 
		}
	}	
	
	if($("clsNewsFeed"))
    $("clsNewsFeed").innerHTML = rep ;   	
	
	if((!bAtHome) && (clsNewsCount > 1000)) {
		rep +='<div id="pNav">';
		if(alldata.page>0) {
 			rep +='<a href="javascript:fnFeed('+showtype+',' + (alldata.page - 1) + ',0)">上一页</a>';  
		}else if (bAtHome==0){
			rep +='<span  style="color: #999999; text-decoration:none">上一页</span>';
		}
		if(alldata.page < ((friendsNewsCount - friendsNewsCount % NUMBER_PER_PAGE) / NUMBER_PER_PAGE) ){		
 			if(alldata.page>0) rep +="<span class='separator'> </span>";
			rep += '<a href="javascript:fnFeed('+showtype+',' + (alldata.page + 1) + ',0)">下一页</a></div>';
		}else if (bAtHome==0){
 			if(alldata.page>0) rep +="<span class='separator'> </span>";
			rep += '<span  style="color: #999999; text-decoration:none">下一页</span></div>';			
		}
		rep +='</div>';
	}
	if($("ClsNewsAllFeed"))
	{		
		$("ClsNewsAllFeed").innerHTML = rep ;
	}
}catch(E){
	$('clsNewsFeed').innerHTML ="当你的班级有新鲜事，这里会有提示";
	}	
}

CampusInfo.readOneNew = function(type,no,atttype,sourceno,link,orgtype,unread){	
	if (type==1){
		isreadone1 = 'read';
	}
	if(unread){
		var cur, first;
		if($("fangle_curpage_hid")) {
			cur = $("fangle_curpage_hid").value ;
		} else {
			cur = 0; 	
		}
		if($("fangle_first_hid")) {
		 	first = 0 ;
		} else {
			first = 1;
		}
		var url="/dispatchreadone.do";
		var pars="type="+type+"&cur="+cur+"&isfrist="+first+"&dispatchNo="+no+"&atttype="+atttype+"&sourceno="+sourceno+"&ran="+Math.random() ;
	
		var myAjax = new Ajax.Request(
					url, 
					{
								method: 'get', 
								parameters: pars, 
								onComplete: getReplyList,
								onFailure: showError
					});
	}  
}

CampusInfo.readOne = function(type,no,atttype,sourceno,link,orgtype,unread){	
	if (type==1){
		isreadone1 = 'read';
	}
	if(unread){
		var cur, first;
		if($("fangle_curpage_hid")) {
			cur = $("fangle_curpage_hid").value ;
		} else {
			cur = 0; 	
		}
		if($("fangle_first_hid")) {
		 	first = 0 ;
		} else {
			first = 1;
		}
		var url="/dispatchreadone.do";
		var pars="type="+type+"&cur="+cur+"&isfrist="+first+"&dispatchNo="+no+"&atttype="+atttype+"&sourceno="+sourceno+"&ran="+Math.random() ;
		if (type == 1)
			doRead1(url,pars,orgtype);
		else if (type == 2)
			doRead2(url,pars,orgtype);
		else if (type == 3)
			doRead3(url,pars,orgtype);
		else
			doRead(url,pars,orgtype);
	}  
}
CampusInfo.readAll = function(){
	var url = '/dispatchreadall.do';
 	var pars = 'type=2'   
		 + '&t=' + myDate.getTime();
	var myAjax = new Ajax.Request(
				url, 
				{
							method: 'get', 
							parameters: pars, 
							onComplete: CampusInfo.readAllOK,
							onFailure: showError
				});

}
CampusInfo.readAllOK=function(){
	fnFeed(2,gCurPage,0);	
}

CampusInfo.readAllTribe = function(){
	var url = '/dispatchreadall.do';
 	var pars = 'type=3'   
		 + '&t=' + myDate.getTime();
	var myAjax = new Ajax.Request(
				url, 
				{
							method: 'get', 
							parameters: pars, 
							onComplete: CampusInfo.readAllTribeOK,
							onFailure: showError
				});

}
CampusInfo.readAllTribeOK=function(){
	fnFeed(3,gCurPage,0);	
}

function readSuccess(r){
	fnFeed(showtype,gCurPage,bAtHome);
}


function readSuccess1(r){
	fnFeed(1,gCurPage,bAtHome);
}

function readSuccess2(r){
	fnFeed(2,gCurPage,bAtHome);
}

function readSuccess3(r){
	fnFeed(3,gCurPage,bAtHome);
}

function doRead(url,pars,orgtype) {
	var tmpurl = url;
 	var tmppars =  pars;
	var myAjax = new Ajax.Request(
				tmpurl, 
				{
							method: 'get', 
							parameters: tmppars, 
							onComplete: readSuccess,
							onFailure: showError
				});
}

function doRead1(url,pars,orgtype) {
	var tmpurl = url;
 	var tmppars =  pars;
	var myAjax = new Ajax.Request(
				tmpurl, 
				{
							method: 'get', 
							parameters: tmppars, 
							onComplete: readSuccess1,
							onFailure: showError
				});
}

function doRead2(url,pars,orgtype) {
	var tmpurl = url;
 	var tmppars =  pars;
	var myAjax = new Ajax.Request(
				tmpurl, 
				{
							method: 'get', 
							parameters: tmppars, 
							onComplete: readSuccess2,
							onFailure: showError
				});
}

function doRead3(url,pars,orgtype) {
	var tmpurl = url;
 	var tmppars =  pars;
	var myAjax = new Ajax.Request(
				tmpurl, 
				{
							method: 'get', 
							parameters: tmppars, 
							onComplete: readSuccess3,
							onFailure: showError
				});
}

domainImg = "img.hi.mop.com";
domainStatic = "img.hi.mop.com";
domainGroup = "";
myDomain = "http://hi.mop.com";
var CampusUtils = new Object();
CampusUtils.iconRep=[    {atype:1,ln:"http://"+domainStatic+"/img/dispatch/icon04.gif"},
	                     {atype:2,ln:"http://"+domainStatic+"/img/dispatch/icon05.gif"},
	                     {atype:4,ln:"http://"+domainStatic+"/img/dispatch/icon05.gif"},
	                     {atype:8,ln:"http://"+domainStatic+"/img/dispatch/icon02.gif"},
	                     {atype:16,ln:"http://"+domainStatic+"/img/dispatch/icon06.gif"},
	                     {atype:32,ln:"http://"+domainStatic+"/img/dispatch/icon04.gif"},
	                     {atype:64,ln:"http://"+domainStatic+"/img/dispatch/icon05.gif"},
	                     {atype:128,ln:"http://"+domainStatic+"/img/dispatch/icon05.gif"},
	                     {atype:256,ln:"http://"+domainStatic+"/img/dispatch/icon02.gif"},
	                     {atype:512,ln:"http://"+domainStatic+"/img/dispatch/icon06.gif"}];

CampusUtils.iconFangle=[ {atype:1,ln:"http://"+domainStatic+"/img/dispatch/icon06.gif"},
	                     {atype:2,ln:"http://"+domainStatic+"/img/dispatch/icon04.gif"},
	                     {atype:4,ln:"http://"+domainStatic+"/img/dispatch/icon05.gif"},
	                     {atype:8,ln:"http://"+domainStatic+"/img/dispatch/icon01.gif"},
	                     {atype:16,ln:"http://"+domainStatic+"/img/dispatch/xiangji.gif"},
	                     {atype:32,ln:"http://"+domainStatic+"/img/dispatch/icon04.gif"},
	                     {atype:64,ln:"http://"+domainStatic+"/img/dispatch/icon06.gif"},
	                     {atype:128,ln:"http://"+domainStatic+"/img/dispatch/icon02.gif"},
	                     {atype:256,ln:"http://"+domainStatic+"/img/dispatch/icon02.gif"},
	                     {atype:512,ln:"http://"+domainStatic+"/img/dispatch/icon05.gif"}];

CampusUtils.iconGroup=[  {atype:1,ln:"http://"+domainStatic+"/img/dispatch/icon02.gif"},
	                     {atype:2,ln:"http://"+domainStatic+"/img/dispatch/icon05.gif"},
	                     {atype:4,ln:"http://"+domainStatic+"/img/dispatch/icon02.gif"},
	                     {atype:8,ln:"http://"+domainStatic+"/img/dispatch/icon05.gif"}];
CampusUtils.getIcon= function(type,atttype){
   var icons = null ;
   if(type ==1)
       icons = CampusUtils.iconRep ;
   else if(type ==2){
   	   icons = CampusUtils.iconFangle ;
   }else
   	   icons = CampusUtils.iconGroup ;

   if(icons==null)
       return "http://"+domainImg+"/images/ico_talk.gif" ;
   for(var i = 0 ;i<icons.length;i++){
       if(Math.abs(icons[i].atype)==Math.abs(atttype))
          return icons[i].ln ;
  }
  return "http://"+domainImg+"/images/ico_talk.gif" ;
}
CampusUtils.resizeName = function (name, limit){
	return CampusUtils.substring(name,7,null); //原来显示3，修改为7个汉字  yuxinyi
	
}
CampusUtils.resizeTitle = function (title, limit){

   try{
    if(title==null||title=="")
        //return "无标题" ;        
        return "去看看" ;
	return title;
	// bell(2009-4-14): 这种缩减方式可能造成html标签被中断，危害太大了
    // return CampusUtils.substring(title,16,null) ;
   }catch(e){
   	//return "无标题" ; 	
   	return "去看看" ;        
   }
}
CampusUtils.resizeTitle2 = function (title){
    if(title==null)
        return "" ;
    return CampusUtils.substring(title,15,null);
}
CampusUtils.substring = function(str, len, postfix) {
	var res = "";
	var p = 0;
	for (var i=0; i<str.length; i++) {
		var ch = str.charAt(i);
		if (ch > '!' && ch < '~') {
			p += 1;
		} else {
			p += 2;
		}
		if (p <= len*2) {
			res += ch;
		}
	}
	if (p > len*2) {
		if (postfix != null)
			res += postfix;
		else
			res += "...";
	}
	return res;
}
CampusUtils.shortString = function (str){
	document.write(str.substring(0,5));
}
CampusUtils.readCookie=function(name){
	var cookieValue = '';
	var search = name + '=';
	  if(document.cookie.length > 0){
	    offset = document.cookie.indexOf(search);
	    if (offset != -1){
	      offset += search.length;
	      end = document.cookie.indexOf(';', offset);
	      if (end == -1) end = document.cookie.length;
	      cookieValue = unescape(document.cookie.substring(offset, end))
	    }
	  }
	  return cookieValue;
}
CampusUtils.writeCookie=function(name, value, hours){
	var expires = new Date((new Date()).getTime() + hours * 3600000);
	document.cookie = name + "=" + escape (value) +	((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
}

function GetCookieVal (offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value)
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

CampusUtils.show = function(div, _url){
	Request.sendGET(_url, CampusUtils.process, div) ;
}
CampusUtils.process = function(req, div){
	if (req!=null && req.responseText!=""){
		$(div).innerHTML = req.responseText;
	}else{
		$(div).outerHTML = "";
	}
}
CampusUtils.firstLogon=function(){
	if (""==CampusUtils.readCookie("CampusInfo_firstLogon")){
		CampusUtils.writeCookie("CampusInfo_firstLogon","hascheckd", 6)
		return true;
	}else{
		return false;
	}
}

var FloatPhoto = new Object();
FloatPhoto.imageover;
FloatPhoto.overImage=function(e,imgurl, v, ttime){
	if (!e) var e = window.event;
        var ot = e.clientY+document.documentElement.scrollTop-v.offsetWidth;
        var ol = e.clientX;        
        FloatPhoto.imageover= window.setTimeout("FloatPhoto.viewFloatPhoto('"+imgurl+"',"+ol+","+ot+")",ttime);
}
FloatPhoto.outImage=function(){
        FloatPhoto.viewFloatPhoto();
        if (FloatPhoto.imageover){
                window.clearTimeout(FloatPhoto.imageover);
        }
}
FloatPhoto.viewFloatPhoto=function(imgurl,ol,ot){
	if ($('floatphoto')==null){
		var t = document.createElement("div");
		t.id='floatphoto';
		t.style.position = 'absolute';
		t.style.border = 'thin';
		t.style.width = '75px';
		t.style.height = '75px';
		t.style.zIndex = 9;
		document.body.appendChild(t);
	}
        if (imgurl){
                $('floatphoto').style.left=ol+"px";
                $('floatphoto').style.top=ot+"px";
//                        left = ol;
//                        top = ot;
                $("floatphoto").style.background="url("+imgurl+") center center no-repeat";
                $('floatphoto').style.display = "block";
        }else{
                $('floatphoto').style.display = "none";
        }
}

function findElement(parentEl,id,type) {
	var tempEl;
	tempEl = document.createElement(type);	
	tempEl.id = id;
	tempEl.className = id + "_css";
	parentEl.appendChild(tempEl);
 	return tempEl;
}

function today(dt) {
	var result = dt;

	var nnn = new Date();
	var nmm = nnn.getMonth() + 1;
	var ndd = nnn.getDate();
	if(nmm < 10) nmm = "0" + nmm;
	if(ndd < 10) ndd = "0" + ndd;

	var dmm = dt.substring(0, 2);
	var ddd = dt.substring(3, 5);
	
	if(nmm == dmm && ndd == ddd) {
		result = dt.substring(6);
	} else {
		result = dt.substring(0, 6);
	}
	return result;
}
