<%
dim keyword,sea_type,sea_term,sql_tmp
sql_tmp=""

sub format_search(stype_1,stypes,sqlt,st)
  keyword=code_search(request.querystring("keyword"))
  if keyword<>"" then
    sea_type=trim(request.querystring("sea_type"))
    sea_term=trim(request.querystring("sea_term"))
    if instr(","&stypes&",",","&sea_type&",")<1 then sea_type=stype_1
    if sea_term<>"all" then sea_term="only"
    sql_tmp=sql_key(keyword,sea_type,sqlt,sea_term)
    if sql_tmp<>"" then pageurl=pageurl&"sea_type="&sea_type&"&sea_term="&sea_term&"&keyword="&server.urlencode(keyword)&"&"
  end if
  if st=1 and sql_tmp<>"" then
    if sql_add="" then
      sql_add=" where "&sql_tmp
    else
      sql_add=sql_add&" and "&sql_tmp
    end if
  end if
end sub

function code_search(strers)
  dim strer
  strer=trim(strers)
  if isnull(strer) or strer="" then
    code_search=""
    exit function
  end if
  strer=replace(strer,"'","")
  code_search=strer
end function

function sql_key(keyes,fields,kt,kterm)
  if var_null(keyes)="" or var_null(fields)="" then
    sql_key=""
    exit function
  end if
  dim ddim,dnum,di,spvar,termvar
  spvar=","
  termvar="or"
  if kt=2 then spvar=" "
  if kterm="all" then termvar="and"
  keyes=replace(keyes,"'","")
  ddim=split(keyes,spvar)
  dnum=ubound(ddim)
  sql_key="("&fields&" like '%"&ddim(0)&"%'"
  for di=1 to dnum
    sql_key=sql_key&" "&termvar&" "&fields&" like '%"&ddim(di)&"%'"
  next
  erase ddim
  sql_key=sql_key&")"
end function
%>