<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<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/rps/templates/global.xsl" />
    <xsl:include href="../shared_layouts/statements.xsl" />


    <xsl:template name="pickLayout">
        <form action="{$area}" name="createRun" id="createRun" method="post">
            <input type="hidden" name="formSubmit" value="1" />
            <input type="hidden" name="c" value="create" />
            <xsl:call-template name="createRunForm" />
        </form>
        <xsl:call-template name="checkForNewSales" />
    </xsl:template>


    <xsl:template name="createRunForm">
        <div class="MechanicalCreate MainBaseSection">
            <div class="Form-header">
                <p>Use the fields below to create a new royalty run.</p>
                <div class="Required-notice" />
            </div>
            <xsl:choose>
                <xsl:when test="Form/RoyaltyRunStatus/CanEdit = 0">
                    <xsl:call-template name="openRunStatusMessage" />
                </xsl:when>
                <xsl:when test="Form/HasRunError &gt; 0">
                    <xsl:call-template name="errorRunMessage" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:call-template name="errorMessageGeneral" />
                </xsl:otherwise>
            </xsl:choose>

            <fieldset class="Form-fieldset Form-fieldset-standart">

                <div class="Form-item">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item Form-item-required</xsl:text>
                        <xsl:if test="Form/PayorID[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>

                    </xsl:attribute>
                    <label class="Form-label">
                        <span class="Form-label-caption">
                            Payor
                        </span>
                        <div class="Form-input-wrapper">

                            <xsl:variable name="payorIDItems">
                                <map>
                                    <mapEntry><name>Choose...</name><value></value></mapEntry>
                                    <xsl:for-each select="Form/PayorList/Payor">
                                        <mapEntry>
                                            <name><xsl:value-of select="Name" /></name>
                                            <value><xsl:value-of select="PayorID" /></value>
                                        </mapEntry>
                                    </xsl:for-each>
                                </map>
                            </xsl:variable>
                            <xsl:call-template name="uiDropdown">
                                <xsl:with-param name="items" select="$payorIDItems"/>
                                <xsl:with-param name="id" select="'Form_PayorID'"/>
                                <xsl:with-param name="name" select="'Form_PayorID'"/>
                                <xsl:with-param name="active" select="/Root/Form/PayorID"/>
                            </xsl:call-template>
                            <xsl:if test="Form/PayorID/@required = 1">
                                <script type="text/javascript">
                                    requireField('Form_PayorID','Payor must be selected.<br />');
                                </script>
                            </xsl:if>
                        </div>
                    </label>
                    <xsl:call-template name="inlineError">
                        <xsl:with-param name="path">Form/PayorID</xsl:with-param>
                        <xsl:with-param name="displayName">Payor</xsl:with-param>
                    </xsl:call-template>
                </div>

                <div class="Form-item">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item Form-item-required</xsl:text>
                        <xsl:if test="Form/StartDate[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>

                    </xsl:attribute>
                    <label class="Form-label">
                        <span class="Form-label-caption">
                            Start Date
                        </span>
                        <div class="Form-input-wrapper">
                            <xsl:call-template name="uiDatepicker">
                                <xsl:with-param name="id" select="'Form_StartDate'" />
                                <xsl:with-param name="name" select="'Form_StartDate'" />
                                <xsl:with-param name="value" select="Form/StartDate" />
                            </xsl:call-template>

                            <xsl:if test="Form/StartDate/@required = 1">
                                <script type="text/javascript">
                                    requireField('Form_StartDate','Start Date cannot be blank.<br />');
                                </script>
                            </xsl:if>
                        </div>
                    </label>
                    <xsl:call-template name="inlineError">
                        <xsl:with-param name="path">Form/StartDate</xsl:with-param>
                        <xsl:with-param name="displayName">Start Date</xsl:with-param>
                    </xsl:call-template>
                </div>

                <div class="Form-item">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item Form-item-required</xsl:text>
                        <xsl:if test="Form/EndDate[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>

                    </xsl:attribute>
                    <label class="Form-label">
                        <span class="Form-label-caption">
                            End Date
                        </span>
                        <div class="Form-input-wrapper">
                            <xsl:call-template name="uiDatepicker">
                                <xsl:with-param name="id" select="'Form_EndDate'" />
                                <xsl:with-param name="name" select="'Form_EndDate'" />
                                <xsl:with-param name="value" select="Form/EndDate" />
                            </xsl:call-template>

                            <xsl:if test="Form/EndDate/@required = 1">
                                <script type="text/javascript">
                                    requireField('Form_EndDate','End Date cannot be blank.<br />');
                                </script>
                            </xsl:if>
                        </div>
                    </label>
                    <xsl:call-template name="inlineError">
                        <xsl:with-param name="path">Form/EndDate</xsl:with-param>
                        <xsl:with-param name="displayName">End Date</xsl:with-param>
                    </xsl:call-template>
                </div>

                <xsl:call-template name="royaltyRunEndDate" />
                <xsl:call-template name="logLevelRow" />

            </fieldset>

            <xsl:call-template name="buttons" />
        </div>
    </xsl:template>

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

    <xsl:template name="cancelButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Back to Royalty Runs'" />
            <xsl:with-param name="className" select="'Form-button'" />
            <xsl:with-param name="name" select="'Back'" />
            <xsl:with-param name="url" select="$area" />
        </xsl:call-template>
    </xsl:template>

</xsl:stylesheet>
