<!--                                                                  -->
<!--  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:variable name="helpLinkOptions" select="'width=800, height=500, scrollbars=yes, resizable=yes'" />

    <!--
        By default, the help link will be created using the current page's area and command.
        You only have to pass those in if you want to do something different.
        The helpType param is used to style it differently depending on where it shows up on the page.
    -->

    <xsl:template name="buttons">
        <fieldset class="Form-fieldset Form-fieldset-buttons">
            <xsl:call-template name="cancelButton" />
            <xsl:call-template name="submitButton" />
        </fieldset>
    </xsl:template>


    <xsl:template name="buttonsWithoutBox">
        <table class="buttons">
            <tr>
                <td><xsl:call-template name="cancelButton" /></td>
                <td class="defaultButton"><xsl:call-template name="submitButton" /></td>
            </tr>
        </table>
    </xsl:template>

    <xsl:variable name="dateFormat" select="translate(/Root/Client/Locale/DateTimeFormat/DateFormat, 'MD', 'md')" />

    <xsl:variable name="calendarDateFormat">%<xsl:value-of select="substring($dateFormat, 1, 2)" />%<xsl:value-of select="substring($dateFormat, 3, 2)" />%<xsl:value-of select="substring($dateFormat, 5, 1)" /></xsl:variable>

	<xsl:template name="calendar">
		<xsl:param name="fieldID" />
		<xsl:param name="buttonID" />
		<script type="text/javascript">
			Calendar.setup({
				inputField     :    "<xsl:value-of select="$fieldID" />",     // id of the input field
				ifFormat       :    "<xsl:value-of select="$calendarDateFormat" />",     // format of the input field (even if hidden, this format will be honored)
				daFormat       :    "<xsl:value-of select="$calendarDateFormat" />",// format of the displayed date
				button         :    "<xsl:value-of select="$buttonID" />",  // trigger button (well, IMG in our case)
				align          :    "Tl",           // alignment (defaults to "Bl")
				singleClick    :    true
			});
		</script>
	</xsl:template>

    <xsl:template name="publishingStatusDisplay">
        <xsl:param name="statusID" />
        <xsl:if test="normalize-space($statusID) and $statusID != '00' and $statusID != '04'">
            <xsl:text> (</xsl:text>
            <xsl:call-template name="onixCodePublishingStatus">
                <xsl:with-param name="statusID" select="$statusID" />
            </xsl:call-template>
            <xsl:text>)</xsl:text>
        </xsl:if>
    </xsl:template>


<!-- Escape URIs -->


<!-- According to the RFC, non-ascii chars will be utf-8 encoded and escaped
     with %s by the xslt-engine when in a 'uri' attribute or by the browser
     if the xlst-engine doesn't. This is ok, but not enough since we still
     won't have working RFC822 (email) Froms! since they need =s.
     However, as there is nothing I can do about this, I will just hope for
     the best if an xslt engine doesn't have uri-escape. -->
<xsl:variable name="ascii-charset"> !&quot;#$%&amp;&apos;()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~&#127;</xsl:variable>
<xsl:variable name="uri-ok">-_.!~*&apos;()0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="hex">0123456789ABCDEFabcdef</xsl:variable>

<xsl:template name="do-escape-uri">
 <xsl:param name="str"/>
 <xsl:param name="allow-utf8"/>

 <xsl:if test="$str">
  <xsl:variable name="first-char" select="substring($str,1,1)"/>
  <xsl:choose>
   <xsl:when test="$first-char = '%' and string-length($str) &gt;= 3 and contains($hex, substring($str,2,1)) and contains($hex, substring($str,3,1))">
    <!-- The percent char is ok IF it followed by a valid hex pair -->
    <xsl:value-of select="$first-char"/>
   </xsl:when>
   <xsl:when test="contains($uri-ok, $first-char)">
    <!-- This char is ok inside urls -->
    <xsl:value-of select="$first-char"/>
   </xsl:when>
   <xsl:when test="not(contains($ascii-charset, $first-char))">
    <!-- Non-ascii output raw based on utf8 allowed or not -->
    <xsl:choose>
     <xsl:when test="$allow-utf8">
      <xsl:value-of select="$first-char"/>
     </xsl:when>
     <xsl:otherwise>
      <xsl:text>%3F</xsl:text>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:when>
   <xsl:otherwise>
    <!-- URL escape this char -->
    <xsl:variable name="ascii-value" select="string-length(substring-before($ascii-charset,$first-char)) + 32"/>
    <xsl:text>%</xsl:text>
    <xsl:value-of select="substring($hex,floor($ascii-value div 16) + 1,1)"/>
    <xsl:value-of select="substring($hex,$ascii-value mod 16 + 1,1)"/>
   </xsl:otherwise>
  </xsl:choose>

  <xsl:call-template name="do-escape-uri">
   <xsl:with-param name="str" select="substring($str,2)"/>
   <xsl:with-param name="allow-utf8" select="$allow-utf8"/>
  </xsl:call-template>
 </xsl:if>
</xsl:template>

<xsl:template name="my-escape-uri">
 <xsl:param name="str"/>
 <xsl:param name="allow-utf8"/>

 <xsl:choose>
  <xsl:when test="0">
   <!--<xsl:value-of select="escape-uri($str, true())"/>-->
  </xsl:when>
  <xsl:otherwise>
   <xsl:call-template name="do-escape-uri">
    <xsl:with-param name="str" select="$str"/>
    <xsl:with-param name="allow-utf8" select="$allow-utf8"/>
   </xsl:call-template>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>




</xsl:stylesheet>
