<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="FormPicker.ascx.vb" Inherits="WebFoundations.WFForms.UI.FormPicker" %>
<%@ Register Assembly="WebFoundations.WFPortal.UI" Namespace="WebFoundations.WFPortal.UI" TagPrefix="LST" %>
<script src="/WFServices/WFForms/FormPickerService.asmx/js"></script>
<script type="text/javascript">
    function GetAreaList<%:Me.id%>() 
    {
        var e = document.getElementById('<%:lstportal.ClientID%>');
        if (e.options[e.selectedIndex]) {
            var strPortalId = e.options[e.selectedIndex].value;
            WebFoundations.WFForms.UI.FormPickerService.ListAreas(strPortalId, AreaListSuccessCallback<%:Me.id%>, ListFailedCallback<%:Me.id%>);
        }
    }

    function AreaListSuccessCallback<%:Me.id%>(result) 
    {
        var e = document.getElementById('<%:lstarea.ClientID%>');
        EmptyAreaList<%:Me.id%>();
        EmptyFormsList<%:Me.id%>();
        for (var i = 0; i < result.length; i++) {
            var option = document.createElement('option');
            option.text = result[i].Name;
            option.value = result[i].Id;
            e.add(option, i + 1);
        }
        e.selectedIndex = 0;
        e.focus();
    }

    function ListFailedCallback<%:Me.id%>(errors) 
    {
        alert(errors.get_message());
    }

    function GetFormsList<%:Me.id%>() {
        var e = document.getElementById('<%:lstarea.ClientID%>');
        if (e.options[e.selectedIndex]) {
            var strAreaId = e.options[e.selectedIndex].value;
            WebFoundations.WFForms.UI.FormPickerService.ListForms(strAreaId, FormsListSuccessCallback<%:Me.id%>, ListFailedCallback<%:Me.id%>);
        }
    }

    function FormsListSuccessCallback<%:Me.id%>(result) {
        var e = document.getElementById('<%:lstform.ClientID%>');
        EmptyFormsList<%:Me.id%>();
        for (var i = 0; i < result.length; i++) {
            var option = document.createElement('option');
            option.text = result[i].Name;
            option.value = result[i].Id;
            e.add(option, i + 1);
        }
        e.selectedIndex = 0;
        e.focus();
    }

    function EmptyAreaList<%:Me.id%>(){
        var e = document.getElementById('<%:lstarea.ClientID%>');
        var length = e.options.length;
        var i;
        for (i = e.options.length - 1; i >= 0; i--) {
            e.remove(i);
        }
        var option = document.createElement('option');
        option.text = '<%:GetText("msgselect")%>';
        option.value = '0';
        e.add(option, 0);
    }
    function EmptyFormsList<%:Me.id%>() {
        var e = document.getElementById('<%:lstform.ClientID%>');
        var length = e.options.length;
        var i;
        for (i = e.options.length - 1; i >= 0; i--) {
            e.remove(i);
        }
        var option = document.createElement('option');
        option.text = '<%:GetText("msgselect")%>';
        option.value = '0';
        e.add(option, 0);
    }
</script>
<label>
    <asp:Label ID="lblportal" runat="server" />
    <LST:MyList ID="lstportal" runat="server" />
</label>
<label>
    <asp:Label ID="lblarea" runat="server" />
    <LST:MyList ID="lstarea" runat="server" />
</label>
<label>
    <asp:Label ID="lblform" runat="server" />
    <LST:MyList ID="lstform" runat="server" AutoPostBack="true" />
</label>
