<!--                                                                  -->
<!--  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="edit.xsl" />
    <xsl:include href="show.xsl" />

    <xsl:variable name="showAlbumPurchaseOnly">
        <xsl:choose>
            <xsl:when test="/Root/ClientTypes/ClientType[ClientTypeID = 4]/IsClientTypeFlag = 1 and ((normalize-space(/Root/Form/Product/ProductDigital/ProductID) and /Root/Form/Product/ProductDigital/ProductID &gt; 0) or not(/Root/Params/ProductID))">1</xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>


    <xsl:template name="pickLayout">
        <div class="MainBaseSection">
            <xsl:if test="$cmd = 'show'">
                <xsl:call-template name="productShowLayout" />
            </xsl:if>
            <xsl:if test="$cmd = 'edit'">
                <xsl:call-template name="productEditLayout" />
            </xsl:if>
        </div>
    </xsl:template>

    <xsl:template name="submitButton">
        <xsl:choose>
            <xsl:when test="$cmd = 'edit'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'primary'" />
                    <xsl:with-param name="id" select="'submitButton'" />
                    <xsl:with-param name="name" select="'submit'" />
                    <xsl:with-param name="elemType" select="'submit'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="disabled">
                        <xsl:if test="$openRuns = 1">
                            <xsl:text>true</xsl:text>
                        </xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="content">
                        <xsl:if test="normalize-space(Form/Product/ProductID)">Update</xsl:if>
                        <xsl:if test="not(normalize-space(Form/Product/ProductID))">Create</xsl:if>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>

            <xsl:when test="$cmd = 'show'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'primary'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="content" select="'Edit'" />
                    <xsl:with-param name="url">
                        <xsl:text>product?ProductID=</xsl:text>
                        <xsl:value-of select="Form/Product/ProductID" />
                        <xsl:text>&amp;c=edit</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>

            <xsl:otherwise>
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'primary'" />
                    <xsl:with-param name="id" select="'selectMatch'" />
                    <xsl:with-param name="name" select="'selectMatch'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="disabled" select="'true'" />
                    <xsl:with-param name="content">
                        <xsl:text>Use this </xsl:text><xsl:value-of select="$area" />
                    </xsl:with-param>
                    <xsl:with-param name="onClick">
                        <xsl:text>useMatch('</xsl:text>
                        <xsl:value-of select="$area" />
                        <xsl:text>')</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:otherwise>

        </xsl:choose>
    </xsl:template>

    <xsl:template name="deleteButton">
        <xsl:variable name="productCanBeDeleted" select="Form/Product/CanBeDeleted" />
        <xsl:call-template name="uiButton">
            <xsl:with-param name="className" select="'Form-button-left'"/>
            <xsl:with-param name="content" select="'Delete'"/>
            <xsl:with-param name="type" select="'danger'"/>
            <xsl:with-param name="name" select="'deleteButton'"/>
            <xsl:with-param name="disabled">
                <xsl:if test="$productCanBeDeleted != 1 or $openRuns = 1"><xsl:value-of select="'true'" /></xsl:if>
            </xsl:with-param>
            <xsl:with-param name="onClick">confirmDeleteProductConf(<xsl:value-of select="Params/ProductID"/>)</xsl:with-param>
        </xsl:call-template>

        <xsl:if test="$productCanBeDeleted != 1 or $openRuns = 1">
            <div class="HelpText HelpText-bybutton">
                <span >This product configuration cannot be deleted.&#160;</span>
                <span>
                    <xsl:call-template name="helpIcon" style="display: inline-block; float:left">
                        <xsl:with-param name="tip">
                            <![CDATA[
                            This product configuration cannot be deleted due to one or more of the following:<br>
                            &#8226 Sales and/or reserves are attached to the product<br>
                            &#8226 A UK mechanical license has been configured against the product.
                            ]]>
                        </xsl:with-param>
                    </xsl:call-template>
                </span>
            </div>
        </xsl:if>

    </xsl:template>

    <xsl:template name="cancelButton">
        <xsl:choose>
            <xsl:when test="$cmd = 'edit' and normalize-space(Form/Product/ProductID)">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="content" select="'Return to Product'" />
                    <xsl:with-param name="url">
                        <xsl:text>/rps/product?c=show&amp;ProductID=</xsl:text>
                        <xsl:value-of select="Form/Product/ProductID" />
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>

            <xsl:otherwise>
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="content" select="'Return to Album'" />
                    <xsl:with-param name="onClick">
                        <xsl:choose>
                            <xsl:when test="Params/_inline">hideInlinePop()</xsl:when>
                            <xsl:otherwise>location.href='catalog?AlbumID=<xsl:value-of select="Form/Album/AlbumID" />&amp;c=show'</xsl:otherwise>
                        </xsl:choose>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:otherwise>

        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>
