﻿<?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 ="../Version_2_0/GoalActions.xslt"/>
	<xsl:import href="../Version_2_0/CompiledNumberGoalData.xslt"/>
	<xsl:import href="../Version_2_0/CompiledNumberGoalIndividualDataTemplate.xslt"/>
	<xsl:import href="../Version_2_0/GoalUsersLeaderboard.xslt"/>
	<xsl:import href="../Version_2_0/GroupChallenge/FBDiscussions.xslt"/>
	<xsl:import href="../Version_2_0/GoalMediaList.xslt"/>
	<xsl:import href="../GenericTemplates/StringReplace.xslt"/>
    <xsl:output method="xml" indent="yes"/>
	
    <xsl:template match="/">
		<xsl:variable name="TemplateURL" select="AjaxRequest/TemplateURL"></xsl:variable>
		<xsl:variable name="HostName" select="AjaxRequest/HostName"></xsl:variable>
		<xsl:variable name="GoalItemID">
			<xsl:choose>
				<xsl:when test="AjaxRequest/GoalProgressDetail/Item/GoalItemID[text()]">
					<xsl:value-of select="AjaxRequest/GoalProgressDetail/Item/GoalItemID"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="AjaxRequest/Params/GoalItemID"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="OfWhat" select="AjaxRequest/GoalProgressDetail/Item/GoalNumberMeasure"></xsl:variable>
		<xsl:variable name="Track" select="AjaxRequest/GoalProgressDetail/Item/GoalNumberTracking"></xsl:variable>
		<xsl:variable name="GoalStart" select="AjaxRequest/GoalProgressDetail/Item/GoalNumberStart"></xsl:variable>
		<xsl:variable name="GoalDirection" select="AjaxRequest/GoalProgressDetail/Item/GoalNumberDirection"></xsl:variable>
		<xsl:variable name="Updating" select="AjaxRequest/GoalProgressDetail/Item/GoalMetricsUpdate"></xsl:variable>
		<xsl:variable name="LastAmount" select="AjaxRequest/GoalProgressDetail/Item/LastAmount"></xsl:variable>
		<xsl:variable name="TotalAmount" select="AjaxRequest/GoalProgressDetail/Item/GoalNumber"></xsl:variable>
		<xsl:variable name="Format" select="AjaxRequest/GoalProgressDetail/Item/GoalNumberFormat"></xsl:variable>
		<xsl:variable name="OldPeriodKey" select="AjaxRequest/GoalProgressDetail/Item/PeriodKey"></xsl:variable>
		<xsl:variable name="CurrentAmount" select="round(AjaxRequest/GoalProgressDetail/Item/CurrentAmount)">
		</xsl:variable>
		<xsl:variable name="GoalMetricsXML" select="AjaxRequest/GoalMetricXML/."></xsl:variable>
		<xsl:variable name="PortalMetricsXML" select="AjaxRequest/PortalMetrics/."></xsl:variable>
		<xsl:variable name="MetricHeaderXML" select="AjaxRequest/NumberGoalDataXML/."></xsl:variable>
		<xsl:variable name="PeriodData" select="AjaxRequest/NumberGoalDataXML/PeriodData/."></xsl:variable>
		<xsl:variable name="MasterPortalItemID" select="AjaxRequest/Settings/MasterPortalItemID"></xsl:variable>
		<xsl:variable name="PermissionID" select="AjaxRequest/ActionCounts/Count/PermissionID"></xsl:variable>
		<xsl:variable name="BetaVersion" select="AjaxRequest/Settings/BetaVersion"></xsl:variable>
		<xsl:variable name="PageNumber" select="AjaxRequest/Params/PageNumber"></xsl:variable>
		<xsl:variable name="PageSize" select="AjaxRequest/Params/PageSize"></xsl:variable>
		<xsl:variable name="UserSettingHideCompleted" select="AjaxRequest/ActionCounts/Count/HideCompleted"></xsl:variable>
		<xsl:variable name="UserSettingMyTasks" select="AjaxRequest/ActionCounts/Count/MyTasks"></xsl:variable>
		<xsl:variable name="UserSettingThisWeek" select="AjaxRequest/ActionCounts/Count/ThisWeek"></xsl:variable>
		<xsl:variable name="UserSettingCollapseAll" select="AjaxRequest/ActionCounts/Count/CollapseAll"></xsl:variable>
		<xsl:variable name="GoalStartDate" select="AjaxRequest/GoalProgressDetail/Item/GoalStartDate"></xsl:variable>
		<xsl:variable name="GoalEndDate" select="AjaxRequest/GoalProgressDetail/Item/GoalEndDate"></xsl:variable>
		<xsl:variable name="UserPermissionOnGoal" select="AjaxRequest/UserPermissionOnGoal"></xsl:variable>
		<xsl:variable name="MediaFiles" select="AjaxRequest/MediaFiles/."></xsl:variable>
		<xsl:variable name="LoggedInUserID" select="AjaxRequest/LoggedInUserID"></xsl:variable>
		<xsl:variable name="GoalNotesFormat" select="AjaxRequest/Items/Item/GoalNotesFormat"></xsl:variable>
		<xsl:variable name="OwnerBrandID" select="AjaxRequest/Items/Item/OwnerBrandID"></xsl:variable>
		<xsl:variable name="SuccessKey" select="AjaxRequest/ActionCounts/SuccessKey"></xsl:variable>
		<xsl:variable name="CommunityAdmin" select="AjaxRequest/UserRoles/Role[RoleName = 'Community Admin']"/>
		<xsl:variable name="GoalType">
			
			<xsl:choose>
				<xsl:when test="AjaxRequest/Items/Item/GoalType != ''">
					<xsl:value-of select="AjaxRequest/Items/Item/GoalType"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="AjaxRequest/ActionCounts/GoalType"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="PutAddItemBoxYN">
			<xsl:choose>
				<xsl:when test='($GoalNotesFormat = 1 or $GoalNotesFormat = 2) and $GoalType = 2'>
					<xsl:number value='0'/>
				</xsl:when>
			</xsl:choose>
		</xsl:variable>
		<table class="tableMaster" cellpadding="0" cellspacing="0">
			<tr>
				<td width="100%">
					<xsl:choose>
						<xsl:when test="$GoalType = 2">
							<div class="marginTop10">
								<xsl:call-template name="MediaList">
									<xsl:with-param name="GoalItemID" select="$GoalItemID"></xsl:with-param>
									<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
									<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
									<xsl:with-param name="MediaFiles" select="$MediaFiles"></xsl:with-param>
								</xsl:call-template>
							</div>
							<xsl:call-template name="GoalShareFooter">
								<xsl:with-param name="GoalItemID" select="$GoalItemID"></xsl:with-param>
								<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
								<xsl:with-param name="LoggedInUserID" select="$LoggedInUserID"></xsl:with-param>
								<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:call-template name="GoalActionsTemplate">
								<xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
								<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
								<xsl:with-param name="GoalItemID" select="$GoalItemID"></xsl:with-param>
								<xsl:with-param name="SummaryItems" select="AjaxRequest/Goal/SummaryItems/."></xsl:with-param>
								<xsl:with-param name="DetailItems" select="AjaxRequest/Goal/DetailItems/."></xsl:with-param>
								<xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
								<xsl:with-param name="PutAddItemBox" select="$PutAddItemBoxYN"></xsl:with-param>
								<xsl:with-param name="LoggedInUserID" select="$LoggedInUserID"></xsl:with-param>
								<xsl:with-param name="OwnerBrandID" select="$OwnerBrandID"></xsl:with-param>
								<xsl:with-param name="IsGoalCoach" select="AjaxRequest/Goal/IsGoalCoach"></xsl:with-param>
								<xsl:with-param name="IsGoalObserver" select="AjaxRequest/Goal/IsGoalObserver"></xsl:with-param>
								<xsl:with-param name="UserSettingHideCompleted" select="$UserSettingHideCompleted"></xsl:with-param>
								<xsl:with-param name="UserSettingMyTasks" select="$UserSettingMyTasks"></xsl:with-param>
								<xsl:with-param name="UserSettingThisWeek" select="$UserSettingThisWeek"></xsl:with-param>
								<xsl:with-param name="UserSettingCollapseAll" select="$UserSettingCollapseAll"></xsl:with-param>
								<xsl:with-param name="SuccessKey" select="$SuccessKey"></xsl:with-param>
								<xsl:with-param name="CommunityAdmin" select="$CommunityAdmin"></xsl:with-param>
							</xsl:call-template>
						</xsl:otherwise>
					</xsl:choose>
				</td>
			</tr>
		</table>
    </xsl:template>
</xsl:stylesheet>
