// JavaScript Document
var DATA_SEPARATOR_FOR_MT="========\t\t\t=========";
var ZH_CN="zh_cn"
var g_oldTime = "-1";
/* var g_strDataType = "all"; */
var g_nClickTimes = 0;
var g_IsNewsRunning = false;
var g_IsMsgRunning = false;
var g_nMsgMoreCount=0//。
var g_arrayMsg = new Array(); 
var g_getMoreHtml= "";//私信列表的查看更多
var g_strMemberId = "";
var g_strSendContent = "";
//var g_strRefreshType = "numRefresh"; //为了区分大刷新，小刷新，查看更多的刷新
var g_strMsgRefreshType = "msg";
var g_strPageNum = "1";
var g_intervalCount=0;

//界面初始化
$(document).ready(function(){
    
	g_nClickTimes = 0;
	//g_strRefreshType = "zeroRefresh";
	//F5时进行数据刷新
    //判断是否登录才决定要不要刷新
  	if(document.getElementById("hdx_notlogin"))
	{
		$(".shuaxin").hide();//未登录刷新按钮隐藏
	}
	else
	{ 
		$("#all").find(".big").show();
		g_oldTime = "-1";
		$("#all").find(".shuaxin").hide();
		excuteAction("refresh","all");
		//循环查询私信数据是否刷新完，刷新完则把最近联系人刷一遍
		//QueryIsRunning();
        	//获取我的圈子
		$(".groups_loading").show();
		QueryAppIsRunning();
		g_strMemberId = "";
		excuteMsgAction("refreshmsg");
				
	}
	
	jQuery(window).resize(function(){
		fixReplyBox();
	});
	
	jQuery(window).scroll(function(){
	    fixReplyBox();
	})
	

 	window.onload = function(){
            document.onclick = function(e){
                e = e || window.event;
                var dom =  e.srcElement|| e.target;
                if(dom.id == "reply-default") {
						$("#reply-default").hide(); 
						document.getElementById('msg_letter_replay').value="";
						$("#msg_letter_replay").focus();
						
                }
				var strVal = $("#msg_letter_replay").val() +"";
                if(dom.id != "reply-default" && dom.id != "msg_letter_replay" && strVal == "") {

					$("#reply-default").show(); 
                }				
	
                
            };
        }; 

});

function showContactDetail(node)
{
    $node = $(node);
	$node.parent().find(".tooltip").show();
}


function fixReplyBox()
{
    if($(".replayletter").length <= 0)
	{
	    return;
	}

  
	if($(window).height() - $("#letter_box").height() - $(".replayletter").height() > 181)
	{
	   $("#letter_box").css("margin-bottom","0px");
	   $("#letter_box").css("border-bottom","0px");
	   $(".replayletter").css("position","static");	  	   
	   
	   return;	   
	}
	else
	{
		$("#letter_box").css("margin-bottom","130px");
	    var iLeftBottom = $(document).height() -$(document).scrollTop()-$(window).height();
		//一屏显示不完并且私信列表底部到页面底部宽度大于回复框的高度时，直接将回复框接到私信列表后
		var iVal = $(window).height() - (119+$("#letter_box").height()-$(document).scrollTop());
		var iReplyLetterHeight =  $(".replayletter").height();
		
	    $(".replayletter").removeClass("fixed0");
		$(".replayletter").removeClass("fixed40");
		
		 if(iVal >= iReplyLetterHeight )
		 {
			 $("#letter_box").css("margin-bottom","0px");
			 $("#letter_box").css("border-bottom","0px");
		 }
		 else if(iLeftBottom < 40)
		{
			$(".replayletter").addClass("fixed40");
		}
		else
		{
		   $(".replayletter").addClass("fixed0");
		}
		
		
	
	}
 
	

}

function hideContactDetail(node)
{

    $node = $(node);
	$node.parent().find(".tooltip").hide();
}


function NaviShow(obj,strType)
{
   // g_strDataType = strType;
	g_oldTime = "-2";
	g_nClickTimes = 0;
	g_arrayMsg.splice(0,g_arrayMsg.length);
	g_nMsgMoreCount = 0;
	
	$(obj).children("a").addClass("current");
	$(obj).siblings().children("a").removeClass("current");
	
	$(".all_refresh").hide();	
	$(".all_refresh_failed").hide();
	$(".big").hide();	
	$(".big_failed").hide();
	$(".shuaxin").hide();
     
	if(strType == "msg")
	{
	   // 切换导航私信和全部动态分开
	   g_strMsgRefreshType = "msg";
		excuteMsgAction(strType);
	}
	else
	{
		excuteAction(strType,strType);
	}
	

	
	var strMiddleType = "#" + strType;
	$(strMiddleType).css("display","block");
	$(strMiddleType).siblings().css("display","none");
}
function excuteMsgAction(strAction)
{

	$.ajax(
	{
	    async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,
		data:{
			action:strAction,
			timestamp:g_oldTime,
			clicktimes:g_nClickTimes,
 			memberid:g_strMemberId, 
			sendcontent:g_strSendContent
			//msgrefreshtype:g_strMsgRefreshType
			},
		success: function(data)
		{	
			if(data == "notlogin")
			{
				return;
			}		
			else if(strAction == "more_msgletter")
			{
				$("#msg_box").html(data);
			}	
			else if(strAction == "msg")
			{
				showMsg(data);
			}
			else if(strAction == "sendletter")
			{
				var eleLetterBox = document.getElementById("letter_box");
				var newNode = document.createElement("div");
				if(window.navigator.userAgent.indexOf("MSIE")>=1)
				{
					newNode.setAttribute("className", "chat");  //for IE
				}
				else
				{
					newNode.setAttribute("class", "chat");
				}
				//newNode.innerHTML =" This is a newcon ";
				newNode.innerHTML =data;
				eleLetterBox.appendChild(newNode);
				var lastLength;
				if(ZH_CN ==g_language)
				{
					lastLength = "<span class=\"lastwordnum_zh\">";
				}
				else
				{
					lastLength = "<span class=\"lastwordnum_en\">";
				}
				lastLength = lastLength + "200";
				lastLength += "</span>";
				var lastLengthHtml = g_letterLengthOver.replaceAll("{0}", lastLength);
				$(".repay_letter_word").html(lastLengthHtml);
				document.getElementsByTagName('BODY')[0].scrollTop=document.getElementsByTagName('BODY')[0].scrollHeight;
				//发送完私信之后把滚动条拉倒最低端，以看到最新发送的私信DTS2014041705614		
				var sh = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);//考虑滚动的情况
				window.scrollTo(0,sh);
			}
			else if(strAction == "refreshmsg")
			{
				excuteMsgAction("refreshmsgresult")
			}
			else if(strAction == "refreshmsgresult")
			{
				refreshMsgResult(data);
			}
			else if(strAction == "tolookletter")
			{
				var arrayData =  data.split(DATA_SEPARATOR_FOR_MT);
				$("#msg_box").html(arrayData[1]);	
				fixReplyBox();
				var sh=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);
				window.scrollTo(0,sh); 
			}		
			
        }
	});	
}
function excuteAction(strAction,strDataType)
{

	$.ajax(
	{
	    async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,
		data:{
			action:strAction,
			timestamp:g_oldTime,
			datatype:strDataType,
			clicktimes:g_nClickTimes,
			sendcontent:g_strSendContent,
			pageNum:g_strPageNum
			},
		success: function(data)
		{	
			var strTypeObj = strDataType + "_box";
			strTypeObj = "#" + strTypeObj;

			if(data == "notlogin")
			{
				return;
			}		
			else if(strAction == "more_history")
			{
				MoreResult(strDataType,data);
			}
			else if(strAction == "refresh")
			{
				RefreshResult(strDataType,data);
			}
			else  //导航
			{
			   			    
				NaviResult(strDataType,data);
			} 			
			
        }
	});	
}

function RefreshResult(strDataType,data)
{
	var strTypeObj = "#" + strDataType;
	var strBoxObj = strTypeObj + "_box";
	var arrayData =  data.split(DATA_SEPARATOR_FOR_MT);
		
	if(arrayData[0] == "refresh_succ")
	{
		$(strTypeObj).find(".all_refresh").hide();
		$(strTypeObj).find(".big").hide();
		$(strTypeObj).find(".big_failed").hide();
		$(strTypeObj).find(".all_refresh_failed").hide();
		$(strTypeObj).find(".shuaxin").show(); 
		$(strBoxObj).show();
		$(strBoxObj).html(arrayData[1]);

/* 		$(".textcontent").find("img").each(function(i){
			if($(this).width() > 118)
			{
			   $(this).addClass("taboild");
			}
			
		}); */
		//显示查看更多
		$(strBoxObj).find(".loading").show();
		//如果刷新失败和刷新中都不进行倒计时
		//countdownSupport(data);		
	}
	else if(arrayData[0] == "refresh_failed")
	{	
		$(strTypeObj).find(".all_refresh").hide();
		$(strTypeObj).find(".big").hide();
		$(strTypeObj).find(".shuaxin").show(); 		
        if($(strBoxObj).children(".box").length < 1)//大失败
		{	
			$(strBoxObj).hide();
			$(strTypeObj).find(".all_refresh_failed").hide();
			$(strTypeObj).find(".big_failed").show();
		}
		else //小失败
		{	
			$(strBoxObj).show();
			$(strTypeObj).find(".big_failed").hide();
			$(strTypeObj).find(".all_refresh_failed").show();
			//显示查看更多
			$(strBoxObj).find(".loading").show();		
		}
	    
	}
	else 
	{
	    //继续刷，直到问到刷新完成为止
/* 		setTimeout(function(){
			refresh();
		},500); */
		var queryFunc = setTimeoutRefresh(strDataType);
		queryFunc();
	}

	
}
function MoreResult(strDataType,data)
{
	if(data=="more_failed")
	{
		$(".more_refresh").hide();
		$(".more_refresh_failed").show();
		$(".loading").show();
		//按钮的名改成“重新试一试”
		$(".more_text").text(more_try);
	}
	else
	{
		var strTypeObj = "#" + strDataType;
		if($(strTypeObj).is(":visible"))
		{
		    //查看更多成功了，且返回数据时当前type还未切到其他时，点击次数加1，如果当前已经隐藏，则不需要+1
			g_nClickTimes += 1; 
		}
		var strBoxObj = strTypeObj + "_box";
		$(".more_refresh_failed").remove();
		$(".more_refresh").remove();
		$(".loading").remove();
		//筛选时有可能有哭页面
		$(strTypeObj).find(".box_empty").remove();
		$(strBoxObj).append(data);

	}

}



function NaviResult(strDataType,data)
{
	var strTypeObj = "#" + strDataType;
	var strBoxObj = strTypeObj + "_box";
	var arrayData =  data.split(DATA_SEPARATOR_FOR_MT);
	if(arrayData[0] == "not_login")
	{
		$(strTypeObj).find(".shuaxin").hide()
		$(strBoxObj).html(arrayData[1]);		
	}	
	else if(arrayData[0] == "refresh_succ")
	{
		$(strTypeObj).find(".shuaxin").show(); 
	    //如果刷新成功，要把所有刷新中和失败隐藏；
		$(strTypeObj).find(".all_refresh").hide();
		$(strTypeObj).find(".big").hide();
		$(strTypeObj).find(".all_refresh_failed").hide();
		$(strTypeObj).find(".big_failed").hide();		
	
		$(strBoxObj).show();
		$(strBoxObj).html(arrayData[1]);

		//显示查看更多
		$(strBoxObj).find(".loading").show();
		//如果刷新失败和刷新中都不进行倒计时
		//countdownSupport(data);
	
	}
	else if(arrayData[0] == "refresh_failed")
	{
		$(strTypeObj).find(".shuaxin").show(); 
		$(strTypeObj).find(".all_refresh").hide();
		$(strTypeObj).find(".big").hide();
		
		if(data.indexOf("box_empty") > -1)//大失败
		{	
			$(strBoxObj).hide();
			$(strTypeObj).find(".all_refresh_failed").hide();
			$(strTypeObj).find(".big_failed").show();
		}
		else //小失败
		{
			$(strBoxObj).show();
			$(strTypeObj).find(".big_failed").hide();
			$(strTypeObj).find(".all_refresh_failed").show();
			$(strBoxObj).html(arrayData[1]);
			//显示查看更多
			$(strBoxObj).find(".loading").show();
		}
	    
	}
	else if(arrayData[0] == "refreshing")
	{
	
		//只隐藏自己模块的刷新
		
		$(strTypeObj).find(".shuaxin").hide();
		$(strTypeObj).find(".all_refresh_failed").hide();
		$(strTypeObj).find(".big_failed").hide();
		
		if(data.indexOf("box_empty") > -1)//大刷新
		{	
			$(strBoxObj).hide();
			$(strTypeObj).find(".all_refresh").hide();
			$(strTypeObj).find(".big").show();
		}
		else //小刷新
		{
			$(strTypeObj).find(".all_refresh").show();
			$(strBoxObj).show();
			$(strTypeObj).find(".big").hide();			
			$(strBoxObj).html(arrayData[1]);
		}
		//隐藏查看更多
		$(strBoxObj).find(".loading").hide();
		//还在刷新中的时候再发一次请求，相当于手动点了一下刷新，直到问到刷新完成
		
		var queryFunc = setTimeoutRefresh(strDataType);
		queryFunc();
	
		
	
	}
	
	//DTS2014041604652 
/* 	$(".textcontent").find("img").each(function(i){
		if($(this).width() > 118)
		{
			$(this).addClass("taboild");
		}

	}); */
	
		
}


function setTimeoutRefresh(strDataType)
{
    var m_strDataType = strDataType;
	
	function query()
	{
	    setTimeout(function(){
			excuteAction("refresh",m_strDataType);
		},500);	
	}
	
	return query;


}

/*
//倒计时跳转到support
function countdownSupport(data)
{
    clearInterval(g_intervalCount);
	
	g_intervalCount = setInterval(function(){
	    var iTimeCount = $(".countdowntime").html();
		iTimeCount--;
		if(iTimeCount > 0)
		{
		   $(".countdowntime").html(iTimeCount);		
		}
		else
		{
			clearInterval(g_intervalCount);
		}	
	},1000);
   
	if(data.indexOf("redirectToSup") > -1)
	{
		setTimeout(function(){
			var strDestUrl =  $(".redirectToSup").attr("redirectsrc");
			strDestUrl = "/loginSupport.cgi?action=AutoLogin&url=" + handlerSpecialCharsWithDoubleEscape(strDestUrl) + "&cgiType=GroupSpace&fun=onlineView";
			window.location.href=strDestUrl;
		 },3000);	
	} 
}
*/
function showMsg(data)
{
	var strTypeObj = "#msg";
	var strBoxObj = "#msg_box";
	var arrayData =  data.split(DATA_SEPARATOR_FOR_MT);
	$(strBoxObj).show();
	if(arrayData[0] == "not_login")
	{
		$(strTypeObj).find(".shuaxin").hide();
		$(strBoxObj).html(arrayData[1]);		
	}	
	else if(arrayData[0] == "true")
	{
		$(strTypeObj).find(".all_refresh").hide();
		$(strTypeObj).find(".big").hide();
		$(strTypeObj).find(".big_failed").hide();
		$(strTypeObj).find(".all_refresh_failed").hide();

		$(strTypeObj).find(".shuaxin").show();
		getMsgArray(arrayData[1]);
		displayMsgList(strBoxObj);
		//切导航时不需要替换最近联系人
		//$(".contacts_box").html(arrayData[3]);
	}
	else if(arrayData[0] == "false")
	{
		$(strTypeObj).find(".all_refresh").hide();
		$(strTypeObj).find(".big").hide();
		$(strTypeObj).find(".shuaxin").show();
		if(data.indexOf("box_empty") > -1)//大失败
		{	
			$(strBoxObj).hide();
			$(strTypeObj).find(".all_refresh_failed").hide();
			$(strTypeObj).find(".big_failed").show();
		}
		else //小失败
		{	
			$(strBoxObj).show();
			$(strTypeObj).find(".big_failed").hide();
			$(strTypeObj).find(".all_refresh_failed").show();
			//显示查看更多
			$(strBoxObj).find(".loading").show();
			getMsgArray(arrayData[1]);
			displayMsgList(strBoxObj);			
		}
	}
	else if(arrayData[0] == "refreshing")
	{
		$(strTypeObj).find(".shuaxin").hide();
		if(data.indexOf("box_empty") > -1)//大刷新
		{	
			$(strBoxObj).hide();
			$(strTypeObj).find(".all_refresh").hide();
			$(strTypeObj).find(".big").show();
		}
		else //小刷新
		{
			$(strBoxObj).show();
			$(strTypeObj).find(".all_refresh").show();
			$(strTypeObj).find(".big").hide();			
			getMsgArray(arrayData[1]);
			displayMsgList(strBoxObj);	
		}
		//setTimeout(excuteMsgAction("refreshmsgresult"),500);
		setTimeout(RefreshMsgResult,500);
	} 
}

function refreshMsgResult(data)
{
	var strTypeObj = "#msg";
	var strBoxObj = "#msg_box";
	var arrayData =  data.split(DATA_SEPARATOR_FOR_MT);
	if(arrayData[0] == "true")
	{
		$(strTypeObj).find(".all_refresh").hide();
		$(strTypeObj).find(".big").hide();
		$(strTypeObj).find(".big_failed").hide();
		$(strTypeObj).find(".shuaxin").show();
		$(strTypeObj).find(".all_refresh_failed").hide();
		$(strBoxObj).show();
		//$(strBoxObj).html(arrayData[1]);
		
		if(g_strMsgRefreshType == "msg")
		{
			getMsgArray(arrayData[1]);
			displayMsgList(strBoxObj);
		}
		else if(g_strMsgRefreshType == "letter")
		{
			//这种情况会在起来之后调起来刷新功能，这个时候g_strMemberId为空，
			//这个时候就没必要再去查了，通常正常的调用起来的刷新功能memberID都是存在，memberid不存在的时候就没必要去拼网页了
			if(arrayData[2] != "")
			{
				$(strBoxObj).html(arrayData[2]);
			}
		}

		$(".contacts_box").html(arrayData[3]);
	}
	else if(arrayData[0] == "false")
	{
		$(strTypeObj).find(".all_refresh").hide();
		$(strTypeObj).find(".big").hide();
		$(strTypeObj).find(".shuaxin").show();
        if($(strBoxObj).find(".box").length < 1)//大失败
		{	
			$(strBoxObj).hide();
			$(strTypeObj).find(".all_refresh_failed").hide();
			$(strTypeObj).find(".big_failed").show();
		}
		else //小失败
		{	
			$(strBoxObj).show();
			$(strTypeObj).find(".big_failed").hide();
			$(strTypeObj).find(".all_refresh_failed").show();
			//显示查看更多
			getMsgArray(arrayData[1]);
			displayMsgList(strBoxObj);
			//$(strBoxObj).find(".loading").show();		000000000000000000
		}
	}
	else if(arrayData[0] == "refreshing")
	{
		//setTimeout(excuteMsgAction("refreshmsgresult"),500);
		setTimeout(RefreshMsgResult,500);
	} 
}

function RefreshMsgResult()
{
	excuteMsgAction("refreshmsgresult");
}
//从服务器获取数据失败的提示
/* function getFailed(strDataType)
{
	var strTypeObj = "#" + strDataType;
	$(strTypeObj).find(".big").hide(); 
	$(strTypeObj).find(".all_refresh").hide();
	$(".more_refresh").hide();
	$(strTypeObj).find(".shuaxin").show();
	
    //如果是大刷新
	if(g_strRefreshType == "zeroRefresh")
	{	
	    $(strTypeObj).find(".big_failed").show();
	}
	//有数据时的全部刷新
	else if(g_strRefreshType == "numRefresh")
	{
		
		$(strTypeObj).find(".all_refresh_failed").show();
	}
	//查看历史记录的刷新
	else
	{	
		$(".more_refresh_failed").show();
		$(".loading").show();
		//按钮的名改成“重新试一试”
		$(".more_text").text(more_try);
	}
	
} */
/*
获取前台展示的私信列表。
所有的数据已经返回，只展示前三十条数据其他数据隐藏。
*/
function getMsgArray(msg)
{
	var tmp = msg.split("===<>===");	
	g_getMoreHtml = tmp[tmp.length - 1];
	var temArrayMeb="";
	for(var i=0; i<(tmp.length-1); i++)
	{
		if(i == 0)
		{
			temArrayMeb = "<div class=Msg_"+g_nMsgMoreCount;
			temArrayMeb+=" style=\"display:block;\">";
		}
		else if(i%30 == 0 && i != 0)
		{
			temArrayMeb += "</div>";
			g_arrayMsg[g_nMsgMoreCount] = temArrayMeb;
			g_nMsgMoreCount += 1;
			temArrayMeb  = "<div class=Msg_"+g_nMsgMoreCount;
			temArrayMeb += " style=\"display:block;\">";
		}
		
		temArrayMeb += tmp[i];
		
		//-2是因为下标是从0开始 而数组的最后一个不是私信而是查看更多所以要排除
		if(i == (tmp.length-2))
		{
			temArrayMeb += "</div>";
			g_arrayMsg[g_nMsgMoreCount] = temArrayMeb;
		}
	}
	
}

/*
要显示的私信列表。
*/
function displayMsgList(strBoxObj)
{
	$(strBoxObj).show();
	if(g_nClickTimes > g_nMsgMoreCount)
	{
		return;
	}
	
	var displaydata = "";
	for(var i = 0; i <= g_nClickTimes; i++)
	{
		if(g_arrayMsg.length != 0)
		{
			displaydata += g_arrayMsg[i];
		}
	}
	
	displaydata += g_getMoreHtml;
	$(strBoxObj).html(displaydata);
	
	if(g_nClickTimes == g_nMsgMoreCount)
	{
		$(".msg_loading").css("display","none");
	}
	else
	{
		$(".msg_loading").css("display","block");
	}
}

/*
私信列表中，查看更多。
*/
function getMsgMore()
{
	g_nClickTimes += 1; 
	displayMsgList("#msg_box");
}
/*
私信对话中，查看更多。
*/
function getLetterMore()
{
	g_nClickTimes += 1; 
	excuteMsgAction("more_msgletter");
}
function openSupportUrl(strOpenUrl)
{
	var strDestUrl =  "";
	strDestUrl = "/loginSupport.cgi?action=AutoLogin&url=" + handlerSpecialCharsWithDoubleEscape(strOpenUrl) + "&cgiType=GroupSpace&fun=onlineView";
	window.open(strDestUrl); 
}
//字符串转码，用于url的前后台传递*/
function handlerSpecialCharsWithDoubleEscape(value)
{
	value =escape(escape(value));
	value=value.replaceAll("+", "%2B");
	value=value.replaceAll("@", "%40");
	return value;
}

//字符串替换
function ReadMore(strTimestamp)
{
	//g_strRefreshType = "moreRefresh";
	g_oldTime = strTimestamp;
	$(".loading").hide();
	$(".more_refresh_failed").hide();
	$(".more_refresh").css("display","block");
	//查找当前显示的type
	var strDataType = $(".Middle").children(":visible").attr("id");
	excuteAction("more_history",strDataType);   
}

function toSupport(strUrl)
{
 	//g_nClickTimes += 1; 
	openSupportUrl(strUrl);  
	//ReadMore("111","this");
	
}

function refreshMsg()
{
	var strTypeObj = "#msg";
	var strBoxObj = strTypeObj + "_box";
	$(strTypeObj).find(".shuaxin").hide();
	$(strTypeObj).find(".all_refresh_failed").hide();
	$(strTypeObj).find(".big_failed").hide();
	if($(strBoxObj).find(".box").length < 1)
	{	
		$(strBoxObj).hide();
		$(strBoxObj).find(".box_empty").remove();		
	    $(strTypeObj).find(".all_refresh").hide();
		$(strTypeObj).find(".big").show();
	}
	else //小刷新
	{
		$(strTypeObj).find(".big").hide();
		$(strTypeObj).find(".all_refresh").show();
	}
	
	g_nClickTimes = 0;
	excuteMsgAction("refreshmsg");	
}

function refresh()
{
	var strDataType = $(".Middle").children(":visible").attr("id");	
	var strTypeObj = "#" + strDataType;
	//只隐藏自己模块的刷新
	$(strTypeObj).find(".shuaxin").hide();
	$(strTypeObj).find(".all_refresh_failed").hide();
	$(strTypeObj).find(".big_failed").hide(); 
	var strBoxObj = strTypeObj + "_box";
	//隐藏查看更多
	$(strBoxObj).find(".loading").hide();
	//大刷新
	if($(strBoxObj).children(".box").length < 1)
	{	
		$(strBoxObj).hide();
		$(strBoxObj).find(".box_empty").remove();		
	    $(strTypeObj).find(".all_refresh").hide();
		$(strTypeObj).find(".big").show();
	}
	else //小刷新
	{
		$(strTypeObj).find(".big").hide();
		$(strTypeObj).find(".all_refresh").show();
	}
	
	g_oldTime = "-1";

	excuteAction("refresh",strDataType);
	
	
	
}


/*
私信列表中，去看看按钮响应。
*/
function toLookLetter(strMemberId)
{
	//g_strDataType = "msg";
	g_nClickTimes = 0;
	g_strMsgRefreshType = "letter";
	g_strMemberId = strMemberId;
	//g_strMemberId = $(obj).parent().parent().parent().attr("memberid");
	excuteMsgAction("tolookletter");
}

/*
全部动态中，点击私信去看看响应。
*/
function msg_toletter(strId)
{  
    //先隐藏，如果是从弹出层查看私信的话
	//closeDlg();
	$("#msg").find(".all_refresh").hide();	
	$("#msg").find(".all_refresh_failed").hide();
	$("#msg").find(".big").hide();	
	$("#msg").find(".big_failed").hide();
	g_strMsgRefreshType = "letter";
	g_nClickTimes = 0;
	//g_strDataType = "msg";
	g_strMemberId = strId;
	var strMiddleType = "#msg";
	$(strMiddleType).css("display","block");
	$(strMiddleType).siblings().css("display","none");
	excuteMsgAction("tolookletter");
	//查看私信的时候“私信动态”要高亮。
	$("#navi_msg").children("a").addClass("current");
	$("#navi_msg").siblings().children("a").removeClass("current");
}

function opendowntopic(strTopicId)
{
	
	$.ajax({
	    async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,
		data:{
			action:"opendowntopic",	
			topicId:strTopicId
			},
		success: function(data)
		{	
			if(data == "open_failed")
			{
				var dlObj = "#dl_" + strTopicId;
				$(dlObj).remove();
				if($("ul.listDl>li").length < 1)
				{
				    $(".dl_more").hide();
					$(".listDl").remove(); 
					$(".download").append(strnofile);
					
				} 
				
			}

        }
	});		
	
}
function openGroupSpace(strGroupId, strDocId)
{
    var strOpenUrl = "/GroupSpace.cgi?groupId="+strGroupId+"&topicId=" + strDocId +"&isAutoRefresh=true"
    window.open(strOpenUrl);

}

function showLastWord(obj)
{
	var tem = obj.value;
	var intro = obj.innerHTML.replace(/^\s+|\s+$/g,"");
	if(tem.length > 200)
	{
		obj.innerHTML = intro.substr(0,200);
	}
	
	var lastLength = 200 - tem.length;
	if(lastLength < 0)
	{
		lastLength = 0;
	}
	
	var lastLengthSpan;
	if(ZH_CN ==g_language)
	{
		lastLengthSpan = "<span class=\"lastwordnum_zh\">";
	}
	else
	{
		lastLengthSpan = "<span class=\"lastwordnum_en\">";
	}
				
	lastLengthSpan = lastLengthSpan + lastLength;

	lastLengthSpan += "</span>";
	var lastLengthHtml = g_letterLengthOver.replaceAll("{0}", lastLengthSpan);
	$(".repay_letter_word").html(lastLengthHtml);
}

function showReplayValue(obj,type){ 
	var tem = obj.value;
	tem = $.trim(tem);
    if(type)
	{ 
		if(tem=="")
		{
			 $("#reply-default").hide(); 
		}
		$("#msg_letter_replay").css("color","#333333");			
    }
	else
	{ 
		if(tem=="") 
		{
			if($("#msg_letter_replay").html() == "" )
			{
				$("#reply-default").show(); 
			}
			
		}
    } 
} 
function replayLetter(obj)
{
	var tem =document.getElementById('msg_letter_replay').value;
	tem = $.trim(tem);
	if(tem == g_letterReplay || tem == "")
	{
		alert(g_letterReplayEmpty);
		return;
	}
	
	g_strSendContent = tem;
	excuteMsgAction("sendletter");
	
	//发送完成之后
	//$("#msg_letter_replay").css("color","#b9b9b9");
	document.getElementById('msg_letter_replay').value="";

	$("#reply-default").show(); 
	//var strDefault = "<span id='reply-default'>" + g_letterReplay + "</span>"
	//$(".hdx_Answer").append(strDefault);
	//showReplayValue(document.getElementById('msg_letter_replay'),0);
	
}

function closeDlg()
{
    //显示滚动条
	var temp_h1 = 0;
  	temp_h1 = document.body.clientHeight;  
	var temp_h2 = document.documentElement.clientHeight;  
	var isXhtml = (temp_h2<=temp_h1&&temp_h2!=0)?true:false;   
	var htmlbody = isXhtml?document.documentElement:document.body;  
	//htmlbody.style.overflowX = "auto";  
	//window.onmousewheel=function(){return true};
	$("#dlgBgDiv").hide();
	$(".dialogdiv").hide();
}

function ShowDlg()
{
 	var temp_h1 = 0;
	temp_h1 = document.body.clientHeight;  
	var temp_h2 = document.documentElement.clientHeight;  
	var isXhtml = (temp_h2<=temp_h1&&temp_h2!=0)?true:false;   
	var htmlbody = isXhtml?document.documentElement:document.body; 
	
	var cw = htmlbody.clientWidth;
	var ch = htmlbody.clientHeight;//必须考虑文本框处于页面边缘处，控件显示不全的问题
	var sl = 0;
	var st = 0;
	sl = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
	st = Math.max(document.documentElement.scrollTop, document.body.scrollTop);//考虑滚动的情况
	var sw = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
	var sh = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);//考虑滚动的情况
	sw=Math.max(sw,cw);
	sh=Math.max(sh,ch);
    //为了避免一开始浏览器窗口很小，拉伸浏览器窗口后，背景宽度不对，则把背景宽度设置成屏幕最大值
	$("#dlgBgDiv").width(screen.width);
	//高度包含滚轮的高度
	$("#dlgBgDiv").height(sh);
	//htmlbody.style.overflowX = "hidden";
	var Top = (ch - 580) / 2 + st + 50;

	var Left = (cw - 435) / 2 + sl - 75;
	//计算弹出层的位置
	$(".dialogdiv").css({ left: Left, top:Top });
	$("#dlgBgDiv").show();
	$(".dialogdiv").show();
	
	gotoPage("1");
}

//根据页码跳转
function gotoPage(pageNum)
{
   //取当前页码
  	g_strPageNum = pageNum;
    	$.ajax({
	    async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,
		data:{
			action:"showdlg",
			pageNum:g_strPageNum
			},
		success: function(data)
		{
			$(".dlgcontent").html(data);
		}
	});	
	
}
/* 
function QueryIsRunning()
{
	$.ajax({
		async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,
		data:{
			action:"refreshmsgresult"			
		},
		success: function(data)
		{
			var arrayData = data.split("==<>==");
			var strTypeObj = "#msg_box";
			if(arrayData[0] == "refreshing")
			{				
				setTimeout(QueryIsRunning,500);
			}			
			else  if(arrayData[0] == "false")
			{
				if(g_strMsgRefreshType == "msg")
				{
					getMsgArray(arrayData[1]);
					displayMsgList(strTypeObj);
				}
				else if(g_strMsgRefreshType == "letter")
				{
					$(strTypeObj).html(arrayData[2]);
				}
				return;
			}
			else
			{
				if(g_strMsgRefreshType == "msg")
				{
					getMsgArray(arrayData[1]);
					displayMsgList(strTypeObj);
				}
				else if(g_strMsgRefreshType == "letter")
				{
					$(strTypeObj).html(arrayData[2]);
				}
				$(".contacts_box").html(data);	
			}
	    }
	});		
	
} */

/* function changeContacts()
{
	$.ajax({
		async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,
		data:{
			action:"changeContacts"			
		},
		success: function(data)
		{
			$(".contacts_box").html(data);
		}
		
	});
} */

function QueryAppIsRunning()
{
	$.ajax({
		async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,
		data:{
			action:"queryAppRefresh"			
		},
		success: function(data)
		{
		    //var arrayData =  data.split(DATA_SEPARATOR_FOR_MT);
			if(data == "AppRefreshing")
			{				
				setTimeout(QueryAppIsRunning,500);
			}
			else if(data == "App_succ")
			{	
				$(".groups_loading").hide();
				$(".groups_loading_failed").hide();
				ViewApp("less_app");		
			}
			else  if(data == "App_failed")
			{

				$(".groups_loading").hide();
				$(".groups_loading_failed").show();
				return;
			}
	    }
	});		
	
}

function openAppUrl(strAppUrl)
{  
	//点击数字提醒消失 
	var i = strAppUrl.indexOf("=");
	var strGroupId = strAppUrl.substr(i + 1);
	var tipObj = "#tips_" + strGroupId;
	$(tipObj).hide();
    window.open(strAppUrl);
	
	$.ajax({
		async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,
		data:{
			action:"clearTip",
			appId:strGroupId
		},
		success: function(data)
		{
		}
		
	});	
}

function ViewApp(strViewType)
{  
	$.ajax({
		async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,
		data:{
			action:strViewType			
		},
		success: function(data)
		{
			if(strViewType == "less_app")
			{
			    //如果更少的话，则滚动条滑到顶部
				window.scrollTo(0,0); 
			}
			$(".grouplistbrd").html(data);
		}
		
	});
}


 
function onLogin()
{
	$.ajax({
	    async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,			
		data:{action:"login"},
		error: function(){window.location.href='/gsnews.cgi';},
		success: function(data){	
			if(data.trim() == "login_ok")
			{
				window.location.href='/gsnews.cgi';
			}
			else
			{
				setTimeout(queryIsLogin,500);
			}
		}
	});	
}

function queryIsLogin()
{
	$.ajax({
	    async: true,
		url: '/GPNewsaction.cgi',
		type: 'POST',
		cache: false,			
		data:{action:"isLogin"},
		error: function(){window.location.href='/gsnews.cgi';},
		success: function(data){	
			if(data.trim() == "true")
			{
				 window.location.href='/gsnews.cgi';
			}
			else if(data.trim() == "false")
			{
				setTimeout(queryIsLogin,500);
			}
		}
	});	
} 
function refreshGroup()
{
	$(".groups_loading").show();
	$(".groups_loading_failed").hide();
	$.ajax({
		async: true,
		url: '/GroupSpaceaction.cgi',
		type: 'POST',
		cache: false,
		data:{
			action:"RefreshData"			
		},
		success: function(data)
		{	
			if(data == "notlogin")
			{
				return;
			}
			QueryAppIsRunning();		
		}
	});
}
