﻿<?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:output method="xml" indent="yes"/>

    <xsl:template match="/">

        <xsl:choose>
            <xsl:when test="ActionInfo/ItemID">
                <xsl:call-template name="ItemTitleName">
                    <xsl:with-param name="ItemID" select="ActionInfo/ItemID"></xsl:with-param>
                    <xsl:with-param name="ItemName" select="ActionInfo/ItemName"></xsl:with-param>
                    <xsl:with-param name="StatusID" select="ActionInfo/StatusID"></xsl:with-param>
                    <xsl:with-param name="TotalDays" select="ActionInfo/TotalDays"></xsl:with-param>
                    <xsl:with-param name="Mode" select="ActionInfo/Mode"></xsl:with-param>
                    <xsl:with-param name="ShortName" select="ActionInfo/ShortItemName"></xsl:with-param>
                    <xsl:with-param name="TemplateURL" select="ActionInfo/TemplateURL"></xsl:with-param>
                    <xsl:with-param name="GoalID" select="ActionInfo/GoalID"></xsl:with-param>
                    <xsl:with-param name="ItemDivPrefix" select="ActionInfo/ItemDivPrefix"></xsl:with-param>
                    <xsl:with-param name="OwnerPortalItemID" select="ActionInfo/OwnerPortalItemID"></xsl:with-param>
                    <xsl:with-param name="ItemType" select="ActionInfo/TypeID"></xsl:with-param>
                    <xsl:with-param name="HostName" select="ActionInfo/HostName"></xsl:with-param>
                    <xsl:with-param name="TopicName" select="ActionInfo/TopicName"></xsl:with-param>
                    <xsl:with-param name="PermissionID" select="ActionInfo/PermissionID"></xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="ItemTitleName">
                    <xsl:with-param name="ItemID" select="TournamentDetail/Tournament/ItemID"></xsl:with-param>
                    <xsl:with-param name="ItemName" select="TournamentDetail/Tournament/Name"></xsl:with-param>
                    <xsl:with-param name="StatusID" select="TournamentDetail/Tournament/StatusID"></xsl:with-param>
                    <xsl:with-param name="TotalDays" select="TournamentDetail/Tournament/TotalDays"></xsl:with-param>
                    <xsl:with-param name="Mode" select="TournamentDetail/Mode"></xsl:with-param>
                    <xsl:with-param name="ShortName" select="TournamentDetail/Tournament/ShortItemName"></xsl:with-param>
                    <xsl:with-param name="TemplateURL" select="TournamentDetail/TemplateURL"></xsl:with-param>
                    <xsl:with-param name="GoalID" select="TournamentDetail/Tournament/PortalItemID"></xsl:with-param>
                    <xsl:with-param name="ItemDivPrefix" select="TournamentDetail/ItemDivPrefix"></xsl:with-param>
                    <xsl:with-param name="OwnerPortalItemID" select="TournamentDetail/Tournament/PortalItemID"></xsl:with-param>
                    <xsl:with-param name="ItemType" select="TournamentDetail/Tournament/TypeID"></xsl:with-param>
                    <xsl:with-param name="BrandKey" select="TournamentDetail/Tournament/BrandKey"></xsl:with-param>
                    <xsl:with-param name="HostName" select="TournamentDetail/HostName"></xsl:with-param>
                    <xsl:with-param name="TournamentTime" select="TournamentDetail/Tournament/TournamentTime"></xsl:with-param>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>

    <xsl:template name="ItemTitleName">

        <xsl:param name="ItemID" select="'Not Available'"></xsl:param>
        <xsl:param name="ItemName" select="'Not Available'"></xsl:param>
        <xsl:param name="StatusID" select="'Not Available'"></xsl:param>
        <xsl:param name="FirstName" select="'Not Available'"></xsl:param>
        <xsl:param name="MineOrOther" select="'Not Available'"></xsl:param>
        <xsl:param name="Mode" select="'Not Available'"></xsl:param>
        <xsl:param name="TotalDays" select="'Not Available'"></xsl:param>
        <xsl:param name="ShortName" select="'Not Available'"></xsl:param>
        <xsl:param name="OrderBy" select="'Not Available'"></xsl:param>
        <xsl:param name="ItemType" select="'Not Available'"></xsl:param>
        <xsl:param name="TemplateURL" select="'Not Available'"></xsl:param>
        <xsl:param name="GoalID" select="'Not Available'"></xsl:param>
        <xsl:param name="ItemDivPrefix" select="'Not Available'"></xsl:param>
        <xsl:param name="OwnerPortalItemID" select="'Not Available'"></xsl:param>
        <xsl:param name="BrandKey" select="'N/A'"></xsl:param>
        <xsl:param name="HostName" select="'N/A'"></xsl:param>
        <xsl:param name="TournamentTime" select="'N/A'"></xsl:param>
        <xsl:param name="TopicName" select="'N/A'"></xsl:param>
        <xsl:param name="PermissionID" select="'N/A'"></xsl:param>
        <xsl:param name="UserID" select="'N/A'"></xsl:param>

        <xsl:variable name="DisplayTitle">
            <xsl:choose>
                <xsl:when test="($Mode = 'Planner') and $ShortName != $ItemName">
                    <xsl:value-of select="$ShortName"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$ItemName"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <xsl:variable name="ItemStatusCSSClass">
            <xsl:choose>
                <xsl:when test="($StatusID = 2 and $Mode != 'DayPlanner' and $Mode != 'Planner')
                          or ($StatusID = 2 and $TotalDays &gt;= 0 and ($Mode = 'DayPlanner' or $Mode = 'Planner'))">
                    <xsl:text>inProgress</xsl:text>
                </xsl:when>
                <xsl:when test="$StatusID = 4">
                    <xsl:text>completed</xsl:text>
                </xsl:when>
                <xsl:when test="$StatusID = 3">
                    <xsl:text>waiting</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>notStarted</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <xsl:variable name="SpanFontSize">
            <xsl:choose>
                <xsl:when test="$Mode = 'Planner'">
                    <xsl:text>10px</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>16px</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <xsl:variable name="divID">
            <xsl:choose>
                <xsl:when test="$Mode = 'Planner' or $Mode = 'DayPlanner'">
                    <xsl:text>divHover</xsl:text>
                </xsl:when>
            </xsl:choose>
        </xsl:variable>

        <xsl:variable name="OnClickFunction">
            <xsl:choose>
                <xsl:when test="$ItemType != ''">
                    <xsl:text>return viewItemDetailVersion2('</xsl:text>
                    <xsl:value-of select="$ItemID"></xsl:value-of>
                    <xsl:text>', '</xsl:text>
                    <xsl:value-of select="$GoalID"></xsl:value-of>
                    <xsl:text>', '</xsl:text>
                    <xsl:value-of select="$ItemDivPrefix"></xsl:value-of>
                    <xsl:text>_detail_container', '</xsl:text>
                    <xsl:value-of select="$ItemDivPrefix"></xsl:value-of>
                    <xsl:text>','2.0', 'view');</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>return workout_GetWorkoutView('</xsl:text>
                    <xsl:value-of select="$ItemID"></xsl:value-of>
                    <xsl:text>', '</xsl:text>
                    <xsl:value-of select="$UserID"></xsl:value-of>
                    <xsl:text>', '</xsl:text>
                    <xsl:value-of select="$OwnerPortalItemID"></xsl:value-of>
                    <xsl:text>', '</xsl:text>
                    <xsl:text>ClientAccount_Operations_Filters');</xsl:text>        
                </xsl:otherwise>
            </xsl:choose>

        </xsl:variable>

        <xsl:variable name="TitleValue">
            <xsl:value-of select="$ItemName"/>
            <xsl:text> (</xsl:text>
            <xsl:value-of select="$TopicName"/>
            <xsl:text>)</xsl:text>
        </xsl:variable>

        <xsl:choose>
            <xsl:when test="$ItemType = 33">
                <div id="{$divID}" class="textLeft">
         
                    <a title="{$ItemName}" style="color:#808285;" target="_blank" href="http://{$HostName}/TournamentAdmin/{$ItemID}" class="decorationNone {$ItemStatusCSSClass}"
					   onmouseover="this.style.color='#414042';" onmouseout="this.style.color='#808285';">
                        <xsl:value-of select="$DisplayTitle"/>
                        <xsl:if test="$TournamentTime !=''">
                            <div class="marginLeft5">
                                <xsl:value-of select="$TournamentTime"/>
                            </div>
                        </xsl:if>
                    </a>
                </div>
            </xsl:when>
            <xsl:when test="not($ItemType) or $ItemType = ''">
                <div id="{$divID}" class="textLeft">
                    <xsl:choose>
                        <xsl:when test="($StatusID = 2 and $TotalDays &gt;= 0 and $Mode != 'DayPlanner' and $Mode != 'Planner')
                                        or 
                                        ($StatusID = 2 and $TotalDays &gt;= 0 and ($Mode = 'DayPlanner' or $Mode = 'Planner'))">
                        </xsl:when>
                        <xsl:when test="$StatusID = 4">
                        </xsl:when>
                        <xsl:when test="$TotalDays &lt; 0 and $Mode != 'DayPlanner' and $Mode != 'Planner' and $StatusID != 3">
                            <img src="/DesktopModules/LifeSpaceTemplates/Web/Images/Ver_2_0/alertRedDot.png" style="margin-right:5px;"></img>
                        </xsl:when>
                        <xsl:otherwise>
                        </xsl:otherwise>
                    </xsl:choose>

                    <xsl:choose>
                        <xsl:when test="$ItemType = 30">
                            <xsl:if test="$PermissionID &gt;= 4">
                                <span title="{$TitleValue}" class="{$ItemStatusCSSClass}" style="color:#01A9DB;font-size:{$SpanFontSize};">
                                    <xsl:value-of select="$DisplayTitle"/>
                                </span>
                            </xsl:if>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:choose>
                                <xsl:when test="$StatusID!=4">

                                    <span title="{$TitleValue}" class="{$ItemStatusCSSClass}" style="font-size:{$SpanFontSize};"
										  onclick="{$OnClickFunction}">
                                        <xsl:value-of select="$DisplayTitle"/>
                                    </span>
                                </xsl:when>
                                <xsl:otherwise>
                                    <span title="{$TitleValue}" class="{$ItemStatusCSSClass}" onclick="{$OnClickFunction}" style="font-size:{$SpanFontSize};">
                                        <xsl:value-of select="$DisplayTitle"/>
                                    </span>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:otherwise>
                    </xsl:choose>
                    <xsl:if test="$OrderBy!='2' and $ItemType != 30">
                        <span class="{$ItemStatusCSSClass}" style="font-size:{$SpanFontSize};">
                            <xsl:choose>
                                <xsl:when test="$Mode = 'ActionPlan' or $Mode = 'PastDue' or $Mode = 'Day/Goal' or $Mode = 'Planner' or $Mode = 'DayPlanner'">

                                </xsl:when>
                                <xsl:otherwise>
                                    (<xsl:choose>
                                        <xsl:when test="$MineOrOther = 'Me'">
                                            <span>
                                                <xsl:value-of select="$MineOrOther"/>
                                            </span>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <span>
                                                <xsl:value-of select="$FirstName"/>
                                            </span>
                                        </xsl:otherwise>
                                    </xsl:choose>)
                                </xsl:otherwise>
                            </xsl:choose>
                        </span>
                    </xsl:if>

                    <xsl:if test="$Mode != 'Planner' and $Mode != 'DayPlanner'">
                        <xsl:choose>
                            <xsl:when test="$ItemType=28">
                                <img id="img_editItem_{$ItemID}" style="display:none;padding-bottom:5px;" 
                                     align="absmiddle" class="onMouseOver marginLeft5" alt="" height="12" width="12" title="Edit This Workout"
                                     src="{$TemplateURL}Web/Images/Ver_2_0/edit_goal.png" onclick="{$OnClickFunction}"></img>
                            </xsl:when>
                            <xsl:when test="$ItemType=14">
                                <img id="img_editItem_{$ItemID}" style="display:none;padding-bottom:5px;" 
                                     align="absmiddle" class="onMouseOver marginLeft5" alt="" height="12" width="12" title="Edit This Worksheet"
                                     src="{$TemplateURL}Web/Images/Ver_2_0/edit_goal.png" 
                                     onclick="return viewSurveyItemDetail('{$ItemID}', '{$GoalID}', '{$ItemDivPrefix}_detail_container');"></img>
                            </xsl:when>
                            <xsl:otherwise>
                                <img id="img_editItem_{$ItemID}" style="display:none;padding-bottom:5px;" 
                                     align="absmiddle" class="onMouseOver marginLeft5" alt="" height="12" width="12" title="Edit This Action"
                                     src="{$TemplateURL}Web/Images/Ver_2_0/edit_goal.png" 
                                     onclick="return viewItemDetailVersion2('{$ItemID}', '{$GoalID}', '{$ItemDivPrefix}_detail_container', '{$ItemDivPrefix}','2.0', 'edit');"></img>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:if>
                </div>
            </xsl:when>
            <xsl:otherwise>
                <div id="{$divID}" class="textLeft" 
                     onmouseover="if({$ItemType}==9 || {$ItemType}==14 || {$ItemType}==28)document.getElementById('img_editItem_{$ItemID}').style.display='inline';"
                     onmouseout="if({$ItemType}==9 || {$ItemType}==14 || {$ItemType}==28)document.getElementById('img_editItem_{$ItemID}').style.display='none';">
                    <xsl:choose>
                        <xsl:when test="($StatusID = 2 and $TotalDays &gt;= 0 and $Mode != 'DayPlanner' and $Mode != 'Planner')
                                        or 
                                        ($StatusID = 2 and $TotalDays &gt;= 0 and ($Mode = 'DayPlanner' or $Mode = 'Planner'))">
                        </xsl:when>
                        <xsl:when test="$StatusID = 4">
                        </xsl:when>
                        <xsl:when test="$TotalDays &lt; 0 and $Mode != 'DayPlanner' and $Mode != 'Planner' and $StatusID != 3">
                            <img src="/DesktopModules/LifeSpaceTemplates/Web/Images/Ver_2_0/alertRedDot.png" style="margin-right:5px;"></img>
                        </xsl:when>
                        <xsl:otherwise>
                        </xsl:otherwise>
                    </xsl:choose>



                    <xsl:choose>
                        <xsl:when test="$ItemType = 30">
                            <xsl:if test="$PermissionID &gt;= 4">
                                <span title="{$TitleValue}" class="{$ItemStatusCSSClass}" style="color:#01A9DB;font-size:{$SpanFontSize};">
                                    <xsl:value-of select="$DisplayTitle"/>
                                </span>
                            </xsl:if>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:choose>
                                <xsl:when test="$StatusID!=4">
                                    <span id="span_Title_{$ItemID}" title="{$TitleValue}" class="{$ItemStatusCSSClass}" onclick="{$OnClickFunction}" style="font-size:{$SpanFontSize};" >                              
                                        <xsl:value-of select="$DisplayTitle"/>
                                    </span>
                                </xsl:when>
                                <xsl:otherwise>
                                    <span id="span_Title_{$ItemID}" title="{$TitleValue}" class="{$ItemStatusCSSClass}" onclick="{$OnClickFunction}" style="font-size:{$SpanFontSize};">
                                        <xsl:value-of select="$DisplayTitle"/>
                                    </span>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:otherwise>
                    </xsl:choose> 
      
                    <xsl:if test="$OrderBy!='2' and $ItemType != 30">
                        <span class="{$ItemStatusCSSClass}" style="font-size:{$SpanFontSize};">
                            
                            <xsl:choose>
                                <xsl:when test="$Mode = 'ActionPlan' or $Mode = 'PastDue' or $Mode = 'Day/Goal' or $Mode = 'Planner' or $Mode = 'DayPlanner'">

                                </xsl:when>
                                <xsl:otherwise>
                                    (<xsl:choose>
                                        <xsl:when test="$MineOrOther = 'Me'">
                                            <span>
                                                <xsl:value-of select="$MineOrOther"/>
                                            </span>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <span>
                                                <xsl:value-of select="$FirstName"/>
                                            </span>
                                        </xsl:otherwise>
                                    </xsl:choose>)
                                </xsl:otherwise>
                            </xsl:choose>
                        </span>
                    </xsl:if>

                    <xsl:if test="$Mode != 'Planner' and $Mode != 'DayPlanner'">
                        <xsl:choose>
                            <xsl:when test="$ItemType=28">
                                <img id="img_editItem_{$ItemID}" style="display:none;padding-bottom:5px;" align="absmiddle" class="onMouseOver marginLeft5" alt="" height="12" width="12" title="Edit This Workout"
                                src="{$TemplateURL}Web/Images/Ver_2_0/edit_goal.png" onclick="{$OnClickFunction}"></img>
                            </xsl:when>
                            <xsl:when test="$ItemType=14">
                                <img id="img_editItem_{$ItemID}" style="display:none;padding-bottom:5px;" align="absmiddle" class="onMouseOver marginLeft5" alt="" height="12" width="12" title="Edit This Worksheet"
                                     src="{$TemplateURL}Web/Images/Ver_2_0/edit_goal.png"
                                     onclick="return viewSurveyItemDetail('{$ItemID}', '{$GoalID}', 'div_item_{$ItemID}_detail_container');"></img>
                            </xsl:when>
                            <xsl:otherwise>
                                <img id="img_editItem_{$ItemID}" style="display:none;padding-bottom:5px;" align="absmiddle" class="onMouseOver marginLeft5" alt="" height="12" width="12" title="Edit This Action"
                                src="{$TemplateURL}Web/Images/Ver_2_0/edit_goal.png" onclick="return viewItemDetailVersion2('{$ItemID}', '{$GoalID}', 
						 '{$ItemDivPrefix}_detail_container', '{$ItemDivPrefix}','2.0', 'edit');"></img>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:if>               
                </div>
              <div>
              </div>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
