﻿<?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: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:call-template>

    </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:variable name="DisplayTitle">
            <xsl:choose>
                <xsl:when test="($Mode = 'Planner' or $Mode = 'DayPlanner') and $ShortName != $ItemName">                  
                    <xsl:value-of select="$ItemName"/>
                </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="$TotalDays &lt; 0 and ($Mode = 'Planner' or $Mode = 'DayPlanner')">
                    <xsl:text>pastDue</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>notStarted</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>
        <div id="{$divID}">
            <xsl:choose>
                <xsl:when test="$StatusID != 4">
                    <span title="{$ItemName}" class="{$ItemStatusCSSClass}"
                          onmouseover="this.style.textDecoration='underline';"
                          onmouseout="this.style.textDecoration='none';">
                        <xsl:value-of select ="$DisplayTitle"/>
                    </span>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <xsl:when test="$ItemType = 30">
                      <span title="{$ItemName}" class="{$ItemStatusCSSClass}" style="color:#01A9DB;">
                        <xsl:value-of select ="$DisplayTitle"/>
                      </span>
                    </xsl:when>
                    <xsl:when test="$ItemType != 30">
                      <span title="{$ItemName}" class="{$ItemStatusCSSClass}">
                        <xsl:value-of select ="$DisplayTitle"/>
                      </span>
                    </xsl:when>
                  </xsl:choose>
                   
                </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="$OrderBy!='2' and $ItemType != 30">
                <span class="{$ItemStatusCSSClass}">
                    <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>
        </div>
    </xsl:template>
</xsl:stylesheet>
