<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="NextDocument.xsl"/>
    <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <xsl:apply-templates select="ShowPage" mode="block">
            <xsl:with-param name="hide">append</xsl:with-param>
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="ShowPage" mode="Untergeordnet">
        <style type="text/css">
            table#detail {width: 680px;}
            #detail td {border-right: white 1px solid;border-bottom: white 1px solid;font-size: 12;
            padding-top: 2px; padding-bottom: 2px;}
            input,select {font-size: 12; font-family: tahoma; }
            .i3 {width: 556px;}
            .i1 {width: 250px;}
            .i2 {width: 176px;}
            td {font-size: 12; text-align: left}
            #editor td {font-size: 12; text-align: right}
            .submit {font-size: 11; font-family: tahoma; width: 100%; padding-left: 0px; padding-right: 0px;}
            #detail tr.header td {font-weight: bold}
            img {vertical-align: bottom}
            table.biblio {border: 1px solid #888888; background-color0: #fcfcfc;}
            table.biblio td {vertical-align: middle}
            table#detail td {border-bottom: 1px solid #cccccc;}
            table.biblio a, table#detail a {text-decoration: none}
            a.numberoffiles { font-size: 8pt; text-decoration: none;}
            a.numberoffiles:hover {color: white; background-color: black;}

        </style>
        <xsl:choose>
            <xsl:when test="count(sTitle)=0">
                <xsl:apply-templates select="." mode="NoTitle"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="count(ListOption/@stitle)">
                        <xsl:apply-templates select="Subobj" mode="folder">
                            <xsl:sort select="sTitle" data-type="text"/>
                        </xsl:apply-templates>
                    </xsl:when>
                    <xsl:when test="count(ListOption/@reverse)">
                        <xsl:apply-templates select="Subobj" mode="folder">
                            <xsl:sort select="@sort" data-type="number"/>
                        </xsl:apply-templates>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:apply-templates select="Subobj" mode="folder"/>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:if test="count(Edit)">
                    <form method="post" action="?f={/ShowPage/@id}&amp;m=create" onsubmit="return CreateDoc(this.sTitle);">
                        <table border="0" cellspacing="0" cellpadding="0" style="width: 680px;margin-top: 20px;">
                            <tbody>
                                <tr>
                                    <td style="text-align: left;">
                                        <input type="text" name="sTitle" onfocus="ResetEmpty(this);" 
                                               style="width: 590px; color: #888888; font-style: italic; "
                                               value="Title of a new document" />
                                    </td>
                                    <td style="width: 80px; text-align:right;">
                                        <input type="submit" value="{$lsSubmit}" style="width: 80px;"/>
                                        <input type="hidden" name="f" value="{/ShowPage/@id}"/>
                                        <input type="hidden" name="m" value="create"/>
                                        <input type="hidden" name="sTemplate" value="NextDocument.xsl"/>
                                        <input type="hidden" name="bSave" value="bSave"/>
                                        <input type="hidden" name="iOwner" value="{/ShowPage/Owner}" />
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </form>
                    <div style="font-size: 6pt;">&#160;</div>
                    <form name="addform" method="post" ENCTYPE="multipart/form-data" 
                        action="?f={/ShowPage/@id}&amp;m=create&amp;v=PrivateFile&amp;next=show_{/ShowPage/@id}">
                        <input type="hidden" name="xBodyFields" value="xVersion,xCheckin,xNotice"/>
                        <xsl:apply-templates select="." mode="version">
                            <xsl:with-param name="checkin">M</xsl:with-param>
                        </xsl:apply-templates>
                    </form>
                </xsl:if>
            </xsl:otherwise>
        </xsl:choose>
        <script language="JavaScript" type="text/javascript">
            var sN =  'dbfldr';
            function ChangeCookie(id, add){
            var cka = getCookie(sN).split('.');
            for(var i=cka.length - 1; i &gt; -1; i--)
            if(cka[i]==id)cka.splice(i,1);
            if(add!=0)cka.push(id);
            setCookie(sN,cka.join('.'),100);
            }
            function ShowDiv(id){
            var dv = document.getElementById('dv' + id);
            var bt = document.getElementById('bt' + id);
            if(dv.style.display == ''){
            dv.style.display = 'none';
            bt.src='<xsl:value-of select="/ShowPage/ImgDir"/>DynDown.gif';
            ChangeCookie(id,0);
            }
            else {
            dv.style.display = '';
            bt.src = '<xsl:value-of select="/ShowPage/ImgDir"/>DynUp.gif';
            ChangeCookie(id,1);
            }
            };
            function RestoreOpen(){
            var ck = getCookie(sN);
            var cka = ck.split('.');
            for(var i=0; i &lt; cka.length; i++){
            var id = cka[i];
            var dv = document.getElementById('dv' + id);
            if(dv != null)ShowDiv(id);
            }
            };
            var ex = document.getElementById('dv' + '<xsl:value-of select="/ShowPage/ex"/>');
            if(ex!=null){
            if(ex.style.display == 'none') ShowDiv(<xsl:value-of select="/ShowPage/ex"/>);
            ex.style.backgroundColor = '#eeeeee';
            }
            else RestoreOpen();
        </script>
        <script language="JavaScript" type="text/javascript">
            function MoveAll(frm){
            var sPara = '';
            <xsl:for-each select="Subobj/Subobj">
                if(document.getElementById('pr<xsl:value-of select="@id"/>').checked)
                sPara += '<xsl:value-of select="@id"/>,';
            </xsl:for-each>
            sPara = sPara.substring(0,sPara.length-1);
            frm.para.value = sPara;
            frm.submit();
            }
            function DelTree(id){
            open('<xsl:value-of select="Script"/>?f=deltree' + '\x26' + 'ex='+id,'deltree_'+id);
            }
            function CreateDoc(ctrl){
            CheckEmpty(ctrl);
            if(ctrl.value=='')return false;
            }
        </script>
        <script language="Javascript" type="text/javascript">
            function SubmitForm(id){
            var frm = document.getElementById('addform' + id);
            frm.submit();
            }
        </script>
        <xsl:apply-templates select="." mode="bodyscript"/>
    </xsl:template>
    <xsl:template match="Subobj" mode="folder">
        <table cellspacing="0" cellpading="0" style="width: 680px;border-top: 1px solid #666666; margin-top: 6px;">
            <tbody>
                <tr id="tr{@id}" style="text-align: left; ">
                    <td>
                        <a class="under" style="text-decoration: none;">
                            <xsl:choose>
                                <xsl:when test="sTemplate[.='PrivateFile' or .='PublicFile']">
                                    <xsl:apply-templates select="." mode="link">
                                        <xsl:with-param name="target" select="'_blank'"/>
                                    </xsl:apply-templates>
                                </xsl:when>
                                <xsl:when test="sTemplate != 'NextDocument.xsl'">
                                    <xsl:apply-templates select="." mode="link"/>
                                </xsl:when>
                                <xsl:when test="count(Subobj[xRelease!=''])">
                                    <xsl:apply-templates select="Subobj[xRelease!=''][last()]" mode="link">
                                        <xsl:with-param name="target" select="'_blank'"/>
                                    </xsl:apply-templates>
                                </xsl:when>
                                <xsl:when test="count(Subobj[count(xCheckin) or count(xCheckin|xCheckout)=0])">
                                    <xsl:apply-templates select="Subobj[count(xCheckin) or count(xCheckin|xCheckout)=0][last()]" mode="link">
                                        <xsl:with-param name="target" select="'_blank'"/>
                                    </xsl:apply-templates>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:attribute name="href">
                                        <xsl:text>javascript:ShowDiv('</xsl:text>
                                        <xsl:value-of select="@id"/>
                                        <xsl:text>');</xsl:text>
                                    </xsl:attribute>
                                </xsl:otherwise>
                            </xsl:choose>
                            <xsl:value-of select="sTitle"/>
                        </a>
                        <xsl:if test="contains(/ShowPage/Edit/@link,'m=edit') ">
                            <xsl:apply-templates select="." mode="Status"/>
                        </xsl:if>
                        <xsl:if test="/ShowPage/ex = @id">
                            <a name="focus">&#160;</a>
                        </xsl:if>
                    </td>
                    <td style="text-align: right;width: 94px; ">
                        <xsl:choose>
                            <xsl:when test="sTemplate[ .='NextDocument.xsl' or .='PrivateFile' or .='PublicFile']">
                                <xsl:if test="sTemplate = 'NextDocument.xsl'">
                                    <a class="numberoffiles" href="?f={/ShowPage/@id}&amp;ex={@id}">
                                        <xsl:attribute name="style">
                                            <xsl:choose>
                                                <xsl:when test="Subobj[last()][count(xCheckout) !=0 and count(xCheckin)=0]">
                                                    <xsl:text>background-color: </xsl:text>
                                                    <xsl:choose>
                                                        <xsl:when test="count(/ShowPage/bgcolor)">
                                                            <xsl:value-of select="/ShowPage/bgcolor"/>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <xsl:value-of select="$bgcolor"/>
                                                        </xsl:otherwise>
                                                    </xsl:choose>
                                                    <xsl:text>;</xsl:text>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:attribute>
                                        <xsl:text> </xsl:text>
                                        <xsl:value-of select="count(Subobj)"/>
                                        <xsl:text>x </xsl:text>
                                    </a>
                                </xsl:if>
                                <a>
                                    <xsl:attribute name="href">
                                        <xsl:choose>
                                            <xsl:when test="sTemplate='PrivateFile'">
                                                <xsl:text>javascript:SubmitForm('</xsl:text>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:text>javascript:ShowDiv('</xsl:text>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                        <xsl:value-of select="@id"/>
                                        <xsl:text>');</xsl:text>
                                    </xsl:attribute>
                                    <img id="bt{@id}" src="{/ShowPage/ImgDir}DynDown.gif" border="0" title="Details..."/>
                                </a>
                            </xsl:when>
                            <xsl:otherwise>
                                <a href="{/ShowPage/SysURL}?f={@id}">
                                    <img src="{/ShowPage/ImgDir}/closed.gif" border="0"/>
                                </a>
                            </xsl:otherwise>
                        </xsl:choose>
                    </td>
                </tr>
            </tbody>
        </table>
        <xsl:if test="sTemplate='PrivateFile'">
            <form id="addform{@id}" method="post"
                action="?f={@id}&amp;m=checkin&amp;next=show_{/ShowPage/@id}">
                <input type="hidden" name="sTitle" value="{sTitle}"/>
                <input type="hidden" name="sTemplate" value="NextDocument.xsl" />
                <xsl:apply-templates select="." mode="version" >
                    <xsl:with-param name="checkin">1</xsl:with-param>
                </xsl:apply-templates>
            </form>
        </xsl:if>
        <div id="dv{@id}" style="display: none; margin-bottom: 12px;">
            <xsl:apply-templates select="." mode="document"/>
        </div>
    </xsl:template>
</xsl:stylesheet>

