﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

    <xsl:import href="AddExercise.xslt"></xsl:import>
    <xsl:import href="Exercise.xslt"></xsl:import>

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:variable name="PortalItemID">
            <xsl:choose>
                <xsl:when test="AjaxRequest/Params/ItemID">
                    <xsl:value-of select="AjaxRequest/Params/ItemID"/>
                </xsl:when>
                <xsl:when test="AjaxRequest/Params/PortalItemID">
                    <xsl:value-of select="AjaxRequest/Params/PortalItemID"/>
                </xsl:when>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="Action" select="AjaxRequest/Action"/>
        <xsl:variable name="TemplateURL" select="AjaxRequest/TemplateURL"></xsl:variable>
        <xsl:variable name="LoggedInUserID" select="AjaxRequest/LoggedInUserID"></xsl:variable>
        <xsl:variable name="CurrentTimeStamp" select="AjaxRequest/CurrentTimeStamp"></xsl:variable>

        <xsl:if test="$Action!='GetFilteredExerciseList'">
            <div align="right" id="div_ExerciseList_{$PortalItemID}_Add_Control" style="margin:10px;">
                <div class="verticallyMiddle onMouseOver divBrowseGradient spanBrowseGradientTextGray" style="width:130px;line-height:25px;text-align:center;"
                   onmouseover="document.getElementById('img_AddNewExer').src='{$TemplateURL}Web/Images/Ver_2_0/icon_add_over.png';"
                   onmouseout="document.getElementById('img_AddNewExer').src='{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png';"
                   onClick="return workoutTracker_AddNewExercise('div_ExerciseList_{$PortalItemID}_Add_Operations','{$PortalItemID}');">
                    <img id="img_AddNewExer" src="{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png" align="absmiddle" class="marginRight5"></img>
                    <span id="span_Cancel" class="capitalFont">Add Exercise</span>
                </div>
            </div>
            <table width="100%">
                <tr>
                    <td>
                        <Span class="packageTitle" style="vertical-align: center;margin-left: 10px;">Exercise</Span>
                        <input id="txtExercice" type="text" class="text" style="width: 100px; margin-left: 10px; margin-right: 15px;"
                                onKeyPress="ExerciseListFilter(event, 'txtExercice', 'ddlType', 'txtCustomType', '{$PortalItemID}', 'div_ExerciseList_{$PortalItemID}')"></input>
                        <Span class="packageTitle" style="vertical-align: center;">Type</Span>
                        <select id="ddlType" class="smallDropdown" style="margin-left: 10px;margin-right: 15px;"
                                           onChange="ExerciseListFilter(null, 'txtExercice', 'ddlType', 'txtCustomType', '{$PortalItemID}', 'div_ExerciseList_{$PortalItemID}')">
                            <option value="-1" selected="selected">
                                Select Type
                            </option>
                            <xsl:for-each select="AjaxRequest/FitnessExerciseTypes/FitnessExerciseType">
                                <option value="{FitnessExerciseTypeID}">
                                    <xsl:value-of select="FitnessExerciseType"/>
                                </option>
                            </xsl:for-each>
                        </select>
                        <Span class="packageTitle" style="vertical-align: center;">Custom Type</Span>
                        <input id="txtCustomType" type="text" class="text" style="width: 100px; margin-left: 10px; margin-right: 15px;"
                                onKeyPress="ExerciseListFilter(event, 'txtExercice', 'ddlType', 'txtCustomType', '{$PortalItemID}', 'div_ExerciseList_{$PortalItemID}')"></input>
                    </td>
                </tr>
            </table>
        </xsl:if>
        <xsl:choose>
            <xsl:when test="$Action='GetFilteredExerciseList'">
                <xsl:call-template name="ExerciseList"></xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <div id="div_ExerciseList_{$PortalItemID}">
                    <xsl:call-template name="ExerciseList"></xsl:call-template>
                </div>
            </xsl:otherwise>
        </xsl:choose>

        <xsl:if test="$Action!='GetFilteredExerciseList'">
            <div id="div_ExerciseList_{$PortalItemID}_Add" style="margin:10px;">


                <div id="div_ExerciseList_{$PortalItemID}_Add_Operations" style="margin:10px;display:none;">

                </div>
            </div>
        </xsl:if>
    </xsl:template>

    <xsl:template name="ExerciseList">              
        <xsl:variable name="PortalItemID" select="AjaxRequest/Params/ItemID"></xsl:variable>
        <xsl:variable name="CurrentTimeStamp" select="AjaxRequest/CurrentTimeStamp"></xsl:variable>
        <xsl:variable name="LoggedInUserID" select="AjaxRequest/LoggedInUserID"></xsl:variable>
        <xsl:variable name="TemplateURL" select="AjaxRequest/TemplateURL"></xsl:variable>

        <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
        <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
        
        


        <table id="div_ExerciseList_{$PortalItemID}_Content" class="tableMaster" style="padding-top:10px;" width="100%" cellpadding="0" cellspacing="0">
            <tbody id="div_ExerciseList_{$PortalItemID}_Content_Body">
                <xsl:for-each select="AjaxRequest/Exercises/Exercise[not(translate(normalize-space(following::CustomGroup), $smallcase, $uppercase) = translate(normalize-space(CustomGroup), $smallcase, $uppercase))]">

                    <xsl:variable name="CustomGroup" select="normalize-space(CustomGroup)"></xsl:variable>
                    <xsl:variable name="PositionCount">
                        <xsl:value-of select ="position()"/>
                    </xsl:variable>
                    <tr>
                        <td colspan="6">

                            <div>
                                <div class="seperatorLine"
                                     onClick="program_ExpandCollapse('div_ExerciseList_{$PositionCount}_Content_Data_Client_Exercise');">
                                    <span class="brandTitle sentenceFont" style="cursor:pointer;">
                                        <xsl:value-of select="$CustomGroup"/>
                                    </span>
                                </div>
                                <div id="div_ExerciseList_{$PositionCount}_Content_Data_Client_Exercise" style="display:block;margin-bottom:20px;">

                                    <xsl:for-each select="../../Exercises/Exercise[translate(normalize-space(CustomGroup), $smallcase, $uppercase) = translate(normalize-space($CustomGroup), $smallcase, $uppercase)]">
                                        <xsl:sort data-type="text" select="ExerciseName"/>
                                        <table class="tableMaster" style="padding-top:10px;" width="100%" cellpadding="5" cellspacing="0">
                                            <tbody>
                                                <xsl:call-template name="Program_Exercise">
                                                    <xsl:with-param name="ItemID" select="PortalItemID"></xsl:with-param>
                                                    <xsl:with-param name="ExerciseID" select="ExerciseID"></xsl:with-param>
                                                    <xsl:with-param name="ExerciseName" select="normalize-space(ExerciseName)"></xsl:with-param>
                                                    <xsl:with-param name="Description" select="Description"></xsl:with-param>
                                                    <xsl:with-param name="TypeID" select="TypeID"></xsl:with-param>
                                                    <xsl:with-param name="CustomType" select="normalize-space(CustomType)"></xsl:with-param>
                                                    <xsl:with-param name="ImageURL" select="ImageURL"></xsl:with-param>
                                                    <xsl:with-param name="ThumbnailURL" select="ThumbnailURL"></xsl:with-param>
                                                    <xsl:with-param name="VideoURL" select="VideoURL"></xsl:with-param>
                                                    <xsl:with-param name="Sets" select="SetsYN"></xsl:with-param>
                                                    <xsl:with-param name="Reps" select="RepsYN"></xsl:with-param>
                                                    <xsl:with-param name="Levels" select="LevelYN"></xsl:with-param>
                                                    <xsl:with-param name="Time" select="TimeYN"></xsl:with-param>
                                                    <xsl:with-param name="Distance" select="DistanceYN"></xsl:with-param>
                                                    <xsl:with-param name="Weight" select="WeightYN"></xsl:with-param>
                                                    <xsl:with-param name="Calories" select="CaloriesYN"></xsl:with-param>
                                                    <xsl:with-param name="Active" select="IsActive"></xsl:with-param>
                                                    <xsl:with-param name="Public" select="IsPublic"></xsl:with-param>
                                                    <xsl:with-param name="Published" select="IsPublished"></xsl:with-param>
                                                    <xsl:with-param name="LoggedInUserID" select="$LoggedInUserID"></xsl:with-param>
                                                    <xsl:with-param name="ApprovedYN" select="ApprovedYN"></xsl:with-param>
                                                    <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                                    <xsl:with-param name="PortalImage" select="PortalImage"></xsl:with-param>
                                                    <xsl:with-param name="VideoThumbnailURL" select="VideoThumbnailURL"></xsl:with-param>
                                                    <xsl:with-param name="CurrentTimeStamp" select="$CurrentTimeStamp"></xsl:with-param>
                                                    <xsl:with-param name="VideoKeyValue" select="VideoKeyValue"></xsl:with-param>
                                                </xsl:call-template>
                                            </tbody>
                                        </table>
                                    </xsl:for-each>
                                </div>
                            </div>
                        </td>
                    </tr>
                </xsl:for-each>
                <tr>
                    <td colspan="6">
                        <xsl:if test="count(AjaxRequest/Exercises/Exercise)=0">
                            <div width="100%" style="text-align:center;padding:15px;">
                                <span class="packageTitle">There are no exercises.</span>
                            </div>
                        </xsl:if>
                    </td>
                </tr>
            </tbody>
        </table>
    </xsl:template>
</xsl:stylesheet>
