<!--#include virtual="inc/conn.inc.asp"-->
<!--#include virtual="inc/CustomClass.inc.asp"-->
<!--#include virtual="inc/BBSFun_Pager.inc.asp"-->
<!--#include virtual="inc/MD5.inc.asp"-->
<%
' 功能描述:根据当前编号生成下一编号
function CreateAutoCode(lastcode)
	slength = len(lastcode)
	svalue = ""
	bvalue = 0
	for i=1 to slength
		ascvalue = asc(mid(lastcode,i,1))
		if (ascvalue >= 65 and ascvalue <= 90) or (ascvalue >= 97 and ascvalue <= 122) then
			bvalue = i
		end if
	next
	svalue = mid(lastcode,bvalue+1,slength-bvalue)
	if svalue="" then svalue="0"
	spacevalue = ""
	if len(svalue)-len(cint(svalue)+1) > 0 then
		spacevalue = replace(space(len(svalue)-len(cint(svalue)+1))," ","0")
	end if
	CreateAutoCode = ucase(mid(lastcode,1,bvalue) & spacevalue & cint(svalue)+1)
end function

'出错提示
function ErrorInfo (errMsg)
	Response.Write "<script language='javascript'>"
	Response.Write "alert('" & errMsg & "');"
	Response.Write "history.back();"
	Response.Write "</script>"
	Response.End
end function

function ErrorInfos (errMsg,goUrl)
	Response.Write "<script language='javascript'>"
	Response.Write "alert('" & errMsg & "');"
	Response.Write "document.location.href='" & goUrl & "';"
	Response.Write "</script>"
	Response.End
end function

function CommitInfo(comMsg)
	Response.Write("<script language=javascript>")
	Response.Write("alert('" & comMsg & "');")
	Response.Write("window.opener.location.reload();")
	Response.Write("window.close();")
	Response.Write("</script>")
end function

function AdjustString(strs)
	AdjustString = replace(replace(strs," ","&nbsp;"),chr(13),"<br>")
end function

function FormatHTMLContent(strs)
	FormatHTMLContent = replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(strs,"``",""""),"`","'"),"<XMP>",""),"</XMP>",""),"<TABLE align=center border=0 cellPadding=5 cellSpacing=2 style=""BORDER-BOTTOM: 0px; BORDER-LEFT: silver 4px double; BORDER-RIGHT: silver 4px double; BORDER-TOP: 0px"" width=750>","<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width='100%'>"),"85%","100%"),"80%","100%"),"<TABLE align=center border=0 cellPadding=5 cellSpacing=2 style=""BORDER-BOTTOM: silver 4px double; BORDER-LEFT: silver 4px double; BORDER-RIGHT: silver 4px double; BORDER-TOP: 0px"" width=750>","<TABLE align=center border=0 cellPadding=5 cellSpacing=2 width='100%'>"),"<TABLE style=""BORDER-RIGHT: silver 4px double; BORDER-TOP: 0px; BORDER-LEFT: silver 4px double; BORDER-BOTTOM: 0px"" cellSpacing=2 cellPadding=5 width=750 align=center border=0>","<TABLE cellSpacing=2 cellPadding=5 width=100% align=center border=0>"),"<HR noShade SIZE=1>","")
end function

'字符串所占像素
function GetLength(strS)
	result = 0
	for iIndex=1 to len(strS) step 1
		sIndex=mid(strS,iIndex,1)
		if asc(sIndex) < 0 or asc(sIndex) > 255 then
			result = result + 14
		elseif asc(sIndex) >= 97 and asc(sIndex)<=113 then
			result = result + 11
		else
			result = result + 7
		end if
	next
	GetLength = result
end function

function GetLengthString(strs,lens)
	if isnull(strs) or strs="" then
		GetLengthString = ""
	else
	result = ""
	iLen = 0
	for iIndex=1 to len(strS) step 1
		sIndex=mid(strS,iIndex,1)
		if asc(sIndex) < 0 or asc(sIndex) > 255 then
			iLen = iLen + 14
		elseif asc(sIndex) >= 97 and asc(sIndex)<=113 then
			iLen = iLen + 11
		else
			iLen = iLen + 7
		end if
		if iLen <= lens then result = result & sIndex
	next
	GetLengthString = result
	end if
end function

function ShowPicture(strn,w,h,sss)
	on error resume next
	if strn="" then
		ShowPicture=""
	else
	set qswh=new qswhImg
	arr = qswh.getImageSize(server.mappath(strn))
	set fso = server.createobject("scripting.filesystemobject")
	if fso.fileexists(server.mappath(strn)) and (isnull(arr(0)) or arr(0)="") then
		arr(0)=fso.GetExtensionName(fso.getfile(server.mappath(strn)))
	end if
	if arr(1)="" or arr(1)=0 then arr(1)=w
	if arr(2)="" or arr(2)=0 then arr(2)=h
	if w=0 and h=0 then
		w = arr(1)
		h = arr(2)
	elseif w=0 and h<>0 then
		w = arr(1)
	elseif w<>0 and h=0 then
		h = arr(2)
	end if
	if arr(1)>w then
		arr(2) = arr(2) * w \ arr(1)
		arr(1) = w
	end if
	if arr(2)>h then
		arr(1) = arr(1) * h \ arr(2)
		arr(2) = h
	end if
	select case lcase(arr(0))
		case "swf":
			ShowPicture="<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' WIDTH='" & arr(1) & "' HEIGHT='" & arr(2) & "'><PARAM NAME=movie VALUE='" & strn & "'> <PARAM NAME=quality VALUE=high><EMBED src='" & strn & "' quality=high WIDTH='" & arr(1) & "' HEIGHT='" & arr(2) & "' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></EMBED></OBJECT>"
		case "jpg","gif","png","jpeg","bmp":
			ShowPicture = "<img src='" & strn & "' alt='' border='0' width='" & arr(1) & "' height='" & arr(2) & "' " & sss & ">"
		case "swf":
			ShowPicture = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' WIDTH='220' HEIGHT='70'><PARAM NAME=movie VALUE='/images/logo/logo2.swf'> <PARAM NAME=quality VALUE=high><EMBED src='/images/logo/logo2.swf' quality=high WIDTH='220' HEIGHT='70' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></EMBED></OBJECT>"
		case else:
			ShowPicture = "<img src='' width='" & arr(1) & "' height='" & arr(2) & "' alt='' border='0'>"
	end select
	end if
	set qswh = nothing
end function

function GetSomeFieldByField(tablename,field1,value,field2)
	on error resume next
	set temprs = server.createobject("adodb.recordset")
	temprs.open "select " & field2 & " from " & tablename & " where " & field1 & "='" & value & "'",conn,1,1
	if errors.count > 0 then temprs.open "select " & field2 & " from " & tablename & " where " & field1 & "=" & value,conn,1,1
	if not temprs.eof then
		GetSomeFieldByField = temprs(field2)
	else
		GetSomeFieldByField = ""
	end if
	temprs.close
	set temprs = nothing
end function

function CheckManageUser()
	manageflag = Request.Cookies("ManageFlag")
	userid = Request.Cookies("UserID")
	if manageflag & "" <> "1" then
		Response.Redirect "/manage/login.asp"
		CheckManageUser = false
	elseif userid&"" = "" or userid&"" = "0" then
		Response.Redirect "/manage/login.asp"
		CheckManageUser = false
	else
		set rs_cmu=server.createobject("adodb.recordset")
		rs_cmu.open "select * from manage where userid=" & userid & " and isstop=0",conn,1,1
		if not rs_cmu.eof then
			CheckManageUser = true
		else
			ErrorInfos "你不是管理员！","/manage/login.asp"
			CheckManageUser = false
		end if
	end if
end function

function AddToCart(tablename,key,id)
	strCart = Request.Cookies("Joyes_ShopCart")&""
	strCount = Request.Cookies("Joyes_ShopCount")&""
	if strCart&""="" then
		Response.Cookies("Joyes_ShopCart") = id & ","
		Response.Cookies("Joyes_ShopCount") = "1,"
	elseif instr(strCart,id&",")<1 then
		set rs_temp = server.createobject("adodb.recordset")
		rs_temp.open "select " & key & " from " & tablename & " where " & key & "='" & id & "'",conn,1,1
		if not rs_temp.eof then
			Response.Cookies("Joyes_ShopCart") = strCart & id & ","
			Response.Cookies("Joyes_ShopCount") = strCount & "1,"
		end if
		rs_temp.close
		set rs_temp = nothing
	end if
end function

function GetCartMoney()
	strCart = Request.Cookies("Joyes_ShopCart")&""
	strCount = Request.Cookies("Joyes_ShopCount")&""
	temp_Money = 0
	if strCart&""<>"" and strCount&""<>"" then
		if left(strCart,1)="," then strCart = right(strCart,len(strCart)-1)
		if right(strCart,1)="," then strCart = left(strCart,len(strCart)-1)
		if left(strCount,1)="," then strCount = right(strCount,len(strCount)-1)
		if right(strCount,1)="," then strCount = left(strCount,len(strCount)-1)
		set rs_temp = server.createobject("adodb.recordset")
		for temp_index=0 to ubound(split(strCart,","))
			if split(strCart,",")(temp_index)&""<>"" then
				rs_temp.open "select isnull(joyesprice,0) from mobile where mobileid='" & split(strCart,",")(temp_index) & "'",conn,1,1
				if not rs_temp.eof then
					temp_Money = temp_Money + cdbl(rs_temp(0)) * cint("0"&split(strCount,",")(temp_index))
				end if
				rs_temp.cancel:rs_temp.close
			end if
		next
		set rs_temp = nothing
		GetCartMoney = temp_Money
	else
		GetCartMoney=0
	end if
end function

function GetCartCount()
	strCount = Request.Cookies("Joyes_ShopCount")&""
	temp_Money = 0
	if strCount&""<>"" then
		if left(strCount,1)="," then strCount = right(strCount,len(strCount)-1)
		if right(strCount,1)="," then strCount = left(strCount,len(strCount)-1)
		for temp_index=0 to ubound(split(strCount,","))
			temp_Money = temp_Money + cint("0"&split(strCount,",")(temp_index))
		next
		GetCartCount = temp_Money
	else
		GetCartCount=0
	end if
end function

function DecimalToUpper(num)
	num = FormatNumber(num,2)
	Dim numList
	Dim rmbList
	Dim numLen
	Dim numChar
	Dim numstr
	Dim n
	Dim n1, n2
	Dim hz
	numList = "零壹贰叁肆伍陆柒捌玖"
	rmbList = "分角元拾佰仟万拾佰仟亿拾佰仟万"
	If num > 9999999999999.99 Then
		DecimalToUpper = "超出范围的人民币值"
		Exit function
	End If
	numstr = CStr(num * 100)
	numLen = Len(numstr)
	n = 1
	Do While n <= numLen
		numChar = CInt(Mid(numstr, n, 1))
		n1 = Mid(numList, numChar + 1, 1)
		n2 = Mid(rmbList, numLen - n + 1, 1)
		If Not n1 = "零" Then
			hz = hz + CStr(n1) + CStr(n2)
		Else
			If n2 = "亿" Or n2 = "万" Or n2 = "元" Or n1 = "零" Then
				Do While Right(hz, 1) = "零"
					hz = Left(hz, Len(hz) - 1)
				Loop
			End If
			If (n2 = "亿" Or (n2 = "万" And Right(hz, 1) <> "亿") Or n2 = "元") Then
				hz = hz + CStr(n2)
			Else
				If Left(Right(hz, 2), 1) = "零" Or Right(hz, 1) <> "亿" Then
					hz = hz + n1
				End If
			End If
		End If
		n = n + 1
	Loop
	Do While Right(hz, 1) = "零"
		hz = Left(hz, Len(hz) - 1)
	Loop
	If Right(hz, 1) = "元" Then
		hz = hz + "整"
	End If
	DecimalToUpper = hz
End function

function CreateMenu()
	set cmrs = server.createobject("adodb.recordset")
	cmrs.open "select * from Menu where isstop=0 order by MenuCode",conn,1,1
	strTable = "var MenuItem = new Array();" & chr(13) & chr(13)
	strTable = strTable & "function menuItem(code,text)" & chr(13)
	strTable = strTable & "{" & chr(13)
	strTable = strTable & "	this.Code = code;" & chr(13)
	strTable = strTable & "	this.Text = text;" & chr(13)
	strTable = strTable & "}" & chr(13) & chr(13)
	strTable = strTable & "var menuItemIndex = 0;" & chr(13) & chr(13)
	lastCode = ""
	while not cmrs.eof
		strTable = strTable & "MenuItem[menuItemIndex++] = new menuItem(""" & cmrs("MenuCode") & """,""" & cmrs("MenuName") & """);" & chr(13)
		lastCode = cmrs("MenuCode")
		cmrs.movenext
	wend
	set fso = server.createobject("scripting.filesystemobject")
	if fso.fileexists(server.mappath("/js/Menu.js"))=false then fso.CreateTextFile server.mappath("/js/Menu.js"),true
	set file = fso.opentextfile(server.mappath("/js/Menu.js"),2)
	file.write strTable
	file.Close
	set file = nothing
	set fso = nothing
	cmrs.close
	set cmrs = nothing
end function

function GetAddressByCode(code)
	if code&""="" or len(code&"")<2 then
		GetAddressByCode=""
		exit function
	end if
	set rstemp = server.createobject("adodb.recordset")
	my_i_index = 2
	strResult = ""
	do while my_i_index<len(code)
		tempcode = left(code,my_i_index)
		rstemp.open "select * from Menu where MenuCode='" & tempcode & "' and IsStop=0",conn,1,1
		if not rstemp.eof then
			strResult = strResult & " &gt; <a href='/Content/list.asp?code=" & rstemp("MenuCode") & "' class=a>" & rstemp("MenuName") & "</a>"
		end if
		rstemp.cancel:rstemp.close
		my_i_index = my_i_index + 2
	loop
	set rstemp = nothing
	GetAddressByCode = strResult
end function
%>