﻿<?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" omit-xml-declaration="yes"/>

	<xsl:template match="/">
		<xsl:variable name="AjaxRequest" select="AjaxRequest/."></xsl:variable>
		<xsl:variable name="MasterPortalItemID" select="AjaxRequest/Params/MasterPortalItemID"></xsl:variable>
		<xsl:variable name="AllPortal" select="$AjaxRequest/UserBrands"></xsl:variable>
		<xsl:variable name="Template" select="$AjaxRequest/TemplateXML"></xsl:variable>
		<xsl:variable name="User" select="$AjaxRequest/Users"></xsl:variable>
		<xsl:variable name="PeriodKeyXML" select="$AjaxRequest/PeriodKeyXML"></xsl:variable>
		<xsl:variable name="TemplateItemID" select="$AjaxRequest/Params/TemplateItemID"></xsl:variable>
		<xsl:variable name="DBRange" select="$AjaxRequest/Params/DBRange"></xsl:variable>
		<xsl:variable name="Metrics" select="$AjaxRequest/Metrics"></xsl:variable>
		<xsl:variable name="DefaultMetric" select="$AjaxRequest/Metrics/Metric/MetricKey"></xsl:variable>
		<xsl:variable name="DefaultMetricDisplay" select="$AjaxRequest/Metrics/Metric/MetricKeyDisplay"></xsl:variable>
		<xsl:variable name="DefaultMetricID" select="$AjaxRequest/Metrics/Metric/PortalMetricID"></xsl:variable>
		<xsl:variable name="UserID">
			<xsl:choose>
				<xsl:when test="$AjaxRequest/Params/UserID != ''" >
					<xsl:value-of select="$AjaxRequest/Params/UserID"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>null</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="PortalItemID">
			<xsl:choose>
				<xsl:when test="$AjaxRequest/Params/PortalItemID != ''" >
					<xsl:value-of select="$AjaxRequest/Params/PortalItemID"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>null</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="GoalItemID">
			<xsl:choose>
				<xsl:when test="$AjaxRequest/Params/GoalItemID != ''">
					<xsl:value-of select="$AjaxRequest/Params/GoalItemID"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>null</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="FilterLoadFunc">
			<xsl:text>LoadScoreCard_3_0(</xsl:text>
			<xsl:value-of select="$AjaxRequest/Params/MasterPortalItemID"/>
			<xsl:text>,</xsl:text>
			<xsl:value-of select="$PortalItemID"/>
			<xsl:text>,</xsl:text>
			<xsl:value-of select="$UserID"/>
			<xsl:text>,</xsl:text>
			<xsl:value-of select="$GoalItemID"/>
			<xsl:text> ,'</xsl:text>
			<xsl:value-of select="$AjaxRequest/Params/divID"/>
			<xsl:text>');</xsl:text>
		</xsl:variable>
		<xsl:variable name="scoreCardFilter">
			<xsl:text>
			portal_LoadMyScoreboard_3_0('divMyNumberDBCompiledNumbers', 'Monthly', </xsl:text>
			<xsl:value-of select="$MasterPortalItemID"/>
			<xsl:text>,'optMyNumbersDBPortal', 'optMyNumberGoals', 'optMyNumbersDBUser','optMyNumbersDBTemplate','optMyNumbersDBDateRange');</xsl:text>
		</xsl:variable>
		<div class="col-sm-12 col-md-12 RiteTxt A" style="padding:10px 0;">
			<div class="col-md-12 dropdown_txt pull-left">
				<div class="col-md-3 col-sm-3 col-xs-6 margnbtm5">
					<select class="form-control" id="optMyNumbersDBTemplate" onchange="{$FilterLoadFunc}">
						<option value="-99">
							--Select--
						</option>
						<xsl:for-each select="$Template/MasterTemplates/Template">
							<xsl:choose>
								<xsl:when test="$TemplateItemID=ItemID">
									<option value="{ItemID}" selected="">
										<xsl:value-of select="Name"/>
									</option>
								</xsl:when>
								<xsl:otherwise>
									<option value="{ItemID}">
										<xsl:value-of select="Name"/>
									</option>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
						<xsl:choose>
							<xsl:when test="count($Template/MasterTemplates/Template) &gt; 0 
								and count($Template/SubPortalTemplates/Template) &gt; 0">
								<option value="-99" disabled="disabled">
									--------------------------------------------------------------------
								</option>
							</xsl:when>
						</xsl:choose>
						<xsl:for-each select="$Template/SubPortalTemplates/Template">
							<xsl:choose>
								<xsl:when test="$TemplateItemID=ItemID">
									<option value="{ItemID}" selected="">
										<xsl:value-of select="Name"/>
									</option>
								</xsl:when>
								<xsl:otherwise>
									<option value="{ItemID}">
										<xsl:value-of select="Name"/>
									</option>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</select>
				</div>
				<div class="col-md-3 col-sm-3 col-xs-6 margnbtm5">
					<select class="form-control" id="optMyNumbersDBDateRange" onchange="{$FilterLoadFunc}">
						<xsl:for-each select="$PeriodKeyXML/PeriodKey">
							<xsl:choose>
								<xsl:when test="$DBRange=PeriodKey">
									<option value="{PeriodKey}" selected="">
										<xsl:value-of select="DateRange"/>
									</option>
								</xsl:when>
								<xsl:otherwise>
									<option value="{PeriodKey}">
										<xsl:value-of select="DateRange"/>
									</option>
								</xsl:otherwise>
							</xsl:choose>

						</xsl:for-each>
					</select>
				</div>

				<div  class="valueSD1 col-md-3 col-sm-3 col-xs-6">
					<select class="form-control" id="optMyNumbersDBPortal" onchange="{$FilterLoadFunc}">
						<xsl:if test="$AjaxRequest/Params/PortalItemID = '' or ItemID = $MasterPortalItemID">
							<option value="{$MasterPortalItemID}">
								All
							</option>
						</xsl:if>
						<xsl:for-each select="$AllPortal/Brand[ItemID != $MasterPortalItemID]">
							<xsl:choose>
								<xsl:when test="$AjaxRequest/Params/SelectedPortalItemID=ItemID">
									<option value="{ItemID}" selected="">
										<xsl:value-of select="Item"/>
									</option>
								</xsl:when>
								<xsl:when test="$AjaxRequest/Params/PortalItemID=ItemID">
									<option value="{ItemID}" selected="">
										<xsl:value-of select="Item"/>
									</option>
								</xsl:when>
								<xsl:otherwise>
									<option value="{ItemID}" >
										<xsl:value-of select="Item"/>
									</option>
								</xsl:otherwise>
							</xsl:choose>

						</xsl:for-each>
					</select>
				</div>


				<div class="col-md-3 col-sm-3 col-xs-6">
					<select class="form-control" id="optMyNumbersDBUser" onchange="{$FilterLoadFunc}">
						<option value="-99">
							--Select--
						</option>
						<xsl:for-each select="$User/User">
							<xsl:choose>
								<xsl:when test="$UserID=UserID">
									<option value="{UserID}" selected="">
										<xsl:value-of select="FirstName"/>
									</option>
								</xsl:when>
								<xsl:otherwise>
									<option value="{UserID}">
										<xsl:value-of select="FirstName"/>
									</option>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</select>
				</div>

				<xsl:variable name="specificID">
					<xsl:choose>
						<xsl:when test="$PortalItemID &gt; 0">
							<xsl:value-of select="$PortalItemID"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:number value="0"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>

				<xsl:variable name="level">
					<xsl:choose>
						<xsl:when test="$PortalItemID &gt; 0">
							<xsl:text>PortalSpecific</xsl:text>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text>All</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>

				<div class="totalscoreRollUp">
					<span id="spanTotalGrid" class="onMouseOver active1" 
						onclick="$('#optMyNumbersDBPortal').change();$('#spanTotalGrid').addClass('active1');$('#spanScorecardGrid').removeClass('active1');">
						<xsl:text>Totals</xsl:text> </span> | 
					<span class="onMouseOver" onclick="LoadActivityDashboard_ScoreCardFrame({$MasterPortalItemID},'Div_ScoreCardFrame','{$level}',{$specificID},'Monthly'); 
						  $('#spanTotalGrid').removeClass('active1');$('#spanScorecardGrid').addClass('active1');" 
						  id="spanScorecardGrid">Scorecard</span>
				</div>
			</div>

			
			<div class="col-md-12 white-bg-new A Featurd">
				<div class="box inner light-gray" style="background: #f6f6f6;border: 1px solid #e9e9e9;">
					<div class="row-fluid padded0">
						<div class="section-title ">
							<p style="100%">
								<span style="width:60%">
									FEATURED METRICS
								</span>
							</p>
						</div>
						<div id="divMyNumberDBCompiledNumbers">
							<div id="divMyNumberDBCompiledNumbers_Content">
								<xsl:for-each select="$Metrics/Metric">
									<xsl:variable name="class">
										<xsl:choose>
											<xsl:when test="(position() mod 6)=1">
												text-blue
											</xsl:when>
											<xsl:when test="(position() mod 6)=2">
												medium-blue
											</xsl:when>
											<xsl:when test="(position() mod 6)=3">
												dark-blue
											</xsl:when>
											<xsl:when test="(position() mod 6)=4">
												border-blue
											</xsl:when>
											<xsl:when test="(position() mod 6)=5">
												text-blue
											</xsl:when>
											<xsl:when test="(position() mod 6)=0">
												medium-blue
											</xsl:when>
										</xsl:choose>
									</xsl:variable>
									<xsl:variable name="CallBack">
										getReportingDashboardLeaderboard_3_0('optMyNumbersDBTemplate','optMyNumbersDBDateRange'
										,'optMyNumbersDBPortal','optMyNumbersDBUser','<xsl:value-of select="MetricKey"/>'
										, 'divNumbersLeaderBoard', 'ReportingNumberGraph', 0, 5, 1);
									</xsl:variable>


									<div class="col-md-2 col-xs-12 col-sm-6 center onMouseOver"
										 onClick="document.getElementById('divNumbersGraph').innerHTML = '';
										 document.getElementById('divNumbersLeaderBoard').innerHTML = '';
										 LoadMyNumbersDashboardGraph_3_0({$MasterPortalItemID}
										 , 'optMyNumbersDBPortal', 'optMyNumberGoals', 'optMyNumbersDBUser'
										 , 'optMyNumbersDBTemplate', 'optMyNumbersDBDateRange', 'divNumbersGraph', '{MetricKey}');
										 {$CallBack}
										 document.getElementById('spanNumberGraphMetric').innerHTML='{MetricKey}';">

										<div class="stat-box {$class}">
											<span class="count">
												<span class="dec_font">
												</span>
											</span>
											<span class="stat-text">
												<xsl:value-of select="MetricKeyDisplay"/>
											</span>
										</div>
									</div>
								</xsl:for-each>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!--Middle Page End-->
			<!--Graph Start-->


			<div class="col-md-12 col-sm-12 pull-left">

				<div class="box bordered">


					<div class="row-fluid resGraph" id="divGraph">
						<div class="col-md-5">
							<div class="section-title">Leaderboard</div>
							<div id="divNumbersLeaderBoard" class="NLeaderBoard">
								<xsl:choose>
									<xsl:when test="$DefaultMetric[text()]">
										<script>
											getReportingDashboardLeaderboard_3_0('optMyNumbersDBTemplate','optMyNumbersDBDateRange'
											,'optMyNumbersDBPortal','optMyNumbersDBUser','<xsl:value-of select="$DefaultMetric"/>', 'divNumbersLeaderBoard', 'ReportingNumberGraph3_0'
											, 0, 5, 1);
										</script>
									</xsl:when>
								</xsl:choose>
							</div>
						</div>
						<div class="col-md-7">
							<div class="section-title" id="MetricTitle">
								<span id="spanNumberGraphMetric" defaultMetric="{$DefaultMetric}">
									<xsl:value-of select="$DefaultMetricDisplay"/>
								</span>
							</div>
							<div id="divNumbersGraph" class="chart" style="width: 100%; height: 330px; padding: 0px; position: relative;">
								<xsl:choose>
									<xsl:when test="$DefaultMetric[text()]">
										<script>
											LoadMyNumbersDashboardGraph_3_0(<xsl:value-of select="$MasterPortalItemID"/>
											, 'optMyNumbersDBPortal', null, 'optMyNumbersDBUser'
											, 'optMyNumbersDBTemplate', 'optMyNumbersDBDateRange', 'divNumbersGraph', '<xsl:value-of select="$DefaultMetric"/>');
										</script>
									</xsl:when>
								</xsl:choose>
							</div>
						</div>


					</div>
				</div>
			</div>
			<script>
				LoadMyNumbersDashboardCompiledMetrics_3_0(<xsl:value-of select="$MasterPortalItemID"/>
				, 'optMyNumbersDBPortal', null, 'optMyNumbersDBUser'
				, 'optMyNumbersDBTemplate', 'optMyNumbersDBDateRange', 'ScoreCard','divMyNumberDBCompiledNumbers');
			</script>
		</div>


	</xsl:template>
</xsl:stylesheet>
