<%@ Page Language="vb" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="TourEx.Bll" %>

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim N As String = FilterStr(Request.QueryString("N")).ToLower
        Dim ThisID As Integer = Val(Request.QueryString("ID"))
        Dim Dt As DataTable = WebCache.Category.Read(N)
        Dim OneCategoryName As String = ",linkcategory,helpcategory,linetopics,hotelbrand,hotelcategory,city,"
        If InStr(OneCategoryName, "," & N & ",") > 0 Then
            Response.Write("<select>")
            For i As Integer = 0 To Dt.Rows.Count - 1
                Response.Write("<option value=""" & Dt.Rows(i)("t_id") & """")
                If Dt.Rows(i)("t_id") = ThisID Then
                    Response.Write(" selected ")
                End If
                Response.Write(">" & Dt.Rows(i)("t_name") & "</option>")
            Next
            Response.Write("</select>")
            Dt.Dispose()
            Exit Sub
        End If
        If N = "template" Then
            Response.Write("<select>")
            For i As Integer = 0 To Dt.Rows.Count - 1
                Response.Write("<option value=""" & Dt.Rows(i)("t_id") & """ Folder=""" & Dt.Rows(i)("t_folder") & """")
                If Dt.Rows(i)("t_id") = ThisID Then
                    Response.Write(" selected ")
                End If
                Response.Write(">" & Dt.Rows(i)("t_name") & "</option>")
            Next
            Response.Write("</select>")
            Dt.Dispose()
            Exit Sub
        End If
        
        Dim P As UInteger = Val(Request.QueryString("P"))
        Dim Path, TempPath() As String
        Dim Dr As DataRow()
        If P = 2 Then
            Path = ","
            If ThisID > 0 Then
                Dr = Dt.Select("t_id=" & ThisID)
                If Dr.Length > 0 Then
                    Path = Dr(0)("t_path")
                End If
                Dr = Nothing
            End If
            TempPath = Split("0" & Path, ",")
            For i As Integer = 0 To UBound(TempPath) - 1
                Dr = Dt.Select("t_pid=" & TempPath(i))
                If Dr.Length > 0 Then
                    Response.Write("<select>")
                    For j As Integer = 0 To Dr.Length - 1
                        Response.Write("<option value=""" & Dr(j)("t_id") & """")
                        If Dr(j)("t_id") = Val(TempPath(i + 1)) Then
                            Response.Write(" selected ")
                        End If
                        Response.Write(">" & Dr(j)("t_name") & "</option>")
                    Next
                    Response.Write("</select>")
                End If
            Next
            Erase TempPath
        ElseIf P = 1 Then
            Dim Selected As Boolean
            Do
                Selected = False
                Dr = Dt.Select("t_pid=" & ThisID)
                ThisID = 0
                If Dr.Length > 0 Then
                    Response.Write("<select>")
                    For i As Integer = 0 To Dr.Length - 1
                        If Not Selected Then
                            Selected = True
                            If Dt.Select("t_pid=" & Dr(i)("t_id")).Length > 0 Then
                                ThisID = Dr(i)("t_id")
                            End If
                        End If
                        Response.Write("<option value=""" & Dr(i)("t_id") & """>" & Dr(i)("t_name") & "</option>")
                    Next
                    Response.Write("</select>")
                End If
            Loop While ThisID <> 0
        Else
            Dr = Dt.Select("t_pid=" & ThisID)
            If Dr.Length > 0 Then
                Response.Write("<select>")
                For i As Integer = 0 To Dr.Length - 1
                    Response.Write("<option value=""" & Dr(i)("t_id") & """>" & Dr(i)("t_name") & "</option>")
                Next
                Response.Write("</select>")
            End If
        End If
        Dr = Nothing
        Dt.Dispose()
    End Sub

</script>

