<!--                                                                  -->
<!--  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="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" 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'">
                <input name="submit" type="submit" id="submitButton" onClick="selectAllMulti('Form_Region_CountryList_CountryCodes');">
                    <xsl:if test="$openRuns = 1">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>            
                    <xsl:attribute name="value">
                        <xsl:if test="normalize-space(Form/Region/RegionID)">Update</xsl:if>
                        <xsl:if test="not(normalize-space(Form/Region/RegionID))">Create</xsl:if>
                    </xsl:attribute>
                </input>
            </xsl:when>
            <xsl:when test="$cmd = 'show'">
                <input type="button" value="Edit" onClick="javascript:location.href='region?RegionID={Form/Region/RegionID}&amp;c=edit'" />
            </xsl:when>
            <xsl:when test="$cmd = 'search' or $cmd = 'search_all'">
                <input type="button" name="selectMatch" id="selectMatch" value="Use this {$area}" disabled="true" onClick="useMatch('{$area}','{Params/prefix}')" />
            </xsl:when>
            <xsl:otherwise>
				<input type="button" value="Add New Region" onClick="javascript:location.href='region?c=edit'" />
            </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)">
                        <input name="deleteButton" type="button" value="Delete" onClick="confirmDeleteRegion({Form/Region/RegionID})">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>                
                            <xsl:if test="Form/Region/LinkedContracts &gt; 0">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                        <xsl:if test="Form/Region/LinkedContracts &gt; 0">
                            <xsl:call-template name="helpIcon">
                                <xsl:with-param name="tip">This region has been associated with a contract and cannot be deleted.</xsl:with-param>
                            </xsl:call-template>
                        </xsl:if>
                    </xsl:when> 
                    <xsl:otherwise>
                        <input type="submit" id="addAnotherButton" value="Create and Add Another" onClick="modifyFieldValue('ReturnTo','/rps/region?c=edit&amp;msg=success|form_submit_success'); selectAllMulti('Form_Region_CountryList_CountryCodes');" />
                    </xsl:otherwise>
                </xsl:choose>
                <input type="button" value="Back to Regions" onClick="location.href='region'" />
            </xsl:when>
            <xsl:when test="$cmd = 'show'">
                <input type="button" name="Back to Regions" value="Back to Regions" onClick="location.href='region'" />
            </xsl:when>
            <xsl:when test="($cmd = 'search' or $cmd = 'search_all') and Params/_inline">
                <input type="button" name="Cancel" value="Cancel" onClick="hideInlinePop()" />
            </xsl:when>
            <xsl:otherwise>
                <input type="button" name="Back" value="Back to Admin" onClick="location.href='/rps/display?d=config'" />
            </xsl:otherwise>      
        </xsl:choose>
    </xsl:template>


</xsl:stylesheet>
