﻿<?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: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:if test="count(CompletedCRMProjects/Project)!=0 and $Action!='GetFilteredCRMProjectList'">

      <table width="100%">
        <tr>
          <td style="padding: 10px;">
              <xsl:choose>
                  <xsl:when test="$CRMProjectTypeID = 2">
                      <Span class="label" style="vertical-align: center;">Employee</Span>
                  </xsl:when>
                  <xsl:otherwise>
                      <Span class="label" style="vertical-align: center;">Client</Span>
                  </xsl:otherwise>
              </xsl:choose>
           
            <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');"></input>

            <Span class="label" 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');"></input>


              <xsl:choose>
                  <xsl:when test="$CRMProjectTypeID = 2">
                      <Span class="label" style="vertical-align: center;">Goal</Span>
                  </xsl:when>
                  <xsl:otherwise>
                      <Span class="label" style="vertical-align: center;">Project</Span>
                  </xsl:otherwise>
              </xsl:choose>  
           
            <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');"></input>

            <xsl:if test="$StageID != 4 and $StageID != 5 and $StageID != 6">
              <Span class="label" style="vertical-align: center;">Stage</Span>
              <select class="smallDropdown" id="ddlFilter_Stage" style="margin-left: 5px;"
                      onChange="return CRMProjectFilter(null,'txtFilter_Client','txtFilter_Account','txtFilter_Project',
                      'ddlFilter_Stage','{$ItemID}','divCompletedProjects','{$StageID}','ddlFilter_Sort');">
                <option value="-1" selected="selected">Select</option>
                <xsl:for-each select="CompletedCRMProjects/ProjectStages/Stage[CRMProjectStageID!=4 and CRMProjectStageID!=5 and CRMProjectStageID!=6]">
                  <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="label" 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');">
                  <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: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:call-template>
        </div>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="ProjectList">
    <xsl:variable name="ItemID" select="CompletedCRMProjects/Project/PortalItemID"/>
    <xsl:variable name="HostName" select="CompletedCRMProjects/HostName"/>
    <xsl:variable name="CommunityAdmin" select="CompletedCRMProjects/CommunityAdmin"/>
    <xsl:variable name="StageID" select="CompletedCRMProjects/Project/CRMProjectStageID"/>
    <xsl:variable name="GoalID" select="N/A"/>
    <xsl:variable name="ID" select="CompletedCRMProjects/ItemID"/>
    <xsl:variable name="Action" select="N/A"/>
    <xsl:variable name="PermissionID" select="normalize-space(CompletedCRMProjects/Permissions/ItemPermission/PermissionID)"/>
    <xsl:variable name="TemplateURL" select="CompletedCRMProjects/TemplateURL"/>
      <xsl:variable name="crmProjectTypeID" select="CompletedCRMProjects/Project/TypeID"/>

    <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 label link">
                      <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="30%" class="label">
                                <span>
                                  <xsl:value-of select="Client"/>
                                </span>
                              </td>
                              <td width="30%">
                                <xsl:choose>
                                  <xsl:when test ="$PermissionID = 4">
                                    <a href="" id= "ancAcc_{normalize-space($ProjectID)}"
                                      onClick = "return portal_EditAccount('ancAcc_{normalize-space($ProjectID)}','ddlAcc_{normalize-space($ProjectID)}')">
                                      <xsl:choose>
                                        <xsl:when test="AccountID">
                                          <xsl:value-of select="Account"/>
                                        </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="label">
                                      <xsl:value-of select="Client"/>
                                    </span>
                                  </xsl:otherwise>
                                </xsl:choose>
                              </td>
                              <td width="23%" class="label" style="padding-right:5px;">
                                  <a id="projectName_{$ProjectID}" href="http://{$HostName}/Goal.aspx?ID={ItemID}" target="_blank" style="cursor:pointer;" class="link">
                                    <xsl:value-of select="Name"/>
                                  </a>
                              </td>
                              <td width="27%">
                                <xsl:choose>
                                  <xsl:when test ="$PermissionID = 4">
                                    <a href="" id = "anc_{normalize-space($ProjectID)}"
                                                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">
                                        <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="label">
                                      <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 label link">
                      <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 = 4">
                                        <xsl:choose>
                                          <xsl:when test="Client!=0">
                                            <span class="link">
                                              <xsl:value-of select="Client"/>
                                            </span>
                                          </xsl:when>
                                          <xsl:otherwise>
                                            <a class="link" id="linkAddUser_{normalize-space($ProjectID)}">[ Add User ]</a>
                                          </xsl:otherwise>
                                        </xsl:choose>
                                      </xsl:when>
                                      <xsl:otherwise>
                                        <span class="link">
                                          <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="cursor:pointer;" class="link">
                                            <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 = 4">
                                            <span  style="font-family: Calibri, Verdana, Arial;font-size: 10pt;color: #003366;cursor: pointer;"
                                            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)}');">
                                      <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>
                                      <xsl:choose>
                                        <xsl:when test ="$PermissionID = 4">
                                          <a  id= "ancAcc_{normalize-space($ProjectID)}" style="cursor:pointer;">
                                            <xsl:choose>
                                              <xsl:when test="AccountID">
                                                <span class="link"
                                                        onClick="client_GetClientDetail('divClientPortalRight_1','{$ItemID}','{ClientUserID}','{Account}','{AccountID}'); 
                                                                                            Portal_getProjectLists('divClientPortalOperations_Container',{$ItemID},'-1','{ClientUserID}','{AccountID}','1');">
                                                  <xsl:value-of select ="Account"/>
                                                </span>
                                              </xsl:when>
                                              <xsl:otherwise>
                                                <span  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="label">
                                            <xsl:value-of select="Account"/>
                                          </span>
                                        </xsl:otherwise>
                                      </xsl:choose>
                                    </div>

                                  </td>
                                  <td>
                                    <span class="label" style="margin-right:10px;">
                                      <xsl:value-of select="ProjectFormattedCreatedDate"/>
                                    </span>
                                    <xsl:choose>
                                      <xsl:when test ="$PermissionID = 4">
                                        <a href="" id = "anc_{normalize-space($ProjectID)}"
                                                    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">
                                            <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="label">
                                          <xsl:value-of select="ProjectStage"/>
                                        </span>
                                      </xsl:otherwise>
                                    </xsl:choose>
                                  </td>
                                  <xsl:if test="SendResponseDate != ''">
                                    <td style="text-align:center;">
                                      <span class="labelSmall" 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 = 4">
                                        <xsl:choose>
                                          <xsl:when test="Client!=0">
                                            <span class="link">
                                              <xsl:value-of select="Client"/>
                                            </span>
                                          </xsl:when>
                                          <xsl:otherwise>
                                            <a id="linkAddUser_{normalize-space($ProjectID)}" class="link">[ Add User ]</a>
                                          </xsl:otherwise>
                                        </xsl:choose>
                                      </xsl:when>
                                      <xsl:otherwise>
                                        <span class="link">
                                          <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="cursor:pointer;" class="link">
                                            <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 = 4">
                                            <span  style="font-family: Calibri, Verdana, Arial;font-size: 10pt;color: #003366;cursor: pointer;"
                                            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)}');">
                                      <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>
                                      <xsl:choose>
                                        <xsl:when test ="$PermissionID = 4">
                                          <a id= "ancAcc_{normalize-space($ProjectID)}" style="cursor:pointer;">
                                            <xsl:choose>
                                              <xsl:when test="AccountID">
                                                <span class="link"
                                                        onClick="client_GetClientDetail('divClientPortalRight_1','{$ItemID}','{ClientUserID}','{Account}','{AccountID}'); 
                                                                                            Portal_getProjectLists('divClientPortalOperations_Container',{$ItemID},'-1','{ClientUserID}','{AccountID}','1');">
                                                  <xsl:value-of select ="Account"/>
                                                </span>
                                              </xsl:when>
                                              <xsl:otherwise>
                                                <span  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="label">
                                            <xsl:value-of select="Account"/>
                                          </span>
                                        </xsl:otherwise>
                                      </xsl:choose>
                                    </div>
                                  </td>
                                  <td>
                                    <span class="label" style="margin-right:10px;">
                                      <xsl:value-of select="ProjectFormattedCreatedDate"/>
                                    </span>
                                    <xsl:choose>
                                      <xsl:when test ="$PermissionID = 4">
                                        <a href="" id = "anc_{normalize-space($ProjectID)}"
                                                    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">
                                            <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="label">
                                          <xsl:value-of select="ProjectStage"/>
                                        </span>
                                      </xsl:otherwise>
                                    </xsl:choose>
                                  </td>
                                  <xsl:if test="SendResponseDate != ''">
                                    <td style="text-align:center;">
                                      <span class="labelSmall" 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>
          <td colspan="4" style="text-align:center;">
            <center>
              <div style="padding:15px;">
                <span class="label">There are no projects</span>
              </div>
              <xsl:choose>
                <xsl:when test ="$PermissionID = 4">
                  <input type="button" class="button" value="Add A Project"
                    onclick="return Portal_AutoSuggestDisplay('{$ID}','divClientPortalOperations_Container','PortalAutoSuggest','1');"></input>
                </xsl:when>
              </xsl:choose>
            </center>
          </td>
        </tr>
      </xsl:if>
    </table>
  </xsl:template>
</xsl:stylesheet>
