﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:include href="GenericTemplates/NewAction.xslt"/>
    <xsl:include href="GenericTemplates/NewItemSummary.xslt"/>
    <xsl:include href="GenericTemplates/NewEvent.xslt"/>
    <xsl:include href="Modules/WorkoutTracker/WorkoutPrograms.xslt"/>
    <xsl:include href="Version_2_0/PopUpHeader.xslt"/>


    <xsl:template match="/">

        <xsl:variable name ="TemplatePathURL" select ="TaskDetail/TemplateURL"/>
        <xsl:variable name ="SiblingID" select ="normalize-space(TaskDetail/Task/SiblingID)"/>
        <xsl:variable name ="LoggedInUserID" select ="normalize-space(TaskDetail/LoggedInUserID)"/>
        <xsl:variable name="IsPortalAdmin">
            <xsl:choose>
                <xsl:when test="TaskDetail/PortalUsers/ShareITRecords/ShareIT[ID = $LoggedInUserID]/PermissionID &gt;= 4">
                    <xsl:number value="1"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:number value="0"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="CommunityAdmin" select="TaskDetail/UserRoles/Role[RoleName = 'Community Admin']"></xsl:variable>

        <xsl:variable name ="responsibleID">
            <xsl:choose>
                <xsl:when test="TaskDetail/Users/User[Coach = 1] and TaskDetail/Users/User[Coach = 1]/ID = TaskDetail/Task/UserID">
                    <xsl:value-of select="TaskDetail/Task/OwnerID"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="TaskDetail/Task/UserID"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <xsl:variable name ="GoalID" select ="normalize-space(TaskDetail/Task/GoalID)"/>
        <xsl:variable name="ParentID" select ="normalize-space(TaskDetail/Task/ParentID)"/>
        <xsl:variable name ="DivPrefix">
            <xsl:text>div_item_</xsl:text>
            <xsl:value-of select ="$SiblingID"/>
        </xsl:variable>
        <xsl:variable name="Version" select="normalize-space(TaskDetail/Version)"/>
        <xsl:variable name ="TopicName" select ="normalize-space(TaskDetail/TopicName)"/>
        <xsl:variable name ="IsPlannerItem" select ="normalize-space(TaskDetail/IsPlannerItem)"/>
        <xsl:variable name ="SelectedDate" select ="normalize-space(TaskDetail/SelectedDate)"/>

        <xsl:variable name="LSItemID" select="TaskDetail/Task/LifeSpaceItemID"></xsl:variable>
        <xsl:variable name="TopicID" select="TaskDetail/TopicID"></xsl:variable>
        <xsl:variable name="LinkedLSIDForBrandBasedOnBrandType" select="TaskDetail/Task/LinkedLSIDForBrandBasedOnBrandType"></xsl:variable>

        <xsl:variable name="Mode">
            <xsl:choose>
                <xsl:when test="number($IsPlannerItem) = 1">
                    <xsl:text>PlannerAction</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>GoalAction</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>


        <div id="divAddNewItem_{$GoalID}">
            <xsl:call-template name="PopUpHeader">
                <xsl:with-param name="ItemID" select="$GoalID"></xsl:with-param>
                <xsl:with-param name="TemplateURL" select="$TemplatePathURL"></xsl:with-param>
                <xsl:with-param name="HeaderText">
                    <xsl:text>Add a New Item</xsl:text>
                </xsl:with-param>
            </xsl:call-template>
            <div id="divAddNewItemHeader_{$GoalID}_PopUpContent" style="margin:15px;" class="labelGoalTopicsText">
                Want to include a new topic or task to your check list? Simply add the new item,
                date and related details below.
            </div>
            <div style="margin:10px;padding-left:95px;">
                <xsl:choose>
                    <xsl:when test="$SiblingID = 0 and $Mode != 'PlannerAction'">
                        <input id="rbItemSummary" type="radio" name="ItemType"
							   onclick='changeNewItemType("div_item_{$SiblingID}_SummaryType", 
                                                "div_item_{$SiblingID}_ActionType", 
                                                "div_item_{$SiblingID}_EventType", 
                                                "lbl_Item_{$SiblingID}_Sibling_Title",
                                                "div_item_{$SiblingID}_Workout","{$SiblingID}")'>
                            <span class="taskFilter capitalFont" style='margin-right:10px'>TOPIC</span>
                        </input>
                        <input id="rbItemAction" type="radio" name="ItemType" checked="true"
							   onclick='changeNewItemType("div_item_{$SiblingID}_SummaryType", 
                                                "div_item_{$SiblingID}_ActionType", 
                                                "div_item_{$SiblingID}_EventType", 
                                                "lbl_Item_{$SiblingID}_Sibling_Title",
                                                "div_item_{$SiblingID}_Workout","{$SiblingID}")'>
                            <span class="taskFilter capitalFont" style='margin-right:10px'>ACTION</span>
                        </input>
                        <xsl:if test="$LSItemID = 3 or $LinkedLSIDForBrandBasedOnBrandType = 3">
                            <input id="rbItemWorkout" type="radio" name="ItemType"
								  onclick='DisplayWorkoutPrograms("div_item_{$SiblingID}_SummaryType", 
                                                "div_item_{$SiblingID}_ActionType",                                                 
                                                "lbl_Item_{$SiblingID}_Sibling_Title",
                                                "div_item_{$SiblingID}_Workout",
                                                "{$GoalID}","{$responsibleID}","{$SiblingID}","NotPlanner","{$SelectedDate}")'>
                                <span class="taskFilter capitalFont" style='margin-right:10px'>WORKOUT</span>
                            </input>
                        </xsl:if>
                       
                        <!--<xsl:if test="$IsPortalAdmin = 1 or $CommunityAdmin">-->
                            <input id="rbItemSurvey" type="radio" name="ItemType"
                                   onclick='changeNewItemType("div_item_{$SiblingID}_SummaryType", 
                                                "div_item_{$SiblingID}_ActionType", 
                                                "div_item_{$SiblingID}_EventType", 
                                                "lbl_Item_{$SiblingID}_Sibling_Title",
                                                "div_item_{$SiblingID}_Workout","{$SiblingID}")'>
                                <span class="taskFilter capitalFont" style='margin-right:10px'>WORKSHEET / CALL SHEET</span>
                            </input>
                        <!--</xsl:if>-->
                    </xsl:when>
                    <xsl:otherwise>
                        <input id="rbItemAction" type="radio" name="ItemType" checked="true"
							   onclick='changeNewItemType("div_item_{$SiblingID}_SummaryType", 
                                                "div_item_{$SiblingID}_ActionType", 
                                                "div_item_{$SiblingID}_EventType", 
                                                "lbl_Item_{$SiblingID}_Sibling_Title",
                                                "div_item_{$SiblingID}_Workout","{$SiblingID}")'>
                            <span class="taskFilter capitalFont" style='margin-right:10px'>ACTION</span>
                        </input>
                        <xsl:if test="$LSItemID = 3 or $LinkedLSIDForBrandBasedOnBrandType = 3">
                            <input id="rbItemWorkout" type="radio" name="ItemType"
								  onclick='DisplayWorkoutPrograms("div_item_{$SiblingID}_SummaryType", 
                                                "div_item_{$SiblingID}_ActionType",                                              
                                                "lbl_Item_{$SiblingID}_Sibling_Title",
                                                "div_item_{$SiblingID}_Workout",
                                                "{$GoalID}","{$responsibleID}","{$SiblingID}","Planner","{$SelectedDate}")'>
                                <span class="taskFilter capitalFont" style='margin-right:10px'>WORKOUT</span>
                            </input>
                        </xsl:if>
                        <input id="rbItemSurvey" type="radio" name="ItemType"
                               onclick='changeNewItemType("div_item_{$SiblingID}_SummaryType", 
                                                "div_item_{$SiblingID}_ActionType", 
                                                "div_item_{$SiblingID}_EventType", 
                                                "lbl_Item_{$SiblingID}_Sibling_Title",
                                                "div_item_{$SiblingID}_Workout","{$SiblingID}")'>
                            <span class="taskFilter capitalFont" style='margin-right:10px'>WORKSHEET / CALL SHEET</span>
                        </input>                        
                    </xsl:otherwise>
                </xsl:choose>
            </div>

            <div style='margin:10px'>
                <div style='margin:0px; padding:0px;'>
                    <table width='100%' cellpadding='4'>
                        <tr>
                            <td style="width: 90px;" class="textRight verticallyMiddle">
                                <span id="lbl_Item_{$SiblingID}_Sibling_Title" class="goalUpdateLabel">Item</span>
                            </td>
                            <td>
                                <table  width='100%' cellpadding='0' cellspacing='0'>
                                    <tr>
                                        <td>
                                            <input id="txt_Item_{$SiblingID}_Sibling_Title" type="text"
												   class="textAreaNotes2" value="" tabindex="1" maxlength="75"/>
                                        </td>
                                        <td>
                                            <span id="span_item_{$SiblingID}_Sibling_ErrorMessage"
											class="labelError" style="display:none;margin-right:-6px;">*</span>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </div>

                <div id="div_item_{$SiblingID}_SummaryType"  style="display:none;margin:0px; padding:0px;">
                    <xsl:call-template name="NewItemSummary">
                        <xsl:with-param name="SiblingID" select="$SiblingID"/>
                        <xsl:with-param name="TemplatePathURL" select="$TemplatePathURL"/>
                        <xsl:with-param name="ItemDivPrefix" select="$DivPrefix"/>
                        <xsl:with-param name="GoalID" select="$GoalID"/>
                        <xsl:with-param name="ParentID" select="$ParentID"/>
                        <xsl:with-param name="Version" select="$Version"/>
                    </xsl:call-template>
                </div>

                <div id="div_item_{$SiblingID}_ActionType" style="display:block;margin:0px; padding:0px;">
                   
                    <xsl:call-template name="NewAction">
                        <xsl:with-param name="SiblingID" select="$SiblingID"/>
                        <xsl:with-param name="ItemDivPrefix" select="$DivPrefix"/>
                        <xsl:with-param name="TemplatePathURL" select="$TemplatePathURL"/>
                        <xsl:with-param name="responsibleID" select="$responsibleID"/>
                        <xsl:with-param name="GoalID" select="$GoalID"/>
                        <xsl:with-param name="ParentID" select="$ParentID"/>
                        <xsl:with-param name="Version" select="$Version"/>
                        <xsl:with-param name="TopicName" select="$TopicName"/>
                        <xsl:with-param name="Mode" select="$Mode"/>
                        <xsl:with-param name="TopicID" select="$TopicID"></xsl:with-param>
                        <xsl:with-param name="LSItemID" select="$LSItemID"></xsl:with-param>
                    </xsl:call-template>
                </div>

                <div id="div_item_{$SiblingID}_EventType" style="display:none">
                    <xsl:call-template name="NewEvent">
                        <xsl:with-param name="SiblingID" select="$SiblingID"/>
                        <xsl:with-param name="ItemDivPrefix" select="$DivPrefix"/>
                        <xsl:with-param name="TemplatePathURL" select="$TemplatePathURL"/>
                        <xsl:with-param name="responsibleID" select="$responsibleID"/>
                        <xsl:with-param name="GoalID" select="$GoalID"/>
                        <xsl:with-param name="ParentID" select="$ParentID"/>
                    </xsl:call-template>
                </div>

                <div id="div_item_{$SiblingID}_Workout" style="display:none;">
                    <xsl:call-template name="WorkOutPrograms">
                        <xsl:with-param name="PortalItemID" select="TaskDetail/FitnessPrograms/FitnessProgram/PortalItemID"></xsl:with-param>
                        <xsl:with-param name="FitnessXML" select="TaskDetail/FitnessPrograms/."></xsl:with-param>
                        <!--<xsl:with-param name="Mode" select="AjaxRequest/Params/Mode"></xsl:with-param>
                    <xsl:with-param name="SelDate" select="AjaxRequest/Params/SelectedDate"></xsl:with-param>
                    <xsl:with-param name="AccName" select="AjaxRequest/Params/AccName"></xsl:with-param>-->
                        <xsl:with-param name="AccID" select="TaskDetail/FitnessPrograms/FitnessProgram/AccountID"></xsl:with-param>
                    </xsl:call-template>
                </div>

                <div id="div_item_{$SiblingID}_Survey" style="display:none;margin:0px; padding-bottom:10px;padding-left:50px;text-align: center" align="center">

                    <table class="tableMaster">
                        <tr>
                            <td width="10%">
                                <span class="publicationSummary">Worksheet</span>
                            </td>
                            <td>
                                <select id="opt_item_{$SiblingID}_Survey" class="largeDropdown"
                                        onChange="suvey_AddSurveyTooal({$GoalID}, 'opt_item_{$SiblingID}_Survey', {$ParentID})">
                                    <option value="-99"></option>
                                    <xsl:for-each select="TaskDetail/SurveyListXML/Survey">
                                        <option value="{SurveyID}">
                                            <xsl:value-of select="Item"/>
                                        </option>
                                    </xsl:for-each>
                                </select>
                            </td>
                        </tr>
                    </table>

                </div>

            </div>
        </div>
    </xsl:template>
</xsl:stylesheet>
