﻿<?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 ="DivID" select ="normalize-space(AjaxRequest/Params/DivID)"></xsl:variable>
		<xsl:variable name="WorkoutItemID" select="AjaxRequest/Params/ItemID"></xsl:variable>
		<xsl:variable name="ItemID">
			<xsl:choose>
				<xsl:when test="AjaxRequest/ActiveGoals/SourceItemID[text()]">
					<xsl:value-of select="AjaxRequest/ActiveGoals/SourceItemID"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="AjaxRequest/Params/PortalItemID"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="TypeID" select="AjaxRequest/ActiveGoals/SourceItemType"></xsl:variable>
		<xsl:variable name="ResponsibleID" select="AjaxRequest/ActiveGoals/ResponsibleID"></xsl:variable>
		<xsl:variable name="SelectedDate" select="AjaxRequest/Params/SelectedDate"></xsl:variable>
		<xsl:variable name="Mode" select="AjaxRequest/Params/Mode"></xsl:variable>
		<xsl:variable name="LoggedInUserID" select="AjaxRequest/LoggedInUserID"></xsl:variable>
		<xsl:variable name="Action" select="AjaxRequest/Action"></xsl:variable>
		<xsl:variable name="PortalItemID" select="AjaxRequest/Params/PortalItemID"></xsl:variable>
		<xsl:variable name="SelectedUserID" select="AjaxRequest/Params/UserID"></xsl:variable>

		<div id="divPlanner_GoalList" style="height: 250p;oxverflow-x: scroll">
			<span class="packageTitle marginLeft10" style="margin-bottom:30px;font-size:20px;">Select a goal/program to add the item to</span>
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td>
						<div style="padding-left:10px;">
							<xsl:variable name="ItemsCount">
								<xsl:value-of select="count(AjaxRequest/ActiveGoals/Items[successkey != 'Number'])"/>
							</xsl:variable>
							<xsl:variable name="coachingGoalCount">
								<xsl:value-of select="count(AjaxRequest/ActiveGoals/Items[successkey = 'Coaching'])"/>
							</xsl:variable>
							<xsl:choose>
								<xsl:when test="$ItemsCount&gt;1 and ($coachingGoalCount=0 or $coachingGoalCount &gt;1)">
									<xsl:for-each select ="AjaxRequest/ActiveGoals/Items[not(following::LifeSpaceID = LifeSpaceID)]">
										<xsl:variable name="LifeSpaceID" select="LifeSpaceID"></xsl:variable>

										<div class="seperatorLine">
											<span class="labelBoldItalic" style="color:#003366;">
												<xsl:value-of select="LifeSpaceName"/>
											</span>
										</div>
										<div id="divPlanner_GoalList_{GoalID}" style="display:block;margin-bottom:20px;">
											<xsl:for-each select ="../Items[LifeSpaceID = $LifeSpaceID and successkey != 'Number']">
												<div id="divPlanner_{GoalID}">
													<xsl:if test="$LoggedInUserID != OwnerID">
														<span class="packageTitle marginRight5" style="font-size:13px;">
															<xsl:value-of select="OwnerName"/>
														</span>
														:
													</xsl:if>

													<xsl:choose>
														<xsl:when test="$Action = 'LoadGoalsListForNewNotes'">
															<span class="link" onClick="LoadAddNoteMemoBox('{GoalID}', '{$ItemID}', '{$SelectedUserID}')">
																<xsl:value-of select ="GoalName"/>
															</span>
														</xsl:when>
														<xsl:otherwise>
															<xsl:choose>
																<xsl:when test="$TypeID=28">
																	<span class="link" onClick="workout_linkGoal({$WorkoutItemID},{GoalID},{$ItemID},{$ResponsibleID},'{$Mode}');">
																		<xsl:value-of select ="GoalName"/>
																	</span>
																</xsl:when>
																<xsl:otherwise>
																	<span class="link" onClick="planner_AddNewActionBox({GoalID},{LifeSpaceID},'{$DivID}',0,'{$SelectedDate}');">
																		<xsl:value-of select ="GoalName"/>
																	</span>
																</xsl:otherwise>
															</xsl:choose>
														</xsl:otherwise>
													</xsl:choose>
												</div>											</xsl:for-each>
										</div>
									</xsl:for-each>
									<!--<script>document.getElementById('btnModalPopup').click();</script>-->
								</xsl:when>
								<xsl:when test="$coachingGoalCount=1">
									<xsl:variable name="GoalID" select="AjaxRequest/ActiveGoals/Items[successkey = 'Coaching']/GoalID"></xsl:variable>
									<script>

										<xsl:text>LoadAddNoteMemoBox('</xsl:text>
										<xsl:value-of select="$GoalID"/>
										<xsl:text>','</xsl:text>
										<xsl:value-of select="$PortalItemID"/>
										<xsl:text>','</xsl:text>
										<xsl:value-of select="$SelectedUserID"/>
										<xsl:text>')</xsl:text>
									</script>
								</xsl:when>
								<xsl:when test="$ItemsCount=1">
									<xsl:variable name="GoalID" select="AjaxRequest/ActiveGoals/Items[successkey != 'Number']/GoalID"></xsl:variable>
									<script>

										<xsl:text>LoadAddNoteMemoBox('</xsl:text>
										<xsl:value-of select="$GoalID"/>
										<xsl:text>','</xsl:text>
										<xsl:value-of select="$PortalItemID"/>
										<xsl:text>','</xsl:text>
										<xsl:value-of select="$SelectedUserID"/>
										<xsl:text>')</xsl:text>
									</script>
								</xsl:when>
								<xsl:otherwise>
									<div style="margin-top: 20px; width: 100%; text-align: center;">
										<span class="label">
											There are no goals.
										</span>
									</div>
								</xsl:otherwise>
							</xsl:choose>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</xsl:template>
</xsl:stylesheet>
