﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <xsl:variable name="PortalItemID" select="AjaxRequest/Params/ItemID"></xsl:variable>
    <xsl:variable name="Source">
      <xsl:choose>
        <xsl:when test="AjaxRequest/Params/Source">
          <xsl:value-of select="AjaxRequest/Params/Source"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>default</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="SourceID">
      <xsl:choose>
        <xsl:when test="AjaxRequest/Params/SourceID">
          <xsl:value-of select="AjaxRequest/Params/SourceID"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:number value ="-99"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="Subject" select="AjaxRequest/CRMResponseDetail/CRMResponse/Subject"></xsl:variable>
    <xsl:variable name="Body" select="AjaxRequest/CRMResponseDetail/CRMResponse/Body"></xsl:variable>
    <xsl:variable name="Active" select="AjaxRequest/CRMResponseDetail/CRMResponse/Active"></xsl:variable>
    <xsl:variable name="Approved" select="AjaxRequest/CRMResponseDetail/CRMResponse/Approved"></xsl:variable>
    <xsl:variable name="Mode" select="AjaxRequest/Params/Mode"></xsl:variable>
    <xsl:variable name="CRMResponseID" select="AjaxRequest/CRMResponseDetail/CRMResponse/CRMResponseID"></xsl:variable>
    <xsl:variable name="User" select="AjaxRequest/CRMResponseDetail/CRMResponse/DisplayName"></xsl:variable>
    <xsl:variable name="DefaultUserID" select="AjaxRequest/DefaultUser"></xsl:variable>



    <div id="div_NewResponse">
      <table class="tableMaster" cellspacing="5">
        <tr>
          <td>
            <span class="labelFormFields">
              Subject
            </span>
          </td>
          <td>
            <input id="txt_Subject" type="text" class="text" style="width:463px;" value="{$Subject}" tabindex="1"></input>
          </td>
        </tr>
        <tr>
          <td>
            <span class="labelFormFields">
              Body
            </span>
          </td>
          <td>
            <div>
              <textarea id="txt_Body" type="text"  class="mceEditor" tabindex="2">
                <xsl:value-of select="$Body"/>
              </textarea>
            </div>
            <!--<span class="labelHeader" style="font-size:10pt;margin-right:5px;">Merge Fields:</span>{First_Name}, {Last_Name}, {Email}, {Display_Name}-->
            <span class="labelHeader" style="font-size:10pt;">Merge Fields:</span>
            <span id="spn_FirstName" style="cursor:pointer;" onclick="setText('spn_FirstName');">{First_Name},</span>
            <span id="spn_LastName" style="cursor:pointer;" onclick="setText('spn_LastName');">{Last_Name},</span>
            <span id="spn_EmailName" style="cursor:pointer;" onclick="setText('spn_EmailName');">{Email},</span>
            <span id="spn_DisplayName" style="cursor:pointer;" onclick="setText('spn_DisplayName');">{Display_Name}</span>
          </td>
        </tr>
        <tr>
          <td>
            <span class="labelFormFields">
              Active
            </span>
          </td>
          <td>
            <xsl:choose>
              <xsl:when test="AjaxRequest/UserRoles/Role[RoleName = 'Brand Admin']">
                <select class="smallDropdown" style="width:70px;" id="ddlResponseActive" tabindex="3">
                  <xsl:choose>
                    <xsl:when test="$Active = 1">
                      <option value="1" selected="selected">
                        <xsl:text>Yes</xsl:text>
                      </option>
                      <option value="0">
                        <xsl:text>No</xsl:text>
                      </option>
                    </xsl:when>
                    <xsl:when test="$Active != 1">
                      <option value="1">
                        <xsl:text>Yes</xsl:text>
                      </option>
                      <option value="0" selected="selected">
                        <xsl:text>No</xsl:text>
                      </option>
                    </xsl:when>
                    <xsl:otherwise>
                      <option value="1">
                        <xsl:text>Yes</xsl:text>
                      </option>
                      <option value="0">
                        <xsl:text>No</xsl:text>
                      </option>
                    </xsl:otherwise>
                  </xsl:choose>
                </select>
              </xsl:when>
              <xsl:otherwise>
                <span id="ResponseActive" class="label">
                  Yes
                </span>
              </xsl:otherwise>
            </xsl:choose>

          </td>
        </tr>
        <tr>
          <td>
            <span class="labelFormFields">
              Approved
            </span>
          </td>
          <td>
            <xsl:choose>
              <xsl:when test="AjaxRequest/UserRoles/Role[RoleName = 'Brand Admin']">
                <select class="smallDropdown" id="ddlResponseApproved" tabindex="4">
                  <xsl:for-each select="AjaxRequest/CRMResponseStatuses/ResponseStatus">
                    <xsl:variable name="ResponseStatus" select="ResponseStatus"></xsl:variable>
                    <xsl:choose>
                      <xsl:when test="$ResponseStatus = $Approved">
                        <option value="{ResponseStatusID}" selected="selected">
                          <xsl:value-of select="$ResponseStatus"/>
                        </option>
                      </xsl:when>
                      <xsl:otherwise>
                        <option value="{ResponseStatusID}">
                          <xsl:value-of select="$ResponseStatus"/>
                        </option>
                      </xsl:otherwise>
                    </xsl:choose>
                  </xsl:for-each>
                </select>
              </xsl:when>
              <xsl:otherwise>
                <span class="label" id="ResponseApproved">
                  Pending
                </span>
              </xsl:otherwise>
            </xsl:choose>
          </td>
        </tr>
        <tr>
          <td>
            <span class="labelFormFields">
              User
            </span>
          </td>
          <td>
            <select id="ddlUsers" class="smallDropdown">
              <option value="-99">
                Select
              </option>
              <xsl:for-each select="AjaxRequest/AutoSuggest/Suggest">
                <xsl:variable name="ID" select="ID"></xsl:variable>
                <xsl:variable name="UserName" select="Name"></xsl:variable>
                
                <xsl:choose>
                  <xsl:when test="$UserName = $User">
                    <option value="{ID}" selected="selected">
                      <xsl:value-of select="Name"/>
                    </option>
                  </xsl:when>
                  <xsl:when test="$ID = $DefaultUserID">
                    <option value="{ID}" selected="selected">
                      <xsl:value-of select="Name"/>
                    </option>
                  </xsl:when>
                  <xsl:otherwise>
                    <option value="{ID}">
                      <xsl:value-of select="Name"/>
                    </option>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:for-each>
            </select>
          </td>
        </tr>
        <tr>
          <xsl:choose>
            <xsl:when test="$Mode = 'Edit'">
              <td>
                <input type="button" class="button" value="Update" style="margin-top:10px;" tabindex="5"
                       onclick="ClientPortal_UpdateResponse('{$PortalItemID}','txt_Subject','txt_Body','ddlResponseActive','ddlResponseApproved','{$CRMResponseID}','ddlUsers');"></input>
              </td>
            </xsl:when>
            <xsl:otherwise>
              <td>
                <input type="button" class="button" value="Save" style="margin-top:10px;" tabindex="5"
                       onclick="ClientPortal_SaveNewResponse('{$PortalItemID}','txt_Subject','txt_Body','ddlResponseActive','ddlResponseApproved','ddlUsers','{$Source}','{$SourceID}');"></input>
              </td>
            </xsl:otherwise>
          </xsl:choose>

          <td>
            <!--<input type="button" class="button" value="Cancel" style="margin-top:10px;margin-right:35px;" tabindex="6"
                               onClick="clientPortal_DisplaySavedResponsesList('{$PortalItemID}','divClientPortalOperations_Container');"></input>-->
            <input type="button" class="button" value="Cancel" style="margin-top:10px;margin-right:35px;" tabindex="6"
       onClick="clientPortal_CancleAddResponse(event,'{$PortalItemID}','divClientPortalOperations_Container','{$Source}','{$SourceID}');"></input>
            <input type="button" class="button" value="Test"
                   onClick="GenerateNewResponseEmail('{$PortalItemID}','txt_Subject','txt_Body');"></input>
          </td>



        </tr>
      </table>
    </div>
  </xsl:template>
</xsl:stylesheet>
