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

    <xsl:template name="productDigitalServiceList">
        <xsl:for-each select="Form/ProductDigital/DistributionServices/DistributionService[(Status = 'active' or (Status = 'depricated' and Staged) or Status = 'maintenance') and ClientAllowed &gt; 0]">
            <xsl:call-template name="productDigitalService" />
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="productDigitalService">
        <tr class="row{position() mod 2}">
            <td class="icon">
                <xsl:choose>
                    <xsl:when test="$cmd = 'edit_service'">
                        <input type="checkbox" name="ServiceToggle_{ServiceID}" onChange="toggleField('productEdit', 'ServicePricingTierID_{ServiceID}');" >
                            <xsl:if test="Queued &gt; 0">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                            <xsl:if test="not(Configured &gt; 0)">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                            <xsl:if test="Denied = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                            <xsl:if test="DeliveryDate != ''">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                            <xsl:if test="Staged">
                                <xsl:attribute name="checked">checked</xsl:attribute>
                            </xsl:if>
                        </input>
                        <xsl:if test="Queued &gt; 0 or not(Configured &gt; 0) or DeliveryDate != ''" >
                            <input type="hidden" name="ServiceToggle_{ServiceID}" >
                                <xsl:choose>
                                    <xsl:when test="Staged">
                                        <xsl:attribute name="value">1</xsl:attribute>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:attribute name="value">0</xsl:attribute>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </input>
                        </xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:if test="Staged and (Configured = 1 or (Configured != 1 and DeliveryDate != ''))">
                            Yes
                        </xsl:if>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
            <td><xsl:value-of select="ServiceName" /></td>
            <td>
                <xsl:choose>
                    <xsl:when test="normalize-space(Denied)"><xsl:value-of select="DeniedDate" /></xsl:when>
                    <xsl:when test="not(Queued)"></xsl:when>
                    <xsl:when test="DeliveryDate = '2008-05-07 15:00:00'">Prior to 2008-05-07</xsl:when>
                    <xsl:otherwise><xsl:value-of select="DeliveryDate" /></xsl:otherwise>
                </xsl:choose>
            </td>
            <td>
                <xsl:if test="Configured = 1 or DeliveryDate != ''">

                    <xsl:choose>
                        <xsl:when test="not(Staged)"></xsl:when>
                        <xsl:when test="ThirdParty = 1">Third Party</xsl:when>
                        <xsl:when test="Source = 'direct'">RS via Direct Account</xsl:when>
                        <xsl:otherwise>RoyaltyShare</xsl:otherwise>
                    </xsl:choose>

                </xsl:if>
            </td>
            <td>
                <xsl:choose>
                    <xsl:when test="normalize-space(Denied)"><xsl:value-of select="Denied" /></xsl:when>
                    <xsl:when test="DeliveryDate != ''">Delivered*</xsl:when>
                    <xsl:when test="not(Configured &gt; 0)">Not Set Up <a href="mailto:cms@royaltyshare.com?subject=Service Inquiry: {ServiceName} [{/Root/User/ClientID}]">(Contact Client Services)</a></xsl:when>
                    <xsl:when test="Queued &gt; 0">In Queue</xsl:when>
                    <xsl:when test="Staged">Ready To Deliver</xsl:when>
                </xsl:choose>
            </td>

            <td>
                <xsl:call-template name="displayPricingTier" >
                    <xsl:with-param name="staged" select="Staged" />
                </xsl:call-template>
            </td>

        </tr>
    </xsl:template>

    <xsl:template name="displayPricingTier">
        <xsl:param name="staged" />
        <xsl:choose>
            <xsl:when test="$cmd = 'edit_service'"><xsl:call-template name="pricingTierSelect" /></xsl:when>
            <xsl:otherwise>
                <xsl:if test="$staged &gt; 0" >
                    <xsl:call-template name="pricingTierText" />
                </xsl:if>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="pricingTierText">
        <xsl:for-each select="PricingTiers/PricingTier">
            <xsl:if test="Current &gt; 0">
                <xsl:value-of select="TierName" />
            </xsl:if>
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="pricingTierSelect">
        <xsl:if test="PricingTiers/PricingTier">
            <select id="ServicePricingTierID" name="ServicePricingTierID_{ServiceID}">
                <xsl:if test="not(Staged &gt; 0)">
                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                </xsl:if>
                <xsl:for-each select="PricingTiers/PricingTier">
                    <option value="{ServicePriceTierID}">
                        <xsl:if test="Current &gt; 0 or ( not (CurrentPrice &gt; 0) and DefaultTier &gt; 0 )">
                            <xsl:attribute name="selected">selected</xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="TierName" />
                    </option>
                </xsl:for-each>
            </select>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>
