﻿<?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="ClientContactControl.xslt"/>
    <xsl:import href="../CorporateGoals/CRMGoalList.xslt"/>

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:variable name="ItemID" select="CompletedCRMProjects/Project/PortalItemID"/>
        <xsl:variable name="StageID" select="CompletedCRMProjects/Project/CRMProjectStageID"/>
        <xsl:variable name="Action" select="normalize-space(CompletedCRMProjects/Action)"/>
        <xsl:variable name="PersonUserID" select="CompletedCRMProjects/Project/PersonUserID"/>
        <xsl:variable name="TemplateURL" select="CompletedCRMProjects/TemplateURL"/>
        <xsl:variable name="CRMProjectTypeID" select="CompletedCRMProjects/CRMProjectTypeID"/>
        <xsl:variable name="HostName" select="CompletedCRMProjects/HostName"/>
        <xsl:variable name="CommunityAdmin" select="CompletedCRMProjects/CommunityAdmin"/>
        <xsl:variable name="ID" select="CompletedCRMProjects/ItemID"/>
        <xsl:variable name="PermissionID" select="normalize-space(CompletedCRMProjects/Permissions/ItemPermission/PermissionID)"/>
        <xsl:variable name="crmProjectTypeID" select="CompletedCRMProjects/CRMProjectTypeID"/>
        <xsl:variable name="PortalTypeID" select="CompletedCRMProjects/PortalTypeID"></xsl:variable>
        <xsl:variable name="ProPackageID" select="CompletedCRMProjects/ProPackageID"></xsl:variable>
        <xsl:variable name="displayAccountName">
            <xsl:choose>
                <xsl:when test="$crmProjectTypeID = 1">
                    <xsl:text>display:block;</xsl:text>
                </xsl:when>
                <xsl:when test="$crmProjectTypeID = 2">
                    <xsl:text>display:none;</xsl:text>
                </xsl:when>
            </xsl:choose>
        </xsl:variable>

        <xsl:choose>
            <xsl:when test="($StageID = 4 and $CRMProjectTypeID = 2) 
                  or ($StageID = 6 and $CRMProjectTypeID = 2)
                  or ($PortalTypeID = 4 and $ProPackageID = -99)">
                <xsl:call-template name="GoalListDashboard">
                    <xsl:with-param name="CompletedCRMProjects" select="CompletedCRMProjects/."></xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="($PortalTypeID = 2 or $PortalTypeID = 8) 
                      and ($ProPackageID = 4 or $ProPackageID = 5 or $ProPackageID = 8 or $ProPackageID = 6 or $ProPackageID = 7 or $ProPackageID = 9) and $crmProjectTypeID = 2">

                <div id="div_ModuleBox" style="border:1px solid #D1D3D4;">
                    <div style="height:45px;" class="moduleBoxHeaderRightSide moduleBoxGradient">
                        <span style="line-height:37px;padding-left:5px;color:#FFFFFF" class="sentenceFont verticallyMiddle">Team Goals</span>
                    </div>
                    <div style="margin:10px">

                        <xsl:call-template name="GoalListDashboard">
                            <xsl:with-param name="CompletedCRMProjects" select="CompletedCRMProjects/."></xsl:with-param>
                        </xsl:call-template>

                    </div>
                </div>
            </xsl:when>
            <xsl:otherwise>

                <table class="tableMaster" cellpadding ="0" cellspacing ="2" width="100%">
                    <tr>
                        <xsl:if test="count(CompletedCRMProjects/Project)!=0">
                            <xsl:call-template name="AddNewItemFormatContainer2">
                                <xsl:with-param name="crmProjectTypeID" select="$crmProjectTypeID"></xsl:with-param>
                                <xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
                                <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                <xsl:with-param name="ID" select="$ID"></xsl:with-param>
                                <xsl:with-param name="DisplayText">
                                    <xsl:text>none</xsl:text>
                                </xsl:with-param>
                                <xsl:with-param name="AddButtonAlign">
                                    <xsl:text>right</xsl:text>
                                </xsl:with-param>
                            </xsl:call-template>
                        </xsl:if>
                    </tr>
                </table>



                <xsl:if test="count(CompletedCRMProjects/Project)!=0 and $Action!='GetFilteredCRMProjectList'">

                    <table width="100%">
                        <tr>
                            <td style="padding: 10px;">

                                <Span class="packageTitle" style="vertical-align: center;">Client</Span>


                                <input id="txtFilter_Client" type="text" style="width: 120px; margin-left: 5px; margin-right: 10px;" class="text"
                                       onKeyPress="CRMProjectFilter(event,'txtFilter_Client','txtFilter_Account','txtFilter_Project',
                                    'ddlFilter_Stage','{$ItemID}','divCompletedProjects','{$StageID}','ddlFilter_Sort','{$CRMProjectTypeID}');"></input>

                                <Span class="packageTitle" style="vertical-align: center;display:none;">Account</Span>
                                <input type="text" id="txtFilter_Account" style="display:none; margin-left: 5px; margin-right: 10px;" class="text"
                                       onKeyPress="CRMProjectFilter(event,'txtFilter_Client','txtFilter_Account','txtFilter_Project',
                                    'ddlFilter_Stage','{$ItemID}','divCompletedProjects','{$StageID}','ddlFilter_Sort','{$CRMProjectTypeID}');"></input>


                                <Span class="packageTitle" style="vertical-align: center;">Project</Span>

                                <input type="text" id="txtFilter_Project" style="width: 75px; margin-left: 5px; margin-right: 10px;" class="text"
                                       onKeyPress="CRMProjectFilter(event,'txtFilter_Client','txtFilter_Account','txtFilter_Project',
                                    'ddlFilter_Stage','{$ItemID}','divCompletedProjects','{$StageID}','ddlFilter_Sort','{$CRMProjectTypeID}');"></input>

                                <xsl:if test="$StageID != 4 and $StageID != 5 and $StageID != 6">
                                    <Span class="packageTitle" style="vertical-align: center;">Stage</Span>
                                    <select class="smallDropdown" id="ddlFilter_Stage" style="margin-left: 5px;margin-right: 10px;"
                                            onChange="return CRMProjectFilter(null,'txtFilter_Client','txtFilter_Account','txtFilter_Project',
                                    'ddlFilter_Stage','{$ItemID}','divCompletedProjects','{$StageID}','ddlFilter_Sort','{$CRMProjectTypeID}');">
                                        <option value="-1" selected="selected">Select</option>
                                        <xsl:for-each select="CompletedCRMProjects/ProjectStages/Stage[CRMProjectStageID!=4 and CRMProjectStageID!=5 and CRMProjectStageID!=6 and CRMProjectStageID!=11]">
                                            <xsl:variable name="ProjectStageID" select="CRMProjectStageID"/>
                                            <xsl:variable name="Stage" select="ProjectStage"/>
                                            <option value="{$ProjectStageID}">
                                                <xsl:value-of select="$Stage"/>
                                            </option>
                                        </xsl:for-each>
                                    </select>
                                </xsl:if>

                                <Span class="packageTitle" style="vertical-align: center;">Sort</Span>
                                <select class="smallDropdown" id="ddlFilter_Sort" style="margin-left: 5px;"
                                        onChange="return CRMProjectFilter(null,'txtFilter_Client','txtFilter_Account','txtFilter_Project',
                                        'ddlFilter_Stage','{$ItemID}','divCompletedProjects','{$StageID}','ddlFilter_Sort','{$CRMProjectTypeID}');">
                                    <option value="-1" selected="selected">Select</option>
                                    <option value="1">First Name</option>
                                    <option value="2">Last Name</option>
                                    <option value="3">Project Name</option>
                                    <option value="4">Project Date</option>
                                    <option value="5">Update Date</option>
                                </select>
                            </td>
                        </tr>
                    </table>
                </xsl:if>
                <xsl:choose>
                    <xsl:when test="$Action='GetFilteredCRMProjectList'">
                        <xsl:call-template name="ProjectList">
                            <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                            <xsl:with-param name="ItemID" select="$ItemID"/>
                            <xsl:with-param name="StageID" select="$StageID"/>
                            <xsl:with-param name="Action" select="$Action"/>
                            <xsl:with-param name="PersonUserID" select="$PersonUserID"/>
                            <xsl:with-param name="crmProjectTypeID" select="$CRMProjectTypeID"/>
                            <xsl:with-param name="HostName" select="$HostName"/>
                            <xsl:with-param name="CommunityAdmin" select="$CommunityAdmin"/>
                            <xsl:with-param name="ID" select="$ID"/>
                            <xsl:with-param name="PermissionID" select="$PermissionID"/>
                            <xsl:with-param name="displayAccountName" select="$displayAccountName"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <div id="divCompletedProjects">
                            <xsl:call-template name="ProjectList">
                                <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                <xsl:with-param name="ItemID" select="$ItemID"/>
                                <xsl:with-param name="StageID" select="$StageID"/>
                                <xsl:with-param name="Action" select="$Action"/>
                                <xsl:with-param name="PersonUserID" select="$PersonUserID"/>
                                <xsl:with-param name="crmProjectTypeID" select="$CRMProjectTypeID"/>
                                <xsl:with-param name="HostName" select="$HostName"/>
                                <xsl:with-param name="CommunityAdmin" select="$CommunityAdmin"/>
                                <xsl:with-param name="ID" select="$ID"/>
                                <xsl:with-param name="PermissionID" select="$PermissionID"/>
                                <xsl:with-param name="displayAccountName" select="$displayAccountName"></xsl:with-param>
                            </xsl:call-template>
                        </div>
                    </xsl:otherwise>
                </xsl:choose>



                <table class="tableMaster" cellpadding ="0" cellspacing ="2" width="100%">
                    <tr>
                        <xsl:if test="count(CompletedCRMProjects/Project)!=0">
                            <xsl:call-template name="AddNewItemFormatContainer2">
                                <xsl:with-param name="crmProjectTypeID" select="$crmProjectTypeID"></xsl:with-param>
                                <xsl:with-param name="PermissionID" select="$PermissionID"></xsl:with-param>
                                <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                <xsl:with-param name="ID" select="$ID"></xsl:with-param>
                                <xsl:with-param name="DisplayText">
                                    <xsl:text>none</xsl:text>
                                </xsl:with-param>
                                <xsl:with-param name="AddButtonAlign">
                                    <xsl:text>right</xsl:text>
                                </xsl:with-param>
                            </xsl:call-template>
                        </xsl:if>
                    </tr>
                </table>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="ProjectList">
        <xsl:param name="ItemID" select="'N/A'"/>
        <xsl:param name="HostName" select="'N/A'"/>
        <xsl:param name="CommunityAdmin" select="'N/A'"/>
        <xsl:param name="StageID" select="'N/A'"/>
        <xsl:param name="GoalID" select="N/A"/>
        <xsl:param name="ID" select="'N/A'"/>
        <xsl:param name="Action" select="N/A"/>
        <xsl:param name="PermissionID" select="'N/A'"/>
        <xsl:param name="TemplateURL" select="'N/A'"/>
        <xsl:param name="crmProjectTypeID" select="'N/A'"/>
        <xsl:param name="displayAccountName" select="'N/A'"></xsl:param>


        <table class="tableMaster" cellpadding ="0" cellspacing ="2" width="100%">
            <xsl:choose>
                <xsl:when test="$StageID = 4 or $StageID = 6">
                    <xsl:for-each select ="CompletedCRMProjects/ProjectStages/Stage">
                        <xsl:variable name="PStage" select="ProjectStage"></xsl:variable>
                        <tr>
                            <td colspan="4">
                                <xsl:if test="count(../../Project[ProjectStage=$PStage])!=0">
                                    <div>
                                        <div onclick="return expandCollapseByGroup('div_Projects_{normalize-space(ProjectStage)}')"
                                           class="onMouseOver seperatorLine packageTitle">
                                            <xsl:value-of select="$PStage"/>
                                        </div>
                                        <div id="div_Projects_{normalize-space(ProjectStage)}" style="margin-left:5px;display:block;">
                                            <xsl:for-each select="../../Project[ProjectStage=$PStage]">
                                                <xsl:variable name="ProjectID" select="normalize-space(CRMProjectID)"/>
                                                <xsl:variable name="Stage" select="ProjectStage"></xsl:variable>
                                                <xsl:variable name="AccountID" select="normalize-space(AccountID)"></xsl:variable>
                                                <div id="divOpenProjects_{CRMProjectID}" name="collapsed" itemID="{CRMProjectID}">
                                                    <itemExpansionStatus id="divOpenProjects_{CRMProjectID}_expansionStatus" status="collapsed"></itemExpansionStatus>
                                                    <table width="100%">
                                                        <tr>
                                                            <td width="20%" class="publicationSummary onMouseOver">
                                                                <span onclick="LoadEmployeeDetail('{ClientUserID}','divClientPortalOperations_Container','{PortalItemID}');">
                                                                    <xsl:value-of select="Client"/>
                                                                </span>
                                                            </td>

                                                            <td width="35%" style="{normalize-space($displayAccountName)};">
                                                                <xsl:choose>
                                                                    <xsl:when test ="$PermissionID &gt;= 4">

                                                                        <a href="" id= "ancAcc_{normalize-space($ProjectID)}" style="font-family: 'PT Sans' , sans-serif;font-size: 12px;color: #6D6E71;font-weight: 700;"
                                                                          onClick = "return portal_EditAccount('ancAcc_{normalize-space($ProjectID)}','ddlAcc_{normalize-space($ProjectID)}')">
                                                                            <xsl:choose>
                                                                                <xsl:when test="AccountID">
                                                                                    <span class="publicationSummary">
                                                                                        <xsl:value-of select="Account"/>
                                                                                    </span>
                                                                                </xsl:when>
                                                                                <xsl:otherwise>
                                                                                    [Add Account]
                                                                                </xsl:otherwise>
                                                                            </xsl:choose>
                                                                        </a>
                                                                        <select style="display:none;" id="ddlAcc_{normalize-space($ProjectID)}"
                                                                                onChange="return portal_UpdateCRMAccount('{normalize-space($ProjectID)}','ancAcc_{normalize-space($ProjectID)}','ddlAcc_{normalize-space($ProjectID)}')">
                                                                            <option value="-1"></option>
                                                                            <xsl:for-each select="../CRMAccounts/Account">
                                                                                <xsl:choose>
                                                                                    <xsl:when test="AccountID = $AccountID">
                                                                                        <option value="{AccountID}" selected="selected"  >
                                                                                            <xsl:value-of select="AccountName"/>
                                                                                        </option>
                                                                                    </xsl:when>
                                                                                    <xsl:otherwise>
                                                                                        <option value="{AccountID}" >
                                                                                            <xsl:value-of select="AccountName"/>
                                                                                        </option>
                                                                                    </xsl:otherwise>
                                                                                </xsl:choose>
                                                                            </xsl:for-each>
                                                                        </select>
                                                                    </xsl:when>
                                                                    <xsl:otherwise>
                                                                        <span class="publicationSummary onMouseOver"
                                                                              onclick="LoadEmployeeDetail('{ClientUserID}','divClientPortalOperations_Container','{PortalItemID}');">
                                                                            <xsl:value-of select="Client"/>
                                                                        </span>
                                                                    </xsl:otherwise>
                                                                </xsl:choose>
                                                            </td>

                                                            <td width="25%" class="label" style="padding-right:5px;">
                                                                <a id="projectName_{$ProjectID}" href="http://{$HostName}/Goal.aspx?ID={ItemID}" target="_blank" style="cursor:pointer;font-family: 'PT Sans' , sans-serif;font-size: 12px;color: #6D6E71;font-weight: 700;">
                                                                    <xsl:value-of select="Name"/>
                                                                </a>
                                                            </td>
                                                            <td width="20%">
                                                                <xsl:choose>
                                                                    <xsl:when test ="$PermissionID &gt;= 4">
                                                                        <!--<a href="" id = "anc_{normalize-space($ProjectID)}" style="font-family: 'PT Sans' , sans-serif;font-size: 12px;color: #6D6E71;font-weight: 700;"
                                                                                    onClick = "return portal_EditStage('anc_{normalize-space($ProjectID)}','ddl_{normalize-space($ProjectID)}');">
                                                                            <xsl:value-of select="ProjectStage"/>
                                                                        </a>-->
                                                                        <select style="display:none;" Origin="{$PStage}" id="ddl_{normalize-space($ProjectID)}"
                                                                                onChange="return portal_UpdateProjectStage('{$ID}','{normalize-space($ProjectID)}','anc_{normalize-space($ProjectID)}','ddl_{normalize-space($ProjectID)}','{$crmProjectTypeID}','')">
                                                                            <xsl:for-each select="../ProjectStages/Stage[CRMProjectStageID!=11]">
                                                                                <xsl:choose>
                                                                                    <xsl:when test="ProjectStage = $Stage">
                                                                                        <option value="{CRMProjectStageID}" selected="selected"  >
                                                                                            <xsl:value-of select="ProjectStage"/>
                                                                                        </option>
                                                                                    </xsl:when>
                                                                                    <xsl:otherwise>
                                                                                        <option value="{CRMProjectStageID}" >
                                                                                            <xsl:value-of select="ProjectStage"/>
                                                                                        </option>
                                                                                    </xsl:otherwise>
                                                                                </xsl:choose>
                                                                            </xsl:for-each>
                                                                        </select>
                                                                    </xsl:when>
                                                                    <xsl:otherwise>
                                                                        <span class="publicationSummary">
                                                                            <xsl:value-of select="ProjectStage"/>
                                                                        </span>
                                                                    </xsl:otherwise>
                                                                </xsl:choose>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                    <div id="divOpenProjects_{CRMProjectID}_detail_container" style="position:absolute;display:none;border: 1px solid black;padding: 5px;
                                                                                                                        background-color:#FFFFFF;visibility: visible;width:600px;"></div>
                                                </div>
                                            </xsl:for-each>
                                        </div>
                                    </div>
                                </xsl:if>
                            </td>
                        </tr>
                    </xsl:for-each>
                </xsl:when>

                <xsl:otherwise>
                    <xsl:for-each select ="CompletedCRMProjects/ProjectStages/Stage[CRMProjectStageID!=4 and CRMProjectStageID!=5 and CRMProjectStageID!=6]">
                        <xsl:variable name="PStage" select="ProjectStage"></xsl:variable>
                        <tr>
                            <td colspan="4">

                                <xsl:if test="count(../../Project[ProjectStage=$PStage])!=0">
                                    <div>
                                        <div onclick="return expandCollapseByGroup('div_Projects_{normalize-space(ProjectStage)}')"
                                           class="onMouseOver seperatorLine packageTitle">
                                            <xsl:value-of select="$PStage"/>
                                            (<xsl:value-of select="count(../../Project[ProjectStage=$PStage])"/>)
                                        </div>
                                        <div id="div_Projects_{normalize-space(ProjectStage)}" style="margin-left:5px;display:block;">
                                            <xsl:for-each select="../../Project[ProjectStage=$PStage]">

                                                <xsl:variable name="ProjectID" select="normalize-space(CRMProjectID)"/>
                                                <xsl:variable name="Stage" select="ProjectStage"></xsl:variable>
                                                <xsl:variable name="AccountID" select="normalize-space(AccountID)"></xsl:variable>

                                                <div id="divOpenProjects_{CRMProjectID}" name="collapsed" itemID="{CRMProjectID}">
                                                    <itemExpansionStatus id="divOpenProjects_{CRMProjectID}_expansionStatus" status="collapsed"></itemExpansionStatus>

                                                    <xsl:choose>
                                                        <xsl:when test="position() mod 2 = 0">
                                                            <table width="100%" style="background-color:#D8D8D8;">
                                                                <tr>
                                                                    <td width="30%">
                                                                        <xsl:choose>
                                                                            <xsl:when test ="$PermissionID &gt;= 4">
                                                                                <xsl:choose>
                                                                                    <xsl:when test="Client!=0">
                                                                                        <span class="publicationSummary onMouseOver"
                                                                                              onclick="LoadEmployeeDetail('{ClientUserID}','divClientPortalOperations_Container','{PortalItemID}');">
                                                                                            <xsl:value-of select="Client"/>
                                                                                        </span>
                                                                                    </xsl:when>
                                                                                    <xsl:otherwise>
                                                                                        <a style="font-family: 'PT Sans' , sans-serif;font-size: 12px;color: #6D6E71;font-weight: 700;"
                                                                                           id="linkAddUser_{normalize-space($ProjectID)}">[ Add User ]</a>
                                                                                    </xsl:otherwise>
                                                                                </xsl:choose>
                                                                            </xsl:when>
                                                                            <xsl:otherwise>
                                                                                <span class="publicationSummary onMouseOver"
                                                                                      onclick="LoadEmployeeDetail('{ClientUserID}','divClientPortalOperations_Container','{PortalItemID}');">
                                                                                    <xsl:value-of select="Client"/>
                                                                                </span>
                                                                            </xsl:otherwise>
                                                                        </xsl:choose>
                                                                    </td>
                                                                    <td width="50%">
                                                                        <xsl:choose>
                                                                            <xsl:when test ="Name != ''">
                                                                                <span id="span_{$ProjectID}_ProjectName">
                                                                                    <a id="projectName_{$ProjectID}" href="http://{$HostName}/Goal.aspx?ID={ItemID}" target="_blank"
                                                                                       style="font-family: 'PT Sans' , sans-serif;font-size: 12px;color: #6D6E71;font-weight: 700;">
                                                                                        <xsl:value-of select="Name"/>
                                                                                    </a>
                                                                                    <img src="{$TemplateURL}Web/Images/Edit_icon.png" style="cursor:pointer;" title="Edit" align="absmiddle"
                                                                                        onClick="displayEditProjectName('txt_{$ProjectID}_ProjectName','span_{$ProjectID}_ProjectName');"></img>
                                                                                </span>
                                                                                <input id="txt_{$ProjectID}_ProjectName" class="text" value="{Name}" style="display:none;width:230px;"
                                                                                       onBlur="updateCRMProjectName('{$ItemID}','{$ProjectID}','{ItemID}',
                                                                                                'txt_{$ProjectID}_ProjectName','projectName_{$ProjectID}','span_{$ProjectID}_ProjectName');"></input>
                                                                            </xsl:when>
                                                                            <xsl:otherwise>
                                                                                <xsl:choose>
                                                                                    <xsl:when test ="$PermissionID &gt;= 4">
                                                                                        <span  style="font-family: 'PT Sans' , sans-serif;font-size: 13px;color: #4B4B4B;font-weight: 700;"
                                                                                        onClick = "return portal_createNewGoal({$ItemID},'divClientPortalOperations_Container','ClientPortal','{ClientUserID}','{CRMProjectID}')">
                                                                                            [ Add New Goal ]
                                                                                        </span>
                                                                                    </xsl:when>
                                                                                </xsl:choose>
                                                                            </xsl:otherwise>
                                                                        </xsl:choose>
                                                                    </td>
                                                                    <td>
                                                                        <select id="ddlAction_{normalize-space($ProjectID)}" class="smallDropdown" style="width:112px;font-size:8pt;"
                                                                                onChange="clientPortal_SelectAction('{$ItemID}','divOpenProjects_{CRMProjectID}','{TemplateSourceID}',
                                                                                            '{ItemID}','{BrandID}','ddlAction_{normalize-space($ProjectID)}',
                                                                                            '{normalize-space(ClientUserID)}','{normalize-space(CRMProjectID)}',
                                                                                            '{$crmProjectTypeID}');">
                                                                            <option value="-99" >
                                                                                --Select Action--
                                                                            </option>
                                                                            <xsl:choose>
                                                                                <xsl:when test="Client != 0 and ($CommunityAdmin = 1 and TemplateSourceID &gt; 0) and Name != ''">
                                                                                    <option value="1">Send Response</option>
                                                                                    <option value="2">Re-apply Template</option>
                                                                                    <option value="3">Add Me</option>
                                                                                </xsl:when>
                                                                                <xsl:when test ="Client != 0 and ($CommunityAdmin = 1 and TemplateSourceID &gt; 0)">
                                                                                    <option value="1">Send Response</option>
                                                                                    <option value="2">Re-apply Template</option>
                                                                                </xsl:when>
                                                                                <xsl:when test="($CommunityAdmin = 1 and TemplateSourceID &gt; 0) and Name != ''">
                                                                                    <option value="2">Re-apply Template</option>
                                                                                    <option value="3">Add Me</option>
                                                                                </xsl:when>
                                                                                <xsl:when test="Client != 0 and Name != ''">
                                                                                    <option value="1">Send Response</option>
                                                                                    <option value="3">Add Me</option>
                                                                                </xsl:when>
                                                                                <xsl:when test="Client != 0">
                                                                                    <option value="1">Send Response</option>
                                                                                </xsl:when>
                                                                                <xsl:when test="($CommunityAdmin = 1 and TemplateSourceID &gt; 0) and Client = 0 and Name = ''">
                                                                                    <option value="2">Re-apply Template</option>
                                                                                </xsl:when>
                                                                                <xsl:when test="Name != ''">
                                                                                    <option value="3">Add Me</option>
                                                                                </xsl:when>
                                                                            </xsl:choose>
                                                                        </select>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <div style="{normalize-space($displayAccountName)};">
                                                                            <xsl:choose>
                                                                                <xsl:when test ="$PermissionID &gt;= 4">
                                                                                    <a  id= "ancAcc_{normalize-space($ProjectID)}" style="cursor:pointer;">
                                                                                        <xsl:choose>
                                                                                            <xsl:when test="AccountID">
                                                                                                <span class="publicationSummary"
                                                                                                      onClick="Portal_getProjectLists('divClientPortalOperations_Container',{$ItemID},'-1','{ClientUserID}','{AccountID}','1');">
                                                                                                    <xsl:value-of select ="Account"/>
                                                                                                </span>
                                                                                            </xsl:when>
                                                                                            <xsl:otherwise>
                                                                                                <span class="publicationSummary"  onClick = "return portal_EditAccount('ancAcc_{normalize-space($ProjectID)}','ddlAcc_{normalize-space($ProjectID)}')">
                                                                                                    [Add Account]
                                                                                                </span>
                                                                                            </xsl:otherwise>
                                                                                        </xsl:choose>
                                                                                    </a>
                                                                                    <select class="smallDropdown" style="display:none;width:130px;" id="ddlAcc_{normalize-space($ProjectID)}"
                                                                                                                  onChange="return portal_UpdateCRMAccount('{normalize-space($ProjectID)}','ancAcc_{normalize-space($ProjectID)}','ddlAcc_{normalize-space($ProjectID)}')">
                                                                                        <option value="-1"></option>
                                                                                        <xsl:for-each select="../CRMAccounts/Account">
                                                                                            <xsl:choose>
                                                                                                <xsl:when test="AccountID = $AccountID">
                                                                                                    <option value="{AccountID}" selected="selected"  >
                                                                                                        <xsl:value-of select="AccountName"/>
                                                                                                    </option>
                                                                                                </xsl:when>
                                                                                                <xsl:otherwise>
                                                                                                    <option value="{AccountID}" >
                                                                                                        <xsl:value-of select="AccountName"/>
                                                                                                    </option>
                                                                                                </xsl:otherwise>
                                                                                            </xsl:choose>
                                                                                        </xsl:for-each>
                                                                                    </select>
                                                                                </xsl:when>
                                                                                <xsl:otherwise>
                                                                                    <span class="publicationSummary">
                                                                                        <xsl:value-of select="Account"/>
                                                                                    </span>
                                                                                </xsl:otherwise>
                                                                            </xsl:choose>
                                                                        </div>

                                                                    </td>

                                                                    <td>
                                                                        <span class="publicationSummary" style="margin-right:10px;">
                                                                            <xsl:value-of select="ProjectFormattedCreatedDate"/>
                                                                        </span>
                                                                        <xsl:choose>
                                                                            <xsl:when test ="$PermissionID &gt;= 4">
                                                                                <!--<a href="" id = "anc_{normalize-space($ProjectID)}" style="font-family: 'PT Sans' , sans-serif;font-size: 12px;color: #6D6E71;font-weight: 700;"
                                                                                   onClick = "return portal_EditStage('anc_{normalize-space($ProjectID)}','ddl_{normalize-space($ProjectID)}');">
                                                                                    <xsl:value-of select="ProjectStage"/>
                                                                                </a>-->
                                                                                <select class="smallDropdown" style="display:none;width:120px" Origin="{$PStage}" id="ddl_{normalize-space($ProjectID)}"
                                                                                                      onChange="return portal_UpdateProjectStage('{$ID}','{normalize-space($ProjectID)}','anc_{normalize-space($ProjectID)}','ddl_{normalize-space($ProjectID)}','{$crmProjectTypeID}','')">
                                                                                    <xsl:for-each select="../ProjectStages/Stage[CRMProjectStageID!=11]">
                                                                                        <xsl:choose>
                                                                                            <xsl:when test="ProjectStage = $Stage">
                                                                                                <option value="{CRMProjectStageID}" selected="selected"  >
                                                                                                    <xsl:value-of select="ProjectStage"/>
                                                                                                </option>
                                                                                            </xsl:when>
                                                                                            <xsl:otherwise>
                                                                                                <option value="{CRMProjectStageID}" >
                                                                                                    <xsl:value-of select="ProjectStage"/>
                                                                                                </option>
                                                                                            </xsl:otherwise>
                                                                                        </xsl:choose>
                                                                                    </xsl:for-each>
                                                                                </select>
                                                                            </xsl:when>
                                                                            <xsl:otherwise>
                                                                                <span class="publicationSummary">
                                                                                    <xsl:value-of select="ProjectStage"/>
                                                                                </span>
                                                                            </xsl:otherwise>
                                                                        </xsl:choose>
                                                                    </td>
                                                                    <xsl:if test="SendResponseDate != ''">
                                                                        <td style="text-align:center;">
                                                                            <span class="publicationSummary" style="color: rgb(115, 111, 110);">
                                                                                <xsl:value-of select="SendResponseDate"/>
                                                                            </span>
                                                                        </td>
                                                                    </xsl:if>
                                                                </tr>
                                                            </table>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <table width="100%">
                                                                <tr>
                                                                    <td width="30%">
                                                                        <xsl:choose>
                                                                            <xsl:when test ="$PermissionID &gt;= 4">
                                                                                <xsl:choose>
                                                                                    <xsl:when test="Client!=0">
                                                                                        <span class="publicationSummary onMouseOver"
                                                                                              onclick="LoadEmployeeDetail('{ClientUserID}','divClientPortalOperations_Container','{PortalItemID}');">
                                                                                            <xsl:value-of select="Client"/>
                                                                                        </span>
                                                                                    </xsl:when>
                                                                                    <xsl:otherwise>
                                                                                        <a id="linkAddUser_{normalize-space($ProjectID)}"
                                                                                           style="font-family: 'PT Sans' , sans-serif;font-size: 12px;color: #6D6E71;font-weight: 700;">[ Add User ]</a>
                                                                                    </xsl:otherwise>
                                                                                </xsl:choose>
                                                                            </xsl:when>
                                                                            <xsl:otherwise>
                                                                                <span class="publicationSummary onMouseOver"
                                                                                      onclick="LoadEmployeeDetail('{ClientUserID}','divClientPortalOperations_Container','{PortalItemID}');">
                                                                                    <xsl:value-of select="Client"/>
                                                                                </span>
                                                                            </xsl:otherwise>
                                                                        </xsl:choose>
                                                                    </td>
                                                                    <td width="50%">
                                                                        <xsl:choose>
                                                                            <xsl:when test ="Name != ''">
                                                                                <span id="span_{$ProjectID}_ProjectName">
                                                                                    <a id="projectName_{$ProjectID}" href="http://{$HostName}/Goal.aspx?ID={ItemID}" target="_blank"
                                                                                       style="font-family: 'PT Sans' , sans-serif;font-size: 12px;color: #6D6E71;font-weight: 700;">
                                                                                        <xsl:value-of select="Name"/>
                                                                                    </a>
                                                                                    <img src="{$TemplateURL}Web/Images/Edit_icon.png" style="cursor:pointer;" title="Edit" align="absmiddle"
                                                                                        onClick="displayEditProjectName('txt_{$ProjectID}_ProjectName','span_{$ProjectID}_ProjectName');"></img>
                                                                                </span>
                                                                                <input id="txt_{$ProjectID}_ProjectName" class="text" value="{Name}" style="display:none;width:230px;"
                                                                            onBlur="updateCRMProjectName('{$ItemID}','{$ProjectID}','{ItemID}','txt_{$ProjectID}_ProjectName','projectName_{$ProjectID}','span_{$ProjectID}_ProjectName');"></input>
                                                                            </xsl:when>
                                                                            <xsl:otherwise>
                                                                                <xsl:choose>
                                                                                    <xsl:when test ="$PermissionID &gt;= 4">
                                                                                        <span  class="publicationSummary"
                                                                                        onClick = "return portal_createNewGoal({$ItemID},'divClientPortalOperations_Container','ClientPortal','{ClientUserID}','{CRMProjectID}')">
                                                                                            [ Add New Goal ]
                                                                                        </span>
                                                                                    </xsl:when>
                                                                                </xsl:choose>
                                                                            </xsl:otherwise>
                                                                        </xsl:choose>
                                                                    </td>
                                                                    <td>
                                                                        <select id="ddlAction_{normalize-space($ProjectID)}" class="smallDropdown" style="width:112px;font-size:8pt;"
                                                                                 onChange="clientPortal_SelectAction('{$ItemID}','divOpenProjects_{CRMProjectID}',
                                                                                            '{TemplateSourceID}','{ItemID}','{BrandID}','ddlAction_{normalize-space($ProjectID)}',
                                                                                            '{normalize-space(ClientUserID)}','{normalize-space(CRMProjectID)}',
                                                                                            '{$crmProjectTypeID}');">
                                                                            <option value="-99">
                                                                                --Select Action--
                                                                            </option>
                                                                            <xsl:choose>
                                                                                <xsl:when test="Client != 0 and ($CommunityAdmin = 1 and TemplateSourceID &gt; 0) and Name != ''">
                                                                                    <option value="1">Send Response</option>
                                                                                    <option value="2">Re-apply Template</option>
                                                                                    <option value="3">Add Me</option>
                                                                                </xsl:when>
                                                                                <xsl:when test ="Client != 0 and ($CommunityAdmin = 1 and TemplateSourceID &gt; 0)">
                                                                                    <option value="1">Send Response</option>
                                                                                    <option value="2">Re-apply Template</option>
                                                                                </xsl:when>
                                                                                <xsl:when test="($CommunityAdmin = 1 and TemplateSourceID &gt; 0) and Name != ''">
                                                                                    <option value="2">Re-apply Template</option>
                                                                                    <option value="3">Add Me</option>
                                                                                </xsl:when>
                                                                                <xsl:when test="Client != 0 and Name != ''">
                                                                                    <option value="1">Send Response</option>
                                                                                    <option value="3">Add Me</option>
                                                                                </xsl:when>
                                                                                <xsl:when test="Client != 0">
                                                                                    <option value="1">Send Response</option>
                                                                                </xsl:when>
                                                                                <xsl:when test="($CommunityAdmin = 1 and TemplateSourceID &gt; 0) and Client = 0 and Name = ''">
                                                                                    <option value="2">Re-apply Template</option>
                                                                                </xsl:when>
                                                                                <xsl:when test="Name != ''">
                                                                                    <option value="3">Add Me</option>
                                                                                </xsl:when>
                                                                            </xsl:choose>
                                                                        </select>
                                                                    </td>
                                                                </tr>
                                                                <tr>

                                                                    <td>
                                                                        <div style="{normalize-space($displayAccountName)};">
                                                                            <xsl:choose>
                                                                                <xsl:when test ="$PermissionID &gt;= 4">

                                                                                    <a id= "ancAcc_{normalize-space($ProjectID)}" style="cursor:pointer;font-family: 'PT Sans' , sans-serif;font-size: 12px;color: #6D6E71;font-weight: 700;">
                                                                                        <xsl:choose>
                                                                                            <xsl:when test="AccountID">
                                                                                                <span class="publicationSummary"
                                                                                                        onClick="Portal_getProjectLists('divClientPortalOperations_Container',{$ItemID},'-1','{ClientUserID}','{AccountID}','1');">
                                                                                                    <xsl:value-of select ="Account"/>
                                                                                                </span>
                                                                                            </xsl:when>
                                                                                            <xsl:otherwise>
                                                                                                <span class="publicationSummary"  onClick = "return portal_EditAccount('ancAcc_{normalize-space($ProjectID)}','ddlAcc_{normalize-space($ProjectID)}')">
                                                                                                    [Add Account]
                                                                                                </span>
                                                                                            </xsl:otherwise>
                                                                                        </xsl:choose>
                                                                                    </a>
                                                                                    <select class="smallDropdown" style="display:none;width:130px;" id="ddlAcc_{normalize-space($ProjectID)}"
                                                                                                                  onChange="return portal_UpdateCRMAccount('{normalize-space($ProjectID)}','ancAcc_{normalize-space($ProjectID)}','ddlAcc_{normalize-space($ProjectID)}')">
                                                                                        <option value="-1"></option>
                                                                                        <xsl:for-each select="../CRMAccounts/Account">
                                                                                            <xsl:choose>
                                                                                                <xsl:when test="AccountID = $AccountID">
                                                                                                    <option value="{AccountID}" selected="selected"  >
                                                                                                        <xsl:value-of select="AccountName"/>
                                                                                                    </option>
                                                                                                </xsl:when>
                                                                                                <xsl:otherwise>
                                                                                                    <option value="{AccountID}" >
                                                                                                        <xsl:value-of select="AccountName"/>
                                                                                                    </option>
                                                                                                </xsl:otherwise>
                                                                                            </xsl:choose>
                                                                                        </xsl:for-each>
                                                                                    </select>
                                                                                </xsl:when>
                                                                                <xsl:otherwise>
                                                                                    <span class="publicationSummary">
                                                                                        <xsl:value-of select="Account"/>
                                                                                    </span>
                                                                                </xsl:otherwise>
                                                                            </xsl:choose>
                                                                        </div>
                                                                    </td>

                                                                    <td>
                                                                        <span class="publicationSummary" style="margin-right:10px;">
                                                                            <xsl:value-of select="ProjectFormattedCreatedDate"/>
                                                                        </span>
                                                                        <xsl:choose>
                                                                            <xsl:when test ="$PermissionID &gt;= 4">
                                                                                <!--<a href="" id = "anc_{normalize-space($ProjectID)}" style="font-family: 'PT Sans' , sans-serif;font-size: 12px;color: #6D6E71;font-weight: 700;"
                                                                                   onClick = "return portal_EditStage('anc_{normalize-space($ProjectID)}','ddl_{normalize-space($ProjectID)}');">
                                                                                    <xsl:value-of select="ProjectStage"/>
                                                                                </a>-->
                                                                                <select class="smallDropdown" style="display:none;width:120px" Origin="{$PStage}" id="ddl_{normalize-space($ProjectID)}"
                                                                                                      onChange="return portal_UpdateProjectStage('{$ID}','{normalize-space($ProjectID)}','anc_{normalize-space($ProjectID)}','ddl_{normalize-space($ProjectID)}','{$crmProjectTypeID}','')">
                                                                                    <xsl:for-each select="../ProjectStages/Stage[CRMProjectStageID!=11]">
                                                                                        <xsl:choose>
                                                                                            <xsl:when test="ProjectStage = $Stage">
                                                                                                <option value="{CRMProjectStageID}" selected="selected"  >
                                                                                                    <xsl:value-of select="ProjectStage"/>
                                                                                                </option>
                                                                                            </xsl:when>
                                                                                            <xsl:otherwise>
                                                                                                <option value="{CRMProjectStageID}" >
                                                                                                    <xsl:value-of select="ProjectStage"/>
                                                                                                </option>
                                                                                            </xsl:otherwise>
                                                                                        </xsl:choose>
                                                                                    </xsl:for-each>
                                                                                </select>
                                                                            </xsl:when>
                                                                            <xsl:otherwise>
                                                                                <span class="publicationSummary">
                                                                                    <xsl:value-of select="ProjectStage"/>
                                                                                </span>
                                                                            </xsl:otherwise>
                                                                        </xsl:choose>
                                                                    </td>
                                                                    <xsl:if test="SendResponseDate != ''">
                                                                        <td style="text-align:center;">
                                                                            <span class="publicationSummary" style="color: rgb(115, 111, 110);">
                                                                                <xsl:value-of select="SendResponseDate"/>
                                                                            </span>
                                                                        </td>
                                                                    </xsl:if>
                                                                </tr>
                                                            </table>
                                                        </xsl:otherwise>
                                                    </xsl:choose>
                                                    <div id="divOpenProjects_{CRMProjectID}_detail_container" style="position:absolute;display:none;border: 1px solid black;padding: 5px;
                                                        background-color:#FFFFFF;visibility: visible;width:600px;"></div>
                                                </div>
                                            </xsl:for-each>
                                        </div>
                                    </div>
                                </xsl:if>
                            </td>
                        </tr>
                    </xsl:for-each>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="count(CompletedCRMProjects/Project)=0">
                <tr>

                </tr>
            </xsl:if>
        </table>
    </xsl:template>



    <xsl:template name="AddNewItemFormatContainer2">
        <xsl:param name="crmProjectTypeID" select="'N/A'"></xsl:param>
        <xsl:param name="PermissionID" select="'N/A'"></xsl:param>
        <xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
        <xsl:param name="ID" select="'N/A'"></xsl:param>
        <xsl:param name="DisplayText" select="'N/A'"></xsl:param>
        <xsl:param name="AddButtonAlign" select="'N/A'"></xsl:param>

        <xsl:choose>
            <xsl:when test="$crmProjectTypeID = 1">
                <td colspan="4" style="text-align:center;">
                    <center>
                        <div style="padding:15px;display:{$DisplayText}">
                            <span class="publicationSummary">There are no projects</span>
                        </div>
                        <xsl:choose>
                            <xsl:when test ="$PermissionID &gt;= 4">
                                <div align="{$AddButtonAlign}">
                                    <div class="verticallyMiddle onMouseOver divBrowseGradient spanBrowseGradientTextGray marginBottom10" style="width:130px;line-height:30px;text-align:center;"
                                       onmouseover="document.getElementById('img_Add2_AddProject').src='{$TemplateURL}Web/Images/Ver_2_0/icon_add_over.png';"
                                       onmouseout="document.getElementById('img_Add2_AddProject').src='{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png';"
                                       onClick="return Portal_AutoSuggestDisplay('{$ID}','divClientPortalOperations_Container','PortalAutoSuggest','1');">
                                        <img id="img_Add2_AddProject" src="{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png" align="absmiddle" style="padding-left:8px;" class="marginRight5"></img>
                                        <span id="span_Cancel">
                                            ADD A PROJECT
                                        </span>
                                    </div>
                                </div>
                            </xsl:when>
                        </xsl:choose>
                    </center>
                </td>
            </xsl:when>
            <xsl:when test="$crmProjectTypeID = 3">
                <td colspan="4" style="text-align:center;">
                    <center>
                        <div style="padding:15px;display:{$DisplayText}">
                            <span class="packageTitle">There are no Challenges</span>
                        </div>
                        <xsl:choose>
                            <xsl:when test ="$PermissionID &gt;= 4">
                                <div align="{$AddButtonAlign}">
                                    <div class="verticallyMiddle onMouseOver divBrowseGradient spanBrowseGradientTextGray marginBottom10" style="width:150px;line-height:30px;text-align:center;"
                                       onmouseover="document.getElementById('img_Add2_AddProject').src='{$TemplateURL}Web/Images/Ver_2_0/icon_add_over.png';"
                                       onmouseout="document.getElementById('img_Add2_AddProject').src='{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png';"
                                       onClick="return Portal_AutoSuggestDisplay('{$ID}','divClientPortalOperations_Container','PortalAutoSuggest','2');">
                                        <img id="img_Add2_AddProject" src="{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png" align="absmiddle" style="padding-left:8px;" class="marginRight5"></img>
                                        <span id="span_Cancel">
                                            ADD A CHALLENGE
                                        </span>
                                    </div>
                                </div>
                            </xsl:when>
                        </xsl:choose>
                    </center>
                </td>
            </xsl:when>
            <xsl:when test="$crmProjectTypeID = 2">
                <td colspan="4" style="text-align:center;">
                    <center>
                        <div style="padding:15px;display:{$DisplayText}">
                            <span class="font-family: 'PT Sans' , sans-serif;font-size: 13px;color: #4B4B4B;font-weight: 700;">There are no goals</span>
                        </div>
                        <xsl:choose>
                            <xsl:when test ="$PermissionID &gt;= 4">
                                <div align="{$AddButtonAlign}">
                                    <div class="verticallyMiddle onMouseOver divBrowseGradient spanBrowseGradientTextGray" style="width:120px;line-height:30px;text-align:center;"
                                         onmouseover="document.getElementById('img_Cancel').src='{$TemplateURL}Web/Images/Ver_2_0/icon_add_over.png';"
                                         onmouseout="document.getElementById('img_Cancel').src='{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png';"
                                         onclick="return Portal_LoadAddNewGoalWizard('{$ID}','divClientPortalOperations_Container','6','1','-99','','');">
                                        <img id="img_Cancel" src="{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png" align="absmiddle" style="padding-left:8px;" class="marginRight5"></img>
                                        <span id="span_Cancel">ADD A GOAL</span>
                                    </div>
                                </div>
                            </xsl:when>
                        </xsl:choose>
                    </center>
                </td>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
