<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<!-- #include file=inc/UserTopic.asp -->
<%
DEF_BBS_HomeUrl = "../"
Dim GBL_ID,GBL_Name

GBL_CHK_TempStr = ""

initDatabase

SiteHead("   选择好友")
UpdateOnlineUserAtInfo GBL_board_ID,"选择好友"

If GBL_ID = 0 and GBL_Name = "" Then
	If GBL_ID = 0 Then GBL_ID = GBL_UserID
	GBL_CHK_TempStr = ""
	If GBL_ID = 0 Then
		GBL_CHK_TempStr = "找不到用户，要查看资料请先登录。<br>" & VbCrLf
	End If
Else
	If GBL_ID <> 0 Then GBL_Name = ""
	GBL_CHK_TempStr = ""
End If

if GBL_CHK_TempStr <> "" Then
	Response.Write "<p align=left><font color=ff0000 class=RedFont><b>" & GBL_CHK_TempStr & "</b></font><hr size=1>"
Else
	GBL_CHK_TempStr = ""
	DisplayCenter
End If

closeDataBase
SiteBottom_Spend
If GBL_ShowBottomSure = 1 Then Response.Write GBL_SiteBottomString

Function DisplayCenter

%>
<head>
	<script>
	function closeit()
	{
		setTimeout("self.close()",90000)
	}
	function MM_findObj(n, d)
	{ //v3.0
		var p,i,x;
		if(!d) d=document;
		if((p=n.indexOf("?"))>0&&parent.frames.length)
		{
			d=parent.frames[n.substring(p+1)].document; 
			n=n.substring(0,p);
		}
		if(!(x=d[n])&&d.all) x=d.all[n]; 
		for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
		return x;
	}
	function MM_setTextOfTextfield(objName,x,newText)
	{ //v3.0
		var obj = MM_findObj(objName);
		if (obj) obj.value = newText;
		opener.document.LeadBBSFm.SdM_ToUser.value=newText;
		window.close();
	}

	function returnvalue(){
		window.returnValue = 1;
		window.close();
	}
	function cancelPost(){
		window.close();
	}
</script>
</head>
<%
	Dim Rs,SQL,NewNum,UserName
	Set rs = Server.CreateObject("ADODB.Recordset")

	If GBL_ID > 0 Then
		SQL = "Select top 1 ID,UserName from LeadBBS_User where ID=" & GBL_ID
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
	Else
		SQL = "Select top 1 ID,UserName from LeadBBS_User where UserName='" & Replace(GBL_Name,"'","''") & "'"
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
	End If
	If Not Rs.Eof Then
		UserName = Rs(1)
		GBL_ID = cCur(Rs(0))
	Else
		Response.Write "<br><br>&nbsp; &nbsp; &nbsp; 错误，此用户不存在！"
		Rs.Close
		Set Rs = Nothing
		Exit Function
	End if
	Rs.close

	GBL_CHK_TempStr=""
	Dim UpDownPageFlag
	UpDownPageFlag = Request("UpDownPageFlag")

	Dim Start,key
	
	
	Dim SQLendString

	Start = Left(Trim(Request("Start")),14)
	Start = start
	If isNumeric(Start)=0 or Start="" Then Start=999999999
	Start = cCur(Start)
	If Start = 0 Then Start=999999999

	Dim SQLCountString,whereFlag
	whereFlag = 1
	SQLendString = " where T1.UserID=" & GBL_ID

	SQLCountString = SQLendString
	If UpDownPageFlag = "1" and Start>0 then
		If whereFlag = 1 Then
			SQLendString = SQLendString & " and T1.ID>" & Start
		Else
			SQLendString = SQLendString & " where T1.ID>" & Start
			whereFlag = 1
		End If
	Else
		If whereFlag = 1 Then
			SQLendString = SQLendString & " and T1.ID<" & Start
		Else
			SQLendString = SQLendString & " where T1.ID<" & Start
			whereFlag = 1
		End If
	end If

	If UpDownPageFlag = "1" then
		SQLendString = SQLendString & " Order by T1.ID ASC"
	Else
		SQLendString = SQLendString & " Order by T1.ID DESC"
	End If
	
	Dim MaxRecordID,MinRecordID
	MaxRecordID = 0

	SQL = "select Max(T1.id) from LeadBBS_FriendUser as T1 " & SQLCountString
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	
	If not Rs.Eof Then
		If Rs(0) <> "" Then
			MaxRecordID = cCur(Rs(0))
		Else
			MaxRecordID = 0
		End If
	End If
	Rs.Close
	Set Rs = Nothing
	
	SQL = "select Min(T1.id) from LeadBBS_FriendUser as T1 " & SQLCountString
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1

	If not Rs.Eof Then
		If Rs(0) <> "" Then
			MinRecordID = cCur(Rs(0))
		else
			MinRecordID = 0
		end If
	End If

	Rs.Close
	Set Rs = Nothing

	Dim FirstID,LastID
	'Dim recordCount	
	'SQL = "select count(*) from LeadBBS_FriendUser as T1 " & SQLCountString
	'Set Rs = Con.ExeCute(SQL)
	'GBL_DBNum = GBL_DBNum + 1
	'if rs.eof then
	'	recordCount=0
	'else
	'	recordCount=rs(0)
	'	if recordCount="" or isNull(recordCount) or len(recordCount)<1 Then recordCount=0
	'End If
	'Rs.Close
	'Set Rs = Nothing

	SQL = "select TOP 16 T2.UserName,T2.Mail,T2.Sex,T2.LastDoingTime,T2.Userphoto,T2.FaceUrl,T2.FaceWidth,T2.FaceHeight,T1.ID from LeadBBS_FriendUser as T1 inner join LeadBBS_User as T2 on T1.FriendUserID=T2.ID " & SQLendString
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	Dim Num
	Dim GetData
	If Not rs.Eof Then
		GetData = Rs.GetRows(DEF_MaxListNum)
		Num = Ubound(GetData,2)
	Else
		Num = -1
	End If
	Rs.close
	Set Rs = Nothing
	
	
	Dim i,N
	If Num>=0 Then
		i=1
	
		Dim MinN,MaxN,StepValue
		SQL = ubound(getdata,2)
		If UpDownPageFlag = "1" then
			MinN = SQL
			MaxN = 0
			StepValue = -1
		Else
			MinN = 0
			MaxN = SQL
			StepValue = 1
		End If
		
		LastID = cCur(GetData(8,MaxN))
		FirstID = cCur(GetData(8,MinN))
	
		Dim EndwriteQueryString,PageSplictString
		EndwriteQueryString = "?ID=" & GBL_ID
		If key<>"" Then EndwriteQueryString = EndwriteQueryString & "&key=" & urlencode(key)
	
		PageSplictString = PageSplictString & "<img src=../images/null.gif width=2 height=2><br>&nbsp;"
		If FirstID >= MaxRecordID Then
			PageSplictString = PageSplictString & "<font color=999999 class=GrayFont>首页</font> " & VbCrLf
			PageSplictString = PageSplictString & " <font color=999999 class=GrayFont>上页</font> " & VbCrLf
		else
			PageSplictString = PageSplictString & "<a href=SelectFriend.asp" & EndwriteQueryString & "&Start=0>首页</a> " & VbCrLf
			PageSplictString = PageSplictString & " <a href=SelectFriend.asp" & EndwriteQueryString & "&Start=" & FirstID & "&UpDownPageFlag=1>上页</a> " & VbCrLf
		end if
	
		if LastID<MaxRecordID and LastID<>0 then
		else
		end if
	
		If LastID <= MinRecordID Then
			PageSplictString = PageSplictString & " <font color=999999 class=GrayFont>下页</font> " & VbCrLf
			PageSplictString = PageSplictString & " <font color=999999 class=GrayFont>尾页</font> " & VbCrLf
		else
			PageSplictString = PageSplictString & " <a href=SelectFriend.asp" & EndwriteQueryString & "&Start=" & LastID & ">下页</a> " & VbCrLf
			PageSplictString = PageSplictString & " <a href=SelectFriend.asp" & EndwriteQueryString & "&Start=1&UpDownPageFlag=1>尾页</a> " & VbCrLf
		end if
		
		'PageSplictString = PageSplictString & "共<b>" & recordCount & "</b>个好友"
	
	End If
	%>
	
	<script language=javascript>
		function kill(killID)
		{
			window.open('DelFriend.asp?BoardID=<%=GBL_board_ID%>&DelID='+killID,'','width=450,height=37,scrollbars=auto,status=no');
		}
		function killall(str)
		{
			window.open('DelFriend.asp?kasdie=3&ClearFlag='+str,'','width=450,height=37,scrollbars=auto,status=no');
		}
		function addfriend(id)
		{
			window.open('../announce/AddFriend.asp?BoardID=<%=GBL_board_ID%>&AddSureFlag=yes&FriendName='+id,'','width=450,height=37,scrollbars=auto,status=no');
		}
	</script>
	请点击名字选择好友
	<table width="100%" border="0" cellspacing="1" cellpadding="3" bordercolor="#000000" bgcolor="<%=DEF_BBS_DarkColor%>" class=TBone>
	  <tbody> 
	<%
	If Num = -1 Then
		response.write "<tr bgcolor=" & DEF_BBS_LightestColor & " class=TBBG9><td colspan=6 height=30>&nbsp; 没有任何好友!</td></tr>"
	end if

	Dim TempN,Temp,Temp1
	
	if Num <> -1 then
		i=1
		LastID = GetData(0,ubound(getdata,2))
		for n= MinN to MaxN Step StepValue
			Response.Write "<tr height=19 bgcolor=" & DEF_BBS_LightestColor & " class=TBBG9><td>"
			Response.Write "&nbsp;<a href=#1 onClick="&chr(34)&"MM_setTextOfTextfield('SdM_ToUser','','" & htmlencode(GetData(0,n)) & "')" & chr(34) & ">" & htmlencode(GetData(0,n)) & "</a>"
			Response.Write "</tr>" & VbCrLf
			i=i+1
		next
	End If
	Response.Write "<tr bgcolor=" & DEF_BBS_TableHeadColor & " class=TBfour><td colspan=6>" & PageSplictString
	Response.Write "</td></tr>"
	%>
	      </table><%

End Function
%>