﻿<?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="GoalTaskItemDetailed.xslt"/>
	<xsl:output method="xml" indent="yes"/>
	<!--<xsl:key name="GoalItemKey" match="Record/GoalItem" use="." />-->
	<xsl:key name="GroupOwnerGoalTopicKey" match="Record/GroupOwnerGoalTopic" use="."/>
	<xsl:key name="GroupKey" match="Record/GroupOwnerAndGoal" use="." />
	<xsl:key name="TopicKey" match="Record/TopicID" use="." />
	<xsl:template match="/">
		<xsl:variable name="SuccessKey" select="AjaxRequest/Params/SuccessKey"></xsl:variable>
		<xsl:variable name="itemID" select="AjaxRequest/Params/ItemID"></xsl:variable>
		<xsl:variable name="GoalsRecords" select="AjaxRequest/Goal/Records"></xsl:variable>
		<xsl:variable name="GoalIsLand" select="AjaxRequest/Goal/IsLand"></xsl:variable>
		<xsl:variable name="List" select="AjaxRequest/Goal/List"/>
		<xsl:variable name="MasterPortalItemID" select="AjaxRequest/Params/MasterPortalItemID"></xsl:variable>
		<xsl:variable name="PortalItemID" select="AjaxRequest/Params/PortalItemID"></xsl:variable>
		<xsl:variable name="LoggedInUser" select="AjaxRequest/LoggedInUserID"/>
		<xsl:variable name="OnClickTask">
			<xsl:text>	LoadCoreGoalTask_3_0('</xsl:text>
			<xsl:value-of select="$itemID"></xsl:value-of>
			<xsl:text>', 'div_Goal_</xsl:text>
			<xsl:value-of select="$itemID"></xsl:value-of>
			<xsl:text>_Operations', 'Topic', 'asc', 1);</xsl:text>
		</xsl:variable>
		<div class="tab_screen leftRowDiv">
			<div class="tab_grid TabWid noBorder" id="divIsLandTask" SelectedTask="0" count="{count($GoalsRecords/Record)}" >
				<xsl:variable name="GetGoalBySort">
					<xsl:choose>
						<xsl:when test="$SuccessKey=''">
							<xsl:copy-of select="$GoalsRecords/Record/GroupOwnerAndGoal[generate-id() = generate-id(key('GroupKey',.))]"/>
						</xsl:when>
						<xsl:when test="$itemID = '-99'">
							<xsl:copy-of select="$GoalsRecords/Record/GroupOwnerGoalTopic[generate-id() = generate-id(key('GroupOwnerGoalTopicKey',.))]"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:copy-of select="$GoalsRecords/Record/TopicID[generate-id() = generate-id(key('TopicKey',.))]"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:for-each select="msxsl:node-set($GetGoalBySort)/child::node()">
					<xsl:variable name="GroupBy">
						<xsl:value-of select="."/>
					</xsl:variable>
					<div class="fontstyl">
						<span>
							<xsl:choose>
								<xsl:when test="$SuccessKey=''">
									<xsl:value-of select="$GroupBy"/>
								</xsl:when>
								<xsl:when test="$itemID = '-99'">
									<xsl:value-of select="$GroupBy"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$GoalsRecords/Record[TopicID=$GroupBy]/Topic"/>
								</xsl:otherwise>
							</xsl:choose>
						</span>
					</div>
					<xsl:variable name="GetGoalRecordGroupBy">
						<xsl:choose>
							<xsl:when test="$SuccessKey=''">
								<xsl:copy-of select="$GoalsRecords/Record[GroupOwnerAndGoal=$GroupBy]"/>
							</xsl:when>
							<xsl:when test="$itemID = '-99'">
								<xsl:copy-of select="$GoalsRecords/Record[GroupOwnerGoalTopic=$GroupBy]"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:copy-of select="$GoalsRecords/Record[TopicID=$GroupBy]"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:variable>
					<xsl:for-each select="msxsl:node-set($GetGoalRecordGroupBy)/child::node()">
						<xsl:call-template name="GoalTaskSmall">
							<xsl:with-param name="CurrentBriefRecordRow" select="."></xsl:with-param>
							<xsl:with-param name="GoalIsLand" select="$GoalIsLand"></xsl:with-param>
							<xsl:with-param name="List" select="$List"></xsl:with-param>
							<xsl:with-param name="LoggedInUser" select="$LoggedInUser"></xsl:with-param>
							<xsl:with-param name="itemID" select="GoalItemID"></xsl:with-param>
							<xsl:with-param name="SuccessKey" select="$SuccessKey"></xsl:with-param>
						</xsl:call-template>
					</xsl:for-each>
				</xsl:for-each>
			</div>
		</div>
		<xsl:if test="$itemID !=-99 and $SuccessKey !='BusinessPlanning'">
			<div class="onMouseOver" style=" margin: 10px;   width: 95%;   padding: 8px;  text-align: center;    float: left;" onclick="{$OnClickTask}">
				<a href="javacripit:void()" onclick="return false;" style="font-size:14px; text-decoration:underline;">View All</a>
			</div>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>
