﻿<?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="../../GenericTemplates/StringReplace.xslt"/>
	<xsl:output method="xml" indent="yes"/>

	<xsl:template match="/">
		<xsl:variable name="MasterPortalItemID" select="AjaxRequest/Params/MasterPortalItemID"></xsl:variable>
		<xsl:variable name="GoalItemID" select="AjaxRequest/GoalItemID"></xsl:variable>
		<xsl:variable name="UserID" select="AjaxRequest/Params/UserID"></xsl:variable>
		<xsl:variable name="GoalList" select="AjaxRequest/Items/Item"></xsl:variable>
		<xsl:variable name ="HostName" select ="normalize-space(AjaxRequest/HostName)"></xsl:variable>
		<xsl:variable name="IsSecureConnection" select="AjaxRequest/IsSecureConnection"></xsl:variable>
		<xsl:variable name="LoggedInUserID" select="AjaxRequest/LoggedInUserID"></xsl:variable>
		<xsl:variable name="divID" select="AjaxRequest/Params/DivID"></xsl:variable>
		<xsl:variable name="Item" select="AjaxRequest/Goals/Goal/Item"></xsl:variable>
		<xsl:variable name="ItemID" select="AjaxRequest/Goals/Goal/ItemID"></xsl:variable>
		<xsl:variable name="ImageURL" select="AjaxRequest/Goals/Goal/Flat_ImageURL"></xsl:variable>
		<xsl:variable name="SuccessKey" select="AjaxRequest/Goals/Goal/SuccessKey"></xsl:variable>
		<xsl:variable name="Classification" select="AjaxRequest/Params/Classification"></xsl:variable>
		<xsl:variable name="Key" select="AjaxRequest/Params/Key"></xsl:variable>
		<xsl:variable name="PortalItemID">
			<xsl:choose>
				<xsl:when test="AjaxRequest/Params/PortalItemID=''">
					<xsl:text>-99</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="AjaxRequest/Params/PortalItemID"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="PortalID">
			<xsl:choose>
				<xsl:when test="$PortalItemID=-99">
					<xsl:value-of select="$MasterPortalItemID"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$PortalItemID"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="Protocol">
			<xsl:choose>
				<xsl:when test="$IsSecureConnection = 1">
					<xsl:text>https://</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>http://</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="varAddProgram">
			<xsl:choose>
				<xsl:when test="$Classification='BusinessPlanning'">
					<xsl:text>BusinessPlan</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$Classification"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="OnClickAddProgram">
			<xsl:choose>
				<xsl:when test="$MasterPortalItemID =$PortalItemID">
					<xsl:text>getUserAndPortalDetailsByPortalID(</xsl:text>
					<xsl:value-of select="$PortalItemID"/>
					<xsl:text>, null, 'Onboarding', 'divAddProgramDashboardContent','</xsl:text>
					<xsl:value-of select="$varAddProgram"/><xsl:text>');</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>baseBrandAutoSuggest_selectAutoSuggetData('</xsl:text>
					<xsl:value-of select="$PortalItemID"/>
					<xsl:text>','</xsl:text>
					<xsl:value-of select="$UserID"/>
					<xsl:text>', 'N/A', 'PortalAddGoalWizardForSelectedUser', 'divAddProgramDashboardContent','-99','-99','MarkAutoSuggestDataSelected_3_0','</xsl:text>
					<xsl:value-of select="$varAddProgram"/>
					<xsl:text>','</xsl:text>
					<xsl:value-of select="$Classification"/>
					<xsl:text>');</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<div>
			<xsl:choose>
				<xsl:when test="$GoalItemID=-99">
					<!--<span>
						Program is not available
					</span>-->
					<div  class="verticallyMiddle onMouseOver divBrowseGradient spanBrowseGradientTextGray adbtn"
						   style="width:150px;line-height:30px;text-align:center;float:left;display:none;"
						   onclick="$('#btnClickOnBoardingAddPlan').css('display','none');
							$('#divAddProgramDashboardContent').css('display','inline-block');{$OnClickAddProgram}" id="btnClickOnBoardingAddPlan">
							<span class="glyphicon glyphicon-plus"></span>
							<span id="span_Cancel">
								Create a Plan 
							</span>
						</div>
					<script>
						$("#btnClickOnBoardingAddPlan").click();
					</script>

					<div style="display:none;" id="divAddProgramDashboardContent"></div>
				</xsl:when>
				<xsl:otherwise>
					<xsl:variable name="EscapedItem">
						<xsl:call-template name="replaceCharsInString">
							<xsl:with-param name="stringIn" select="$Item"></xsl:with-param>
							<xsl:with-param name="charsIn">
								<xsl:text>'</xsl:text>
							</xsl:with-param>
							<xsl:with-param name="charsOut">
								<xsl:text>\'</xsl:text>
							</xsl:with-param>
						</xsl:call-template>
					</xsl:variable>
					<script>
						<xsl:text>loadGoal_3_0('</xsl:text>
						<xsl:value-of select="$ItemID"/>
						<xsl:text>','</xsl:text>
						<xsl:value-of select="$divID"/>
						<xsl:text>','</xsl:text>
						<xsl:value-of select="$EscapedItem"/>
						<xsl:text>','</xsl:text>
						<xsl:value-of select="$ImageURL"/>
						<xsl:text>','</xsl:text>
						<xsl:value-of select="$SuccessKey"/>
						<xsl:text>','-99','</xsl:text>
						<xsl:value-of select="$PortalID"/>
						<xsl:text>','</xsl:text>
						<xsl:value-of select="$LoggedInUserID"/>
						<xsl:text>','QuickStart');</xsl:text>
					</script>
				</xsl:otherwise>
			</xsl:choose>

		</div>
	</xsl:template>
</xsl:stylesheet>
