<!-- #include file="format.asp" -->
<!-- #include file="jk_encrypt.asp" -->
<%
function first_id(ndata)
  dim rsf
  set rsf=conn.execute("select top 1 id from "&ndata&" order by id desc")
  first_id=rsf("id")
  rsf.close:set rsf=nothing
end function

function first_ids(ndata,id)
  dim rsf
  set rsf=conn.execute("select top 1 "&id&" from "&ndata&" order by "&id&" desc")
  first_ids=rsf(id)
  rsf.close:set rsf=nothing
end function

'-------------------------------------Cookies---------------------------------------
sub cookies_type(ct)
  response.cookies(web_cookies)("time_load")=DateAdd("s",-5,now_time)
  response.cookies(web_cookies)("old_url")=request.servervariables("http_referer")
  response.cookies(web_cookies)("error_action")=ct
  call cookies_yes()
  call format_redirect("error.asp")
  response.end
end sub

sub cookies_yes()
  if request.cookies(web_cookies)("iscookies")="yes" then
    response.cookies(web_cookies).expires=date+365
  end if
end sub

sub format_redirect(fr)
  if isobject(objv7) then set objv7=nothing
  response.clear
  response.redirect fr
  'server.transfer fr
  response.end
end sub

'------------------------------------time_load--------------------------------------
sub time_load(tt)
  if tt=0 then
    response.cookies(web_cookies)("time_load")=now_time
    call cookies_yes():exit sub
  end if
  dim tims,vars,tts
  tims=int(objv7.web_var(web_num,16))
  if login_mode=objv7.format_power2(user_power,1,1) then tims=-1
  vars=objv7.time_type(request.cookies(web_cookies)("time_load"),9)
  if vars="" or not(isdate(vars)) then exit sub
  tts=int(DateDiff("s",vars,now_time))
  if tts<=tims then
    call cookies_type("time_load")
    response.end
  end if
end sub

'-----------------------------------power minus----------------------------------
function power_minus(mvars)
  dim mvar:mvar=mvars
  if not(isnumeric(mvar)) then power_minus=0:exit function
  select case login_mode
  case objv7.format_power2(user_power,1,1)
    mvar=0
  case objv7.format_power2(user_power,2,1)
    mvar=mvar-2
  end select
  if int(mvar)<0 then mvar=0
  power_minus=mvar
end function

'------------------------------------integral------------------------------------
sub integral_del(emm,url)
  if int(login_integral)<int(emm) then
%><script language=javascript>
alert("您没有足够的积分进行刚才的操作！\n\n点击返回……");
location.href='<%response.write url%>';
</script><%
    response.end
  end if
  if int(emm)>0 then
    conn.execute("update user_data set integral=integral-"&emm&" where username='"&login_username&"'")
  end if
end sub

'----------------------------------power integral---------------------------------
sub integral_notei(emoney,n_sort,iid,err_type,rss,conns,url)
  dim temp1:temp1=integral_note(emoney,n_sort,iid)
  if temp1<>"yes" then
    if int(rss)=1 then rs.close:set rs=nothing
    if int(conns)=1 then call close_conn()
    select case err_type
    case "error"
      call cookies_type("power")
    case "js"
%><script language=javascript>
alert("您没有足够的权限或钱币进行刚才的操作！\n\n点击返回……");
location.href='<%response.write url%>';
</script><%
      response.end
    end select
  end if
end sub

function integral_note(emoney,n_sort,iid)
  dim userp,sql,rs,notess:notess="no"
  if login_mode="" and int(emoney)>0 then notess="no"
  if notess="yes" then
    set rs=conn.execute("select id from notei where username='"&login_username&"' and nsort='"&n_sort&"' and iid="&iid)
    if rs.eof and rs.bof then notess="no2"
    rs.close:set rs=nothing
  end if
  if notess="no2" then
    if int(emoney)=0 then
      notess="yes"
    elseif int(emoney)>0 and int(login_emoney)>=int(emoney) then
      conn.execute("update user_data set emoney=emoney-"&emoney&" where username='"&login_username&"'")
      conn.execute("insert into notes(username,nsort,iid,integral,tim) values('"&login_username&"','"&n_sort&"',"&iid&","&emoney&",'"&now_time&"')")
      login_integral=login_integral-emoney:notess="yes"
    end if
  end if
  emoney_note=notess
end function

'----------------------------------power emoney----------------------------------
sub emoney_notes(power,emoney,n_sort,iid,err_type,rss,conns,url)
  dim temp1:temp1=emoney_note(power,emoney,n_sort,iid)
  if temp1<>"yes" then
    if int(rss)=1 then rs.close:set rs=nothing
    if int(conns)=1 then call close_conn()
    select case err_type
    case "error"
      call cookies_type("power")
    case "js"
%><script language=javascript>
alert("您不够电影币了或者你的级别不能观看该电影！");
location.href='<%response.write url%>';
</script><%
      response.end
    end select
  end if
end sub

function emoney_note(power,emoney,n_sort,iid)
  dim userp,sql,rs,notess:notess="no"
  if len(power)>0 then
    userp=objv7.format_power(user_power,login_mode,2)
    if not(isnumeric(userp)) then userp=0
    userp=int(userp)
    if userp=0 then login_emoney=0
    if instr(1,"."&power&".","."&userp&".")>0 then notess="yes"
  end if
  if login_mode="" and int(emoney)>0 then notess="no"
  if notess="yes" then
    set rs=conn.execute("select id from notes where username='"&login_username&"' and nsort='"&n_sort&"' and iid="&iid)
    if rs.eof and rs.bof then notess="no2"
    rs.close:set rs=nothing
  end if
  if notess="no2" then
    if int(emoney)=0 then
      notess="yes"
    elseif int(emoney)>0 and int(login_emoney)>=int(emoney) then

    if objv7.format_power(user_power,login_mode,0)="gold" then
      conn.execute("insert into notes(username,nsort,iid,emoney,tim) values('"&login_username&"','"&n_sort&"',"&iid&",0,'"&now_time&"')")
    elseif objv7.format_power(user_power,login_mode,0)="vip" then
      conn.execute("update user_data set emoney=emoney-"&emoney&" where username='"&login_username&"'")
      conn.execute("insert into notes(username,nsort,iid,emoney,tim) values('"&login_username&"','"&n_sort&"',"&iid&","&emoney&",'"&now_time&"')") 
    elseif objv7.format_power(user_power,login_mode,0)="admin" then
      conn.execute("insert into notes(username,nsort,iid,emoney,tim) values('"&login_username&"','"&n_sort&"',"&iid&",0,'"&now_time&"')")
    else
      conn.execute("update user_data set emoney=emoney-"&emoney&" where username='"&login_username&"'")
      conn.execute("insert into notes(username,nsort,iid,emoney,tim) values('"&login_username&"','"&n_sort&"',"&iid&","&emoney&",'"&now_time&"')")
    end if
      login_emoney=login_emoney-emoney:notess="yes"
    end if
  end if
  emoney_note=notess
end function

function user_star(u_s,u_p,u_t)
  dim tempp,tempn,ui,sdim,sn,u1,u2,uu
  tempp="":tempn="":u_s=int(u_s):u_t=int(u_t)
  select case u_p
  case objv7.format_power2(user_power,1,1)
    user_star=objv7.format_power2(user_power,1,u_t):exit function
  case objv7.format_power2(user_power,2,1)
    user_star=objv7.format_power2(user_power,2,u_t):exit function
  case objv7.format_power2(user_power,3,1)
    tempp="p"
  end select
  sdim=split(user_grade,"|"):sn=ubound(sdim)
  for ui=0 to sn
    u1=int(left(sdim(ui),instr(sdim(ui),":")-1))
    select case ui
    case 0
      u1=int(left(sdim(ui+1),instr(sdim(ui+1),":")-1))
      if u_s<u1 then
        uu=ui:exit for
      elseif u_s=u1 then
        uu=ui+1:exit for
      end if
    case sn
      response.write u_s&"-"&u1
      if u_s>=u1 then uu=ui:exit for
    case else
      u2=int(left(sdim(ui+1),instr(sdim(ui+1),":")-1))
      if u_s>=u1 and u_s<u2 then uu=ui:exit for
    end select
  next
  if u_t=2 then
    tempp=right(sdim(uu),len(sdim(uu))-instr(sdim(uu),":"))
  else
    tempp=tempp&uu
  end if
  erase sdim:user_star=tempp
end function

'-------------------------------------地址处理--------------------------------------
function filename_apart(fname,ft)
  if int(instr(1,fname,ft))>0 then
    filename_apart=right(fname,(len(fname)-Instr(fname,ft)))
  end if
  if instr(1,filename_apart,ft)>0 then filename_apart=filename_apart(filename_apart,ft)
end function

function encode_url(cvar)
  if var_null(cvar)="" then encode_url="":exit function
  dim j,k,urlh,temp1,temp2,fname,ftype,ddim,dnum
  k=0:urlh="":temp2="":temp1=cvar
  j=instr(1,cvar,"://")
  if int(j)>0 then
    k=1
    urlh=left(cvar,j+2)
    temp1=right(cvar,len(cvar)-(j+2))
  end if
  ddim=split(temp1,"/")
  dnum=ubound(ddim)
  if k=1 then temp2=ddim(0)
  for j=k to dnum-1
    temp2=temp2&"/"&server.urlencode(ddim(j))
  next
  if int(instr(1,ddim(dnum),"."))>0 then
    ftype=filename_apart(ddim(dnum),".")
    fname=left(ddim(dnum),len(ddim(dnum))-(len(ftype)+1))
    fname=server.urlencode(fname)&"."&ftype
  end if
  erase ddim
  temp2=temp2&"/"&fname
  if left(temp2,1)="/" then temp2=right(temp2,len(temp2)-1)
  encode_url=urlh&temp2
end function

'--------------------------判断用户名、代号和密码的合法性--------------------------
function symbol_name(sn_var)
  dim safety_char:symbol_name="yes":sn_var=trim(sn_var)
  if sn_var="" or isnull(sn_var) or len(sn_var)>20 or instr(sn_var,"|")>0 or instr(sn_var,":")>0 or instr(sn_var,chr(9))>0 or instr(sn_var,chr(32))>0 or instr(sn_var,"'")>0 or instr(sn_var,"""")>0 then symbol_name="no":exit function
  safety_char=objv7.web_var(web_safety,1)
  for i=1 to len(sn_var)
    if instr(1,safety_char,mid(sn_var,i,1))>0 then symbol_name="no":exit function
  next
end function

function symbol_ok(symbol_var)
  dim safety_char:symbol_ok="yes":symbol_var=trim(symbol_var)
  if symbol_var="" or isnull(symbol_var) or len(symbol_var)>20 then symbol_ok="no":exit function
  safety_char=objv7.web_var(web_safety,2)
  for i=1 to len(symbol_var)
    if instr(1,safety_char,mid(symbol_var,i,1))=0 then symbol_ok="no":exit function
  next
end function
'-------------------------------------字符处理--------------------------------------
function health_name(hnn)
  health_name="yes":dim ti,tnum,tdim,hn
  hn=hnn:tdim=split(objv7.web_var(web_safety,3),":"):tnum=ubound(tdim)
  for ti=0 to tnum
    if instr(hn,tdim(ti))>0 then health_name="no":erase tdim:exit function
  next
  erase tdim
  tdim=split(objv7.web_var(web_safety,4),":"):tnum=ubound(tdim)
  for ti=0 to tnum
    if instr(hn,tdim(ti))>0 then health_name="no":erase tdim:exit function
  next
  erase tdim
end function

function health_var(hnn,vt)
  dim ti,tj,tdim,ht,hn:hn=hnn
  if int(mid(web_setup,4,1))=1 and vt=1 then
    tdim=split(objv7.web_var(web_safety,4),":")
    for ti=0 to ubound(tdim)
      ht=""
      for tj=1 to len(tdim(ti))
        ht=ht&"*"
      next
      hn=replace(hn,tdim(ti),ht)
    next
    erase tdim
  end if
  health_var=hn
end function

'-------------------------------------错误信息--------------------------------------
function found_error(error_type,error_len)
  if error_len>600 or error_len<200 then error_len=300
  found_error=error_type
  found_error=replace(found_error,"+",img_small("jt0"))
  found_error=VbCrLf & "<table border=0 width=" & error_len & "><tr><td align=center height=50><font class=red>系统发现你输入的数据有以下错误：</font></td></tr><tr><td class=htd>" & found_error & "</td></tr><!--390970--><tr><td align=center height=50>" & go_back & "</td></tr></table>"
end function
%>