<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:variable name="lockedRecord">
        <xsl:choose>
            <xsl:when test="$openRuns = 1 or /Root/Form/ArtistContract/Status = 2 or /Root/Form/ArtistContract/Status = 3">1</xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:template name="cCompEditLayout">
        <form action="/rps/ccomp" name="cCompEntry" id="cCompEntry" method="post">
            <xsl:call-template name="contractView"/>
            <xsl:call-template name="openRunStatusMessage"/>
            <xsl:call-template name="cCompEdit"/>
            <xsl:call-template name="buttons"/>
        </form>
    </xsl:template>

    <xsl:template name="cCompEdit">
        <fieldset class="Form-fieldset">
            <h3>Controlled Composition Clause</h3>
            <script>
                validationSet = {
                    'Form_ControlledComposition_TrackCap': {
                        regexp: /^.*$/,
                        errorBlank: 'Track Cap cannot be blank.'
                    },
                    'Form_ControlledComposition_RateType': {
                        regexp: /^.*$/,
                        errorBlank: 'Rate Type must be selected.'
                    },
                    Form_ControlledComposition_RatePercentage: {
                        regexp: /^.*$/,
                        errorBlank: 'Rate Percent cannot be blank.'
                    }
                };
            </script>
            <input type="hidden" name="formSubmit" value="1"/>
            <input type="hidden" name="c" value="edit"/>
            <input type="hidden" name="ArtistContractID" value="{Params/ArtistContractID}"/>
            <input type="hidden" name="Form_ControlledComposition_ArtistContractID" value="{Form/ArtistContract/ArtistContractID}"/>
            <xsl:if test="normalize-space(Form/ControlledComposition/ControlledCompositionID)">
                <input type="hidden" name="Form_ControlledComposition_ControlledCompositionID" value="{Form/ControlledComposition/ControlledCompositionID}"/>
                <input type="hidden" name="CCompID" value="{Form/ControlledComposition/ControlledCompositionID}"/>
            </xsl:if>

            <div class="Form-header">
                <div class="Form-header-wrapper Form-header-wrapper-text">
                    <p class="Form-header-text">
                        <xsl:choose>
                            <xsl:when test="Form/ArtistContract/Status = 2">This clause is used in a pending statement and may not be edited at this time.</xsl:when>
                            <xsl:when test="Form/ArtistContract/Status = 3">This clause has been locked and may not be edited.</xsl:when>
                            <xsl:otherwise>Enter controlled composition clause information here.</xsl:otherwise>
                        </xsl:choose>
                    </p>
                </div>
                <div class="Form-header-wrapper Form-header-wrapper-required">
                    <span class="Required-notice" />
                </div>
            </div>

            <xsl:call-template name="errorMessageGeneral"/>
            <xsl:call-template name="column1Edit"/>
        </fieldset>
    </xsl:template>

    <xsl:template name="column1Edit">
        <fieldset class="Form-fieldset">
            <div class="Form-item Form-item-standart Form-item-required">
                <label class="Form-label">
                    <span class="Form-label-caption">Track Cap</span>
                    <div class="Form-input-wrapper">
                        <input type="text" class="Input Form-input" name="Form_ControlledComposition_TrackCap" id="Form_ControlledComposition_TrackCap" value="{Form/ControlledComposition/TrackCap}">
                            <xsl:if test="$lockedRecord = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ControlledComposition/TrackCap</xsl:with-param>
                    <xsl:with-param name="displayName">Track Cap</xsl:with-param>
                </xsl:call-template>
            </div>
            <div class="Form-item Form-item-standart Form-item-required">
                <label class="Form-label">
                    <span class="Form-label-caption">Rate Type</span>
                    <div class="Form-input-wrapper">
                        <xsl:variable name="rateTypeOptions">
                            <map>
                                <mapEntry>
                                    <name>Choose...</name>
                                    <value></value>
                                </mapEntry>
                                <mapEntry>
                                    <name>Stat Rate</name>
                                    <value>1</value>
                                </mapEntry>
                                <mapEntry>
                                    <name>Minimum Stat</name>
                                    <value>2</value>
                                </mapEntry>
                                <mapEntry>
                                    <name>Penny Rate</name>
                                    <value>3</value>
                                </mapEntry>
                            </map>
                        </xsl:variable>
                        <xsl:call-template name="uiDropdown">
                            <xsl:with-param name="items" select="$rateTypeOptions"/>
                            <xsl:with-param name="name" select="'Form_ControlledComposition_RateType'" />
                            <xsl:with-param name="active" select="Form/ControlledComposition/RateType"/>
                            <xsl:with-param name="onChange">
                                ContractPage.checkRateType(this, 'Form_ControlledComposition_');
                            </xsl:with-param>
                            <xsl:with-param name="disabled">
                                <xsl:if test="$lockedRecord = 1">true</xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ControlledComposition/RateType</xsl:with-param>
                    <xsl:with-param name="displayName">Rate Type</xsl:with-param>
                </xsl:call-template>
            </div>
            <div class="Form-item Form-item-standart Form-item-required">
                <label class="Form-label">
                    <span class="Form-label-caption">Rate Percent</span>
                    <div class="Form-input-wrapper Form-input-wrapper-compound">
                        <input type="text" class="Input Form-input" name="Form_ControlledComposition_RatePercentage" id="Form_ControlledComposition_RatePercentage" value="{Form/ControlledComposition/RatePercentage}">
                            <xsl:if test="$lockedRecord = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                        <div class="Form-input-additive">%</div>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ControlledComposition/RatePercentage</xsl:with-param>
                    <xsl:with-param name="displayName">Rate Percent</xsl:with-param>
                </xsl:call-template>
            </div>
            <div class="Form-item Form-item-standart Form-item-required">
                <label class="Form-label">
                    <span class="Form-label-caption">Rate Basis</span>
                    <div class="Form-input-wrapper">
                        <xsl:variable name="rateBasisOptions">
                            <map>
                                <mapEntry>
                                    <name>Choose...</name>
                                    <value></value>
                                </mapEntry>
                                <mapEntry>
                                    <name>Lock Date</name>
                                    <value>2</value>
                                </mapEntry>
                                <mapEntry>
                                    <name>Sales Date</name>
                                    <value>1</value>
                                </mapEntry>
                            </map>
                        </xsl:variable>
                        <xsl:call-template name="uiDropdown">
                            <xsl:with-param name="items" select="$rateBasisOptions"/>
                            <xsl:with-param name="id" select="'Form_ControlledComposition_RateBasis'" />
                            <xsl:with-param name="name" select="'Form_ControlledComposition_RateBasis'" />
                            <xsl:with-param name="active" select="Form/ControlledComposition/RateType"/>
                            <xsl:with-param name="onChange">
                                ContractPage.checkRateBasis(this, 'Form_ControlledComposition_');
                            </xsl:with-param>
                            <xsl:with-param name="disabled">
                                <xsl:if test="$lockedRecord = 1 or Form/ControlledComposition/RateType = '3'">true</xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ControlledComposition/RateBasis</xsl:with-param>
                    <xsl:with-param name="displayName">Rate Basis</xsl:with-param>
                </xsl:call-template>
            </div>
            <div class="Form-item Form-item-standart Form-item-required">
                <label class="Form-label">
                    <span class="Form-label-caption">Penny Rate</span>
                    <div class="Form-input-wrapper">
                        <input type="text" class="Input Form-input" name="Form_ControlledComposition_PennyRate" id="Form_ControlledComposition_PennyRate">
                            <xsl:if test="Form/ControlledComposition/RateType = 3">
                                <xsl:attribute name="value">
                                    <xsl:value-of select="Form/ControlledComposition/PennyRate"/>
                                </xsl:attribute>
                            </xsl:if>
                            <xsl:if test="$lockedRecord = 1 or Form/ControlledComposition/RateType != '3'">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ControlledComposition/PennyRate</xsl:with-param>
                    <xsl:with-param name="displayName">Penny Rate</xsl:with-param>
                </xsl:call-template>
            </div>
            <div class="Form-item Form-item-standart">
                <label class="Form-label">
                    <span class="Form-label-caption">Lock Date</span>
                    <div class="Form-input-wrapper">
                        <xsl:call-template name="uiDatepicker">
                            <xsl:with-param name="id" select="'Form_ControlledComposition_LockDate'" />
                            <xsl:with-param name="name" select="'Form_ControlledComposition_LockDate'" />
                            <xsl:with-param name="value" select="Form/ControlledComposition/LockDate" />
                            <xsl:with-param name="disabled">
                                <xsl:if test="$openRuns = 1">true</xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ControlledComposition/LockDate</xsl:with-param>
                    <xsl:with-param name="displayName">Lock Date</xsl:with-param>
                </xsl:call-template>
            </div>
            <div class="Form-item Form-item-standart">
                <label class="Form-label">
                    <span class="Form-label-caption">Reserve Percent</span>
                    <div class="Form-input-wrapper Form-input-wrapper-compound">
                        <input type="text" class="Input Form-input" name="Form_ControlledComposition_ReservePercentage" id="Form_ControlledComposition_ReservePercentage" value="{Form/ControlledComposition/ReservePercentage}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                        <div class="Form-input-additive">%</div>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ControlledComposition/ReservePercentage</xsl:with-param>
                    <xsl:with-param name="displayName">Reserve Percent</xsl:with-param>
                </xsl:call-template>
            </div>
            <div class="Form-item Form-item-standart">
                <label class="Form-label">
                    <span class="Form-label-caption">Liquidation Schedule</span>
                    <div class="Form-input-wrapper">
                        <xsl:call-template name="liquidationSchedule">
                            <xsl:with-param name="liquidationPrefix">Form_ControlledComposition_ReserveLiquidationList_ReserveLiquidation_</xsl:with-param>
                            <xsl:with-param name="liquidationList" select="Form/ControlledComposition/ReserveLiquidationList/ReserveLiquidation"/>
                            <xsl:with-param name="lockedRecord" select="$lockedRecord"/>
                            <xsl:with-param name="liquidationID" select="Form/ControlledComposition/ControlledCompositionID"/>
                            <xsl:with-param name="liquidationIDName">TrackLicenseID</xsl:with-param>
                        </xsl:call-template>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ControlledComposition/ReserveLiquidationList</xsl:with-param>
                    <xsl:with-param name="displayName">Liquidation Schedule</xsl:with-param>
                </xsl:call-template>
            </div>
        </fieldset>
        <xsl:if test="normalize-space(Form/ControlledComposition/RateType)">
            <script type="text/javascript">
                <xsl:choose>
                    <xsl:when test="Form/ControlledComposition/RateType = 3">
                        requireField('Form_ControlledComposition_PennyRate','Penny Rate must be entered.');
                    </xsl:when>
                    <xsl:otherwise>
                        requireField('Form_ControlledComposition_RateBasis','Rate Basis must be selected.');
                    </xsl:otherwise>
                </xsl:choose>
            </script>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>
