<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
    <xsl:output method="html" indent="no" doctype-system="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" encoding="utf-8" />

    <xsl:include href="/app/tools/bookpub/templates/global.xsl" />
    <xsl:include href="/app/tools/bookpub/templates/catalog/book_detail.xsl" />
    <!--<xsl:include href="/app/tools/bookpub/templates/catalog/chapter_detail.xsl" />-->


    <!-- do we need this? I think not...-->
    <xsl:variable name="formatType">
        <xsl:for-each select="/Root/Form/TypeList/Type">
            <xsl:if test="ProductTypeID = /Root/Form/Product/ProductTypeID"><xsl:value-of select="Type" /></xsl:if>
        </xsl:for-each>
    </xsl:variable>

    <xsl:template name="pickLayout">
        <form action="/bookpub/catalog" name="chapterProductEdit" id="chapterProductEdit" method="post">
            <input type="hidden" name="formSubmit" value="1" />
            <input type="hidden" name="c" value="edit_chapter_product" />
            <xsl:call-template name="chapterProductEdit" />
            <xsl:call-template name="buttons" />
        </form>
	    <xsl:call-template name="calendar">
		    <xsl:with-param name="fieldID">Form_Product_ReleaseDate</xsl:with-param>
		    <xsl:with-param name="buttonID">calendarIcon</xsl:with-param>
	    </xsl:call-template>
    </xsl:template>


    <xsl:template name="chapterProductEdit">
        <xsl:if test="normalize-space(Form/Chapter/ChapterID)">
            <input type="hidden" name="ChapterID" value="{Form/Chapter/ChapterID}" />
        </xsl:if>
        <xsl:if test="normalize-space(Form/Product/ProductID)">
            <input type="hidden" name="ProductID" value="{Form/Product/ProductID}" />
        </xsl:if>
  	    <xsl:if test="Params/show_errors">
  		    <input type="hidden" name="show_errors" value="1" />
  	    </xsl:if>
        <div class="section">
            <xsl:call-template name="bookDetailView">
                <xsl:with-param name="path" select="/Root/Form/Book"></xsl:with-param>
            </xsl:call-template>
            <br />
            <xsl:call-template name="chapterDetailView">
                <xsl:with-param name="path" select="/Root/Form/Chapter"></xsl:with-param>
            </xsl:call-template>
            <br />
            <xsl:call-template name="errorMessageGeneral" />
            <xsl:call-template name="productInfo" />
            <br />
            <br /><br />
        </div>
    </xsl:template>

  <xsl:template name="submitButton">
        <input name="submitButton" type="submit" id="submitButton">
          <xsl:attribute name="value">
            <xsl:if test="normalize-space(Form/Product/ProductID)">Update</xsl:if>
            <xsl:if test="not(normalize-space(Form/Product/ProductID))">Create</xsl:if>
          </xsl:attribute>
        </input>
  </xsl:template>


    <xsl:template name="cancelButton">
        <input type="button" name="Cancel" value="Return to Chapter" onClick="location.href='catalog?ChapterID={Form/Chapter/ChapterID}&amp;c=show_chapter'" />
    </xsl:template>


  <xsl:template name="productInfo">
    <fieldset>
      <legend>Chapter Product</legend>
      <p class="formHeader">Enter product information here.</p>
      <hr />
      <div class="insideFieldset">
        <table>
            <xsl:call-template name="bookFormatRow" />
            <xsl:call-template name="releaseDateRow" />
        </table>
      </div>
    </fieldset>
  </xsl:template>

	<xsl:template name="bookFormatRow">
		<xsl:choose>
			<xsl:when test="Form/BookFormatList/BookFormat">
				<tr>
					<td class="leftCol"><label for="Form_Product_BookFormatID">Format:</label></td>
					<td>
						<xsl:call-template name="inlineError">
							<xsl:with-param name="path">Form/Product/BookFormatID</xsl:with-param>
							<xsl:with-param name="displayName">Format:</xsl:with-param>
						</xsl:call-template>
						<select name="Form_Product_BookFormatID" id="Form_Product_BookFormatID">
							<option value="">Choose...</option>
							<xsl:for-each select="Form/BookFormatList/BookFormat">
								<option value="{BookFormatID}">
									<xsl:if test="BookFormatID = /Root/Form/Product/BookFormatID">
										<xsl:attribute name="selected">selected</xsl:attribute>
									</xsl:if>
									<xsl:value-of select="Description" />
								</option>
							</xsl:for-each>
						</select>
					</td>
				</tr>
			</xsl:when>
			<xsl:otherwise>
				<input type="hidden" name="Form_Product_BookFormatID" value="{Form/Product/BookFormatID}" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="releaseDateRow">
        <tr>
          <td class="leftCol"><label for="Form_Product_ReleaseDate">Release Date:</label></td>
          <td>
            <xsl:call-template name="inlineError">
              <xsl:with-param name="path">Form/Product/ReleaseDate</xsl:with-param>
              <xsl:with-param name="displayName">Release Date</xsl:with-param>
            </xsl:call-template>
            <input type="text" class="dateField" name="Form_Product_ReleaseDate" id="Form_Product_ReleaseDate">
              <xsl:attribute name="value">
                <xsl:choose>
                  <xsl:when test="normalize-space(Form/Product/ReleaseDate)">
                    <xsl:value-of select="Form/Product/ReleaseDate" />
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="Form/TodaysDate" />
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
            </input>
          </td>
        </tr>
	</xsl:template>

</xsl:stylesheet>
