<!--                                                                  -->
<!--  Copyright (C) 2011 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="reportInput">
        <xsl:param name="type"/>
        <xsl:param name="display"/>
        <xsl:param name="name"/>
        <xsl:param name="value"/>
        <xsl:param name="fieldType"/>

        <xsl:choose>
            <xsl:when test="$type = 'label'">
                <xsl:call-template name="reportInputLabel">
                    <xsl:with-param name="name">
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="value">
                        <xsl:value-of select="$value"/>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$type = 'bool' and not(@group)">
                <xsl:call-template name="reportInputCheckbox">
                    <xsl:with-param name="display">
                        <xsl:value-of select="$display"/>
                    </xsl:with-param>
                    <xsl:with-param name="name">
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="value">
                        <xsl:value-of select="$value"/>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$type = 'bool' and @group">
                <!-- we'll deal with the groups separately -->
            </xsl:when>
            <xsl:when test="$type = 'sclr'">
                <xsl:call-template name="reportInputText">
                    <xsl:with-param name="display">
                        <xsl:value-of select="$display"/>
                    </xsl:with-param>
                    <xsl:with-param name="name">
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="value">
                        <xsl:value-of select="$value"/>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$type = 'date'">
                <xsl:call-template name="reportInputDate">
                    <xsl:with-param name="display">
                        <xsl:value-of select="$display"/>
                    </xsl:with-param>
                    <xsl:with-param name="name">
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="value">
                        <xsl:value-of select="$value"/>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$type = 'rdio'">
                <xsl:call-template name="reportInputRadio">
                    <xsl:with-param name="display">
                        <xsl:value-of select="$display"/>
                    </xsl:with-param>
                    <xsl:with-param name="name">
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="value">
                        <xsl:value-of select="$value"/>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$type = 'menu'">
                <xsl:call-template name="reportInputSelect">
                    <xsl:with-param name="display">
                        <xsl:value-of select="$display"/>
                    </xsl:with-param>
                    <xsl:with-param name="name">
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="value">
                        <xsl:value-of select="$value"/>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="name(../.) = 'Groups'">
                <xsl:call-template name="reportInputCheckboxGroup">
                    <xsl:with-param name="groupName">
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="heading">
                        <xsl:value-of select="Heading"/>
                    </xsl:with-param>
                    <xsl:with-param name="fieldType">
                        <xsl:value-of select="$fieldType"/>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$type = 'cstm'">
            </xsl:when>
            <xsl:otherwise>
                Unknown Input Type:
                <xsl:value-of select="$type"/>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>

    <xsl:template name="reportInputLabel">
        <xsl:param name="value"/>

        <label class="Form-label">
            <span class="Form-label-caption {$name}"><xsl:value-of select="$value"/></span>
        </label>
    </xsl:template>

    <xsl:template name="reportInputText">
        <xsl:param name="display"/>
        <xsl:param name="name"/>
        <xsl:param name="value"/>

        <label class="Form-label {$name}" for="Parameters_{$name}">
            <span class="Form-label-caption">
                <xsl:choose>
                    <xsl:when test="normalize-space($display)">
                        <xsl:if test="$name != PayeeName">
                            <xsl:value-of select="$name"/>
                        </xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$name"/>
                    </xsl:otherwise>
                </xsl:choose>
            </span>
            <div class="Form-input-wrapper {$name}">
                <input type="text" name="Parameters_{$name}" id="Parameters_{$name}" value="{$value}" class="Input Form-input">
                    <xsl:if test="$name = 'PayeeName'">
                        <xsl:attribute name="placeholder">Enter payee here...</xsl:attribute>
                    </xsl:if>
                </input>
            </div>
        </label>

        <xsl:call-template name="inlineError">
            <xsl:with-param name="path">Parameters/<xsl:value-of select="$name"/></xsl:with-param>
            <xsl:with-param name="displayName">
                <xsl:value-of select="$display"/>
            </xsl:with-param>
        </xsl:call-template>

        <xsl:call-template name="includeAutocomplete">
            <xsl:with-param name="name" select="$name" />
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="reportInputCheckbox">
        <xsl:param name="display"/>
        <xsl:param name="name"/>
        <xsl:param name="value"/>

        <label class="Form-label {$name}" for="Parameters_{$name}">
            <div class="Form-input-wrapper {$name}">
                <xsl:call-template name="uiCheckbox">
                    <xsl:with-param name="id">
                        <xsl:text>Parameters_</xsl:text>
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="name">
                        <xsl:text>Parameters_</xsl:text>
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="caption">
                        <xsl:choose>
                            <xsl:when test="normalize-space($display)">
                                <xsl:value-of select="$display"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="$name"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:with-param>
                    <xsl:with-param name="checked">
                        <xsl:if test="normalize-space($value) and $value != 0">
                            <xsl:text>true</xsl:text>
                        </xsl:if>
                    </xsl:with-param>
                </xsl:call-template>
            </div>
        </label>
    </xsl:template>

    <xsl:template name="reportInputCheckboxGroup">
        <xsl:param name="groupName"/>
        <xsl:param name="heading"/>
        <xsl:param name="fieldType"/>

        <xsl:variable name="fieldTypePath">/Root/Form/Parameters/<xsl:value-of select="$fieldType"/>/*</xsl:variable>

        <xsl:if test="dyn:evaluate($fieldTypePath)/@group = $groupName">
            <label class="Form-label {$groupName}">
                <xsl:if test="normalize-space($heading)">
                    <span class="Form-label-caption">
                        <xsl:value-of select="$heading"/>
                    </span>
                </xsl:if>
                <div class="Form-input-wrapper">
                    <xsl:for-each select="dyn:evaluate($fieldTypePath)[@group = $groupName]">
                        <xsl:sort select="@order"/>
                        <xsl:variable name="name" select="name(.)"/>
                        <xsl:variable name="value" select="."/>

                        <xsl:call-template name="uiCheckbox">
                            <xsl:with-param name="id">
                                <xsl:text>Parameters_</xsl:text>
                                <xsl:value-of select="$name"/>
                            </xsl:with-param>
                            <xsl:with-param name="name">
                                <xsl:text>Parameters_</xsl:text>
                                <xsl:value-of select="$name"/>
                            </xsl:with-param>
                            <xsl:with-param name="caption">
                                <xsl:choose>
                                    <xsl:when test="normalize-space($display)">
                                        <xsl:value-of select="$display"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="$name"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:with-param>
                            <xsl:with-param name="checked">
                                <xsl:if test="normalize-space($value) and $value != 0">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:for-each>
                </div>
            </label>
        </xsl:if>

    </xsl:template>

    <xsl:template name="reportInputDate">
        <xsl:param name="display"/>
        <xsl:param name="name"/>
        <xsl:param name="value"/>

        <label class="Form-label {$name}" for="Parameters_{$name}">
            <xsl:if test="normalize-space($display)">
                <span class="Form-label-caption {$name}">
                    <xsl:choose>
                        <xsl:when test="normalize-space($display)">
                            <xsl:value-of select="$display"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="$name"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </span>
            </xsl:if>
            <div class="Form-input-wrapper {$name}">
                <xsl:call-template name="uiDatepicker">
                    <xsl:with-param name="id">
                        <xsl:text>Parameters_</xsl:text>
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="name">
                        <xsl:text>Parameters_</xsl:text>
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="value" select="$value" />

                </xsl:call-template>
            </div>
        </label>
    </xsl:template>

    <xsl:template name="reportInputRadio">
        <xsl:param name="display"/>
        <xsl:param name="name"/>
        <xsl:param name="value"/>

        <label class="Form-label {$name}">
            <xsl:if test="normalize-space($display)">
                <span class="Form-label-caption {$name}">
                    <xsl:value-of select="$display"/>
                </span>
            </xsl:if>
            <div class="Form-input-wrapper {$name}">
                <xsl:for-each select="/Root/Form/Parameters/DisplayOptions/*">
                    <xsl:if test="name(.) = $name">
                        <xsl:for-each select="./Options">
                            <xsl:call-template name="uiRadio">
                                <xsl:with-param name="name">
                                    <xsl:text>Parameters_</xsl:text>
                                    <xsl:value-of select="$name"/>
                                </xsl:with-param>
                                <xsl:with-param name="value" select="Value"/>
                                <xsl:with-param name="caption">
                                    <xsl:choose>
                                        <xsl:when test="normalize-space(Display)">
                                            <xsl:value-of select="Display"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="Value"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:with-param>
                                <xsl:with-param name="checked">
                                    <xsl:if test="Value = $value">
                                        <xsl:text>true</xsl:text>
                                    </xsl:if>
                                </xsl:with-param>
                            </xsl:call-template>
                        </xsl:for-each>
                    </xsl:if>
                </xsl:for-each>
            </div>
        </label>
    </xsl:template>

    <xsl:template name="reportInputSelect">
        <xsl:param name="display"/>
        <xsl:param name="name"/>
        <xsl:param name="value"/>

        <xsl:variable name="options">
            <map>
                <xsl:for-each select="/Root/Form/Parameters/DisplayOptions/*">
                    <xsl:if test="name(.) = $name">
                        <xsl:for-each select="./Options">
                            <mapEntry>
                                <name>
                                    <xsl:choose>
                                        <xsl:when test="normalize-space(Display)">
                                            <xsl:value-of select="Display"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="Value"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </name>
                                <value><xsl:value-of select="Value" /></value>
                            </mapEntry>
                        </xsl:for-each>
                    </xsl:if>
                </xsl:for-each>
            </map>
        </xsl:variable>

        <label class="Form-label" for="Parameters_{$name}">
            <xsl:if test="normalize-space($display)">
                <span class="Form-label-caption {$name}"><xsl:value-of select="$display"/></span>
                <xsl:call-template name="includeHelpIcon">
                    <xsl:with-param name="display" select="$display" />
                </xsl:call-template>
            </xsl:if>

            <div class="Form-input-wrapper {$name}">
                <xsl:call-template name="uiDropdown">
                    <xsl:with-param name="items" select="$options"/>
                    <xsl:with-param name="id">
                        <xsl:text>Parameters_</xsl:text>
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="name">
                        <xsl:text>Parameters_</xsl:text>
                        <xsl:value-of select="$name"/>
                    </xsl:with-param>
                    <xsl:with-param name="active" select="$value"/>
                </xsl:call-template>
            </div>
        </label>
        <xsl:call-template name="inlineError">
            <xsl:with-param name="path">Parameters/<xsl:value-of select="$name"/></xsl:with-param>
            <xsl:with-param name="displayName">
                <xsl:value-of select="$display"/>
            </xsl:with-param>
        </xsl:call-template>

    </xsl:template>

    <xsl:template name="includeHelpIcon">
        <xsl:param name="display" />

        <xsl:if test="$display = 'Payee Detail'">
            <xsl:call-template name="helpIcon">
                <xsl:with-param name="tip">
                    Payee detail is not available for the royalty run selected.
                </xsl:with-param>
                <xsl:with-param name="tip_id">payee_detail_help</xsl:with-param>
                <xsl:with-param name="display">0</xsl:with-param>
            </xsl:call-template>
        </xsl:if>

    </xsl:template>

    <xsl:template name="includeAutocomplete">
        <xsl:param name="name" />

        <xsl:if test="$name = 'PayeeName'">
            <span id="noMatchWarning" class="yui-ac-warning" style="top: 13px;"></span>
            <input type="hidden" name="Parameters_PayeeID" id="Parameters_PayeeID" />
            <div id="myContainer"></div>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>
