<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:include href="/app/tools/support/templates/layout.xsl" />

  <xsl:template name="mainBody" >
    <xsl:call-template name="bodyTitle" >
      <xsl:with-param name="title">Distribution Service Detail</xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="bodyMessage" />
    <xsl:call-template name="displayForm" />
  </xsl:template>

  <xsl:template name="displayForm" >
    <div name="body_form">
    <form method="post" action="{$moduleURL}" >
      <input type="hidden" name="c"><xsl:attribute name="value"><xsl:value-of select="/Root/Cmd" /></xsl:attribute></input>
      <input type="hidden" name="ServiceAccountID"><xsl:attribute name="value"><xsl:value-of select="Form/ServiceAccountID" /></xsl:attribute></input>
      <input type="hidden" name="ClientID"><xsl:attribute name="value"><xsl:value-of select="Params/ClientID" /></xsl:attribute></input>
      <input type="hidden" name="action"><xsl:attribute name="value"><xsl:value-of select="Params/action" /></xsl:attribute></input>
      <xsl:choose>
        <xsl:when test="Form/ServiceAccountID &gt; 0">
          <xsl:call-template name="displayDetail" />
          <xsl:call-template name="displayButtons" />
        </xsl:when>
        <xsl:when test="/Root/Params/action = 'new'">
          <xsl:call-template name="displayDetail" />
          <xsl:call-template name="displayButtons" />
        </xsl:when>
        <xsl:otherwise>
          Service Account not found
        </xsl:otherwise>
      </xsl:choose>
    </form>
    </div>
  </xsl:template>

  <xsl:template name="displayDetail" >
    <fieldset>
      <legend>Service Account</legend>
      <table>

        <tr>
          <xsl:call-template name="textField" >
            <xsl:with-param name="label">Service Account ID</xsl:with-param>
            <xsl:with-param name="value" select = "Form/ServiceAccountID" />
          </xsl:call-template>
        </tr>

        <tr>
          <xsl:call-template name="serviceSelect" />
        </tr>

        <tr>
          <xsl:call-template name="textField" >
            <xsl:with-param name="label">Description</xsl:with-param>
            <xsl:with-param name="name">Form_Description</xsl:with-param>
            <xsl:with-param name="value" select = "Form/Description" />
            <xsl:with-param name="width" >50</xsl:with-param>
          </xsl:call-template>
        </tr>

        <tr>
          <xsl:call-template name="textField" >
            <xsl:with-param name="label">Account Name</xsl:with-param>
            <xsl:with-param name="name">Form_AccountName</xsl:with-param>
            <xsl:with-param name="value" select = "Form/AccountName" />
          </xsl:call-template>
        </tr>

        <tr>
          <xsl:call-template name="textField" >
            <xsl:with-param name="label">Remote Base Path</xsl:with-param>
            <xsl:with-param name="name">Form_RemoteBasePath</xsl:with-param>
            <xsl:with-param name="size">50</xsl:with-param>
            <xsl:with-param name="value" select = "Form/RemoteBasePath" />
          </xsl:call-template>
        </tr>

        <tr>
          <xsl:call-template name="listField" >
            <xsl:with-param name="label">Account Type</xsl:with-param>
            <xsl:with-param name="name">Form_AccountType</xsl:with-param>
            <xsl:with-param name="value" select = "Form/AccountType" />
            <xsl:with-param name="options" >
              <option name="royaltyshare">RoyaltyShare</option>
              <option name="direct">Direct</option>
            </xsl:with-param>
          </xsl:call-template>
        </tr>

        <xsl:call-template name="displayCredentials" />
      </table>
    </fieldset>
  </xsl:template>

  <xsl:template name="displayCredentials" >

    <tr>
      <td>Credentials</td>
      <td>
      <xsl:call-template name="credentialSelect" />

      <xsl:call-template name="backButton" >
        <xsl:with-param name="buttonText">Edit Credential</xsl:with-param>
        <xsl:with-param name="command">service_credential_detail</xsl:with-param>
        <xsl:with-param name="name">Form_ServiceCredentialID</xsl:with-param>
        <xsl:with-param name="args">
          <ServiceCredentialID><xsl:value-of select="Form/ServiceCredentialID" /></ServiceCredentialID>
          <ServiceAccountID><xsl:value-of select="Form/ServiceAccountID" /></ServiceAccountID>
          <ClientID><xsl:value-of select="/Root/Params/ClientID" /></ClientID>
        </xsl:with-param>
      </xsl:call-template>

      <xsl:call-template name="backButton" >
        <xsl:with-param name="buttonText">Add Credential</xsl:with-param>
        <xsl:with-param name="command">service_credential_detail</xsl:with-param>
        <xsl:with-param name="args">
          <ServiceAccountID><xsl:value-of select="Form/ServiceAccountID" /></ServiceAccountID>
          <ClientID><xsl:value-of select="/Root/Params/ClientID" /></ClientID>
          <action>new</action>
        </xsl:with-param>
      </xsl:call-template>
      </td>
    </tr>

  </xsl:template>

  <xsl:template name="credentialSelect" >
    <select name="Form_ServiceCredentialID" >
      <option value=""></option>
      <xsl:for-each select="Form/ServiceCredentials/ServiceCredential" >
        <option value="{ServiceCredentialID}">
          <xsl:if test="ServiceCredentialID = /Root/Form/ServiceCredentialID">
            <xsl:attribute name="selected">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="Description" />
        </option>
      </xsl:for-each>
    </select>
  </xsl:template>

  <xsl:template name="serviceSelect" >
    <td>Service</td>
    <td>
      <xsl:choose>
        <xsl:when test="/Root/Params/action = 'new'" >
          <select name="Form_ServiceID" >
            <option value="" ></option>
            <xsl:for-each select="Form/DistributionServices/Service" >
              <option value="{ServiceID}" >
                <xsl:if test="/Root/Form/ServiceID = ServiceID" >
                  <xsl:attribute name="selected">selected</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="ServiceName" />
              </option>
            </xsl:for-each>
          </select>
        </xsl:when>
        <xsl:otherwise>
          <xsl:for-each select="Form/DistributionServices/Service" >
            <xsl:if test="/Root/Form/ServiceID = ServiceID" >
              <xsl:value-of select="ServiceName" />
            </xsl:if>
          </xsl:for-each>
        </xsl:otherwise>
      </xsl:choose>
    </td>
  </xsl:template>

  <xsl:template name="displayButtons" >
    <xsl:if test="/Root/Params/ClientID" >
      <xsl:call-template name="backButton" >
        <xsl:with-param name="buttonText">Return to Client</xsl:with-param>
        <xsl:with-param name="command" >client_detail</xsl:with-param>
        <xsl:with-param name="args" >
          <ClientID><xsl:value-of select="/Root/Params/ClientID" /></ClientID>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:if>
    <xsl:call-template name="submitButton" />
  </xsl:template>

</xsl:stylesheet>
