<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="" encoding="utf-8" />

    <xsl:include href="/app/tools/bookpub/templates/global.xsl" /> 

    <xsl:template name="pickLayout">
        <xsl:call-template name="varianceLayout" />
    </xsl:template>

    <xsl:template name="varianceLayout">
        <link href="/production/css/bookpub/admin.css?v=1" rel="stylesheet" type="text/css" />
        <xsl:choose>
            <xsl:when test="Form/PriceTypeVarianceList/PriceType">
                <xsl:call-template name="varianceForm" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="helpLink" />
                <p>Price types have not been set up yet.</p>
                <xsl:call-template name="cancelButton" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="varianceForm">
        <form action="/bookpub/admin" method="post" id="priceVariance">
            <input type="hidden" name="c" value="price_variance" />
            <input type="hidden" name="formSubmit" value="1" />
            <xsl:call-template name="helpLink" />
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Price validation thresholds updated!</xsl:with-param>
            </xsl:call-template>
            <table>
                <tr>
                    <th>
                        <h3>Type</h3>
                    </th>
                    <th>
                        <h3>Price Validation Threshold</h3>
                    </th>
                </tr>         
                <xsl:for-each select="Form/PriceTypeVarianceList/PriceType"> 
                    <xsl:sort select="Display" />
                    <xsl:call-template name="varianceRow" />
                </xsl:for-each>
            </table>
            <xsl:call-template name="buttons" />
		</form>
    </xsl:template>

    <xsl:template name="varianceRow">
        <tr>
            <td class="View-label">
                <xsl:value-of select="Display" />
                <input type="hidden" name="Form_PriceTypeVarianceList_PriceType_{@i}_PriceTypeID" value="{PriceTypeID}" />
            </td>
            <td class="View-value Input-variance-wrapper">
                +/- <input class="Input Input-variance" type="text" name="Form_PriceTypeVarianceList_PriceType_{@i}_AllowedVariance" value="{AllowedVariance}" /> %
            </td>
        </tr>
    </xsl:template>

	<xsl:template name="submitButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Update'"/>
            <xsl:with-param name="type" select="'primary'"/>
            <xsl:with-param name="className" select="'Form-button'"/>
            <xsl:with-param name="elemType" select="'submit'"/>
        </xsl:call-template>
	</xsl:template>

    <xsl:template name="cancelButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Cancel'" />
            <xsl:with-param name="type" select="'default'"/>
            <xsl:with-param name="className" select="'Form-button'"/>
            <xsl:with-param name="onClick">location.href='/bookpub/admin'</xsl:with-param>
        </xsl:call-template>
    </xsl:template>

</xsl:stylesheet>
