﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:variable name="Origin" select="Notes/Origin"></xsl:variable>
        <xsl:apply-templates select ="Notes/Note">
            <xsl:with-param name="DisplayReply">
                <xsl:choose>
                    <xsl:when test="$Origin = 'comment'">
                        <xsl:text>False</xsl:text>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>True</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:with-param>
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="Note">
        <xsl:param name="DisplayReply">
            <xsl:text>True</xsl:text>
        </xsl:param>
        <xsl:variable name ="TemplatePathURL" select ="../../Notes/TemplateURL"></xsl:variable>
        <xsl:variable name ="itemID">
            <xsl:value-of select ="normalize-space(ItemID)"/>
        </xsl:variable>

        <div id="div_Note_{normalize-space($itemID)}"  style="margin-top: 2px; padding-left: 10px; padding-top: 3px; padding-bottom: 3px; background-color: #ECEFF8;"
                 class="labelSmall">
            <div id="div_Note_{normalize-space($itemID)}_View">
                <div>
                    <!--To give blue color to the name of the person-->
                    <span class="commentsFrom_Bold">
                        <xsl:value-of select ="FirstName"/>&#xa0;<xsl:value-of select ="LastName"/>
                    </span>
                    &#xa0;
                    <span id="lbl_itemNote_{normalize-space($itemID)}" class="labelSmall" wrap="true" >
                        <xsl:apply-templates select ="NoteDesc"></xsl:apply-templates>
                    </span>
                </div>

                <div>
                    <span style="color: #7F7F7F;" class="labelSmall">
                        <xsl:choose>
                            <xsl:when test="$DisplayReply = 'False'">
                                <xsl:call-template name="TimeStamp">
                                    <xsl:with-param name="CreatedMinutes" select="CreatedMinutes"></xsl:with-param>
                                </xsl:call-template>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select ="NoteDateTime"/>                                
                            </xsl:otherwise>
                        </xsl:choose>
                    </span>
                    <a href="#" class="link" style="font-size: 9pt; margin-left: 5px; margin-right: 5px;"
                                             onClick='return Notes_EditNote(
                                                                        "div_Note_{normalize-space($itemID)}_Update",
                                                                        "div_Note_{normalize-space($itemID)}_View",
                                                                        "lbl_itemNote_{normalize-space($itemID)}",
                                                                        "txt_itemNote_{normalize-space($itemID)}"
                                                                        );'>
                        Edit
                    </a>
                    <a href="#" class="link" style="font-size: 9pt;"
                                             onClick='return Notes_DeleteNote(
                                                                    "{normalize-space($itemID)}", 
                                                                    "div_Note_{normalize-space($itemID)}"
                                                                    );'>
                        Delete
                    </a>
                </div>
            </div>

            <div id="div_Note_{normalize-space($itemID)}_Update" style="display:none">
                <div>
                    <textarea id="txt_itemNote_{normalize-space($itemID)}" rows="2" class="textAreaEditMode" style="font-size: 9pt;">
                        <xsl:value-of select ="NoteDesc"/>
                    </textarea>
                </div>
                <div>
                    <a href="#" class="link" style="font-size: 9pt; margin-right: 5px;" onClick='return Notes_UpdateNote(
                                                                            "txt_itemNote_{normalize-space($itemID)}",
                                                                            "{normalize-space($itemID)}",
                                                                            "div_Note_{normalize-space($itemID)}_Update",
                                                                            "div_Note_{normalize-space($itemID)}_View",
                                                                            "lbl_itemNote_{normalize-space($itemID)}"
                                                                           );'>Update</a>
                    <a href="#" class="link" style="font-size: 9pt;" onClick='return Notes_CancelNote(
                                                                            "div_Note_{normalize-space($itemID)}_Update",
                                                                            "div_Note_{normalize-space($itemID)}_View"
                                                                          )'>Cancel</a>
                </div>
            </div>

            <!--<div id="div_Note_{normalize-space($itemID)}_Replies" style="margin-left: 20px; display: none;">

            </div>

            <div style="margin-left: 20px; display: none;">
                <xsl:if test ="$DisplayReply = 'True'">
                    <div>
                        <textarea id="txt_Note_{normalize-space($itemID)}_Replies" rows="1"
                                  onclick='return addReply("div_Note_{normalize-space($itemID)}_Replies_AddReply",
                              "txt_Note_{normalize-space($itemID)}_Replies");'
                                  onblur='return retainReplyPrevState("div_Note_{normalize-space($itemID)}_Replies_AddReply",
                              "txt_Note_{normalize-space($itemID)}_Replies");'
                                  class="textAreaNotes">Add reply here..</textarea>
                    </div>
                    <div id="div_Note_{normalize-space($itemID)}_Replies_AddReply" style="margin-top: 10px; display: none;">
                        <input value="Submit" type="button" class="button"
                               onClick='return Notes_SubmitNoteReply(
                             "div_Note_{normalize-space($itemID)}_Replies",
                             "div_Note_{normalize-space($itemID)}_Replies_AddReply",
                             "txt_Note_{normalize-space($itemID)}_Replies",
                             "{normalize-space($itemID)}"
                             );'></input>
                    </div>
                </xsl:if>
            </div>-->
        </div>
    </xsl:template>

    <xsl:template name ="TimeStamp">
        <xsl:param name="CreatedMinutes" select="'N/A'"></xsl:param>
        <font color="#7F7F7F">
            <xsl:if test ="$CreatedMinutes &lt; 1">
                &#xa0;<xsl:value-of select="round(normalize-space($CreatedMinutes) * 60)"/> second(s) ago
            </xsl:if>
            <xsl:if test ="$CreatedMinutes &gt;= 1 and $CreatedMinutes &lt; 60">
                &#xa0;<xsl:value-of select="round(normalize-space($CreatedMinutes))"/> minute(s) ago
            </xsl:if>
            <xsl:if test ="$CreatedMinutes &gt;= 60 and $CreatedMinutes &lt; 1440 ">
                &#xa0;<xsl:value-of select="round(normalize-space($CreatedMinutes) div 60)"/> hour(s) ago
            </xsl:if>
            <xsl:if test ="$CreatedMinutes &gt; 1440 ">
                &#xa0;<xsl:value-of select="round(normalize-space($CreatedMinutes) div 1440)"/> day(s) ago
            </xsl:if>
        </font>
    </xsl:template>

    <xsl:template match ='NoteDesc'>
        <xsl:call-template name ='break'></xsl:call-template>
    </xsl:template>

    <xsl:include href="GenericTemplates/Notes_LineBreak.xslt"/>

</xsl:stylesheet>
