﻿<?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="WorkoutViewHeader.xslt"/>
    <xsl:import href="WorkoutExerciseMeasures.xslt"/>
    <xsl:include href="../../GenericTemplates/Notes_LineBreak.xslt" />

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:variable name="WorkoutName" select="AjaxRequest/ItemWorkouts/Workout/WorkoutName"></xsl:variable>
        <xsl:variable name="ResponsibleName" select="AjaxRequest/ItemWorkouts/ResponsibleName"></xsl:variable>
        <xsl:variable name="WorkoutItemID" select="AjaxRequest/ItemWorkouts/Workout/WorkoutID"></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="TodayDate" select="AjaxRequest/ItemWorkouts/Workout/TodaysDate"></xsl:variable>
        <xsl:variable name="LastWorkoutDate" select="AjaxRequest/ItemWorkouts/LastWorkoutDate"></xsl:variable>
        <xsl:variable name="WorkoutExercisesXML" select="AjaxRequest/."></xsl:variable>
        <xsl:variable name="TemplateURL" select="AjaxRequest/TemplateURL"></xsl:variable>
        <xsl:variable name="HostName" select="AjaxRequest/HostName"></xsl:variable>
        <xsl:variable name="PTName" select="AjaxRequest/ItemWorkouts/PTName"></xsl:variable>
        <xsl:variable name="FormattedStartDateTime" select="AjaxRequest/ItemWorkouts/Workout/FormattedStartDateTime"></xsl:variable>
        <xsl:variable name="FormattedCompleteDateTime" select="AjaxRequest/ItemWorkouts/Workout/FormattedCompleteDateTime"></xsl:variable>
        <xsl:variable name="PortalImage" select="AjaxRequest/ItemWorkouts/PortalImage"></xsl:variable>
        <xsl:variable name="Duration" select="AjaxRequest/ItemWorkouts/Workout/Duration"></xsl:variable>
        <xsl:variable name="LoggedInUserID" select="AjaxRequest/LoggedInUserID"></xsl:variable>
        <xsl:variable name="PrimaryInternalUserID" select="AjaxRequest/ItemWorkouts/PrimaryInternalUserID"></xsl:variable>
        <xsl:variable name="PermissionID" select="AjaxRequest/PermissionID"></xsl:variable>
        <xsl:variable name="ApprovedUserDisplayName" select="AjaxRequest/ItemWorkouts/Workout/ApprovedUserDisplayName"></xsl:variable>
        <xsl:variable name="InternalComments" select="AjaxRequest/ItemWorkouts/Workout/InternalComments"></xsl:variable>
        <xsl:variable name="FormattedApprovedDate" select="AjaxRequest/ItemWorkouts/Workout/FormattedApprovedDate"></xsl:variable>
        <xsl:variable name="AccountID" select="AjaxRequest/Params/AccountID"></xsl:variable>
        <xsl:variable name="PortalItemID" select="AjaxRequest/Params/PortalItemID"></xsl:variable>

        <div align="right" class="marginRight5">
            <div id="div_EditWorkoutButton" class="verticallyMiddle onMouseOver smallGreenButton"
                     style="width:120px;text-align:center;line-height:20px;"
                     onclick="closePopupWhiteLayerContainer();
                              client_GetClientDetail('divClientPortalOperations_Container','{$PortalItemID}','','','{$AccountID}','no');
                              workout_GetWorkoutView('{$WorkoutItemID}', '{$AccountID}', '{$PortalItemID}', 'ClientAccount_Operations_Filters');">
                <span id="span_Cancel">EDIT WORKOUT</span>
            </div>
            <div class="marginTop10">
                <a id="anc_PrintWorkout" style="margin-right:5px;"
                         href="http://{$HostName}/LifeSpacePrintMedia.aspx?ID={$WorkoutItemID}&amp;Target=2" class="link" target="_blank">
                    <img src="{$TemplateURL}Web/Images/icon_pdf.gif" alt="Print Summary"
                        width="16" height="16" hspace="3" border="0"/>
                    <span class="packageTitle" style="padding-top:20px;">
                        PRINT WORKOUT
                    </span>
                </a>
            </div>
        </div>

        <table class="tableMaster" cellpadding="2" cellspacing="2">
            <tr>
                <td width="70%">
                    <img src="{$PortalImage}" style="display:none;margin-top:10px;margin-bottom:10px;" onload="setWidthAndHeightImage(this,'200')"></img>
                </td>
                <td colspan="2" width="30%">
                    <table class="tableMaster" style="margin-top:10px;margin-bottom:10px;">
                        <tr>
                            <td>
                                <span class="packageTitle">Patient:</span>
                                <span class="packageTitle">
                                    <xsl:value-of select="$ResponsibleName"/>
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="packageTitle">Supervised By:</span>
                                <span class="packageTitle">
                                    <xsl:value-of select="$PTName"/>
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="packageTitle">
                                    <xsl:value-of select="$TodayDate"/>
                                </span>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3" style="background-color:#D1D2D3;">
                    <span class="brandTitle">
                        <xsl:value-of select="$WorkoutName"/>
                    </span>
                </td>
            </tr>
            <xsl:for-each select="$WorkoutExercisesXML/ItemWorkouts/WorkoutExercises/WorkoutExercise">
                <xsl:variable name="ExerciseID" select="ExerciseID"></xsl:variable>
                <tr>
                    <td colspan="3">
                        <table class="tableMaster">
                            <tr>
                                <td width="8%">
                                    <xsl:choose>
                                        <xsl:when test="ThumbnailURL != ''">
                                            <img src="{ThumbnailURL}"></img>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <img src="{VideoThumbnailURL}"></img>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </td>
                                <td width="55%">
                                    <div class="brandTitle">
                                        <xsl:value-of select="ExerciseName"/>
                                    </div>
                                    <div class="marginTop5 publicationSummary">
                                        <xsl:call-template name="break">
                                            <xsl:with-param name="text" select="Description"></xsl:with-param>
                                        </xsl:call-template>
                                    </div>
                                </td>
                                <td width="37%">
                                    <xsl:variable name="MeasureValue">
                                        <xsl:choose>
                                            <xsl:when test="RepsYN = 1 and RepsNum != 0">
                                                <xsl:value-of select="RepsNum"/>
                                            </xsl:when>
                                            <xsl:when test="LevelYN = 1 and LevelNum != 0">
                                                <xsl:value-of select="LevelNum"/>
                                            </xsl:when>
                                            <xsl:when test="TimeYN = 1 and TimeActValue != 0">
                                                <xsl:value-of select="TimeActValue"/>
                                            </xsl:when>
                                            <xsl:when test="DistanceYN = 1 and DistanceActValue != 0">
                                                <xsl:value-of select="DistanceActValue"/>
                                            </xsl:when>
                                            <xsl:when test="WeightYN = 1 and WeightActValue != 0">
                                                <xsl:value-of select="WeightActValue"/>
                                            </xsl:when>
                                            <xsl:when test="CaloriesYN = 1 and CaloriesActValue != 0">
                                                <xsl:value-of select="CaloriesActValue"/>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:text></xsl:text>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:variable>

                                    <xsl:variable name="MeasureTextLabel">
                                        <xsl:choose>
                                            <xsl:when test="RepsYN = 1">
                                                <xsl:text>Reps</xsl:text>
                                            </xsl:when>
                                            <xsl:when test="LevelYN = 1">
                                                <xsl:text>Levels</xsl:text>
                                            </xsl:when>
                                            <xsl:when test="TimeYN = 1">
                                                <xsl:text>Seconds</xsl:text>
                                            </xsl:when>
                                            <xsl:when test="DistanceYN = 1">
                                                <xsl:value-of select="DistanceMeasureValue"/>
                                            </xsl:when>
                                            <xsl:when test="WeightYN = 1">
                                                <xsl:value-of select="WeightMeasureValue"/>
                                            </xsl:when>
                                            <xsl:when test="CaloriesYN = 1">
                                                <xsl:text>Cals</xsl:text>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:text></xsl:text>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:variable>

                                    <xsl:if test="$MeasureValue != ''">
                                        <span class="brandTitle">
                                            <xsl:value-of select="$MeasureValue"/>
                                        </span>

                                        <span class="brandTitle marginRight5">
                                            <xsl:value-of select="$MeasureTextLabel"/>
                                        </span>
                                    </xsl:if>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <xsl:if test="ExerciseNotes != ''">
                    <tr>
                        <td colspan="3" style="padding-left:80px;">
                            <xsl:value-of select="ExerciseNotes" disable-output-escaping="yes"/>
                        </td>
                    </tr>
                </xsl:if>
            </xsl:for-each>
            <tr>
                <td colspan="3">
                    <div style="border-top:1px solid #D1D2D3"></div>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <span class="packageTitle">Start:</span>
                    <span class="publicationSummary" style="margin-right:25px;">
                        <xsl:value-of select="$FormattedStartDateTime"/>
                    </span>

                    <span class="packageTitle">End:</span>
                    <span class="publicationSummary">
                        <xsl:value-of select="$FormattedCompleteDateTime"/>
                    </span>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <span class="packageTitle">Duration:</span>
                    <input id="txt_Duration" type="text" class="text" style="width:35px;" value="{$Duration}"
                           onblur="updateWorkoutDuration('{$WorkoutItemID}','txt_Duration');
                                   numberOnlyForNumbers('txt_Duration');"></input>
                    <span class="packageTitle">mins</span>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <textarea id="text_WorkoutComments" style="width:300px;" class="textAreaNotes" type="text"
                              onFocus="removeWhiteSpace('text_WorkoutComments');
                                       SetTextAreaValue('text_WorkoutComments','Comments','focus');
                                       document.getElementById('text_WorkoutComments').className = 'text';"
                              onBlur="SetTextAreaValue('text_WorkoutComments','Comments','blur');
                                      SaveInternalComments('text_WorkoutComments','{$WorkoutItemID}');">
                        <xsl:choose>
                            <xsl:when test="$InternalComments = ''">
                                <xsl:text></xsl:text>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="$InternalComments"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </textarea>
                </td>
            </tr>
            <tr>
                <td>
                    <xsl:variable name="DisplayApprovedUserName">
                        <xsl:choose>
                            <xsl:when test="$ApprovedUserDisplayName != ''">
                                <xsl:text>inline;</xsl:text>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:text>none;</xsl:text>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:variable>

                    <xsl:variable name="DisplayApprovedByBtn">
                        <xsl:choose>
                            <xsl:when test="$ApprovedUserDisplayName != ''">
                                <xsl:text>none;</xsl:text>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:text>inline;</xsl:text>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:variable>


                    <div style="width:230px;">
                        <div class="packageTitle marginRight5" style="float:left;">Approved By:</div>
                        <xsl:choose>
                            <xsl:when test="$PermissionID &gt;= 4 or $PermissionID = 3">
                                <span id="span_ApprovedUserName" class="publicationSummary sentenceFont" style="display:{$DisplayApprovedUserName}">
                                    <xsl:value-of select="$ApprovedUserDisplayName"/>
                                    <span style="margin-left:5px;">
                                        <xsl:value-of select="$FormattedApprovedDate"/>
                                    </span>
                                </span>


                                <div id="div_ApproveWorkoutButton" class="verticallyMiddle onMouseOver smallGreenButton"
                                    style="width:100px;text-align:center;line-height:15px;float:right;display:{$DisplayApprovedByBtn}"
                                    onclick="PT_ApproveWorkout('{$WorkoutItemID}');">
                                    <span id="span_Cancel">APPROVE</span>
                                </div>
                            </xsl:when>
                            <xsl:when test="$PermissionID &lt; 3">
                                <xsl:choose>
                                    <xsl:when test="$ApprovedUserDisplayName != ''">
                                        <span id="span_ApprovedUserName" class="publicationSummary sentenceFont" style="display:{$DisplayApprovedUserName}">
                                            <xsl:value-of select="$ApprovedUserDisplayName"/>
                                        </span>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <span class="publicationSummary">Approval Pending</span>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:when>
                        </xsl:choose>
                    </div>
                </td>
            </tr>
        </table>
    </xsl:template>
</xsl:stylesheet>
