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

    <xsl:include href="/app/tools/rps/templates/global.xsl" />
    <xsl:include href="show.xsl" />
    <xsl:include href="search.xsl" />
    <xsl:include href="edit.xsl" />
    <xsl:include href="list.xsl" />

    <xsl:template name="pickLayout">
        <xsl:choose>
            <xsl:when test="$cmd = 'edit'">
                <xsl:call-template name="regionEditLayout" />
            </xsl:when>
            <xsl:when test="$cmd = 'show'">
                <xsl:call-template name="regionViewLayout" />
            </xsl:when>
            <xsl:when test="$cmd = 'search' or $cmd = 'search_all'">
                <xsl:call-template name="regionSearchLayout" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="regionListLayout" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="submitButton">
        <xsl:choose>
            <xsl:when test="$cmd = 'edit'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="className" select="'Form-button'"/>
                    <xsl:with-param name="content">
                        <xsl:choose>
                            <xsl:when test="normalize-space(Form/Region/RegionID)">Update</xsl:when>
                            <xsl:otherwise>Create</xsl:otherwise>
                        </xsl:choose>
                    </xsl:with-param>
                    <xsl:with-param name="type" select="'primary'"/>
                    <xsl:with-param name="elemType" select="'submit'"/>
                    <xsl:with-param name="name" select="'submit'"/>
                    <xsl:with-param name="id" select="'submitButton'"/>
                    <xsl:with-param name="disabled">
                        <xsl:if test="$openRuns = 1">true</xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="onClick">selectAllMulti('Form_Region_CountryList_CountryCodes');</xsl:with-param>
                </xsl:call-template>
                <xsl:choose>
                    <xsl:when test="not(normalize-space(Form/Region/RegionID))">
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="className" select="'Form-button'"/>
                            <xsl:with-param name="content" select="'Create and Add Another'"/>
                            <xsl:with-param name="type" select="'primary'"/>
                            <xsl:with-param name="onClick">modifyFieldValue('ReturnTo','/rps/region?c=edit&amp;msg=success|form_submit_success'); selectAllMulti('Form_Region_CountryList_CountryCodes');</xsl:with-param>
                            <xsl:with-param name="name" select="'submitButton'"/>
                            <xsl:with-param name="id" select="'addAnotherButton'"/>
                            <xsl:with-param name="elemType" select="'submit'"/>
                            <xsl:with-param name="disabled">
                                <xsl:if test="$openRuns = 1">true</xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:when>
                </xsl:choose>
            </xsl:when>
            <xsl:when test="$cmd = 'show'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="className" select="'Form-button'"/>
                    <xsl:with-param name="content" select="'Edit'"/>
                    <xsl:with-param name="type" select="'primary'"/>
                    <xsl:with-param name="onClick">javascript:location.href='region?RegionID=<xsl:value-of select="Form/Region/RegionID" />&amp;c=edit'</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$cmd = 'search' or $cmd = 'search_all'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="className" select="'Form-button'"/>
                    <xsl:with-param name="name" select="'selectMatch'"/>
                    <xsl:with-param name="id" select="'selectMatch'"/>
                    <xsl:with-param name="content">Use this <xsl:value-of select="$area"/></xsl:with-param>
                    <xsl:with-param name="disabled" select="'true'"/>
                    <xsl:with-param name="type" select="'primary'"/>
                    <xsl:with-param name="onClick">useMatch('<xsl:value-of select="$area"/>','<xsl:value-of select="Params/prefix"/>')</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="'Add New Region'"/>
                    <xsl:with-param name="type" select="'primary'"/>
                    <xsl:with-param name="onClick">javascript:location.href='region?c=edit'</xsl:with-param>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="cancelButton">
        <xsl:choose>
            <xsl:when test="$cmd = 'edit'">
                <xsl:choose>
                    <xsl:when test="normalize-space(Form/Region/RegionID)">
                        <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="($openRuns = 1) or (Form/Region/LinkedContracts &gt; 0)">true</xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="onClick">confirmDeleteRegion(<xsl:value-of select="Form/Region/RegionID"/>)</xsl:with-param>
                        </xsl:call-template>
                        <xsl:if test="Form/Region/LinkedContracts &gt; 0">
                            <div class="HelpText HelpText-bybutton">This region has been associated with a contract and cannot be deleted.</div>
                        </xsl:if>
                    </xsl:when>
                </xsl:choose>
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="name" select="'Back'"/>
                    <xsl:with-param name="className" select="'Form-button'"/>
                    <xsl:with-param name="content" select="'Back to Regions'"/>
                    <xsl:with-param name="onClick">location.href='region'</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$cmd = 'show'">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="name" select="'Back'"/>
                    <xsl:with-param name="className" select="'Form-button'"/>
                    <xsl:with-param name="content" select="'Back to Regions'"/>
                    <xsl:with-param name="onClick">location.href='region'</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="($cmd = 'search' or $cmd = 'search_all') and Params/_inline">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="name" select="'Cancel'"/>
                    <xsl:with-param name="className" select="'Form-button'"/>
                    <xsl:with-param name="content" select="'Cancel'"/>
                    <xsl:with-param name="onClick">hideInlinePop()</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="name" select="'Back'"/>
                    <xsl:with-param name="className" select="'Form-button'"/>
                    <xsl:with-param name="content" select="'Back to Admin'"/>
                    <xsl:with-param name="onClick">location.href='/rps/display?d=config'</xsl:with-param>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>
