﻿<?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="WorkoutProgramexerciseNode.xslt"/>
    <xsl:import href="Exercise.xslt"></xsl:import>


    <xsl:output method="xml" indent="yes"/>


    <xsl:template match="/">
        <xsl:variable name="PortalItemID" select="AjaxRequest/Params/PortalItemID"/>
        <xsl:variable name="BoxYN" select="AjaxRequest/Params/BoxYN"/>
        <xsl:variable name="ProgItemID" select="AjaxRequest/Params/ProgramID"/>
        <xsl:variable name="ProgName" select="AjaxRequest/Exercises/ProgramName"/>
        <xsl:variable name="Description" select="AjaxRequest/Exercises/Description"/>
        <xsl:variable name="ThumbnailURL" select="AjaxRequest/Exercises/ThumbnailURL"/>
        <xsl:variable name="IsActive" select="AjaxRequest/Exercises/IsActive"></xsl:variable>
        <xsl:variable name="ProgType" select="AjaxRequest/Exercises/WorkoutProgramType"/>
        <xsl:variable name="CustType" select="AjaxRequest/Exercises/CustomType"/>
        <xsl:variable name="Frequency" select="AjaxRequest/Exercises/Frequency"/>
        <xsl:variable name="ExerciseCount" select="count(AjaxRequest/Exercises/Exercise)"></xsl:variable>
        <xsl:variable name="TemplateURL" select="AjaxRequest/TemplateURL"/>
        <xsl:variable name="HostName" select="AjaxRequest/HostName"/>
        <xsl:variable name="WorkoutItemID">
            <xsl:choose>
                <xsl:when test="not(AjaxRequest/Params/WorkoutItemID)">
                    <xsl:number value ="-99"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="AjaxRequest/Params/WorkoutItemID"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="DesiredData" select="AjaxRequest/Params/DesiredData"></xsl:variable>
        <xsl:variable name="TargetDiv" select="AjaxRequest/Params/TargetDiv"/>
        <xsl:variable name="GoalID" select="AjaxRequest/Params/GoalID"/>
        <xsl:variable name="ProgramTypes" select="AjaxRequest/WorkOutTypes/."></xsl:variable>
        <xsl:variable name="SettingsData" select="AjaxRequest/Settings/."></xsl:variable>

        <xsl:choose>
            <xsl:when test="$DesiredData ='Body'">
                <xsl:for-each select="AjaxRequest/Exercises/Exercise">
                    <xsl:call-template name="ProgramList_Exercise">
                        <xsl:with-param name="ExerciseCount" select="$ExerciseCount"></xsl:with-param>
                        <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
                        <xsl:with-param name="ProgItemID" select="$ProgItemID"></xsl:with-param>
                        <xsl:with-param name="ExerciseID" select="ProgExcerID"></xsl:with-param>
                        <xsl:with-param name="ExerciseName" select="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="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="IsActive" select="IsActive"></xsl:with-param>
                        <xsl:with-param name="IsPublic" select="IsPublic"></xsl:with-param>
                        <xsl:with-param name="IsPublished" select="IsPublished"></xsl:with-param>
                        <xsl:with-param name="SetsTarget" select="SetsTarget"></xsl:with-param>
                        <xsl:with-param name="RepsTarget" select="RepsTarget"></xsl:with-param>
                        <xsl:with-param name="LevelTarget" select="LevelTarget"></xsl:with-param>
                        <xsl:with-param name="TimeTarget" select="TimeTarget"></xsl:with-param>
                        <xsl:with-param name="DistanceTarget" select="DistanceTarget"></xsl:with-param>
                        <xsl:with-param name="WeightTarget" select="WeightTarget"></xsl:with-param>
                        <xsl:with-param name="CaloriesTarget" select="CaloriesTarget"></xsl:with-param>
                        <xsl:with-param name="CalorieUnits" select="../CalUnits/."></xsl:with-param>
                        <xsl:with-param name="DistanceUnits" select="../DistUnits/."></xsl:with-param>
                        <xsl:with-param name="TimeUnits" select="../TimeUnits/."></xsl:with-param>
                        <xsl:with-param name="WeightUnits" select="../WeightUnits/."></xsl:with-param>
                        <xsl:with-param name="CaloriesMeasureID" select="CaloriesMeasureID"></xsl:with-param>
                        <xsl:with-param name="DistanceMeasureID" select="DistanceMeasureID"></xsl:with-param>
                        <xsl:with-param name="TimeMeasureID" select="TimeMeasureID"></xsl:with-param>
                        <xsl:with-param name="WeightMeasureID" select="WeightMeasureID"></xsl:with-param>
                        <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                        <xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
                        <xsl:with-param name="VideoKeyValue" select="VideoKeyValue"></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="ProgExcerID" select="ProgExcerID"></xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
                <div id="div_ProgramListExcercise_{$ProgItemID}" style="width:95%;padding:3px;">
                    <table id="div_ProgramList_{$ProgItemID}_Content" width="100%" cellpadding="0" cellspacing="3" style="padding-top:5px;">
                        <thead style="background-color: #FFFFFF;">
                            <tr>
                                <td colspan="5" style="text-align:right;padding-bottom:5px;">
                                    <span class="link" onclick="workoutTracker_CloseAddExerciseToProgram('{$PortalItemID}','{$ProgItemID}','{$WorkoutItemID}','{$TargetDiv}','{$GoalID}','{$BoxYN}');">[X]</span>
                                </td>

                            </tr>
                            <tr>
                                <td colspan="5">
                                    <table width="100%">
                                        <tr>
                                            <td width="20%" >
                                                <span class="packageTitle">Protocol Name</span>
                                            </td>
                                            <td width="35%">
                                                <input type="text" id="txtProgram" value="{$ProgName}" style="width:516px;" class="text"
                                                    onBlur="workoutTracker_saveFeild('{$ProgItemID}','{$PortalItemID}','{$ProgName}','txtProgram', 'ProgramName');"></input>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <span class="packageTitle">Type</span>
                                            </td>
                                            <td>
                                                <select id="ddlType" name="Type" class="smallDropdown"
                                                        onchange="workoutTracker_saveFeild('{$ProgItemID}','{$PortalItemID}','{$ProgType}','ddlType', 'TypeID');">
                                                    <option value="-1" selected="selected">
                                                        Select
                                                    </option>
                                                    <xsl:for-each select="$ProgramTypes/WorkOutType">
                                                        <xsl:choose>
                                                            <xsl:when test="WorkoutProgramType = $ProgType">
                                                                <option value="{WorkoutProgramTypeID}" selected="selected">
                                                                    <xsl:value-of select="WorkoutProgramType"/>
                                                                </option>
                                                            </xsl:when>
                                                            <xsl:otherwise>
                                                                <option value="{WorkoutProgramTypeID}">
                                                                    <xsl:value-of select="WorkoutProgramType"/>
                                                                </option>
                                                            </xsl:otherwise>
                                                        </xsl:choose>
                                                    </xsl:for-each>
                                                </select>
                                                <input id="txtCustomType" type="text" class="text" style="width:138px;" value="{$CustType}"
                                                       onBlur="workoutTracker_saveFeild('{$ProgItemID}','{$PortalItemID}','{$CustType}','txtCustomType', 'CustomType');"></input>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <span class="packageTitle">Description</span>
                                            </td>
                                            <td>
                                                <textarea id="txtDesc" rows="5" cols="62"
                                                          onBlur="workoutTracker_saveFeild('{$ProgItemID}','{$PortalItemID}','{$Description}','txtDesc', 'Description');">
                                                    <xsl:value-of select="$Description"/>
                                                </textarea>
                                            </td>
                                        </tr>
                                        <tr style="display:none;">
                                            <td>
                                                <span class="packageTitle">Thumbnail URL</span>
                                            </td>
                                            <td>
                                                <input id="thumbnailURL" type="text" value="{$ThumbnailURL}" class="text" style="width:515px;"
                                                       onBlur="workoutTracker_saveFeild('{$ProgItemID}','{$PortalItemID}','{$ThumbnailURL}','thumbnailURL', 'ThumbnailURL');"/>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <span class="packageTitle">Active</span>
                                            </td>
                                            <td>
                                                <select id="ddlActive" name="Type" class="smallDropdown"
                                                        onchange="workoutTracker_saveFeild('{$ProgItemID}','{$PortalItemID}','{$IsActive}','ddlActive', 'IsActive');">
                                                    <xsl:choose>
                                                        <xsl:when test="$IsActive = 1">
                                                            <option value="1" selected="selected">
                                                                <xsl:text>Yes</xsl:text>
                                                            </option>
                                                            <option value="0">
                                                                <xsl:text>No</xsl:text>
                                                            </option>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <option value="1" >
                                                                <xsl:text>Yes</xsl:text>
                                                            </option>
                                                            <option value="0" selected="selected">
                                                                <xsl:text>No</xsl:text>
                                                            </option>
                                                        </xsl:otherwise>
                                                    </xsl:choose>



                                                </select>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </thead>

                        <tbody id="div_ProgramListExcercise_{$ProgItemID}_Content_Body">
                            <xsl:for-each select="AjaxRequest/Exercises/Exercise">
                                <xsl:call-template name="ProgramList_Exercise">
                                    <xsl:with-param name="ExerciseCount" select="$ExerciseCount"></xsl:with-param>
                                    <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
                                    <xsl:with-param name="ProgItemID" select="$ProgItemID"></xsl:with-param>
                                    <xsl:with-param name="ExerciseID" select="ProgExcerID"></xsl:with-param>
                                    <xsl:with-param name="ExerciseName" select="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="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="IsActive" select="IsActive"></xsl:with-param>
                                    <xsl:with-param name="IsPublic" select="IsPublic"></xsl:with-param>
                                    <xsl:with-param name="IsPublished" select="IsPublished"></xsl:with-param>
                                    <xsl:with-param name="SetsTarget" select="SetsTarget"></xsl:with-param>
                                    <xsl:with-param name="RepsTarget" select="RepsTarget"></xsl:with-param>
                                    <xsl:with-param name="LevelTarget" select="LevelTarget"></xsl:with-param>
                                    <xsl:with-param name="TimeTarget" select="TimeTarget"></xsl:with-param>
                                    <xsl:with-param name="DistanceTarget" select="DistanceTarget"></xsl:with-param>
                                    <xsl:with-param name="WeightTarget" select="WeightTarget"></xsl:with-param>
                                    <xsl:with-param name="CaloriesTarget" select="CaloriesTarget"></xsl:with-param>
                                    <xsl:with-param name="CalorieUnits" select="../CalUnits/."></xsl:with-param>
                                    <xsl:with-param name="DistanceUnits" select="../DistUnits/."></xsl:with-param>
                                    <xsl:with-param name="TimeUnits" select="../TimeUnits/."></xsl:with-param>
                                    <xsl:with-param name="WeightUnits" select="../WeightUnits/."></xsl:with-param>
                                    <xsl:with-param name="CaloriesMeasureID" select="CaloriesMeasureID"></xsl:with-param>
                                    <xsl:with-param name="DistanceMeasureID" select="DistanceMeasureID"></xsl:with-param>
                                    <xsl:with-param name="TimeMeasureID" select="TimeMeasureID"></xsl:with-param>
                                    <xsl:with-param name="WeightMeasureID" select="WeightMeasureID"></xsl:with-param>
                                    <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                    <xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
                                    <xsl:with-param name="VideoKeyValue" select="VideoKeyValue"></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="ProgExcerID" select="ProgExcerID"></xsl:with-param>
                                </xsl:call-template>
                            </xsl:for-each>
                        </tbody>
                    </table>
                </div>
                <div id="div_ProgramListExcercise_{$ProgItemID}_Suggest" style="margin:10px;width:100%;">
                    <div>
                        <input id="txt_shareIt_{$ProgItemID}_Add_Exercise" type="text" value="Add Exercise..." Class="autoSuggest" defaultValue="Add Exercise..."
                           onFocus='return AutoSuggest_ClearAutoSuggestTextbox("txt_shareIt_{$ProgItemID}_Add_Exercise");'
                          onBlur='return AutoSuggest_RestoreAutoSuggestTextbox(
                                                                            "txt_shareIt_{$ProgItemID}_Add_Exercise", 
                                                                            "div_ProgramListExcercise_{$ProgItemID}_Suggest_Suggestions");'
                          onKeyUp='brandAutoSuggest_getAutoSuggestData(event,
                                                    "{$ProgItemID}",
                                                    "txt_shareIt_{$ProgItemID}_Add_Exercise", 
                                                    "AddExerciseToProgram",
                                                    "div_ProgramListExcercise_{$ProgItemID}_Suggest_Suggestions",
                                                    "div_ProgramListExcercise_{$ProgItemID}_Suggest");'
                          onKeyPress='return brandAutoSuggest_selectAutoSuggestFromAutoSuggestTextBox(event,
                                                "{$ProgItemID}",
                                                "txt_shareIt_{$ProgItemID}_Add_Exercise", 
                                                "AddExerciseToProgram",
                                                "div_ProgramListExcercise_{$ProgItemID}_Suggest");'
                          suggestID='-99'></input>
                        <input style='margin-left:5px;' id="div_ExerciseList_{$PortalItemID}_Add_Control" type='button' class='button' value='Add'
                                 onclick='brandAutoSuggest_selectAutoSuggestFromAutoSuggestTextBox_OnButton("{$ProgItemID}",
                                                "txt_shareIt_{$ProgItemID}_Add_Exercise", 
                                                "AddExerciseToProgram",
                                                "div_ProgramListExcercise_{$ProgItemID}_Suggest","div_ProgramListExcercise_{$ProgItemID}_Suggest_Suggestions");'></input>
                    </div>
                    <div id='div_AddExercise'>
                        <div id="div_ExerciseList_{$PortalItemID}_Add_Operations" style="display:none;">
                            <xsl:call-template name="AddNewExercise">
                                <xsl:with-param name="PortalItemID" select="$PortalItemID"></xsl:with-param>
                                <xsl:with-param name="Origin">
                                    <xsl:text>Exercise_List</xsl:text>
                                </xsl:with-param>
                                <xsl:with-param name="ProgramID">
                                    <xsl:number value ="0"/>
                                </xsl:with-param>
                                <xsl:with-param name="WorkoutID">
                                    <xsl:number value ="0"/>
                                </xsl:with-param>
                                <xsl:with-param name="FitnessExerciseTypes" select="AjaxRequest/FitnessExerciseTypes/."></xsl:with-param>
                                <xsl:with-param name="ExerciseName" select="Exercises/Exercise/ExerciseName"></xsl:with-param>
                                <xsl:with-param name="Description" select="Exercises/Exercise/Description"></xsl:with-param>
                                <xsl:with-param name="TypeID" select="Exercises/Exercise/TypeID"></xsl:with-param>
                                <xsl:with-param name="CustomType" select="Exercises/Exercise/CustomType"></xsl:with-param>
                                <xsl:with-param name="ThumbnailURL" select="Exercises/Exercise/ThumbnailURL"></xsl:with-param>
                                <xsl:with-param name="ImageURL" select="Exercises/Exercise/ImageURL"></xsl:with-param>
                                <xsl:with-param name="VideoURL" select="Exercises/Exercise/VideoURL"></xsl:with-param>
                                <xsl:with-param name="LevelYN" select="Exercises/Exercise/LevelYN"></xsl:with-param>
                                <xsl:with-param name="SetsYN" select="Exercises/Exercise/SetsYN"></xsl:with-param>
                                <xsl:with-param name="RepsYN" select="Exercises/Exercise/RepsYN"></xsl:with-param>
                                <xsl:with-param name="TimeYN" select="Exercises/Exercise/TimeYN"></xsl:with-param>
                                <xsl:with-param name="DistanceYN" select="Exercises/Exercise/DistanceYN"></xsl:with-param>
                                <xsl:with-param name="WeightYN" select="Exercises/Exercise/WeightYN"></xsl:with-param>
                                <xsl:with-param name="CaloriesYN" select="Exercises/Exercise/CaloriesYN"></xsl:with-param>
                                <xsl:with-param name="IsActive" select="Exercises/Exercise/IsActive"></xsl:with-param>
                                <xsl:with-param name="IsPublic" select="Exercises/Exercise/IsPublic"></xsl:with-param>
                                <xsl:with-param name="IsPublished" select="Exercises/Exercise/IsPublished"></xsl:with-param>
                                <xsl:with-param name="BrandName" select="Exercises/BrandName"></xsl:with-param>
                                <xsl:with-param name="SettingsData" select="$SettingsData"></xsl:with-param>
                            </xsl:call-template>
                        </div>
                    </div>
                    <div id="div_ProgramListExcercise_{$ProgItemID}_Suggest_Suggestions" class="tableLocal"
                         style="position:absolute;background-color:White;display:none;">
                    </div>
                    <div style="margin-top:5px;display:none;" id ="divInsertProgramExcerciseLink">
                    </div>
                </div>

            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>
</xsl:stylesheet>
