﻿<?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="WorkoutMedia.xslt"/>
    <xsl:import href="WorkoutExerciseSort.xslt"/>
    <xsl:import href="WorkoutExerciseMeasures.xslt"/>
    <xsl:import href="WorkoutViewHeader.xslt"/>

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:variable name="WorkoutItemID">
            <xsl:choose>
                <xsl:when test="AjaxRequest/Params/WorkoutItemID">
                    <xsl:value-of select="AjaxRequest/Params/WorkoutItemID"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="AjaxRequest/ItemWorkouts/Workout/WorkoutID"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="WorkoutExercisesXML" select="AjaxRequest/."></xsl:variable>
        <xsl:variable name="PortalItemID" select="AjaxRequest/ItemWorkouts/PortalItemID"></xsl:variable>
        <xsl:variable name="AccountID" select="AjaxRequest/ItemWorkouts/Workout/ResponsibleID"></xsl:variable>
        <xsl:variable name="TemplateURL" select="AjaxRequest/TemplateURL"></xsl:variable>
        <xsl:variable name="ExerciseCount" select="count($WorkoutExercisesXML/ItemWorkouts/WorkoutExercises/WorkoutExercise)"></xsl:variable>
        <xsl:variable name="StatusID" select="AjaxRequest/ItemWorkouts/Workout/StatusID"></xsl:variable>
        <xsl:variable name="StartDate" select="AjaxRequest/ItemWorkouts/Workout/FormattedStartDate"></xsl:variable>
        <xsl:variable name="LastWorkoutDate" select="AjaxRequest/ItemWorkouts/LastWorkoutDate"></xsl:variable>
        <xsl:variable name="TodayDate" select="AjaxRequest/ItemWorkouts/Workout/TodaysDate"></xsl:variable>
        <xsl:variable name="DueDate" select="AjaxRequest/Params/DueDate"></xsl:variable>

        <xsl:call-template name="WorkoutViewExercisesContent">
            <xsl:with-param name="WorkoutItemID" select="$WorkoutItemID"></xsl:with-param>
            <xsl:with-param name="WorkoutExercisesXML" select="$WorkoutExercisesXML"></xsl:with-param>
            <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
            <xsl:with-param name="AccountID" select="$AccountID"></xsl:with-param>
            <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
            <xsl:with-param name="ExerciseCount" select="$ExerciseCount"></xsl:with-param>
            <xsl:with-param name="StatusID" select="$StatusID"></xsl:with-param>
            <xsl:with-param name="StartDate" select="$StartDate"></xsl:with-param>
            <xsl:with-param name="LastWorkoutDate" select="$LastWorkoutDate"></xsl:with-param>
            <xsl:with-param name="TodayDate" select="$TodayDate"></xsl:with-param>
        </xsl:call-template>
    </xsl:template>


    <xsl:template name="WorkoutViewExercisesContent">
        <xsl:param name="WorkoutItemID" select="'N/A'"></xsl:param>
        <xsl:param name="WorkoutExercisesXML" select="'N/A'"></xsl:param>
        <xsl:param name="PortalItemID" select="'N/A'"></xsl:param>
        <xsl:param name="AccountID" select="'N/A'"></xsl:param>
        <xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
        <xsl:param name="ExerciseCount" select="'N/A'"></xsl:param>
        <xsl:param name="StatusID" select="'N/A'"></xsl:param>
        <xsl:param name="StartDate" select="'N/A'"></xsl:param>
        <xsl:param name="LastWorkoutDate" select="'N/A'"></xsl:param>
        <xsl:param name="TodayDate" select="'N/A'"></xsl:param>
        <xsl:param name="DueDate" select="'N/A'"></xsl:param>
        <xsl:param name="DisplayLastWorkoutCol" select="'N/A'"></xsl:param>
        <xsl:param name="DisplayWorkoutHistoryIcon" select="'N/A'"></xsl:param>
        <xsl:param name="WorkoutViewExercisesContent" select="'N/A'"></xsl:param>
        <xsl:param name="MeasureLabelFontStyle" select="'N/A'"></xsl:param>
        <xsl:param name="BlankTDWidth" select="'N/A'"></xsl:param>
        <xsl:param name="MeasureEntryBoxWidth" select="'N/A'"></xsl:param>
        <xsl:param name="MeasureEntryBoxHeight" select="'N/A'"></xsl:param>
        <xsl:param name="MeasureEntryBoxFontSize" select="'N/A'"></xsl:param>
        <xsl:param name="DisplayExerciseDescription" select="'N/A'"></xsl:param>



        <div id="div_Workout_Container_{$WorkoutItemID}">
            <xsl:call-template name="WorkoutHeaderTemplate">
                <xsl:with-param name="WorkoutItemID" select="$WorkoutItemID"></xsl:with-param>
                <xsl:with-param name="StatusID" select="$StatusID"></xsl:with-param>
                <xsl:with-param name="StartDate" select="$StartDate"></xsl:with-param>
                <xsl:with-param name="LastWorkoutDate" select="$LastWorkoutDate"></xsl:with-param>
                <xsl:with-param name="TodayDate" select="$TodayDate"></xsl:with-param>
                <xsl:with-param name="DueDate" select="$DueDate"></xsl:with-param>
                <xsl:with-param name="Mode">
                    <xsl:text>Workout</xsl:text>
                </xsl:with-param>
                <xsl:with-param name="DisplayLastWorkoutCol" select="$DisplayLastWorkoutCol"></xsl:with-param>
                <xsl:with-param name="BlankTDWidth" select="$BlankTDWidth"></xsl:with-param>
                <xsl:with-param name="AccountID" select="$AccountID"></xsl:with-param>
                <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
            </xsl:call-template>


            <table class="tableMaster" id="table_ExerciseList_{$WorkoutItemID}" cellpadding="0" cellspacing="0">
                <xsl:for-each select="$WorkoutExercisesXML/ItemWorkouts/WorkoutExercises/WorkoutExercise">
                    <xsl:variable name="ExerciseID" select="ExerciseID"></xsl:variable>
                    <xsl:variable name="position" select="position()"></xsl:variable>

                    <tr id="tr_WorkoutExercise_{WorkoutExerciseID}">
                        <td width="5%">
                            <span id="span_Expand_{WorkoutExerciseID}" class="packageTitle onMouseOver" style="font-size:15px;"
                                  onclick="ExerciseDetailsExpandCollapse('{$WorkoutItemID}','{WorkoutExerciseID}', '{$PortalItemID}', 'expand','{$AccountID}');">
                                <img src="{$TemplateURL}Web/Images/Ver_2_0/arrow_right.png" height="20" width="20" title="Click to Expand"></img>
                            </span>
                            <span id="span_collapse_{WorkoutExerciseID}" class="packageTitle onMouseOver" style="font-size:15px;display:none;"
                                onclick="ExerciseDetailsExpandCollapse('{$WorkoutItemID}','{WorkoutExerciseID}', '{$PortalItemID}', 'collapse','{$AccountID}');">
                                <img src="{$TemplateURL}Web/Images/Ver_2_0/arrow_down.png" height="20" width="20" title="Click to Collapse"></img>
                            </span>
                        </td>
                        <td width="15%">
                            <span>
                                <xsl:call-template name="WorkoutMedia">
                                    <xsl:with-param name="ThumbnailURL" select="ThumbnailURL"></xsl:with-param>
                                    <xsl:with-param name="VideoURL" select="VideoURL"></xsl:with-param>
                                    <xsl:with-param name="VideoKeyValue" select="VideoKeyValue"></xsl:with-param>
                                    <xsl:with-param name="WorkoutExerciseID" select="WorkoutExerciseID"></xsl:with-param>
                                    <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                    <xsl:with-param name="VideoImage" select="VideoImage"></xsl:with-param>
                                    <xsl:with-param name="VimeoThumbnailURL" select="VimeoThumbnailURL"></xsl:with-param>
                                    <xsl:with-param name="ImageURL" select="ImageURL"></xsl:with-param>
                                    <xsl:with-param name="ExerciseName" select="ExerciseName"></xsl:with-param>
                                    <xsl:with-param name="VideoThumbnailURL" select="VideoThumbnailURL"></xsl:with-param>
                                </xsl:call-template>
                            </span>
                        </td>
                        <td  width="30%" class="verticallyMiddle">
                            <span class="packageTitle onMouseOver" style="font-size:17px;color:#58595B"
                                  onclick="ExerciseDetailsExpandCollapse('{$WorkoutItemID}','{WorkoutExerciseID}', '{$PortalItemID}', 'expand','{$AccountID}');">
                                <xsl:value-of select="ExerciseName"/>
                            </span>
                            <xsl:if test="$DisplayExerciseDescription = 'True'">
                                <div>
                                    <span class="publicationSummary">
                                        <xsl:value-of select="Description"/>
                                    </span>
                                </div>
                            </xsl:if>
                        </td>
                        <td width="20%" class="verticallyMiddle">
                            <xsl:call-template name="ThisWorkoutMeasuresValues">
                                <xsl:with-param name="RepsYN" select="RepsYN"></xsl:with-param>
                                <xsl:with-param name="RepsNum" select="RepsNum"></xsl:with-param>
                                <xsl:with-param name="WorkoutItemID" select="$WorkoutItemID"></xsl:with-param>
                                <xsl:with-param name="WorkoutExerciseID" select="WorkoutExerciseID"></xsl:with-param>
                                <xsl:with-param name="LevelYN" select="LevelYN"></xsl:with-param>
                                <xsl:with-param name="LevelNum" select="LevelNum"></xsl:with-param>
                                <xsl:with-param name="TimeYN" select="TimeYN"></xsl:with-param>
                                <xsl:with-param name="TimeActValue" select="TimeActValue"></xsl:with-param>
                                <xsl:with-param name="DistanceYN" select="DistanceYN"></xsl:with-param>
                                <xsl:with-param name="DistanceActValue" select="DistanceActValue"></xsl:with-param>
                                <xsl:with-param name="WeightYN" select="WeightYN"></xsl:with-param>
                                <xsl:with-param name="WeightActValue" select="WeightActValue"></xsl:with-param>
                                <xsl:with-param name="CaloriesYN" select="CaloriesYN"></xsl:with-param>
                                <xsl:with-param name="CaloriesActValue" select="CaloriesActValue"></xsl:with-param>
                                <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                <xsl:with-param name="TimeMeasueValue" select="TimeMeasueValue"></xsl:with-param>
                                <xsl:with-param name="DistanceMeasureValue" select="DistanceMeasureValue"></xsl:with-param>
                                <xsl:with-param name="WeightMeasureValue" select="WeightMeasureValue"></xsl:with-param>
                                <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
                                <xsl:with-param name="AccountID" select="$AccountID"></xsl:with-param>
                                <xsl:with-param name="position" select="$position"></xsl:with-param>
                                <xsl:with-param name="MeasureLabelFontStyle" select="$MeasureLabelFontStyle"></xsl:with-param>
                                <xsl:with-param name="MeasureEntryBoxWidth" select="$MeasureEntryBoxWidth"></xsl:with-param>
                                <xsl:with-param name="MeasureEntryBoxHeight" select="$MeasureEntryBoxHeight"></xsl:with-param>
                                <xsl:with-param name="MeasureEntryBoxFontSize" select="$MeasureEntryBoxFontSize"></xsl:with-param>
                            </xsl:call-template>
                        </td>

                        <td width="20%" class="verticallyMiddle textRight" style="padding-right:45px;">
                            <xsl:if test="$DisplayLastWorkoutCol = 'True'">
                                <xsl:for-each select="$WorkoutExercisesXML/MeasureTotalXML/MeasureTotal[ExerciseID = $ExerciseID]">
                                    <span class="packageTitle">
                                        <xsl:choose>
                                            <xsl:when test="RepsTotal &gt; 0">
                                                <xsl:value-of select="RepsTotal"/>
                                                <span class="marginLeft5">Reps</span>
                                            </xsl:when>
                                            <xsl:when test="LevelTotal &gt; 0">
                                                <xsl:value-of select="LevelTotal"/>
                                                <span class="marginLeft5">Levels</span>
                                            </xsl:when>
                                            <xsl:when test="TimeTotal &gt; 0">
                                                <xsl:value-of select="TimeTotal"/>
                                                <span class="marginLeft5">Seconds</span>
                                            </xsl:when>
                                            <xsl:when test="WeightTotal &gt; 0">
                                                <xsl:value-of select="WeightTotal"/>
                                                <span class="marginLeft5">Gram</span>
                                            </xsl:when>
                                            <xsl:when test="DistanceTotal &gt; 0">
                                                <xsl:value-of select="DistanceTotal"/>
                                                <span class="marginLeft5">Miles</span>
                                            </xsl:when>
                                            <xsl:when test="CaloriesTotal &gt; 0">
                                                <xsl:value-of select="CaloriesTotal"/>
                                                <span class="marginLeft5">Cals</span>
                                            </xsl:when>

                                        </xsl:choose>
                                    </span>
                                </xsl:for-each>
                            </xsl:if>
                        </td>
                        <xsl:if test="$DisplayWorkoutHistoryIcon = 'True'">
                            <td width="8%" class="verticallyMiddle">
                                <span class="packageTitle textCenter">
                                    <div class="verticallyMiddle onMouseOver">
                                        <img id="img_History" src="{$TemplateURL}Web/Images/Ver_2_0/Bar-chart-icon.png" align="absmiddle" title="History" width="40" height="40"
                                             onClick="LoadWorkoutHistory('{WorkoutExerciseID}','{$WorkoutItemID}','{$PortalItemID}','{$AccountID}');"></img>
                                    </div>
                                </span>
                            </td>
                        </xsl:if>
                        <td width="5%" class="verticallyMiddle">
                            <xsl:if test="TimeYN != 0">
                                <span class="packageTitle textCenter">
                                    <div class="verticallyMiddle onMouseOver">
                                        <img id="img_History" src="{$TemplateURL}Web/Images/Ver_2_0/history.png" align="absmiddle" title="Stop Watch" width="40" height="40"
                                             onclick="workoutTracker_LoadWorkoutStopWatch('{$WorkoutItemID}','{WorkoutExerciseID}','{$PortalItemID}','{$AccountID}');
                                                      resetTimer();"></img>
                                    </div>
                                </span>
                            </xsl:if>
                        </td>
                        <xsl:if test="$DisplayWorkoutHistoryIcon = 'True'">
                            <td width="5%" class="verticallyMiddle textCenter onMouseOver packageTitle">
                                <span title="Delete Exercise"
                                      onclick="DeleteWorkoutExercise('{WorkoutExerciseID}','tr_WorkoutExercise_{WorkoutExerciseID}');">
                                    <img src="{$TemplateURL}/Web/Images/Ver_2_0/BT_x.png"></img>
                                </span>
                            </td>
                        </xsl:if>
                    </tr>
                    <tr style="display:none" id="row_ExerciseDetail_{WorkoutExerciseID}" WorkoutExerciseID="{WorkoutExerciseID}" name="ExerciseDetail">
                        <td></td>
                        <td>
                            <div id="div_ExerciseSort_{WorkoutExerciseID}">
                                <table align="center" style="margin-right:30px;">
                                    <tr>
                                        <xsl:call-template name="WorkoutExerciseSort">
                                            <xsl:with-param name="ExerciseCount" select="$ExerciseCount"></xsl:with-param>
                                            <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                            <xsl:with-param name="position" select="position()"></xsl:with-param>
                                            <xsl:with-param name="WorkoutExerciseID" select="WorkoutExerciseID"></xsl:with-param>
                                            <xsl:with-param name="WorkoutItemID" select="$WorkoutItemID"></xsl:with-param>
                                            <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
                                            <xsl:with-param name="AccountID" select="$AccountID"></xsl:with-param>
                                        </xsl:call-template>
                                    </tr>
                                </table>
                            </div>
                        </td>
                        <td colspan="6">
                            <div id="div_ExerciseDetail_{WorkoutExerciseID}">

                            </div>
                        </td>
                    </tr>
                    <tr id="tr_SeperatorLine_{WorkoutExerciseID}">
                        <td colspan="8">
                            <div class="seperatorLine"></div>
                        </td>
                    </tr>
                </xsl:for-each>

            </table>
        </div>
    </xsl:template>
</xsl:stylesheet>
