//合并group.js,friend.js,msg.js

if (typeof(TopPanel)!='function'){
	document.write("<script type=\"text/javascript\" src=\"http://js.itiexue.net/com/tiexue/TxBase.js\"></script>");
}

//好友配置
var FriendConfig = {
	GoodFriendUrl:"http://i.tiexue.net/js/InfoBar.aspx?FunName=GetMyFriend&num=10",	//取好友列表的链接地址
	AddDelFriendUrl:"http://i.tiexue.net/AddDeleteFriend.aspx?UserID=",	//添加删除好友
	AddMyFriendUrl:"http://i.tiexue.net/AddFriendByName.aspx",//添加好友
	JudgeFriendUrl:"http://i.tiexue.net/JudgeFriend.aspx?UserID=",//判断是否为好友
	OverTime:10,	//10分钟数据超时失效
	RefreshDataTime:10	//同步好友数据
}
//短信配置
var MsgConfig={
	NewInfoUrl	:"http://msg.tiexue.net/Out/ToolBar.aspx",	//获取是否有新短信
	//短信服务链接地址
	ReadNewMsgUrl	:"http://msg.tiexue.net/Out/ReadNote.aspx",	//读新短信
	SendMsgUrl	:"http://msg.tiexue.net/Out/SendMsg.aspx",		//短信发送链接地址
	ValidateUrl	:"http://msg.tiexue.net/Dlg/Validate.aspx",		//验证码

	RefreshMsgTimeLength:10,	//取新短信的时间间隔(分钟)
	RefreshDataTime	: 10	//从缓冲区获取新数据的时间间隔(秒)
}
//我的公社
var GroupConfig = {
	MyGroupUrl:"http://i.tiexue.net/js/InfoBar.aspx?FunName=GetMyGroup&num=10",	//取好友列表的链接地址
	AddGroupUrl:"http://group.tiexue.net/XmlHttp/g_addmemberByGroupName.aspx", //加入公社的链接地址，传入GroupName参数
	AddGroupUrlByID:"http://group.tiexue.net/XmlHttp/g_addmemberByGroupID.aspx" //加入公社的链接地址，传入GroupID参数
}

document.domain = "tiexue.net";
//仿YUI对话框类保存位置
document.write("<div id='TxCustomDiv' style='z-Index:998;position:absolute;display:none;' class='dd-demo'></div>");
var TxCustomDlg=null;

var FriendInfo = null;	//好友信息管理实例
GoodFriend = function(){
	this.IsGetting = false;	//正在获取数据
	this.CacheData = "";	//好友数据
	this.CallBack = null;

	//启动最新好友定时获取功能
	this.oIntervalCache=null;
	this.GetMyFriendsFromCookie();
}

//定时器调用函数，更新网页数据
GetMyFriendsFromCookie = function(){
	if (FriendInfo!=null){
		FriendInfo.GetMyFriendsFromCookie();
	}
}
//服务器端的反馈信息,同时设置数据的失效时间
Tx_GetMyFriendFun = function(value){
	if (FriendInfo==null) return;

	FriendInfo.CacheData = value;
	FriendInfo.IsGetting=false;
	//if (value=="")return;
	//更新缓冲Cookie值
	temp = value;
	if (temp==""){
		temp="null";
	}
	//取当前时间
	var curdate = new Date();
	curdate.setTime(curdate.getTime()+FriendConfig.OverTime*60000);
    temp = temp + "|" + curdate.getFullYear() + "-" + (curdate.getMonth()+1) + "-" + curdate.getDate() + " " + curdate.getHours() + ":" + curdate.getMinutes() + ":" + curdate.getSeconds();
	BaseCookie.SetCookie("TxFriends",escape(temp),3600*24);
	//更新数据失效时间
	//BaseCookie.SetCookie("FDataAvail","1",FriendConfig.OverTime*60);//数据有效
	if (FriendInfo.CallBack!=null){
		if (typeof FriendInfo.CallBack == 'function'){
			FriendInfo.CallBack(value);
		}
	}
	document.getElementById("TxFriendJs").outerHTML="";
}
GoodFriend.prototype = {
	RunTimer:function(AutoDetect,callBackFun){
		this.CallBack = callBackFun;
		if (AutoDetect){
			if (this.oIntervalCache==null){
				this.oIntervalCache=window.setInterval("GetMyFriendsFromCookie()",FriendConfig.RefreshDataTime * 1000);
			}
		}else{
			if (this.oIntervalCache!=null){
				window.clearInterval(this.oIntervalCache);
				this.oIntervalCache=null;
			}
		}
	},
	SendSubmit:function(){
		var obj = document.getElementById("TxAddUserName");
		var UserName = obj.value;
		if (UserName==""){
			TxAlert('好友名不能为空');
			return;
		}
		this.AddMyFriend(UserName);
	},
	OpenAddDlg:function(UserName,CallBack){
		this.CallBack = CallBack;
		
		if (TxCustomDlg==null) TxCustomDlg = new CustomDlg("TxCustomDiv");
		var SendHtmlData = '<table cellSpacing="0" cellPadding="0" height="100%" border="0" align="center">';
		SendHtmlData += '<tr><td colspan="3"></td></tr>';
		SendHtmlData += '<tr>';
		//SendHtmlData += '	<td noWrap></td>';
		SendHtmlData += '	<td colspan="2" noWrap>添加登录名：<input id="TxAddUserName" class="inp" style="WIDTH:110px;HEIGHT: 15px" maxLength="80" NAME="TxAddUserName"></td>';
		SendHtmlData += '</tr>';
		//SendHtmlData += '<tr><td colspan="3"><input type="checkbox" value="on" ID="ToSendedCheck" NAME="ToSendedCheck">将发送短信保存到“已发送的”中&nbsp;</td></tr>';
		SendHtmlData += '<tr>';
		SendHtmlData += '	<td vAlign="middle" align="center" colSpan="3" height="40px">';
		SendHtmlData += '		<INPUT id="AddFriendBt" type="button" value="添加" onClick="FriendInfo.SendSubmit();">&nbsp;';
		SendHtmlData += '		<INPUT id="CancelAddBt" type="button" value="取消" onClick="TxCustomDlg.Close()">&nbsp;';
		SendHtmlData += '	</td>';
		SendHtmlData += '</tr>';
		SendHtmlData += '</table>';

		TxCustomDlg.YUIShow("<font size ='2'>添加好友</font>",SendHtmlData,'225px');
	},

	AddMyFriend:function(UserName){
		var SendCallback =
		{
			success:function(o){
			    TxProcessHide();
				if(o.responseText !== undefined){
					TxCustomDlg.Close();
					if (o.status==200){
						var temp = o.responseText;
						if (FriendInfo.CallBack!=null)
							FriendInfo.CallBack(temp);
						else
							TxAlert(temp);
					}
				}
			},
			failure:function(o){
			    TxProcessHide();
				if(o.responseText !== undefined){
					TxCustomDlg.Close();
					TxAlert(o.statusText);
				}
			}
		};
		var sUrl = "agent.aspx?desturl=" + encodeURIComponent(FriendConfig.AddMyFriendUrl);
		var postData = "UserName=" + encodeURIComponent(UserName);
		var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, SendCallback,postData);
		TxProcessShow("正在加好友,请等待...",true);
	},


	AddDelMyFriend:function(UserID,CallBack,UserName){	
	    var SendJudgeCallback =
	    {
	    	success:function(o){
	    	    TxProcessHide();
	    		if(o.responseText != undefined){
	    			if(o.status == 200){
	    				var returnText = o.responseText;
	    				if(returnText != ""){
	    				    var temp = returnText.split('|');
	    				    var msg = "";
	    				    var isFailure = false;
	    				    if(temp[1] == 1){//是好友
	    					    msg = "已经是好友，确定删除好友"+ UserName +"？";
	    				    }
	    				    else if(temp[1] == 0){//不是好友
	    					    msg = "确定添加"+ UserName +"为好友？";
	    				    }
	    				    else{//错误格式
	    					    msg = temp[2];
	    					    isFailure = true;
	    				    }
	    				}
	    				else{
	    				    msg = "服务器错误,请重试!";
	    				    isFailure = true;
	    				}
	    				if(!isFailure){
	    				
	    					function ClickOK(){
	    					
							    var SendCallback =
							    {
								    success:function(o){
								        TxProcessHide();
									    if(o.responseText !== undefined){
										    if (o.status==200){
											    var temp = o.responseText;
											    if (CallBack!=null)
												    CallBack(temp,UserID);
											    else
												    TxAlert(temp);
										    }
									    }
								    },
								    failure:function(o){
								        TxProcessHide();
									    if(o.responseText !== undefined){
										    TxAlert(o.statusText);
									    }
								    }
							    };
							    
							    var sUrl = "agent.aspx?desturl=" + encodeURIComponent(FriendConfig.AddDelFriendUrl + UserID + "&rd=" + Math.random());
							    var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, SendCallback);	
							    TxProcessShow("正在操作,请等待...",true); 
						    }
	    					TxConfirm(msg,ClickOK);
						}
						else{
							TxAlert(msg);						
						}
	    			}
	    		}	    		
	    	},
			failure:function(o){
			    TxProcessHide();
				if(o.responseText !== undefined){
					TxAlert(o.statusText);
				}
			}
	    };
	    var jUrl = "agent.aspx?desturl=" +  encodeURIComponent(FriendConfig.JudgeFriendUrl + UserID + "&rd=" + Math.random())
	    var request = YAHOO.util.Connect.asyncRequest('GET', jUrl, SendJudgeCallback);
	    TxProcessShow("正在操作,请等待...",true); 
	},

	//从服务器端获取新短信数据
	GetMyFriendsFromServer:function(){
		var TxTB_UserID = BaseCookie.TxBBS_CurrentUserID();
		if (TxTB_UserID==0) return;

		this.IsGetting=true;
		var objJs = document.getElementById("TxFriendJs");
		if (objJs==null){
			var IsFinish = true;
			if(document.all){
				if (document.readyState!="complete") IsFinish=false;
			}
			if (!IsFinish) return;
			objJs = document.createElement("script");
			objJs.setAttribute("id","TxFriendJs");
			objJs.setAttribute("language","javascript");
			try{document.body.appendChild(objJs);}catch(e){return;}
		}
		
		var Url = FriendConfig.GoodFriendUrl;
		if (Url.lastIndexOf("?")!=-1){
			Url += "&";
		}else{
			Url += "?";
		}
		Url += "tmp=" + Math.round(Math.random()*10000);
		objJs.src = Url;
	},
	//从缓冲区中取判断是否有新短信
	GetMyFriendsFromCookie:function(){
		//读取Cookie
		var temp = BaseCookie.GetCookie("TxFriends");
		//如果Cookie获取为空值,立即从服务器段获取
		if (temp==null){
			this.GetMyFriendsFromServer();
			return this.CacheData;
		}
		var arr = unescape(temp).split("|");

        this.CacheData = arr[0];
		//判断好友数据是否过期 FDataAvail=1:有效,=0:正在获取,=null:数据过期
		if (arr.length==2){
		    SaveDate = arr[1];
		    var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/; 
	        var r = SaveDate.match(reg); 
	        if(r!=null){
		        var dt = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
		        var curdate = new Date();
		        if (curdate>dt){
		            this.GetMyFriendsFromServer();
		        }
	        }
	    }
	    
		return this.CacheData;
	},
	ClearCookie:function(){
		BaseCookie.ClearCookie("TxFriends");
		this.CacheData="";
	}

}
var cswmTI="";
var RollPlace=0;//外部滚动后的滚动Top位置(xy修改好友弹出窗位置bug)
function ClearPanel(){
	var obj = document.getElementById("PopupPanel");
	if (obj!=null)obj.outerHTML = "";
}
function HideMenu(){cswmTI=setTimeout("ClearPanel()",700);}
function StopHideMenu(){clearTimeout(cswmTI);}
//鼠标移动到头像上出现右侧菜单按钮,好友列表页
function SetFriendFaceMenu(isShow,obj){
    if(isShow){
    	YAHOO.util.Dom.removeClass(obj,"area2_hy_4_hide");
    	YAHOO.util.Dom.addClass(obj,"area2_hy_4");
    	YAHOO.util.Dom.setStyle(obj,"display","");
    }
    else{
    	YAHOO.util.Dom.removeClass(obj,"area2_hy_4");
    	YAHOO.util.Dom.addClass(obj,"area2_hy_4_hide");
    }
}

//弹出窗口
OnClickEvent = function(thisObj,uID,uName){
    if(document.all){//是否为IE。ff不支持document.readyState.wangzhe modify at 2008-2-27
        if(document.readyState != "complete") return;
    }
	
    var userID = uID;
    var userName = uName;
    var obj = document.getElementById("PopupPanel");
    if(obj == null){
        obj=document.createElement("div");
		obj.className = "menu";
		obj.id = "PopupPanel";
	    obj.onclick = function(){this.outerHTML = "";}
	    obj.onmouseout = function(){HideMenu();}
	    obj.onmouseover = function(){StopHideMenu();}
	    obj.onblur = function(){this.outerHTML = "";}
		document.body.appendChild(obj);
    }
    var temp = '<A class="menuItem" href="javascript:FriendInfo.AddDelMyFriend(' + userID + ',AddDelFriendCallBack,\''+ userName +'\')">删除好友</A>';
	temp += "<A class='menuItem' href='javascript:DlgInfo.CreateInfo(\"" + userName + "\")'>发送短信</A>";
	temp += '<A class="menuItem" href="http://'+ userID + '.i.tiexue.net" target="_blank">个人中心</A>';
	temp += '<A class="menuItem" href="http://'+ userID + '.i.tiexue.net/blog/" target="_blank">博客</A>';
	obj.innerHTML = temp;
	//设置显示的位置
	var top = getIEPosY(thisObj);
	var left = getIEPosX(thisObj);
	obj.style.left = left-80 + "px";
	obj.style.top = top+98-RollPlace + "px";

	obj.style.visibility="visible";
	HideMenu();
}

function AddDelFriendCallBack(value,uId){
	if (value.indexOf('成功删除')==0 && uId != null && uId != "" && document.getElementById("Friend"+uId) != null && document.getElementById("Friend"+uId) != undefined){
	    document.getElementById("Friend"+uId).outerHTML = "";
	    //更新Cookie
	    FriendInfo.ClearCookie();
		FriendInfo.GetMyFriendsFromServer();
	}
	TxAlert(value);
}

// 得到IE中各元素真正的位移量，即使这个元素在一个表格中
function getIEPosX(elt) { return getIEPos(elt,"Left"); }
function getIEPosY(elt) { return getIEPos(elt,"Top"); }
function getIEPos(elt,which) {
 iPos = 0
 while (elt!=null) {
  iPos += elt["offset" + which]
  elt = elt.offsetParent
 }
 return iPos
}

//个人中心页弹出窗口
OnClickEventHome = function(thisObj,uID,uName){
    if(document.all){//是否为IE。ff不支持document.readyState.wangzhe modify at 2008-2-27
       if(document.readyState != "complete") return;
    }
    var userID = uID;
    var userName = uName;
    var obj = document.getElementById("PopupPanel");
    if(obj == null){
        obj=document.createElement("div");
		obj.className = "menu";
		obj.id = "PopupPanel";
		obj.onclick = function(){this.outerHTML = "";}
		obj.onmouseout = function(){HideMenu();}
	    obj.onmouseover = function(){StopHideMenu();}
	    obj.onblur = function(){this.outerHTML = "";}
		document.body.appendChild(obj);
    }
    var temp = '<A class="menuItem" style="white-space:nowrap;" href="javascript:void(0)" onclick="FriendInfo.AddDelMyFriend(' + userID + ',AddDelFriendCallBack,\''+ userName +'\')">添加(删除)好友</A>';
	temp += "<A class='menuItem' href='javascript:void(0)' onclick='DlgInfo.CreateInfo(\"" + userName + "\")'>发送短信</A>";
	temp += '<A class="menuItem" href="http://'+ userID + '.i.tiexue.net" target="_blank">个人中心</A>';
	temp += '<A class="menuItem" href="http://'+ userID + '.i.tiexue.net/blog/" target="_blank">博客</A>';
	obj.innerHTML = temp;
	
	//设置显示的位置
	var top = getIEPosY(thisObj);
	var left = getIEPosX(thisObj);
	obj.style.left = left-60 + "px";
	obj.style.top = top+50 + "px";
	obj.style.visibility="visible";
	HideMenu();
}

//个人中心页回调
function HomeAddDelFriendCallBack(value,uId){
	TxAlert(value);
}

//短信功能类
var DlgInfo = null;	//短信管理实例

//写信短信，编辑新短信，回复
MsgDlgInfo = function(AutoDetect,callBackFun){	//自动检测新短信标志
	this.CallBack = callBackFun;
	this.oIntervalCache = null;	//新短信检测时钟
	this.NewInfoCount = 0;	//新短信总数
	this.UpdateInfo=true;	//显示需要更新

	//新短信总数更新服务
	this.Tx_GetMsgCount_Cache();
	if (FriendInfo==null) FriendInfo=new GoodFriend();
}

//服务器段的反馈信息,同时设置数据的失效时间
function Tx_NewMsgFeedback(Count){
	if (DlgInfo==null) return;
	DlgInfo.NewInfoCount = Count;
	//更新缓冲Cookie值
	BaseCookie.SetCookie("TxMsgNew",Count,3600*24);
	//更新数据失效时间
	BaseCookie.SetCookie("TxMsgAvail","1",MsgConfig.RefreshMsgTimeLength*60);//数据有效
	if (typeof DlgInfo.CallBack == 'function'){
		DlgInfo.CallBack(Count);
	}
}

MsgDlgInfo.prototype = {
	RunTimer:function(AutoDetect){
		if (AutoDetect){
			if (this.oIntervalCache==null){
				DlgInfo.Tx_GetMsgCount_Cache();
				this.oIntervalCache=window.setInterval("DlgInfo.Tx_GetMsgCount_Cache()",MsgConfig.RefreshDataTime * 1000);	//取缓冲新短信数据(15秒)
			}
		}else{
			if (this.oIntervalCache!=null){
				window.clearInterval(this.oIntervalCache);
				this.oIntervalCache=null;
			}
		}
	},
	//读取一条新短信消息
	ReadOneInfo:function(){
		var temp = BaseCookie.GetCookie("TxMsgNew");
		//如果Cookie获取为空值,立即从服务器段获取
		if (temp==null){
			BaseCookie.SetCookie("TxMsgNew","0",MsgConfig.RefreshMsgTimeLength*60);
			this.Tx_GetMsgCount_Server();
			return;
		}
		if (temp=="")temp="0";
		this.NewInfoCount = parseInt(temp);
		if (this.NewInfoCount>0) this.NewInfoCount--;

		//更新缓冲Cookie值
		BaseCookie.SetCookie("TxMsgNew",this.NewInfoCount,MsgConfig.RefreshMsgTimeLength*60);
		if (typeof this.CallBack == 'function'){
			this.CallBack(this.NewInfoCount);
		}
	},
	ClearCookie:function(){
		this.NewInfoCount = 0;
		//删除缓冲Cookie值
		BaseCookie.ClearCookie("TxMsgNew");
		BaseCookie.ClearCookie("TxMsgAvail");

	},
	//初始化短信Panel
	InitPanel:function(){},
    GetJsObj:function(JsName){
		var objJs = document.getElementById(JsName);
		if (objJs==null){
			var IsFinish = true;
			if(document.all){
				if (document.readyState!="complete") IsFinish=false;
			}
			if (!IsFinish) return null;

			var objJs = document.createElement("script");
			objJs.setAttribute("id",JsName);
			objJs.setAttribute("language","javascript");
			try{document.body.appendChild(objJs);}catch(e){return;}
		}
		return objJs;
    },
	//从服务器端获取新短信数据
	Tx_GetMsgCount_Server:function(){
		var objJs = this.GetJsObj("TxMsgJs");
		if (objJs==null)return;

		var TxTB_UserID = BaseCookie.TxBBS_CurrentUserID();
		if (TxTB_UserID==0) return;

		var Url = MsgConfig.NewInfoUrl + "?tmp=" + Math.round(Math.random()*10000) ;
		objJs.src = Url;
	},
	//从缓冲区中取判断是否有新短信
	Tx_GetMsgCount_Cache:function(){
		//判断短信数据是否过期 TxMsgAvail=1:有效,=0:正在获取,=null:数据过期
		temp = BaseCookie.GetCookie("TxMsgAvail");
		if (temp==null){
			this.Tx_GetMsgCount_Server();
			BaseCookie.SetCookie("TxMsgAvail","0",40);	//短信数据获取中
		}
		//读取Cookie
		var temp = BaseCookie.GetCookie("TxMsgNew");
		//如果Cookie获取为空值,立即从服务器段获取
		if (temp==null){
			BaseCookie.SetCookie("TxMsgNew","0",MsgConfig.RefreshMsgTimeLength*60);
			this.Tx_GetMsgCount_Server();
			return;
		}
		if (temp=="")temp="0";
		var Count = parseInt(temp);
		var NeedUpdate = (this.NewInfoCount != Count || this.UpdateInfo);
		this.NewInfoCount = Count;

		if (NeedUpdate){
			this.UpdateInfo=true;
			//if (typeof this.CallBack == 'function'){
				try{
					this.CallBack(Count);
					this.UpdateInfo=false;
				}catch(e){}
			//}
		}
	},

	//从服务器获取最新的短信数量
	GetNewInfo:function(){
		this.Tx_GetMsgCount_Server();
	},

	//网页调用获取新短信的总条数
	NewInfoSum : function(){
		return this.NewInfoCount;
	},

	//创建、转发、回复短信对话框
	CreateInfo : function(UserName,Title,Content)
	{
		if (TxCustomDlg==null) TxCustomDlg = new CustomDlg("TxCustomDiv");

		var inputBoxHeight=20;
		if (xmlns1999) inputBoxHeight = 15;
		//短信对话框网页脚本数据
		var inputstyle = "";
		var temp = "<style>";
		temp += '.inputInfo{BORDER-LEFT: #84a1bd 1px solid;BORDER-TOP:#84a1bd 1px solid;BORDER-RIGHT:#84a1bd 1px solid;BORDER-BOTTOM: #84a1bd 1px solid;FONT-SIZE:12px;PADDING-LEFT:2px;PADDING-TOP:2px;PADDING-RIGHT:2px;PADDING-BOTTOM:0px;text-valign: middle;}\r\n';
		temp += '#msgContent{';
		temp += 'font-size:10pt;SCROLLBAR-HIGHLIGHT-COLOR: #ffffff; SCROLLBAR-SHADOW-COLOR: #cccccc; COLOR: #000000; SCROLLBAR-3DLIGHT-COLOR: #cccccc;SCROLLBAR-FACE-COLOR: #ffffff;SCROLLBAR-ARROW-COLOR: #666666;SCROLLBAR-TRACK-COLOR: #ffffff;SCROLLBAR-DARKSHADOW-COLOR: #fff; FONT-FAMILY: 宋体;';
		temp += 'BORDER-RIGHT: #333 1px dashed; PADDING-RIGHT: 6px; BORDER-TOP: #333 1px dashed; PADDING-LEFT: 6px; PADDING-BOTTOM: 6px; BORDER-LEFT: #333 1px dashed; PADDING-TOP: 6px; BORDER-BOTTOM: #333 1px dashed';
		temp += '}';
		temp += '</style>';
		temp += '<form id="thisForm" name="thisForm" method="post" action="return false">';	//SendFlag MsgID
		temp += '<table cellSpacing="0" cellPadding="0" width="97%" height="100%" border="0" align="center">';
		temp += '<tr>';
		temp += '	<td noWrap width="52">收件人：</td>';
		temp += '	<td noWrap width="214"><input title="收件人" onKeyUp="SendTo_onkeyup()" style="WIDTH:210px;HEIGHT:' + inputBoxHeight + 'px" maxLength="60" size="100" ID="UserList" NAME="UserList" class="inputInfo"></td>';
		temp += '	<td>';
		temp += '		<select onChange="return SelGoodFriend()" ID="SelUser" NAME="SelUser" class="inputInfo">';
		temp += '		<option value="-1" selected>--选好友--</option>';
		temp += '		</select>';
		temp += '	</td>';
		temp += '</tr>';
		temp += '<tr><td colspan="3"></td></tr>';
		temp += '<tr>';
		temp += '	<td noWrap>主题：</td>';
		temp += '	<td colspan="2" noWrap align="left"><input id="Title" style="WIDTH:210px;HEIGHT:' + inputBoxHeight + 'px" maxLength="80" NAME="Title" class="inputInfo"></td>';
		temp += '</tr>';
		temp += '<tr>';
		temp += '	<td align="center" colspan="3">';
		temp += '		<textarea title="键入短信文本内容" style="WIDTH:97%;height:180px;" name="msgContent" rows="12" cols="60" ID="msgContent"></textarea>';
		temp += '	</td>';
		temp += '</tr>';
		temp += '<tr>';
		temp += '	<td colspan="3" align="left"><input type="checkbox" value="on" ID="ToSendedCheck" NAME="ToSendedCheck">将发送短信保存到“已发送的”中&nbsp;</td>';
		temp += '</tr>';
		temp += '<tr>';
		temp += '	<td height="12" colspan="3" valign="bottom" align="left">';
		inputBoxHeight=22;
		if (xmlns1999) inputBoxHeight = 17;
		temp += '		验证码:<INPUT id="ValidateCode" style="WIDTH:72px;HEIGHT:' + inputBoxHeight + 'px" NAME="ValidateCode" class="inputInfo"> <IMG id="MsgCodeImage" alt="" src="" align="absMiddle" border="0">&nbsp;';
		temp += '		<INPUT type="button" value="刷新验证码" onClick="RefreshCode()" ID="RefreshCodeBt" class="inputInfo">';
		temp += '	</td>';
		temp += '</tr>';
		temp += '<tr><td colSpan="3" align="left"><b>说明</b>：&nbsp;&nbsp;标题最多<b>50</b>个字符，内容最多<b>500</b>个字符</td></tr>';
		temp += '<tr>';
		temp += '	<td vAlign="middle" align="center" colSpan="3">';
		temp += '		<INPUT id="SendMsgBt" type="button" value="发送短信" onClick="SendSubmit(null);" class="inputInfo">&nbsp;';
		temp += '		<INPUT id="SaveMsgBt" type="button" value="保存短信" onClick="SendSubmit(-1);" class="inputInfo">&nbsp;';
		temp += '	</td>';
		temp += '</tr>';
		temp += '</table>';
		temp += '</form>';

		TxCustomDlg.YUIShow("<font size ='2'>发送短信</font>",temp);
		
		RefreshCode();

		if (UserName!=null){
			YAHOO.util.Event.onAvailable("UserList",function(){thisForm.UserList.value = UserName;});
		}
		if (Title!=null){
			YAHOO.util.Event.onAvailable("Title",function(){thisForm.Title.value = Title;});
		}
		if (Content!=null){
			YAHOO.util.Event.onAvailable("msgContent",function(){thisForm.msgContent.value = Content;});
		}
		//取好友信息
		var temp = FriendInfo.GetMyFriendsFromCookie();
		if (temp!=""){
			Tx_FillFriendData(temp);
		}
		temp = null;
		
	},

	ReadNoteDlg:function(MsgID){
		if (TxCustomDlg==null) TxCustomDlg = new CustomDlg("TxCustomDiv");

		var temp = MsgConfig.ReadNewMsgUrl;
		if (typeof(MsgID)!='undefined')	temp = MsgConfig.ReadNewMsgUrl + "?MsgID=" + MsgID;
		TxProcessShow("正在读取,请等待...");
		temp = "<iframe src=\"" + temp + "\" scrolling=\"no\" width=\"100%\" height=\"330px\" frameborder=\"0\" onload=\"TxProcessHide()\"></iframe>";
		TxCustomDlg.YUIShow("<font size ='2'>读短信</font>",temp);
	},

	//读新短信消息
	ReadNewMsg : function(){
		if (TxCustomDlg==null) TxCustomDlg = new CustomDlg("TxCustomDiv");

		//判断是否有新短信
		if (this.NewInfoCount==0){
			TxAlert('没有新的短信消息！');
			return;
		}
		
		this.ReadNoteDlg();
		/*TxProcessShow("正在读取,请等待...");
		with(YAHOO.example.container.MsgDialog){
			setHeader("<div class='tl'></div><font size ='2'>读短信</font><div class='tr'></div>");
			setBody("<iframe src=\"" + MsgConfig.ReadNewMsgUrl + "\" scrolling=\"no\" width=\"100%\" height=\"330px\" frameborder=\"0\" onload=\"TxProcessHide()\"></iframe>");
			show();
		}*/
	},
	//读指定编号的短信
	ReadMsg : function(MsgID){
		if (TxCustomDlg==null) TxCustomDlg = new CustomDlg("TxCustomDiv");

		this.ReadNoteDlg(MsgID);
	},

	//关闭短信对话框
	CloseWindow : function(){
		if (TxCustomDlg!=null) TxCustomDlg.Close();
	}
}
//短信对话框关闭
function TxMsgCloseWindow(){
	DlgInfo.CloseWindow();
}
//短信脚本内容

function RefreshCode(){
	document.getElementById("MsgCodeImage").src = MsgConfig.ValidateUrl + '?tmp=' + Math.random();
}

function Tx_FillFriendData(value){
	var FriendID,Friend;
	if (value!=""){
		var tempArr;
		var arr=value.split(";");
		try{
		with(thisForm){
			while(SelUser.options.length>0) SelUser.remove(0);
			SelUser.options.add(new Option("--选择好友--",-1));
			for (var i=0;i<arr.length;i++){
				tempArr=arr[i].split(",");
				FriendID=tempArr[0];
				Friend=tempArr[1];
				SelUser.options.add(new Option(Friend,FriendID));
			}
		}
		}catch(e){}
	}
}

function SelGoodFriend(){
	with(thisForm){
		if (SelUser.selectedIndex==0){
			if (SelUser.options[SelUser.selectedIndex].value==-1) return;
		}
		FriendName=SelUser.options[SelUser.selectedIndex].text;
		if (UserList.value=="")
			UserList.value=FriendName;
		else{
			if (UserList.value.indexOf(FriendName)==-1)
				UserList.value+=","+FriendName;
		}
	}
}
function SendTo_onkeyup() {
	with(thisForm){
		var indata=UserList.value;
		if (indata==""){
			if (event.keyCode ==13 && SelUser.selectedIndex!=0){
				UserList.value = SelUser.options[SelUser.selectedIndex].text;
			}
			return;
		}
		for(i=0;i<SelUser.length;i++){
			temp=SelUser.options[i].text;
			if (temp==indata){
				SelUser.options[i].selected=true;
				break;
			}
			if (temp.indexOf(indata)!=-1){
				SelUser.options[i].selected=true;
			}
		}
	}
}

function SendSubmit(MsgID){
	with(thisForm){
		if (UserList.value == ""){
			TxAlert('收件人不能为空值!');
			return;
		}
		if (Title.value == ""){
			TxAlert('标题不能为空值!');
			return;
		}
		if (msgContent.value == ""){
			TxAlert('正文不能为空值');
			return;
		}
		if (ValidateCode.value==""){
			TxAlert("验证码不能为空值");
			return;
		}
		SendMsgExecute(MsgID,UserList.value,Title.value,msgContent.value,ValidateCode.value,ToSendedCheck.checked);
	}
}

//发送短信执行过程
function SendMsgExecute(MsgID,UserList,Title,Content,ValidateCode,ToSended){
	var SendMsgCallback =
	{
		success:function(o){
			TxProcessHide();
			if(o.responseText !== undefined){
				if (o.status==200){
					var temp = o.responseText;
					if (temp!="true"){
						TxAlert(temp);
					}else 
					{DlgInfo.CloseWindow();TxAlert('短信发送成功！');}
				}
			}
		},
		failure:function(o){
			//DlgInfo.CloseWindow();
			TxProcessHide();
			if(o.responseText !== undefined){
				TxAlert(o.statusText);
			}
		}
	};
	var sUrl = "agent.aspx?desturl=" + encodeURIComponent(MsgConfig.SendMsgUrl);
	var postData = "UserList=" + encodeURIComponent(UserList);
	if (MsgID!=null) postData += "&MsgID=" + MsgID;
	postData += "&ToSendedCheck=" + ToSended;
	postData += "&Title=" + encodeURIComponent(Title);
	postData += "&Content=" + encodeURIComponent(Content);
	postData += "&ValidateCode=" + ValidateCode;

	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, SendMsgCallback, postData);
	TxProcessShow("发送中,请等待...",true);
}
function OpenSendDlg(UserName,Title,Content){
	DlgInfo.CloseWindow();
	DlgInfo.CreateInfo(UserName,Title,Content);
}

//公社类功能
var MyGroupInfo = null;	//好友信息管理实例

MyGroupClass = function(){
	this.IsGetting = false;	//正在获取数据
	this.CacheData = "";	//好友数据
	this.GetMyGroupsFromCookie();
	this.PanelReady = false;
	this.GetMyGroupsFromCookie();
}
//定时器调用函数，更新网页数据
GetMyGroupsFromCookie = function(){
	if (MyGroupInfo!=null){
		MyGroupInfo.GetMyGroupsFromCookie();
	}
}
//服务器端的反馈信息,同时设置数据的失效时间
Tx_GetMyGroupFun = function(value){
	document.getElementById("TxGroupJs").outerHTML="";
	if (MyGroupInfo==null) return;
	MyGroupInfo.IsGetting = false;
	MyGroupInfo.CacheData = value;
	if (value=="")return;
	//更新缓冲Cookie值
	BaseCookie.SetCookie("TxGroups",escape(value),3600*24);
}
MyGroupClass.prototype = {
	OpenAddDlg:function(UserName,CallBack){
		this.CallBack = CallBack;

		if (TxCustomDlg==null) TxCustomDlg = new CustomDlg("TxCustomDiv");
		var SendHtmlData = '<table cellSpacing="0" cellPadding="0" width="97%" height="100%" border="0" align="center">';
		SendHtmlData += '<tr><td colspan="3"></td></tr>';
		SendHtmlData += '<tr>';
		SendHtmlData += '	<td noWrap>添加公社：</td>';
		SendHtmlData += '	<td colspan="2" noWrap><input id="TxAddGroupName" class="inp" maxLength="80"></td>';
		SendHtmlData += '</tr>';
		SendHtmlData += '<tr>';
		SendHtmlData += '	<td vAlign="middle" align="center" colSpan="3" height="40px">';
		SendHtmlData += '		<INPUT id="AddGroupBt" type="button" value="添加" onClick="MyGroupInfo.SendSubmit();">&nbsp;';
		SendHtmlData += '		<INPUT id="CancelAddBt" type="button" value="取消" onClick="TxCustomDlg.Close()">&nbsp;';
		SendHtmlData += '	</td>';
		SendHtmlData += '</tr>';
		SendHtmlData += '</table>';

		TxCustomDlg.YUIShow("<font size ='2'>我的公社--添加操作</font>",SendHtmlData,'225px');
	},
	SendSubmit:function(){
		var obj = document.getElementById("TxAddGroupName");
		var GroupName = obj.value;
		if (GroupName==""){
			TxAlert('公社名为空！');
			return;
		}
		this.AddMyGroup(GroupName);
	},
	AddMyGroup:function(GroupName){
		var SendCallback =
		{
			success:function(o){
				if(o.responseText !== undefined){
					TxCustomDlg.Close();
					if (o.status==200){
						var temp = o.responseText;
						if (MyGroupInfo.CallBack!=null)
							MyGroupInfo.CallBack(temp);
						else
							TxAlert(temp);
					}
				}
			},
			failure:function(o){
				if(o.responseText !== undefined){
					TxCustomDlg.Close();
					TxAlert(o.statusText);
				}
			}
		};
		var sUrl = "agent.aspx?desturl=" + encodeURIComponent(GroupConfig.AddGroupUrl);
		var postData = "GroupName=" + encodeURIComponent(GroupName);
		var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, SendCallback,postData);
		TxProcessShow("正在加公社,请等待...",true);
	},
	
    //根据GroupID加入公社(xy:2008-06-20)
    AddMyGroupByID:function(GroupID){
		var SendCallback =
		{
			success:function(o){
				if(o.responseText !== undefined){
					TxCustomDlg.Close();
					if (o.status==200){
						var temp = o.responseText;
						if (MyGroupInfo.CallBack!=null)
							MyGroupInfo.CallBack(temp);
						else
							TxAlert(temp);
					}
				}
			},
			failure:function(o){
				if(o.responseText !== undefined){
					TxCustomDlg.Close();
					TxAlert(o.statusText);
				}
			}
		};
		if (TxCustomDlg==null) TxCustomDlg = new CustomDlg("TxCustomDiv");
		var sUrl = "agent.aspx?desturl=" + encodeURIComponent(GroupConfig.AddGroupUrlByID);
		var postData = "GroupID=" + encodeURIComponent(GroupID);
		var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, SendCallback,postData);
		TxProcessShow("正在加公社,请等待...",true);
	},
    
	//从服务器端获取新短信数据
	GetMyGroupsFromServer:function(){
		var TxTB_UserID = BaseCookie.TxBBS_CurrentUserID();
		if (TxTB_UserID==0) return;
	
		var objJs = document.getElementById("TxGroupJs");
		if (objJs==null){	
			var IsFinish = true;
			if(document.all){
				if (document.readyState!="complete") IsFinish=false;
			}
			if (!IsFinish) return;

			var objJs = document.createElement("script");
			objJs.setAttribute("id","TxGroupJs");
			objJs.setAttribute("language","javascript");
			try{document.body.appendChild(objJs);}catch(e){return;}
		}
		
		this.IsGetting=true;
		var Url = GroupConfig.MyGroupUrl;
		if (Url.lastIndexOf("?")!=-1){
			Url += "&";
		}else{
			Url += "?";
		}
		Url += "tmp=" + Math.round(Math.random()*10000);

		objJs.src = Url;
	},
	//从缓冲区中取判断是否有新短信
	GetMyGroupsFromCookie:function(){
		//读取Cookie
		var temp = BaseCookie.GetCookie("TxGroups");
		//如果Cookie获取为空值,立即从服务器段获取
		if (temp==null){
			this.GetMyGroupsFromServer();
			return this.CacheData;
		}
		this.CacheData = unescape(temp);
		return this.CacheData;
	},
	ClearCookie:function(){
		this.CacheData = "";
		BaseCookie.ClearCookie("TxGroups");
	}
}
