<%

function apart_filename(pvar,pt,pf)
  if pvar="" then
    apart_filename=""
    exit function
  end if
  dim tvar,ti
  ti=instrrev(pvar,pf)
  tvar=right(pvar,len(pvar)-ti)
  if instr(tvar,".")>0 then
    select case pt
    case 1
      ti=instrrev(tvar,".")
      tvar=left(tvar,ti-1)
    case 2
      ti=instrrev(tvar,".")
      tvar=right(tvar,len(tvar)-ti)
    end select
  end if
  apart_filename=tvar
end function

function encode_url(cvar)
  if var_null(cvar)="" then
    encode_url=""
    exit function
  end if
  dim j,k,urlh,temp1,temp2,fname,ftype,t_dim,t_num
  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
  t_dim=split(temp1,"/")
  t_num=ubound(t_dim)
  if k=1 then temp2=t_dim(0)
  for j=k to t_num-1
    temp2=temp2&"/"&server.urlencode(t_dim(j))
  next
  if int(instr(1,t_dim(t_num),"."))>0 then
    ftype=apart_filename(t_dim(t_num),1,".")
    fname=left(t_dim(t_num),len(t_dim(t_num))-(len(ftype)+1))
    fname=server.urlencode(fname)&"."&ftype
  end if
  erase t_dim
  temp2=temp2&"/"&fname
  if left(temp2,1)="/" then temp2=right(temp2,len(temp2)-1)
  encode_url=urlh&temp2
end function

%>