<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="MyTunes.Library.Home" %>
<%@ Register src="SearchPagerControl.ascx" tagname="SearchPagerControl" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript">
    function selectAll(obj1, obj2) {
        var checkboxIds = new String();

        checkboxIds = obj1;

        var arrIds = new Array();

        arrIds = checkboxIds.split('|');

        for (var i = 0; i < arrIds.length; i++) {
            document.getElementById(arrIds[i]).checked = obj2.checked;
        }
    }   
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <uc1:SearchPagerControl ID="SongSearchPager" runat="server" />
    <table>
        <tr>
            <td align="right">
                Playlist:
                </td>
            <td align="left">
                <asp:DropDownList ID="ddlPlaylists" runat="server" 
                    DataSourceID="PlaylistDataSource" DataTextField="Name" 
                    DataValueField="PlaylistID" AutoPostBack="True">
                </asp:DropDownList>
                <asp:LinqDataSource ID="PlaylistDataSource" runat="server" 
                    ContextTypeName="MyTunes.Library.MyTunesDataContext" EntityTypeName="" 
                    Select="new (PlaylistID, UserName, Name)" TableName="Playlists" 
                    OrderBy="Name">
                </asp:LinqDataSource>
            </td>
            <td align="left">
                <asp:Button ID="btnAddToPlaylist" runat="server" 
                    onclick="btnAddToPlaylist_Click" Text="Add to Playlist" />
            </td>
            <td align="left">
                <asp:Button ID="btnManagePlaylists" runat="server" 
                    PostBackUrl="~/Library/Playlists.aspx" Text="Manage Playlists..." />
            </td>
        </tr>
    </table>
    <div>
        <asp:Label ID="lblResults" runat="server" CssClass="bold"></asp:Label>
    </div>
    <asp:GridView ID="SongGridView" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="SongID" 
        DataSourceID="SongViewDataSource" ondatabound="SongGridView_DataBound" 
        PageSize="25" style="text-align: center">
        <Columns>
            <asp:TemplateField>
                <HeaderTemplate>
                    <asp:CheckBox ID="chkAll" runat="server" />
                </HeaderTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="chkSong" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="In Playlist?">
                <ItemTemplate>
                    <asp:CheckBox ID="chkSongInPlaylist" runat="server" 
                        Checked='<%# SongInPlaylist(Eval("SongID")) %>' Enabled="False" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Artist" HeaderText="Artist" ReadOnly="True" 
                SortExpression="Artist" />
            <asp:BoundField DataField="Album" HeaderText="Album" ReadOnly="True" 
                SortExpression="Album" />
            <asp:BoundField DataField="Title" HeaderText="Title" ReadOnly="True" 
                SortExpression="Title" />
            <asp:BoundField DataField="Genre" HeaderText="Genre" ReadOnly="True" 
                SortExpression="Genre" />
            <asp:BoundField DataField="Track" HeaderText="Track" ReadOnly="True" 
                SortExpression="Track" />
            <asp:BoundField DataField="Length" HeaderText="Length" ReadOnly="True" 
                SortExpression="Length" />
            <asp:BoundField DataField="ArtistID" HeaderText="ArtistID" ReadOnly="True" 
                SortExpression="ArtistID" Visible="False" />
            <asp:BoundField DataField="AlbumID" HeaderText="AlbumID" ReadOnly="True" 
                SortExpression="AlbumID" Visible="False" />
            <asp:BoundField DataField="SongID" HeaderText="SongID" ReadOnly="True" 
                SortExpression="SongID" Visible="False" />
            <asp:TemplateField HeaderText="Actions">
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink2" runat="server" 
                        NavigateUrl='<%# GetPlayLink(Eval("SongID")) %>'>Play...</asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <PagerSettings Mode="NumericFirstLast" PageButtonCount="25" 
            Position="TopAndBottom" />
    </asp:GridView>
    <asp:LinqDataSource ID="SongViewDataSource" runat="server" 
        ContextTypeName="MyTunes.Library.MyTunesDataContext" EntityTypeName="" 
        TableName="SongViews" 
        Select="new (Artist, Album, Title, URL, Genre, Track, Length, ArtistID, AlbumID, SongID)">
    </asp:LinqDataSource>
</asp:Content>
