﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="section.xsl"/>
    <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="ShowPage" mode="Untergeordnet">
        <!-- Filter -->
        <xsl:for-each select="$Form/Filter">
            <form id="f8" action="{$Root/Script}">
                <input type="hidden" name="f" value="{$Root/@id}" id="in9"/>
                <xsl:choose>
                    <xsl:when test="@type='select'">
                        <select name="sFilter" class="under2">
                            <xsl:apply-templates select="@*" mode="copy"/>
                            <xsl:for-each select="option">
                                <xsl:choose>
                                    <xsl:when test="count(@value)">
                                        <option value="{@value}">
                                            <xsl:if test="$Root/sFilter= @value">
                                                <xsl:attribute name="selected"/>
                                            </xsl:if>
                                            <xsl:value-of select="."/>
                                        </option>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <option>
                                            <xsl:if test="$Form/sFilter= .">
                                                <xsl:attribute name="selected"/>
                                            </xsl:if>
                                            <xsl:value-of select="."/>
                                        </option>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:for-each>
                        </select>
                    </xsl:when>
                    <xsl:otherwise>
                        <input type="text" name="sFilter" value="{$Root/sFilter}" id="in37"/>
                    </xsl:otherwise>
                </xsl:choose>
                <input type="submit" class="under2" id="in40">
                    <xsl:attribute name="value">
                        <xsl:choose>
                            <xsl:when test="@title">
                                <xsl:value-of select="@title"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="$lsSubmit"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>

                </input>
                <xsl:if test="ex = Subobj/@id">
                    <iframe frameborder="0" width="5" height="5" src="{$Root/Script}?f={ex}&amp;m=lock">
                        &#x20;
                    </iframe>
                </xsl:if>
            </form>
        </xsl:for-each>
        <!-- table -->
        <xsl:for-each select="$Form/Fields">
            <xsl:if test="count(@access)=0 or contains($Root/Edit/@link,'m=edit') ">
                <xsl:choose>
                    <xsl:when test="@object!=''">
                        <xsl:apply-templates select="." mode="object"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:apply-templates select="."/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
        </xsl:for-each>

    </xsl:template>
    <xsl:template match="node()" mode="oneline">
        <xsl:param name="option"/>
        <xsl:param name="name"/>
        <tr id="tr{@id}">
            <xsl:if test="$option != ''">
                <td style="{$line}">
                    <input type="checkbox" name="{$option}" value="{@id}" style="height: 14px;"/>
                </td>
            </xsl:if>
            <xsl:apply-templates select="." mode="line">
                <xsl:with-param name="name" select="$name"/>
                <xsl:with-param name="prefix" select="'@'"/>
            </xsl:apply-templates>
            <td style="{$line}">
                <a href="{$Root/Script}?f={$Root/@id}&amp;m=remove&amp;ex={@id}">
                    <img border="0" alt="{$lsDeletePage}" src="{$Root/ImgDir}delete_s.gif"/>
                </a>
            </td>
        </tr>

    </xsl:template>
    <xsl:template match="Fields" mode="object">
        <xsl:variable name="name" select="@object"/>
        <xsl:variable name="option" select="@option"/>
        <form id="f99" action="{$Root/Script}?f={$Root/@id}&amp;m=add" method="post">
            <input type="hidden" name="{@object}" value="-"/>
            <table cellspacing="0" id="data101">
                <tr  style="{$line}">
                    <xsl:if test="count(@option)">
                        <td/>
                    </xsl:if>
                    <xsl:for-each select="Field">
                        <xsl:choose>
                            <xsl:when test="@type='hidden'"></xsl:when>
                            <xsl:otherwise>
                                <td class="under2f"  style="{$line}">
                                    <xsl:choose>
                                        <xsl:when test="/ShowPage/param=@name">
                                            <xsl:value-of select="@title"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <a href="?f={/ShowPage/@id}&amp;param={@name}" style="text-decoration: none;">
                                                <xsl:value-of select="@title"/>
                                            </a>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </td>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:for-each>
                </tr>
                <xsl:choose>
                    <xsl:when test="/ShowPage/param='m'">
                        <xsl:apply-templates select="$Root/node()[name(.)=$name]" mode="oneline">
                            <xsl:sort select="."/>
                            <xsl:with-param name="option" select="$option"/>
                            <xsl:with-param name="name" select="$name"/>
                        </xsl:apply-templates>
                    </xsl:when>
                    <xsl:when test="/ShowPage/param='t'">
                        <xsl:apply-templates select="$Root/node()[name(.)=$name]" mode="oneline">
                            <xsl:sort select="concat(concat(substring(@t,7,4),substring(@t,4,2)),concat(substring(@t,1,2),substring(@t,12)))" order="descending"/>
                            <xsl:with-param name="option" select="$option"/>
                            <xsl:with-param name="name" select="$name"/>
                        </xsl:apply-templates>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:apply-templates select="$Root/node()[name(.)=$name]" mode="oneline">
                            <xsl:sort select="@s"/>
                            <xsl:with-param name="option" select="$option"/>
                            <xsl:with-param name="name" select="$name"/>
                        </xsl:apply-templates>
                    </xsl:otherwise>
                </xsl:choose>
                <tr id="tr149">
                    <xsl:if test="count(@option)">
                        <td style="{$line}"/>
                    </xsl:if>
                    <xsl:apply-templates select="Field" mode="input">
                        <xsl:with-param name="prefix" select="concat(@object,'_')"/>
                    </xsl:apply-templates>
                    <td>
                        <input type="image" alt="{$lsAdd}" title="{$lsAdd}" id="submit157">
                            <xsl:attribute name="src">
                                <xsl:value-of select="$Root/ImgDir"/>
                                <xsl:text>save.gif</xsl:text>
                            </xsl:attribute>
                        </input>
                    </td>
                </tr>

            </table>
        </form>
    </xsl:template>
    <xsl:template match="Fields">
        <xsl:param name="name" select="@name"/>
        <!-- This template will be used by the standard template (match="ShowPage mode="block") in common.xsl -->
        <!-- Edit form -->
        <form id="f173" method="post" name="{@name}" action="{$Root/Script}" >
            <!-- necessary fields  -->
            <input type="hidden" name="f">
                <xsl:attribute name="value">
                    <xsl:choose>
                        <xsl:when test="$Root/ex = $Root/Subobj/@id">
                            <xsl:value-of select="$Root/ex"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="$Root/@id"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
            </input>
            <input type="hidden" name="m">
                <xsl:attribute name="value">
                    <xsl:choose>
                        <xsl:when test="$Root/ex = $Root/Subobj/@id">update</xsl:when>
                        <xsl:otherwise>create</xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
            </input>
            <input type="hidden" name="next" value="Super"/>
            <input type="hidden" name="ex" value="{$Root/@id}"/>
            <xsl:if test="$Root/ex = $Root/Subobj/@id">
                <input type="hidden" name="bSave" value="bSave"/>
                <xsl:variable name="ex" select="$Root/ex"/>
                <input type="hidden" name="sName" value="{$Root/Subobj[@id=$ex]/@name}"/>
            </xsl:if>
            <input type="hidden" name="sTemplate">
                <xsl:attribute name="value">
                    <xsl:choose>
                        <xsl:when test="count(@template)">
                            <xsl:value-of select="@template"/>
                        </xsl:when>
                        <xsl:otherwise>Empty</xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
            </input>
            <!-- xBodyFields: -->
            <xsl:apply-templates select="Field" mode="xBodyFields"/>
            <xsl:if test="contains(@owner,'set')">
                <input type="hidden" name="xBodyFieldsSetowner" value="xUser"/>
            </xsl:if>
            <!-- additional fields -->
            <input type="hidden" name="xBodyFields" value="xUser"/>
            <input type="hidden" name="xClass" value="{@name}"/>
            <input type="hidden" name="xBodyFields" value="xClass"/>
            <table cellspacing="0" id="editable">
                <!-- title -->
                <tr>
                    <xsl:if test="count(@checkbox)">
                        <td  style="{$line}">
                            <img src="{$Root/ImgDir}move.gif" title="{$lsMove}" onclick="document.{@name}.f.value='move';document.{@name}.m.value='';document.{@name}.next.value='';document.{@name}.submit();"/>
                        </td>
                    </xsl:if>
                    <xsl:apply-templates select="Field" mode="td"/>
                    <xsl:if test="(contains(@owner,'read') and contains($Root/Edit/@link,'m=edit')) or contains(@owner,'show')">
                        <td style="font-weight: bold;{$line}">
                            <xsl:choose>
                                <xsl:when test="count(@ownertitle)">
                                    <xsl:value-of select="@ownertitle"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="$lsOwner"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </td>
                    </xsl:if>
                    <xsl:choose>
                        <xsl:when test="$Root/ex=$Root/Subobj/@id">
                            <td class="under2"   style="{$line}">
                                <a href="?f={$Root/@id}" title="{$lsReset}">
                                    <img border="0" src="{/ShowPage/ImgDir}icon_reset.gif" title="{$lsReset}" alt="{$lsReset}"/>
                                </a>
                            </td>
                        </xsl:when>
                        <xsl:when  test="count(@sort)=0">
                            <td  style="{$line}">
                                <a title="{$lsMove}" alt="{$lsMove}">
                                    <xsl:attribute name="href">
                                        <xsl:value-of select="/ShowPage/Script"/>
                                        <xsl:text>?f=move&amp;ex=</xsl:text>
                                        <xsl:value-of select="/ShowPage/@id"/>
                                        <xsl:text>&amp;para=</xsl:text>
                                        <xsl:for-each select="$Root/Subobj[xClass=$name or count(xClass)=0]">
                                            <xsl:value-of select="@id"/>
                                            <xsl:text>,</xsl:text>
                                        </xsl:for-each>
                                        <xsl:text>#focus</xsl:text>
                                    </xsl:attribute>
                                    <img  border="0" src="{/ShowPage/ImgDir}move.gif" title="{$lsMove}" alt="{$lsMove}"/>
                                </a>
                            </td>
                        </xsl:when>
                    </xsl:choose>
                </tr>
                <script>
                    function removeTr(trid){
                    var tr = document.getElementById(trid);
                    var tbody = tr.parentNode;
                    tbody.removeChild(tr);
                    return(0);
                    }
                    function setNow(c){
                    var t = (new Date()).toLocaleString().replace(",","");
                    var a=t.split('.');
                    if(a[0].length==1)a[0]='0'+a[0];
                    if(a[1].length==1)a[1]='0'+a[1];
                    t = a[0]+'.'+a[1]+'.'+a[2];
                    if(c.options != null)
                    c.options[c.selectedIndex].text= t;
                    else
                    c.value = t;
                    }
                </script>
                <!-- content -->
                <xsl:variable name="sep" select="@separator" />
                <xsl:choose>
                    <xsl:when test="count(@sort)=0">
                        <xsl:for-each select="$Root/Subobj[xClass=$name or count(xClass)=0]">
                            <xsl:sort select="@sort" data-type="number"/>
                            <xsl:apply-templates select="." mode="EditList">
                                <xsl:with-param name="name" select="$name"/>
                                <xsl:with-param name="sep" select="$sep"/>
                                <xsl:with-param name="pos" select="position()"/>                            
                            </xsl:apply-templates>
                        </xsl:for-each>
                        <xsl:apply-templates select="." mode="inputs">
                            <xsl:with-param name="name" select="$name"/>
                        </xsl:apply-templates>
                    </xsl:when>
                    <xsl:when test="@sort='reverse'">
                        <xsl:apply-templates select="." mode="inputs">
                            <xsl:with-param name="name" select="$name"/>
                        </xsl:apply-templates>
                        <xsl:for-each select="$Root/Subobj[xClass=$name or count(xClass)=0]">
                            <xsl:sort select="@sort" data-type="number" order="descending"/>
                            <xsl:variable name="pos" select="position()"/>
                            <xsl:variable name="last" select="last()"/>
                            <xsl:apply-templates select="." mode="EditList">
                                <xsl:with-param name="name" select="$name"/>
                                <xsl:with-param name="prev">
                                    <xsl:if test="position()>1">
                                        <xsl:value-of select="../Subobj[position() = $last - $pos + 2]/@id"/>
                                    </xsl:if>
                               </xsl:with-param>
                                 <xsl:with-param name="sep" select="$sep"/>
                                <xsl:with-param name="pos" select="position()"/>                            
                            </xsl:apply-templates>
                        </xsl:for-each>
                    </xsl:when>
                    <xsl:when test="@sort='@id'">
                        <xsl:for-each select="$Root/Subobj[xClass=$name or count(xClass)=0]">
                            <xsl:sort select="@id" data-type="number"/>
                            <xsl:apply-templates select="." mode="EditList">
                                <xsl:with-param name="name" select="$name"/>
                                <xsl:with-param name="sep" select="$sep"/>
                                <xsl:with-param name="pos" select="position()"/>
                            </xsl:apply-templates>
                        </xsl:for-each>
                        <xsl:apply-templates select="." mode="inputs">
                            <xsl:with-param name="name" select="$name"/>
                        </xsl:apply-templates>
                    </xsl:when>
                    <xsl:when test="@sort='time'">
                        <xsl:for-each select="$Root/Subobj[xClass=$name or count(xClass)=0]">
                            <xsl:sort select="substring(Status/@time,7,2)" data-type="number"/>
                            <xsl:sort select="substring(Status/@time,4,2)" data-type="number"/>
                            <xsl:sort select="substring(Status/@time,1,2)" data-type="number"/>
                            <xsl:sort select="substring(Status/@time,10,2)" data-type="number"/>
                            <xsl:sort select="substring(Status/@time,13,2)" data-type="number"/>

                            <xsl:apply-templates select="." mode="EditList">
                                <xsl:with-param name="name" select="$name"/>
                                <xsl:with-param name="sep" select="$sep"/>
                                <xsl:with-param name="pos" select="position()"/>                            
                            </xsl:apply-templates>
                        </xsl:for-each>
                        <xsl:apply-templates select="." mode="inputs">
                            <xsl:with-param name="name" select="$name"/>
                        </xsl:apply-templates>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:for-each select="$Root/Subobj[xClass=$name or count(xClass)=0]">
                            <xsl:sort select="sTitle"/>
                            <xsl:apply-templates select="." mode="EditList">
                                <xsl:with-param name="name" select="$name"/>
                                <xsl:with-param name="sep" select="$sep"/>
                                <xsl:with-param name="pos" select="position()"/>
                            </xsl:apply-templates>
                        </xsl:for-each>
                        <xsl:apply-templates select="." mode="inputs">
                            <xsl:with-param name="name" select="$name"/>
                        </xsl:apply-templates>
                    </xsl:otherwise>
                </xsl:choose>
                <!-- graph -->
                <xsl:choose>
                    <xsl:when test="count(@graph)">
                        <tr>
                            <td height="10"></td>
                        </tr>
                        <xsl:apply-templates select="$Root/Subobj" mode="graph">
                            <xsl:with-param name="Fields" select="."/>
                        </xsl:apply-templates>
                    </xsl:when>
                </xsl:choose>
            </table>
            <iframe name="_lock" width="2" height="2"></iframe>
        </form>
    </xsl:template>
    <xsl:template match="Fields" mode="inputs">
        <!-- inputs -->
        <xsl:param name="name"/>
        <xsl:choose>
            <!-- Darf der Benutzer einen Eintrag machen? -->
            <xsl:when test="count($Root/Edit)=0" />
            <!-- Es wird gerade eine Zeile bearbeitet -->
            <xsl:when test="$Root/ex=$Root/Subobj/@id" />
            <!-- Darf der User noch einen Eintrag machen? -->
            <xsl:when test="count(@limit)=1 and count($Root/Subobj[xUser=$Root/LogonUser]) > @limit - 1 and not(contains($Root/Edit/@link,'m=edit'))"/>
            <xsl:otherwise>
                <tr  id="tr396">
                    <xsl:if test="count(@checkbox)">
                        <td style="{$line}"/>
                    </xsl:if>
                    <xsl:apply-templates select="Field" mode="input"/>
                    <xsl:call-template name="xUser">
                        <xsl:with-param name="name" select="$name"/>
                    </xsl:call-template>
                    <td>
                        <input type="image" alt="{$lsAdd}" title="{$lsAdd}" id="submit397">
                            <xsl:attribute name="src">
                                <xsl:value-of select="$Root/ImgDir"/>
                                <xsl:text>save.gif</xsl:text>
                            </xsl:attribute>
                        </input>
                    </td>
                </tr>
            </xsl:otherwise>
        </xsl:choose>


    </xsl:template>
    <xsl:template match="Subobj" mode="graph">
        <xsl:param name="Fields"/>
        <xsl:variable name="Subobj" select="."/>
        <tr >
            <xsl:for-each select="$Fields/Field">
                <xsl:variable name="name" select="@name"/>
                <xsl:if test="substring($name,1,1)!='f' and substring($name,1,1)!='i'">
                    <td nowrap="nowrap"   style="border-bottom: 1px solid black;">
                        <xsl:value-of select="$Subobj/node()[name() = $name]"/>
                    </td>
                </xsl:if>
            </xsl:for-each>
            <td colspan="{count($Fields/Field[substring(@name,1,1)='f' or substring(@name,1,1)='i'])}" bgcolor="white">
                <xsl:choose>
                    <xsl:when test="$Fields/@graph='bar100'">
                        <table cellpadding="0" cellspacing="0" height="{$Fields/@height}">
                            <tr height="100%">
                                <xsl:for-each select="$Fields/Field">
                                    <xsl:variable name="name" select="@name"/>
                                    <xsl:if test="substring($name,1,1)='f' or substring($name,1,1)='i'">
                                        <td bgcolor="{@barcolor}" width="{translate($Subobj/node()[name()=$name],',','.') * $Fields/@scale}" title="{@title}: {$Subobj/node()[name()=$name]}"/>
                                    </xsl:if>
                                </xsl:for-each>
                            </tr>
                        </table>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:for-each select="$Fields/Field">
                            <table cellpadding="0" cellspacing="0" height="{$Fields/@height}">
                                <tr height="100%">
                                    <xsl:variable name="name" select="@name"/>
                                    <xsl:if test="substring($name,1,1)='f' or substring($name,1,1)='i'">
                                        <td bgcolor="{@barcolor}" width="{translate($Subobj/node()[name()=$name],',','.') * $Fields/@scale}" title="{@title}: {$Subobj/node()[name()=$name]}"/>
                                    </xsl:if>
                                </tr>
                            </table>
                        </xsl:for-each>

                    </xsl:otherwise>
                </xsl:choose>
            </td>
        </tr>
    </xsl:template>
    <xsl:template match="Subobj" mode="EditList">
        <!-- Show a sub-object -->
        <xsl:param name="name" select="''"/>
        <xsl:param name="sep"/>
        <xsl:param name="pos"/>
        <xsl:choose>
            <xsl:when test="@id = $Root/ex and (contains($Root/Edit/@link,'m=edit') or xUser = $Root/LogonUser)">
                <!-- sub-object being edited -->
                <tr>                    
                    <xsl:if test="count($Form/Fields/@checkbox)">
                        <td   style="{$line}"/>
                    </xsl:if>
                    <xsl:apply-templates select="$Form/Fields[@name=$name]/Field" mode="input"/>
                    <xsl:call-template name="xUser">
                        <xsl:with-param name="name" select="$name"/>
                    </xsl:call-template>
                    <td>
                        <input type="image" alt="{$lsSave}" title="{$lsSave}" id="submit470">
                            <xsl:attribute name="src">
                                <xsl:value-of select="$Root/ImgDir"/>
                                <xsl:text>save.gif</xsl:text>
                            </xsl:attribute>
                        </input>
                    </td>
                </tr>
            </xsl:when>
            <xsl:when test="contains($Root/Edit/@link,'m=edit') or xUser = $Root/LogonUser or count($Form/Fields/@myonly) = 0">
                <tr id="tr{@id}">
                    <xsl:if test="$sep >0">
                        <xsl:if test="($pos mod $sep) = 0">
                            <xsl:attribute name="style">background-color: #eeeeee;</xsl:attribute>
                        </xsl:if>
                    </xsl:if>                   
                    <xsl:if test="count($Form/Fields/@checkbox)">
                        <td  style="{$line}">
                            <input type="checkbox" name="para" value="{@id}" style="height: 14px;"/>
                        </td>
                    </xsl:if>
                    <xsl:apply-templates select="." mode="line">
                        <xsl:with-param name="name" select="$name"/>
                    </xsl:apply-templates>
                    <xsl:if test="((contains($Form/Fields[@name=$name]/@owner,'read') and contains($Root/Edit/@link,'m=edit')) or contains($Form/Fields[@name=$name]/@owner,'show')) and xUser != $Root/LogonUser">
                        <td class="under2"   style="{$line}" title="{xUser}">
                            <xsl:choose>
                                <xsl:when test="string-length(xUser) > 26">
                                    <xsl:value-of select="substring(xUser,1,23)"/>
                                    <xsl:text>...</xsl:text>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="xUser"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </td>
                    </xsl:if>
                    <xsl:if test="$Root/Modus!='editex' and (contains($Root/Edit/@link,'m=edit') or xUser = $Root/LogonUser)">
                        <td style="{$line}">
                            <a target="_lock" onclick="removeTr('tr{@id}');">
                                <xsl:attribute name="href">
                                    <xsl:value-of select="/ShowPage/Script"/>
                                    <xsl:text>?f=</xsl:text>
                                    <xsl:value-of select="@id"/>
                                    <xsl:text>&amp;m=delete</xsl:text>
                                </xsl:attribute>
                                <img border="0" alt="{$lsDeletePage}" src="{$Root/ImgDir}delete_s.gif" height="12"/>
                            </a>
                        </td>
                    </xsl:if>
                </tr>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="node()" mode="line">
        <!-- content of an object -->
        <xsl:param name="name"/>
        <xsl:param name="prefix"/>
        <xsl:variable name="Subobj" select="."/>
        <xsl:for-each select="$Form/Fields[@name=$name or @object=$name]/Field">
            <xsl:variable name="field" select="@name"/>
            <xsl:choose>
                <xsl:when test="@type='hidden'"/>
                <xsl:when test="@type='id'">
                    <td align="{@align}"   style="{$line}">
                        <xsl:value-of select="$Subobj/@id"/>
                    </td>
                </xsl:when>
                <xsl:otherwise>
                    <td align="{@align}"   style="{$line}">
                        <!--
                        <xsl:if test="$Subobj/xUser != $Root/LogonUser">
                            <xsl:attribute name="style">
                                <xsl:text>color: #808080; </xsl:text>
                                <xsl:value-of select="$line"/>
                            </xsl:attribute>
                        </xsl:if>
                        -->
                        <xsl:apply-templates select="$Subobj" mode="ex">
                            <xsl:with-param name="field" select="$field"/>
                            <xsl:with-param name="prefix" select="$prefix"/>
                            <xsl:with-param name="maxlength" select="@maxlength" />
                        </xsl:apply-templates>
                    </td>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="xUser">
        <xsl:param name="name" select="''"/>
        <xsl:choose>
            <xsl:when test="contains($Root/Edit/@link,'m=edit') and contains($Form/Fields[@name=$name]/@owner,'set')">
                <td   style="{$line}">
                    <xsl:choose>
                        <xsl:when test="count($Root/Options/node()[name(.)='User' or name(.)='Team'])">
                            <select name="xUser" class="under2">
                                <xsl:if test="count($Form/Fields[@name=$name]/@xuserwidth)">
                                    <xsl:attribute name="style">
                                        <xsl:text>width: </xsl:text>
                                        <xsl:value-of select="$Form/Fields/@xuserwidth"/>
                                        <xsl:text>;</xsl:text>
                                    </xsl:attribute>
                                </xsl:if>
                                <option selected="selected">
                                    <xsl:call-template name="xUserValue"/>
                                </option>
                                <xsl:for-each select="$Root/Options/node()[name(.)='User' or name(.)='Team']">
                                    <xsl:sort select="."/>
                                    <option>
                                        <xsl:value-of select="."/>
                                    </option>
                                </xsl:for-each>
                            </select>
                        </xsl:when>
                        <xsl:otherwise>
                            <input type="text" size="10" name="xUser" class="under2">
                                <xsl:attribute name="value">
                                    <xsl:call-template name="xUserValue"/>
                                </xsl:attribute>
                            </input>
                        </xsl:otherwise>
                    </xsl:choose>
                </td>
            </xsl:when>
            <xsl:otherwise>
                <input type="hidden" name="xUser">
                    <xsl:attribute name="value">
                        <xsl:value-of select="$Root/LogonUser"/>
                    </xsl:attribute>
                </input>
                <xsl:if test="contains($Root/Edit/@link,'m=edit') "/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="xUserValue">
        <xsl:choose>
            <xsl:when test="$Root/ex!=''">
                <xsl:apply-templates select="$Root/Subobj[@id=$Root/ex]" mode="ex">
                    <xsl:with-param name="field" select="'xUser'"/>
                </xsl:apply-templates>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$Root/LogonUser"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="Field" mode="input">
        <!-- show input fields -->
        <xsl:param name="prefix" select="''"/>
        <xsl:choose>
            <xsl:when test="@type='hidden'">
                <input type="hidden" name="{$prefix}{@name}" value="{@value}" id="in629"/>
            </xsl:when>
            <xsl:when test="@type='id'">
                <td   style="{$line}">
                    <xsl:value-of select="$Root/ex"/>
                </td>
            </xsl:when>
            <xsl:when test="@type='select' or @type='selectnow'">
                <xsl:variable name="name" select="@name"/>
                <td  style="{$line}">
                    <select class="under2" name="{$prefix}{@name}" id="{concat('id_',@name)}">
                        <xsl:if test="@type='selectnow'">
                            <xsl:attribute name="onfocus">setNow(this);</xsl:attribute>
                        </xsl:if>
                        <xsl:apply-templates select="@style" mode="copy"/>
                        <xsl:if test="$Root/ex=$Root/Subobj/@id">
                            <option type="b">
                                <xsl:apply-templates select="$Root/Subobj[@id=$Root/ex]" mode="ex">
                                    <xsl:with-param name="field" select="@name"/>
                                </xsl:apply-templates>
                            </option>
                        </xsl:if>
                        <xsl:if test="count(option/@top)=0 and count(option/@bottom)=0 ">
                            <xsl:for-each select="option">
                                <option type="x">
                                    <xsl:value-of select="."/>
                                </option>
                            </xsl:for-each>
                        </xsl:if>
                        <xsl:for-each select="option[count(@top)]">
                            <option type="y">
                                <xsl:value-of select="."/>
                            </option>
                        </xsl:for-each>
                        <xsl:if test="@type='selectnow'">
                            <option>
                                <xsl:value-of select="$Root/@now"/>
                            </option>
                        </xsl:if>
                        <xsl:if test="@list!=''">
                            <xsl:variable name="list" select="@list"/>
                            <xsl:variable name="limit" select="concat('',@limit)"/>
                            <xsl:for-each select="$Root/node()[name(.)=$list]/@s | $Root/Options/node()[name(.)=$list] | $Root/Subobj[xClass=$list]/sTitle[position()=1]|option[count(@top)=0 and count(@bottom)=0]">
                                <xsl:variable name="used">
                                    <xsl:apply-templates select="$Root" mode="count">
                                        <xsl:with-param name="field" select="$name"/>
                                        <xsl:with-param name="value" select="."/>
                                    </xsl:apply-templates>
                                </xsl:variable>
                                <xsl:if test="$limit='' or $used &lt; $limit">
                                    <option type="z">
                                        <xsl:value-of select="."/>
                                    </option>
                                </xsl:if>
                            </xsl:for-each>
                        </xsl:if>

                        <xsl:for-each select="option[count(@bottom)]">
                            <option type="a">
                                <xsl:value-of select="."/>
                            </option>
                        </xsl:for-each>
                    </select>
                </td>
            </xsl:when>
            <xsl:otherwise>
                <td   style="{$line}">
                    <input class="under2" name="{$prefix}{@name}" id="in696">
                        <xsl:apply-templates select="@size | @style" mode="copy"/>
                        <xsl:if test="count(@readonly)">
                            <xsl:attribute name="readonly">readonly</xsl:attribute>
                        </xsl:if>
                        <xsl:attribute name="type">text</xsl:attribute>
                        <xsl:choose>
                            <xsl:when test="count(@readonly)"/>
                            <xsl:when test="$Root[ex!='' and Modus='editex']">
                                <xsl:attribute name="value">
                                    <xsl:apply-templates select="$Root/Subobj[@id=$Root/ex]" mode="ex">
                                        <xsl:with-param name="field" select="@name"/>
                                    </xsl:apply-templates>
                                </xsl:attribute>
                            </xsl:when>
                            <xsl:when test="@type='now'">
                                <xsl:attribute name="onfocus">setNow(this);</xsl:attribute>
                                <xsl:attribute name="value">
                                    <xsl:value-of select="$Root/@now"/>
                                </xsl:attribute>

                            </xsl:when>
                            <xsl:when test="count(@default)">
                                <xsl:attribute name="value">
                                    <xsl:value-of select="@default"/>
                                </xsl:attribute>
                            </xsl:when>
                        </xsl:choose>
                    </input>
                </td>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="node()" mode="ex">
        <!-- show value of a field specified -->
        <xsl:param name="field"/>
        <xsl:param name="prefix"/>
        <xsl:param name="maxlength" />
        <xsl:variable name="this" select="node()[name()=$field]" />
        <xsl:choose>
            <xsl:when test="$field = 'sTitle' and (count($Root/ex)=0 or @id != $Root/ex) and ($Root/LogonUser = xUser or contains($Root/Edit/@link,'m=edit'))">
                <a href="?f={$Root/@id}&amp;ex={@id}&amp;m=editex" style="text-decoration: none;" title="{$this}">
                    <xsl:choose>
                        <xsl:when test="$maxlength > 0 and string-length($this) > $maxlength + 2">
                            <xsl:value-of select="substring($this,1,$maxlength)"/>
                            <xsl:text>...</xsl:text>
                        </xsl:when>
                        <xsl:when test="$this!=''">
                            <xsl:value-of select="$this"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:text>[</xsl:text>
                            <xsl:value-of select="@name"/>
                            <xsl:text>]</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                </a>
            </xsl:when>
            <xsl:when test="$field='xTitle' and node()[name()='xName']!=''">
                <a href="{node()[name()='xName']}" target="_blank" style="text-decoration: none;" title="{$this}">
                    <xsl:choose>
                        <xsl:when test="$maxlength > 0 and string-length($this) > $maxlength + 2">
                            <xsl:value-of select="substring($this,1,$maxlength)"/>
                            <xsl:text>...</xsl:text>
                        </xsl:when>
                        <xsl:when test="$this!=''">
                            <xsl:value-of select="$this"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:text>[</xsl:text>
                            <xsl:value-of select="@name"/>
                            <xsl:text>]</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                </a>
            </xsl:when>
            <xsl:when test="$prefix!=''">
                <xsl:choose>
                    <xsl:when test="$field='s'">
                        <xsl:value-of select="@s"/>
                    </xsl:when>
                    <xsl:when test="$field='t'">
                        <xsl:value-of select="@t"/>
                    </xsl:when>
                    <xsl:when test="$field='i'">
                        <xsl:value-of select="@i"/>
                    </xsl:when>
                    <xsl:when test="$field='f'">
                        <xsl:value-of select="@f"/>
                    </xsl:when>
                    <xsl:when test="$field='m'">
                        <xsl:apply-templates select="."/>
                    </xsl:when>
                </xsl:choose>
            </xsl:when>
            <xsl:when test="$maxlength > 0 and string-length($this) > $maxlength + 2">
                <div title="{$this}">
                    <xsl:value-of select="substring($this,1,$maxlength)"/>
                    <xsl:text>...</xsl:text>
                </div>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$this"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="ShowPage" mode="count">
        <!-- count Subobj's with a specified field with specified value -->
        <xsl:param name="field"/>
        <xsl:param name="value"/>
        <xsl:variable name="count">
            <xsl:apply-templates select="Subobj" mode="count">
                <xsl:with-param name="field" select="$field"/>
                <xsl:with-param name="value" select="$value"/>
            </xsl:apply-templates>
        </xsl:variable>
        <xsl:value-of select="string-length($count)"/>
    </xsl:template>
    <xsl:template match="Subobj" mode="count">
        <!-- used to count Subobj's with a specified field with specified value -->
        <xsl:param name="field"/>
        <xsl:param name="value"/>
        <xsl:if test="node()[name(.)=$field] = $value">
            <xsl:text>+</xsl:text>
        </xsl:if>
    </xsl:template>
    <xsl:template match="Field" mode="td">
        <!-- show a title field -->
        <xsl:choose>
            <xsl:when test="@type='hidden'"/>
            <xsl:otherwise>
                <td style="font-weight: bold;{@style} {$line}">
                    <xsl:attribute name="align">
                        <xsl:value-of select="@align"/>
                    </xsl:attribute>
                    <xsl:value-of select="@title"/>
                </td>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="Field" mode="xBodyFields">
        <!-- build a hidden field named xBodyFields -->
        <input type="hidden" name="xBodyFields" id="in838">
            <xsl:attribute name="value">
                <xsl:value-of select="@name"/>
            </xsl:attribute>
        </input>
    </xsl:template>
    <xsl:param name="tbcolor">
        <xsl:value-of select="$bgcolorUse"/>
    </xsl:param>
    <xsl:template match="/">
        <xsl:choose>
            <xsl:when test="count($Form/Fields)=0">
                <html>
                    <head>

                        <script language="JavaScript" type="text/javascript">
                            <xsl:text>document.location='</xsl:text>
                            <xsl:value-of select="ShowPage/Script"/>
                            <xsl:text>?f=</xsl:text>
                            <xsl:value-of select="ShowPage/@super"/>
                            <xsl:text>&amp;ex=</xsl:text>
                            <xsl:value-of select="ShowPage/@id"/>
                            <xsl:text>&amp;rnd=</xsl:text>
                            <xsl:value-of select="ShowPage/@now"/>
                            <xsl:text>#focus';</xsl:text>
                        </script>
                    </head>
                    <body>
                        <a href="{ShowPage/Script}?f={ShowPage/@super}&amp;ex={ShowPage/@id}#focus">
                            <xsl:value-of select="$lsClick"/>
                        </a>
                    </body>
                </html>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="$Root" mode="block">
                    <xsl:with-param name="hide" select="'append'"/>
                </xsl:apply-templates>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:param name="Form" select="/ShowPage"/>
    <xsl:param name="Root" select="/ShowPage"/>
    <xsl:param name="line" select="'border-bottom: 1px solid #cccccc;'"/>
</xsl:stylesheet>
