<!-- #include file="conn.asp" -->
<!-- #include file="cls_main.asp" -->
<!-- #include file="cls_md5.asp" -->
<%
	Dim Mesky
	Set Mesky = New cls_main
	Call Mesky.Loadsetting()
	dim arrPage,arrMainPage
	arrPage = Split(Mesky.ReadStylePage("Style_Down_Search"),"<!--|||-->")
	arrMainPage = Split(Mesky.ReadStylePage("Style_Down_Main"),"<!--|||-->")
	Response.Write(Replace(arrMainPage(0),"{$page_title}","用户注册"))
	Call RegJs()
	Response.Write(arrMainPage(1))
	Response.Write(arrMainPage(2))
	
	Select Case Request("Step")
	Case "1"
		call saveReg()
	Case Else
		Call regMain()
	End Select
	
	Response.Write(arrMainPage(5))
	
	Set Mesky = Nothing

Sub regJs()
	Response.Write "<style type=""text/css"">" & vbCrlf
	Response.Write "<!--" & vbCrlf
	Response.Write ".style1 {" & vbCrlf
	Response.Write "	color: blue;" & vbCrlf
	Response.Write "	font-weight: bold;" & vbCrlf
	Response.Write "}" & vbCrlf
	Response.Write "-->" & vbCrlf
	Response.Write "</style>" & vbCrlf
	Response.Write "<script language=""Javascript""><!--" & vbCrlf
	
	Response.Write "function checktext(text)" & vbCrlf
	Response.Write "{" & vbCrlf
	Response.Write "			allValid = false;" & vbCrlf
	Response.Write "		if (text.length < 2)" & vbCrlf
	Response.Write "		{" & vbCrlf
	Response.Write "    		allValid = true;" & vbCrlf
	Response.Write "		}" & vbCrlf
	Response.Write vbCrlf
	Response.Write "    	var notuser = ""〓＾＼１２３４５６７８９０～！＂＇·＃￥％……ˇ＠¨〈〉「」『』．‖々〃〔〕〖〗—（），。【】《》？；‘：“”［］｛｝—＋＝｜｀、《》~`!@#$%^&*()_+|-=\'?/<>{}[],.:;"";" & vbCrlf
	Response.Write vbCrlf
	Response.Write "		for (i = 0;  i < text.length;  i++)" & vbCrlf
	Response.Write "		{" & vbCrlf
	Response.Write "			for (j = 0;  j < notuser.length;  j++)" & vbCrlf
	Response.Write "			{" & vbCrlf
	Response.Write "              if (text.charAt(i) == notuser.charAt(j))" & vbCrlf
	Response.Write "              {" & vbCrlf
	Response.Write "				allValid = true;" & vbCrlf
	Response.Write "				break;" & vbCrlf
	Response.Write "              }" & vbCrlf
	Response.Write "			}" & vbCrlf
	Response.Write "			if (text.charAt(i) == "" "")" & vbCrlf
	Response.Write "			{" & vbCrlf
	Response.Write "				allValid = true;" & vbCrlf
	Response.Write "				break;" & vbCrlf
	Response.Write "			}" & vbCrlf
	Response.Write "		}" & vbCrlf
	Response.Write vbCrlf
	Response.Write "return allValid;" & vbCrlf
	Response.Write "}" & vbCrlf

	Response.Write "//测试用户名是否已经存在" & vbCrlf
	Response.Write "function testname_click() {" & vbCrlf
	Response.Write vbCrlf
	Response.Write "  if (UserReg.UserName.value == """")" & vbCrlf
	Response.Write "  {" & vbCrlf
	Response.Write "    alert(""请输入您的注册名!"");" & vbCrlf
	Response.Write "    UserReg.UserName.focus();" & vbCrlf
	Response.Write "    return false;" & vbCrlf
	Response.Write "  }" & vbCrlf
	Response.Write vbCrlf
	Response.Write "  if (!isNaN(UserReg.UserName.value)) {" & vbCrlf
	Response.Write "    alert(""不能注册全部为数字帐号!"");" & vbCrlf
	Response.Write "    UserReg.UserName.focus();" & vbCrlf
	Response.Write "    return false;" & vbCrlf
	Response.Write vbCrlf
	Response.Write "  }" & vbCrlf
	Response.Write vbCrlf
	Response.Write "  if (checktext(UserReg.UserName.value)){" & vbCrlf
	Response.Write "    alert(""注册名包含无效字符!"");" & vbCrlf
	Response.Write "    UserReg.UserName.focus();" & vbCrlf
	Response.Write "    return false;" & vbCrlf
	Response.Write "  }" & vbCrlf
	Response.Write vbCrlf
	Response.Write "	loginname=UserReg.UserName.value;" & vbCrlf
	Response.Write "	aheight=160;" & vbCrlf
	Response.Write "	awidth=380;" & vbCrlf
	Response.Write "	atop=(screen.height-aheight)/2;" & vbCrlf
	Response.Write "	aleft=(screen.width-awidth)/2;" & vbCrlf
	Response.Write "	window.open(""UserRegCheck.asp?UserName=""+loginname,""testregname"",""top=""+atop+"",left=""+aleft+"",width=""+awidth+"",height=""+aheight+"",resize=no,scrollbars=no"");" & vbCrlf
	Response.Write vbCrlf
	Response.Write "}" & vbCrlf

	Response.Write "function VF_UserReg(){ //v2.0" & vbCrlf
	Response.Write "<!--start_of_saved_settings-->" & vbCrlf
	Response.Write "<!--type,text,name,UserEmail,required,true,isEmail,errMsg,请正确填写邮箱地址。-->" & vbCrlf
	Response.Write "<!--type,text,name,UserQuesion,required,true,errMsg,请填写找回密码的安全问题。-->" & vbCrlf
	Response.Write "<!--type,password,name,Pswc,required,true,isEqualTo,Psw,errMsg,请正确输入确认密码。-->" & vbCrlf
	Response.Write "<!--type,password,name,Psw,required,true,errMsg,请输入密码，最少6个字符。-->" & vbCrlf
	Response.Write "<!--type,text,name,UserName,required,true,fLen,2,15,errMsg,请正确填写您的用户名。-->" & vbCrlf
	Response.Write "<!--end_of_saved_settings-->" & vbCrlf
	Response.Write "	var theForm = document.UserReg;" & vbCrlf
	Response.Write "	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;" & vbCrlf
	Response.Write "	var errMsg = """";" & vbCrlf
	Response.Write "	var setfocus = """";" & vbCrlf
	Response.Write vbCrlf
	Response.Write "	if (!emailRE.test(theForm['UserEmail'].value)){" & vbCrlf
	Response.Write "		errMsg = ""请正确填写邮箱地址。"";" & vbCrlf
	Response.Write "		setfocus = ""['UserEmail']"";" & vbCrlf
	Response.Write "	}" & vbCrlf
	Response.Write "	if (theForm['UserQuesion'].value == """"){" & vbCrlf
	Response.Write "		errMsg = ""请填写找回密码的安全问题。"";" & vbCrlf
	Response.Write "		setfocus = ""['UserQuesion']"";" & vbCrlf
	Response.Write "	}" & vbCrlf
	Response.Write "	if (theForm['Pswc'].value == """" || (theForm['Pswc'].value != theForm['Psw'].value)){" & vbCrlf
	Response.Write "		errMsg = ""请正确输入确认密码。"";" & vbCrlf
	Response.Write "		setfocus = ""['Pswc']"";" & vbCrlf
	Response.Write "	}" & vbCrlf
	Response.Write "	if (theForm['Psw'].value == """"){" & vbCrlf
	Response.Write "		errMsg = ""请输入密码，最少6个字符。"";" & vbCrlf
	Response.Write "		setfocus = ""['Psw']"";" & vbCrlf
	Response.Write "	}" & vbCrlf
	Response.Write "	if (theForm['UserName'].value.length < 2 || theForm['UserName'].value.length > 15){" & vbCrlf
	Response.Write "		errMsg = ""请正确填写您的用户名。"";" & vbCrlf
	Response.Write "		setfocus = ""['UserName']"";" & vbCrlf
	Response.Write "	}" & vbCrlf
	Response.Write "	if (checktext(theForm['UserName'].value)){" & vbCrlf
	Response.Write "		errMsg = ""用户名中包含非法字符，请正确填写您的用户名。"";" & vbCrlf
	Response.Write "		setfocus = ""['UserName']"";" & vbCrlf
	Response.Write "	}" & vbCrlf	
	Response.Write "	if (errMsg != """"){" & vbCrlf
	Response.Write "		alert(errMsg);" & vbCrlf
	Response.Write "		eval(""theForm"" + setfocus + "".focus()"");" & vbCrlf
	Response.Write "	}" & vbCrlf
	Response.Write "	else theForm.submit();" & vbCrlf
	Response.Write "}//-->" & vbCrlf
	Response.Write "</script>" & vbCrlf
End Sub
Sub saveReg()
    If Mesky.ChkPost = False Then
        Mesky.strMsg = "非法操作，不要从外部提交数据。"
        Call Mesky.SystemMsg
        Exit Sub
    End If
	dim founderr,num1,rndnum,UserName,UserEmail,Password,UserPassword,TruePassword,UserIM
	
	founderr = false
	TruePassword = Mesky.Createpass()
	UserIM = Trim(Request.Form("UserIM(0)")) & "|" & Trim(Request.Form("UserIM(1)")) & "|" & Trim(Request.Form("UserIM(2)")) & "|" & Trim(Request.Form("UserIM(3)")) & "|" & Trim(Request.Form("UserIM(4)")) & "|" & Trim(Request.Form("UserIM(5)")) & "|" & Trim(Request.Form("UserIM(6)")) & "|" & Trim(Request.Form("UserIM(7)"))

	If Request.form("UserName")="" or strLength(Request.form("UserName"))>Cint(Mesky.setting(46)) or strLength(Request.form("UserName"))<Cint(Mesky.setting(45)) Then
		founderr = True
		Mesky.strMsg = Mesky.strMsg & "<li>注册用户名长度限制为"&Mesky.setting(45)&"-"& Mesky.setting(46)&"个字符。"
	Else
		UserName = Mesky.checkStr(Trim(Request.Form("UserName")))
	End If
	
	If Instr(username,"=")>0 or Instr(username,"%")>0 or Instr(username,chr(32))>0 or Instr(username,"?")>0 or Instr(username,"&")>0 or Instr(username,";")>0 or Instr(username,",")>0 or Instr(username,"'")>0 or Instr(username,",")>0 or Instr(username,chr(34))>0 or Instr(username,chr(9))>0 or Instr(username,"")>0 or Instr(username,"$")>0 Then
		founderr = True
		Mesky.strMsg = Mesky.strMsg & "<li>您填写的用户名中包含非法字符，请返回刷新页面后重新输入。"
	End If
	
	If Cint(Mesky.setting(42))=1 then
		If Not Mesky.CodeIsTrue() Then
			founderr = True
			Mesky.strMsg = Mesky.strMsg & "<li>验证码校验失败，请返回刷新页面后再输入验证码。"
		End If
	End If
	
	If Cint(Mesky.setting(47))=1 Then
		Randomize
		Do While Len(rndnum)<8
		num1=CStr(Chr((57-48)*rnd+48))
		rndnum=rndnum&num1
		loop
		Password = rndnum
		UserPassword=md5(rndnum,32)
	Else
		If Request.form("psw")="" or len(Request.form("psw"))>10 or len(Request.form("psw"))<6 Then
			founderr = True
			Mesky.strMsg = Mesky.strMsg & "<li>输入的密码长度限制为 6-10 个字符，请返回刷新页面后重新输入。"
		Else
			Password=Request.form("psw")
			UserPassword=md5(Password,32)
		End If
		If Request.form("psw")<>Request.form("pswc") then
			founderr = True
			Mesky.strMsg = Mesky.strMsg & "<li>输入的密码与确认密码不相符合，请返回刷新页面后重新输入。"
		End If		
	End if
	
	If Trim(Request.Form("UserQuesion")) = "" then
		founderr = True
		Mesky.strMsg = Mesky.strMsg & "<li>安全提问不能为空，请返回刷新页面后重新输入。"
	End If
	
	If Trim(Request.Form("UserAnswer")) = "" then
		founderr = True
		Mesky.strMsg = Mesky.strMsg & "<li>回答问题的答案不能为空，请返回刷新页面后重新输入。"
	End If
	
	If IsValidEmail(Trim(Request.form("UserEmail")))=false Then
		founderr = True
		Mesky.strMsg = Mesky.strMsg & "<li>输入的邮箱地址格式无效，请返回刷新页面后重新输入。"
	Else
		UserEmail = Mesky.checkStr(Trim(Request.Form("UserEmail")))
	End If
	
	If founderr = True then
		call Mesky.SystemMsg()
		Exit Sub
	End If
	Dim Rs,sql
	If Not IsObject(Conn) Then ConnectionDatabase
	set rs=server.createobject("adodb.recordset")
	If Cint(Mesky.setting(48))=1 Then
		sql = "select * from Mesky_User where UserName='"&UserName&"' or UserEmail ='"&UserEmail&"'"
	Else
		sql = "select * from Mesky_User where UserName='"&UserName&"'"
	End If
	rs.open sql,conn,1,3
	If not rs.eof and not rs.bof Then
		Mesky.strMsg = "您所注册的用户名或者邮箱地址已经存在，请返回刷新页面后重新输入。"
		Call Mesky.SystemMsg()
		Rs.close
		Set Rs = nothing
		Exit Sub
	Else
		Rs.addnew
		Rs("UserName") = UserName 
		Rs("UserEmail") = UserEmail
		Rs("SubmitDownRes") = 0
		Rs("EmbodyDownRes") = 0
		Rs("DownCredited") = 0
		Rs("SubmitCmsRes") = 0
		Rs("EmbodyCmsRes") = 0
		Rs("CmsCredited") = 0
		Rs("CAPDateTime") = Now()
		Rs("UserPassword") = UserPassword  
		Rs("TruePassword") = TruePassword
		If Trim(Request.Form("UserSign"))<>"" then
			Rs("UserSign") = Request.Form("UserSign")
		End If
		Rs("UserSex") = Trim(Request.Form("UserSex"))
		Rs("JoinDate") = Now()
		Rs("UserLogins") = 0
		Rs("LastLogin") = Now()
		Rs("UserLastIP") = Request.ServerVariables("REMOTE_ADDR")
		If Mesky.setting(43) or Mesky.setting(44) then
			Rs("UserState") = 2
		Else
			Rs("UserState") = 1
		End If
		Rs("UserClass") = 0
		If Trim(Request.Form("UserBirthday"))<>"" then
			Rs("UserBirthday") = Trim(Request.Form("UserBirthday"))
		End If
		Rs("UserQuesion") = Trim(Request.Form("UserQuesion"))
		Rs("UserAnswer") = Md5(Trim(Request.Form("UserAnswer")),32)		
		Rs("UserIM") = UserIM
		Rs("UserViews") = 0
		Rs("VipType") = 0
		'Rs("startDate") = ""
		'Rs("endDate") = ""
		RS("Points") = 0
		If Cint(Mesky.setting(121)) = 1 then
			Rs("ftpstate") = 1
		Else
			Rs("ftpstate") = 0
		End if
		Rs.Update	
	End If
	Rs.Close
	Set Rs = Nothing
	If Mesky.setting(44) then
		Mesky.strMsg = "<li>恭喜你，注册成功。您的帐号通过管理员认证后才能真正成为正式注册用户。"
	Else
		Mesky.strMsg = "<li>恭喜你，注册成功。"
	End If
	if Mesky.setting(47) or Mesky.setting(49) then		
		dim MailBody
		MailBody = Replace(Mesky.setting(57),"{$username}",Trim(Request.Form("UserName")))
		MailBody = Replace(MailBody,"{$sitename}",Mesky.setting(0))
		MailBody = Replace(MailBody,"{$siteurl}",Mesky.setting(2))
		MailBody = Replace(MailBody,"{$password}",Trim(Request.Form("Psw")))
		MailBody = Replace(MailBody,"{$useremail}",Trim(Request.Form("UserEmail")))
		MailBody = Replace(MailBody,"{$userquesion}",Trim(Request.Form("userquesion")))
		MailBody = Replace(MailBody,"{$useranswer}",Trim(Request.Form("useranswer")))
		MailBody = Replace(MailBody,"{$copyright}","<div align=""center"">Powered by <a href=""http://Www.Mesky.Cn"" target=""_blank"" >美期卡网站下载管理系统 V3.0</a></div>"&Mesky.setting(7))
		If Mesky.setting(47) then
			Mesky.strMsg = Mesky.strMsg & "<li>您的帐号登录的密码由系统随机生成，将发送到您填写的邮箱中去，请查收。"
		End If
		if sendmail(Trim(Request.Form("UserEmail")),"test",MailBody) then
			Mesky.strMsg = Mesky.strMsg & "<li>您的注册信息（用户名、密码等）已经成功发送到你的邮箱，请查收。"
		Else
			Mesky.strMsg = Mesky.strMsg & "<li>发送注册信息邮件失败，请联系网站管理员。"
		End If
	End If	
	call Mesky.SystemMsg()
End Sub

Sub regMain() %>
<script language="JavaScript" src="js/MyUserinfo.js"></script>
<table width="770"  border="0" align="center" cellpadding="3" cellspacing="1">
<form action="" method="post" name="UserReg" onSubmit="VF_UserReg();return false;">
<input name="Step" type="hidden" value="1">
  <tr>
    <td height="25" colspan="3" align="center" background="images/menubg.gif"><font color=red>新用户注册</font></td>
  </tr>
  <tr>
    <td colspan="3" class="tdbg1">　<span class="style1">注册 - 必填内容</span></td>
  </tr>
  <tr class="tdbg2">
    <td width="20%" align="right">用户名：</td>
    <td><input name="UserName" type="text" id="UserName" size="35" maxlength="30"></td>
    <td width="50%"><input type="button" value="测试用户名" onClick="javascript:testname_click(this)" name="button" style="width:75;height:20;border:1 solid #CCCCCC; font-size:9pt; background-color:#DDDDDD" > 注册用户名长度限制为<%= Mesky.setting(45) %>－<%= Mesky.setting(46) %>字节</td>
  </tr>
  <tr class="tdbg2">
    <td width="20%" align="right">密 码：</td>
    <td><input name="Psw" type="password" size="35" maxlength="50"></td>
    <td width="50%">请输入密码，区分大小写。请尽量设得复杂一些，以防被人暴力猜解。</td>
  </tr>
  <tr class="tdbg2">
    <td width="20%" align="right">确认密码：</td>
    <td><input name="Pswc" type="password" size="35" maxlength="50"></td>
    <td width="50%">请再输一遍确认</td>
  </tr>
  <tr class="tdbg2">
    <td width="20%" align="right">安全提问：</td>
    <td><input name="UserQuesion" type="text" size="35" maxlength="50">
	<select onchange=document.UserReg.UserQuesion.value=this.value name=select> 
              <option value="" selected>快速选择提示问题</option> 
              <option value="我母亲的名字">母亲的名字</option>
              <option value="我爷爷的名字">爷爷的名字</option>
              <option value="我父亲出生的城市">父亲出生的城市</option>
              <option value="我其中一位老师的名字">您其中一位老师的名字</option>
              <option value="我个人计算机的型号">您个人计算机的型号</option>
              <option value="我最喜欢的餐馆名称">您最喜欢的餐馆名称</option>
              <option value="我家的宠物的名字">我家的宠物的名字</option> 
              <option value="我就读的第一所学校的名称">我就读的第一所学校的名称</option> 
              <option value="少年时代心目中的英雄是谁？">少年时代心目中的英雄是谁？</option> 
              <option value="我最喜欢的休闲运动是什么？">我最喜欢的休闲运动是什么？</option> 
              <option value="我最喜欢哪支运动队？">我最喜欢哪支运动队？</option> 
              <option value="我最喜欢的运动员是谁？">我最喜欢的运动员是谁？</option> 
              <option value="驾驶执照的最后四位数字">驾驶执照的最后四位数字</option>
      </select></td>
    <td width="50%">忘记密码的提示问题，最好设成别人不知道答案的问题，以防被人用找回密码功能窃取您的帐号。</td>
  </tr>
  <tr class="tdbg2">
    <td width="20%" align="right">回 答：</td>
    <td><input name="UserAnswer" type="text" id="UserAnswer" size="35" maxlength="50"></td>
    <td width="50%">忘记密码的提示问题答案，用于取回密码，
      请尽量设得复杂一些，以防被人用找回密码功能窃取您的帐号。</td>
  </tr>
  <tr class="tdbg2">
    <td width="20%" align="right">Email：</td>
    <td><input name="UserEmail" type="text" id="UserEmail" size="35" maxlength="50"></td>
    <td width="50%">请输入有效的邮件地址，以便我们可以及时和你联系。</td>
  </tr>
  <% If Mesky.setting(42) then %>
  <tr class="tdbg2">
    <td width="20%" align="right">验证码：</td>
    <td><% = Mesky.GetCode() %></td>
    <td width="50%"></td>
  </tr>
  <% End If %>
  <tr>
    <td colspan="3" class="tdbg1">　<span class="style1">注册 - 选填内容</span></td>
    </tr>
  <tr class="tdbg2">
    <td align="right">性 别：</td>
    <td><input type="radio" checked value="1" name="UserSex"><img src="images/icon_male.gif" align="absmiddle">男孩 
<input type="radio" value="0" name="UserSex"><img src="images/icon_female.gif" align="absmiddle">女孩</td>
    <td width="50%">&nbsp;</td>
  </tr>
  <tr class="tdbg2">
    <td align="right">生 日：</td>
    <td><input name="UserBirthday" type="text" id="UserBirthday" onfocus="show_cele_date(UserBirthday,'','',UserBirthday)" size="33" maxlength="12"></td>
    <td width="50%">如不想填写，请全部留空</td>
  </tr>
  <tr class="tdbg2">
    <td align="right">签 名：</td>
    <td><textarea name="UserSign" cols="33" rows="5" id="UserSign"></textarea></td>
    <td width="50%">&nbsp;</td>
  </tr>
    <tr class="tdbg2">
      <td align="right">个人主页：</td>
      <td><input name="UserIM(0)" type="text" size="33" maxlength="100"></td>
      <td width="50%">&nbsp;</td>
    </tr>
    <tr class="tdbg2">
      <td align="right">联系电话：</td>
      <td><input name="UserIM(1)" type="text" size="33" maxlength="50"></td>
      <td>&nbsp;</td>
    </tr>
    <tr class="tdbg2">
      <td align="right">QQ 号码：</td>
      <td><input name="UserIM(2)" type="text" size="33" maxlength="50"></td>
      <td width="50%">&nbsp;</td>
    </tr>
    <tr class="tdbg2">
      <td align="right">ICQ号码：</td>
      <td><input name="UserIM(3)" type="text" size="33" maxlength="50"></td>
      <td width="50%">&nbsp;</td>
    </tr>
    <tr class="tdbg2">
      <td align="right">MSN：</td>
      <td><input name="UserIM(4)" type="text" size="33" maxlength="50"></td>
      <td width="50%">&nbsp;</td>
    </tr>
    <tr class="tdbg2">
      <td align="right">AIM：</td>
      <td><input name="UserIM(5)" type="text" size="33" maxlength="50"></td>
      <td width="50%">&nbsp;</td>
    </tr>
    <tr class="tdbg2">
      <td align="right">Yahoo：</td>
      <td><input name="UserIM(6)" type="text" size="33" maxlength="50"></td>
      <td>&nbsp;</td>
    </tr>
    <tr class="tdbg2">
      <td align="right">UC：</td>
      <td><input name="UserIM(7)" type="text" size="33" maxlength="50"></td>
      <td width="50%">&nbsp;</td>
    </tr>
  <tr class="tdbg2">
    <td>&nbsp;</td>
    <td colspan="2"><input type="submit" name="Submit" value="看过并同意服务条款!确认注册"> <input type="reset" name="Submit" value=" 重 置 "></td>
    </tr>
</form>
</table>
<br>
<% End Sub
function IsValidEmail(email)

dim names, name, i, c

'Check for valid syntax in an email address.

IsValidEmail = true
names = Split(email, "@")
if UBound(names) <> 1 then
   IsValidEmail = false
   exit function
end if
for each name in names
   if Len(name) <= 0 then
     IsValidEmail = false
     exit function
   end if
   for i = 1 to Len(name)
     c = Lcase(Mid(name, i, 1))
     if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
       IsValidEmail = false
       exit function
     end if
   next
   if Left(name, 1) = "." or Right(name, 1) = "." then
      IsValidEmail = false
      exit function
   end if
next
if InStr(names(1), ".") <= 0 then
   IsValidEmail = false
   exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
   IsValidEmail = false
   exit function
end if
if InStr(email, "..") > 0 then
   IsValidEmail = false
end if

end function

function strLength(str)
       ON ERROR RESUME NEXT
       dim WINNT_CHINESE
       WINNT_CHINESE    = (len("论坛")=2)
       if WINNT_CHINESE then
          dim l,t,c
          dim i
          l=len(str)
          t=l
          for i=1 to l
             c=asc(mid(str,i,1))
             if c<0 then c=c+65536
             if c>255 then
                t=t+1
             end if
          next
          strLength=t
       else 
          strLength=len(str)
       end if
       if err.number<>0 then err.clear
end function

function cutStr(str,strlen)
	dim l,t,c
	l=len(str)
	t=0
	for i=1 to l
	c=Abs(Asc(Mid(str,i,1)))
	if c>255 then
	t=t+2
	else
	t=t+1
	end if
	if t>=strlen then
	cutStr=left(str,i)&"..."
	exit for
	else
	cutStr=str
	end if
	next
	cutStr=replace(cutStr,chr(10),"")
end function

Function sendmail(Email,Topic,Mailbody)
	sendmail = false
	On Error Resume Next
	If Mesky.setting(53) = 1 Then
		Dim JMail
		Set JMail = Server.CreateObject("JMail.Message")
		JMail.silent=true
		JMail.Logging = True
		JMail.Charset = "gb2312"
		If Not(Mesky.Setting(55) = "" Or Mesky.Setting(56) = "") Then
			JMail.MailServerUserName = Mesky.Setting(55) '您的邮件服务器登录名
			JMail.MailServerPassword = Mesky.Setting(56) '登录密码
		End If
		JMail.ContentType = "text/html"
		JMail.Priority = 1
		JMail.From = Mesky.setting(6)
		JMail.FromName = Mesky.setting(0)
		JMail.AddRecipient Email
		JMail.Subject = Topic
		JMail.Body = Mailbody
		JMail.Send (Mesky.Setting(54))
		Set JMail = Nothing
		sendmail = true
		If Err Then
			sendmail = false
		End if
		
	ElseIf Mesky.setting(53) = 2 Then	
		Dim ObjCDOMail
		Set ObjCDOMail = Server.CreateObject("CDONTS.NewMail")
		ObjCDOMail.From = Mesky.setting(6)
		ObjCDOMail.To = Email
		ObjCDOMail.Subject = Topic
		ObjCDOMail.BodyFormat = 0 
		ObjCDOMail.MailFormat = 0 
		ObjCDOMail.Body = Mailbody
		ObjCDOMail.Send
		Set ObjCDOMail = Nothing
		sendmail = true
		If Err Then
			sendmail = false
		End if
	ElseIf Mesky.setting(53) = 2 Then	
		Dim Mailer
		Set Mailer = Server.CreateObject("Persits.MailSender")
		Mailer.Charset = "gb2312"
		Mailer.IsHTML = True
		Mailer.username = Mesky.Setting(55)	'服务器上有效的用户名
		Mailer.password = Mesky.Setting(56)	'服务器上有效的密码
		Mailer.Priority = 1
		Mailer.Host = Mesky.Setting(54)
		Mailer.Port = 25 ' 该项可选.端口25是默认值
		Mailer.From = Mesky.setting(6)
		Mailer.FromName = Mesky.setting(0) ' 该项可选
		Mailer.AddAddress Email,Email
		Mailer.Subject = Topic
		Mailer.Body = Mailbody
		Mailer.Send
		sendmail = true
		If Err Then
			sendmail = false
		End if
		Set Mailer = nothing
	End If
End Function
 %>
