<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="DoubleOben.xsl"/>
    <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="/ShowPage" mode="extendedscript">
        <xsl:apply-templates select="." mode="commonscript"/>
        <xsl:choose>
            <xsl:when test="$lsTemplateSelected = 'ajaxcol.xsl'">
                <xsl:apply-templates select="." mode="colscript"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="." mode="listscript"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="ShowPage" mode="commonscript">
        <script name="common"  language="JavaScript" type="text/javascript">
            var sysurl = "<xsl:value-of select="SysURL"/>?f=";
            var xmlhttp = GetXmlHttpObject();
            var busy=0;
            var queue = [];
            var last=0;
            var received;
        </script>
        <script name="callurl" language="JavaScript" type="text/javascript">
            function callurl(url){
            busy=true;
            xmlhttp.onreadystatechange=stateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
            }
        </script>
    </xsl:template>
    <xsl:template match="ShowPage" mode="colscript">
        <style type="text/css">
            .mapOnly {display: none;}
        </style>
        <script name="stateChanged" language="JavaScript" type="text/javascript">
            function stateChanged(){
            var xmlDoc;
            try {
            xmlDoc = xmlhttp.responseXML.documentElement;
            } catch(e){
            }
            if(xmlhttp.readyState==4 <![CDATA[&&]]> xmlDoc !=null ){
            var sToken = xmlDoc.getElementsByTagName("sTitle")[0].childNodes[0].nodeValue;
            var id = xmlDoc.getAttribute("id");
            received = id;
            var tab = document.getElementById("tab"+id);
            var tbody = tab.getElementsByTagName("tbody")[0];
            if(tbody.getAttribute("class")== null){
            tbody.setAttribute("class","ajax");
            var Options = xmlDoc.getElementsByTagName(sToken);
            if(Options.length)
            <![CDATA[ for(var i=0; i < Options.length; i++)  ]]>
            SetOption(Options[i],tbody);

            try {
            tab.setAttribute("title",xmlDoc.getElementsByTagName("Timer")[0].childNodes[0].nodeValue);
            } catch(e){};
            }
            document.getElementById('img'+id).src = '<xsl:value-of select="ImgDir"/><xsl:value-of select="$gifOpen"/>';
            var url=queue.pop();
            if(url!=null)callurl(url);
            else busy=0;
            }
            }
        </script>
        <script name="SetOption" language="JavaScript" type="text/javascript">
            function SetOption(Subobj,tbody){
            var id = Subobj.getAttribute("id");
            var tr = document.createElement("tr");
            var td = document.createElement("td");
            var template = "Section.xsl";
            try {
            template = Subobj.getElementsByTagName("sTemplate")[0].childNodes[0].nodeValue;
            } catch(e) {};
            var pagename = Subobj.getAttribute("name").toLowerCase();
            var link = sysurl + id;
            var title = '[...]';
            try {
            title =Subobj.getElementsByTagName("sTitle")[0].childNodes[0].nodeValue;
            } catch(e) {};

            <![CDATA[
          if(pagename.match('.jpg')!=null || pagename.match('.jpeg')!=null ||
                pagename.match('.gif')!=null || 
                pagename.match('.png')!=null) link += '&v=imgview.xsl';
            title = '<div style="width: ]]><xsl:value-of select="$width - 24"/>px; <![CDATA[overflow: hidden"><a style="text-decoration: none;" href="' + link + 
                '" title="' + title + '" >' +
                title +
                '</a></div>';
            td.innerHTML = title       
            ]]>
            td.style.borderTop = "1px solid #c0c0c0"; //style for ajax cells
            td.style.paddingTop = "3px";
            td.style.paddingBottom = "3px";
            tr.appendChild(td);
            tbody.appendChild(tr);
            }
        </script>
        <script name="table_switch" language="JavaScript" type="text/javascript">
            function table_switch(id){
            var td = document.getElementById('td' + id);
            if(td.getAttribute('class') != 'open'){
            td.setAttribute('class', 'open');
            table_show(id,'');
            }
            else {
            td.setAttribute('class', 'closed');
            table_show(id,'none');
            }
            };
        </script>
        <script name="table_show" language="JavaScript" type="text/javascript">
            function table_show(id,state){
            var tab = document.getElementById('tab'+id);
            if(state=='none'){
            tab.style.display = state;
            last = id;
            document.getElementById('img'+id).src = '<xsl:value-of select="ImgDir"/><xsl:value-of select="$gifClose"/>';
            myscroll();
            myscroll();
            }
            <xsl:if test="substring(/ShowPage/@config,4,1)='1'">
                else if(last !=id)
                last=0;
            </xsl:if>
            else{
            tab.style.display = state;
            if(tab.getElementsByTagName("tbody")[0].getAttribute("class") == null){
            document.getElementById('img'+id).src = '<xsl:value-of select="ImgDir"/><xsl:value-of select="$gifProcessing"/>';
            var url= sysurl + id + "&amp;m=option&amp;ex=Subobj";
            if(busy)queue.push(url);
            else callurl(url);
            }
            else
            document.getElementById('img'+id).src = '<xsl:value-of select="ImgDir"/><xsl:value-of select="$gifOpen"/>';
            }
            return false;
            };
        </script>
    </xsl:template>
    <xsl:template match="ShowPage" mode="listscript">
        <style type="text/css">
            <!-- font-size -->
            <!-- others -->
            .pageOnly {display: none;}
            table#dynmap td {padding-left: 0px; text-align: left;vertical-align: top;}
            table#dynmap tr.ajax td {font-weight: bold;}
            .dynmap td a:hover {font-weight: bold;}
            .tooldyn {text-decoration: none;}
            .tooldyn:hover, .tool:hover .sidemenu {
            color:<xsl:choose>
                <xsl:when test="bgcolor!=''">
                    <xsl:value-of select="bgcolor"/>
                </xsl:when>
                <xsl:otherwise>white</xsl:otherwise>
            </xsl:choose>;
            background:<xsl:choose>
                <xsl:when test="text!=''">
                    <xsl:value-of select="text"/>
                </xsl:when>
                <xsl:otherwise>black</xsl:otherwise>
            </xsl:choose>;
            text-decoration:none;		font-weight: bold;}
        </style>
        <script name="stateChanged" language="JavaScript" type="text/javascript">
            function stateChanged(){
            if(xmlhttp.readyState==4){
            try {

            var xmlDoc = xmlhttp.responseXML.documentElement;
            var id = xmlDoc.getAttribute("id")
            var anchor = document.getElementById(id)
            var afterRow = anchor.parentNode.parentNode;
            var icon = afterRow.getElementsByTagName('img')[0];
            icon.src="<xsl:value-of select="ImgDir"/>dynopen.gif";
            var sToken = xmlDoc.getElementsByTagName("sTitle")[0].childNodes[0].nodeValue;
            var Options = xmlDoc.getElementsByTagName(sToken);

            if(Options.length){
            if(afterRow.getAttribute("class")== null){
            afterRow.setAttribute("class","ajax");
            if(expandcount)afterRow.scrollIntoView(true);
            var tbody = afterRow.parentNode;
            var beforeRow = afterRow.nextSibling; // can be null!
            var width = 16 + getPixel(anchor.parentNode.style.paddingLeft) + 'px';
            <![CDATA[ 
			    for(var i=0; i < Options.length; i++)  
                    try {
					    SetOption(Options[i], tbody, beforeRow, width);
                    } catch(e1) {};
            ]]>
            }
            }
            }catch(e) {};
            afterRow.setAttribute("class","ajax");
            var url = queue.pop();
            if(url!=null)
            callurl(url);
            else {
            busy = 0;
            if(expandcount) autoexpand();
            else if(iniArray.length > iniStep)IniOptions();
            else if(iniArray.length == iniStep){
            window.scrollTo(0, afterRow.offsetTop - 250);
            iniStep ++;
            }
            }
            }
            }
        </script>
        <script name="SetOption" language="JavaScript" type="text/javascript">
            function SetOption(Subobj, tbody, beforeRow, width){
            var id = Subobj.getAttribute("id"); //attributes[1].value;
            var tr = document.createElement("tr");
            var td = document.createElement("td");
            td.style.paddingLeft = width;
            td.style.textAlign = 'left';
            var template = Subobj.getElementsByTagName("sTemplate")[0].childNodes[0].nodeValue;
            var pagename = Subobj.getAttribute("name").toLowerCase(); //attributes[2].value.toLowerCase();
            var link = sysurl + id;
            var title = Subobj.getElementsByTagName("sTitle")[0];
            if(title==null)
            title = '[...]';
            else
            title = toolong(title.childNodes[0].nodeValue);
            var nUnder = Subobj.getElementsByTagName("nUnder");
            nUnder = nUnder.length;
            var src='<xsl:value-of select="ImgDir"/>';
            src += nUnder?'dynclose.gif':'dynnull.gif';
            if(!nUnder)tr.setAttribute("class","ajaxxx");
            <![CDATA[
          if(pagename.match('.jpg')!=null || pagename.match('.jpeg')!=null ||
            pagename.match('.gif')!=null || 
            pagename.match('.png')!=null) link += '&v=imgview.xsl';
				  td.innerHTML = 
					  (nUnder?('<a class="tooldyn" '+
                      ]]>
            <xsl:text>'href="javascript:ChangeOptions('+id+');"' +</xsl:text>
            <xsl:choose>
                <xsl:when test="substring($config,4,1)=2">
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>'onmouseover="CloseOptions('+id+');"' +</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <![CDATA[
                '>'):'') +
						'<img border="0" style="vertical-align: top;" '+
            ]]>
            <xsl:if test="/ShowPage/Agent='iPhone'">
                'height="26" width="32" '+
            </xsl:if>
            <![CDATA[
     
            'src="'+src+'" alt=""/>'+
					  (nUnder?'</a>':'') +
					  '<a id="'+id+'" '+
             ]]>
            <xsl:choose>
                <xsl:when test="substring($config,4,1)=2">
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>(nUnder?'onmouseover="OpenOptions('+id+');"':'') +</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
            <![CDATA[ 
            'href="' + link + '" class="tooldyn" target="_blank" '+
            '>' +
					  title +
					  '</a>';
            ]]>
            tr.appendChild(td);
            if(beforeRow==null)
            tbody.appendChild(tr);
            else
            tbody.insertBefore(tr,beforeRow);
            }
        </script>
        <script name="OpenOptionsForced" language="JavaScript" type="text/javascript">
            function OpenOptionsForced(id){
            last = id;
            OpenOptions(id);
            }
        </script>
        <script name="OpenOptions" language="JavaScript" type="text/javascript">
            function OpenOptions(id){
            <xsl:if test="substring($config,4,1)='1'">
                if(id != last){
                last=0;
                return false;
                }
            </xsl:if>
            var e = document.getElementById(id);
            if(e==null){
            if(iniArray.length > iniStep)IniOptions();
            return false;
            }
            var tr = e.parentNode.parentNode;
            tr.style.fontWeight = "bold";
            if(tr.getAttribute("class")==null){
            var icon = tr.getElementsByTagName('img')[0];
            icon.src="<xsl:value-of select="ImgDir"/>processing.gif";
            var url= sysurl + id + "&amp;m=option&amp;ex=Subobj";
            if(busy){
            queue.push(url);
            }
            else {
            busy = 1;
            callurl(url);
            }
            }
            return false;
            }
        </script>
        <script name="ChangeOptions" language="JavaScript" type="text/javascript">
            function ChangeOptions(id){
            var anchor = document.getElementById(id);
            var tr = anchor.parentNode.parentNode;
            if(tr.getAttribute("class")==null)
            OpenOptions(id);
            else
            CloseOptions(id);
            }
        </script>
        <script name="CloseOptions" language="JavaScript" type="text/javascript">
            function CloseOptions(id){
            last=id;
            expandcount = 0;
            CloseOptionsDo(id);
            }
            var idclose = 0;
            var idclosecount = 0;
            function CloseOptionsDo(id){
            var anchor = document.getElementById(id)
            var afterRow = anchor.parentNode.parentNode;
            if(afterRow.getAttribute("class")=="ajax"){
            if(id!=idclose){
            idclose=id;
            idclosecount=0;
            }
            else {
            idclosecount++;
            if(idclosecount &lt; 1)return;
            }
            afterRow.removeAttribute("class");
            afterRow.style.fontWeight = "";
            var icon = anchor.parentNode.getElementsByTagName('img')[0];
            icon.src="<xsl:value-of select="ImgDir"/>dynclose.gif";
            var tbody = afterRow.parentNode;
            var widthAfter = getPixel(anchor.parentNode.style.paddingLeft);
            while(1){
            var nextRow = afterRow.nextSibling;
            if(nextRow==null)break;
            var width = getPixel(nextRow.getElementsByTagName('td')[0].style.paddingLeft);
            if(width > widthAfter)
            tbody.removeChild(nextRow);
            else
            break;
            }
            }
            }
        </script>
        <script name="toolong" language="JavaScript" type="text/javascript">
            function toolong(text){
            if(text.length > 50)
            return text.substring(0,50) + '...';
            else
            return text;
            }
        </script>
        <script name="autoexpand" language="JavaScript" type="text/javascript">
            function autoexpand(){
            var rows = document.getElementById("dynmap").getElementsByTagName("tr");
            <![CDATA[
        for(var i=rows.length-1; i>-1; i--){
          if(rows[i].getAttribute("class")==null){
            var anchor = rows[i].getElementsByTagName("a")[1];
            var id = anchor.getAttribute("id");
            OpenOptionsForced(id);
            return;
          }
        }
        ]]>
            expandcount = 0;
            // document.getElementById("expand").innerHTML = rows.length;
            }
        </script>
        <script name="callautoexpand" language="JavaScript" type="text/javascript">
            var expandcount = 0;
            <xsl:if test="/ShowPage/Modus='autoexpand'">
                callautoexpand();
            </xsl:if>
            function callautoexpand(){
            expandcount = 1;
            autoexpand();
            }
        </script>
        <script name="IniOptions" language="JavaScript" type="text/javascript">
            var iniArray=[<xsl:value-of select="/ShowPage/ex"/>];
            var iniStep = 0;
            function IniOptions(){
            iniStep ++;
            OpenOptionsForced(iniArray[iniStep-1]);
            };
            window.onload = function(){
            if(iniArray.length > iniStep)IniOptions();
            }
        </script>
    </xsl:template>
    <xsl:template match="/">
        <xsl:apply-templates select="ShowPage" mode="block">
            <xsl:with-param name="hide" select="'append'"/>
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="ShowPage" mode="Untergeordnet">
        <xsl:choose>
            <xsl:when test="count(ListOption/@nolist)" />
            <xsl:when test="$lsTemplateSelected = 'ajaxcol.xsl'">
                <xsl:apply-templates select="." mode="UnterCol"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="." mode="UnterList"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="ShowPage" mode="UnterCol">
        <xsl:apply-templates select="." mode="NoTitle"/>
        <table border="0" cellspacing="0" cellpadding="0">
            <tr valign="top">
                <xsl:apply-templates select="." mode="ColN">
                </xsl:apply-templates>
            </tr>
        </table>
    </xsl:template>
    <xsl:template match="ShowPage" mode="UnterList">
        <!--
    <a id="test" href="javascript:alert(document.getElementById('dynmap').innerHTML);">DynMap</a>
    <a id="expand" href="javascript:callautoexpand()">Expand all</a>
    -->
        <table id="dynmap" class="dynmap" cellpadding="0" cellspacing="0">
            <tbody>
                <xsl:if test="ex != ''">
                    <tr style="font-weight: bold;">
                        <td>
                            <a class="tooldyn" target="_blank" href="?f={@id}">
                                <xsl:value-of select="sTitle"/>
                            </a>
                        </td>
                    </tr>
                </xsl:if>
                <xsl:apply-templates select="Subobj"/>
            </tbody>
        </table>
    </xsl:template>
    <xsl:template match="Subobj">
        <tr>
            <xsl:if test="count(nUnder)=0">
                <xsl:attribute name="class">ajaxxx</xsl:attribute>
            </xsl:if>
            <td>
                <xsl:choose>
                    <xsl:when test="count(nUnder)">
                        <a class="tooldyn" style="vertical-align: top;" href="javascript:ChangeOptions('{@id}');">
                            <xsl:if test="substring($config,4,1)!='2'">
                                <xsl:attribute name="onmouseover">
                                    <xsl:text>CloseOptions('</xsl:text>
                                    <xsl:value-of select="@id"/>
                                    <xsl:text>');</xsl:text>
                                </xsl:attribute>
                            </xsl:if>
                            <img border="0" style="margin-top: -1px; vertical-align: top;" src="{/ShowPage/ImgDir}dynclose.gif"/>
                        </a>
                    </xsl:when>
                    <xsl:otherwise>
                        <img border="0" style="margin-top: -1px; vertical-align: top;" src="{/ShowPage/ImgDir}dynnull.gif"/>
                    </xsl:otherwise>
                </xsl:choose>
                <a id="{@id}" class="tooldyn" target="_blank">
                    <xsl:if test="substring($config,4,1)!='2'">
                        <xsl:attribute name="onmouseover">
                            <xsl:text>OpenOptions('</xsl:text>
                            <xsl:value-of select="@id"/>
                            <xsl:text>');</xsl:text>
                        </xsl:attribute>
                    </xsl:if>
                    <xsl:apply-templates select="." mode="link"/>
                    <xsl:value-of select="sTitle"/>
                </a>
            </td>
        </tr>
    </xsl:template>
    <xsl:template match="ShowPage" mode="ColN">
        <xsl:param name="col" select="3"/>
        <xsl:param name="start" select="0"/>
        <xsl:choose>
            <xsl:when test="$col &gt; 1">
                <xsl:variable name="next" select="$start + ceiling((count(Subobj)-$start) div $col)"/>
                <td>
                    <table border="0" cellspacing="0" cellpadding="0" width="{$width}">
                        <xsl:for-each select="Subobj[position() &gt; $start and position() &lt; ($next + 1)]">
                            <xsl:apply-templates select="." mode="SpalteN">
                                <xsl:with-param name="width" select="$width"/>
                            </xsl:apply-templates>
                        </xsl:for-each>
                    </table>
                </td>
                <td width="7"/>
                <xsl:apply-templates select="." mode="ColN">
                    <xsl:with-param name="col" select="$col - 1"/>
                    <xsl:with-param name="start" select="$next"/>
                </xsl:apply-templates>
            </xsl:when>
            <xsl:otherwise>
                <td>
                    <table border="0" cellspacing="0" cellpadding="0" width="{$width}">
                        <xsl:for-each select="Subobj[position() &gt; $start]">
                            <xsl:apply-templates select="." mode="SpalteN">
                                <xsl:with-param name="width" select="$width"/>
                            </xsl:apply-templates>
                        </xsl:for-each>
                    </table>
                </td>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="Subobj" mode="SpalteN">
        <xsl:param name="width" select="220"/>
        <tr>
            <td class="closed" style="padding-top: 3px; padding-bottom: 3px; width: 20px; border-top:  #cccccc  1px solid; vertical-align: top; text-align: left;" id="td{@id}">
                <a class="tool">
                    <xsl:attribute name="href">
                        <xsl:text>javascript:table_switch('</xsl:text>
                        <xsl:value-of select="@id"/>
                        <xsl:text>');</xsl:text>
                    </xsl:attribute>
                    <xsl:choose>
                        <xsl:when test="substring(/ShowPage/@config,4,1)='2'">

                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:attribute name="onmouseover">
                                <xsl:text>table_show('</xsl:text>
                                <xsl:value-of select="@id"/>
                                <xsl:text>','none');</xsl:text>
                            </xsl:attribute>
                        </xsl:otherwise>
                    </xsl:choose>
                    <img border="0" id="img{@id}" alt="{$lsPageGif}" src="{../ImgDir}{$gifClose}">
                        <xsl:choose>
                            <xsl:when test="/ShowPage/Agent='iPhone'">
                                <xsl:attribute name="width">32</xsl:attribute>
                                <xsl:attribute name="height">26</xsl:attribute>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:attribute name="width">20</xsl:attribute>
                                <xsl:attribute name="height">16</xsl:attribute>
                            </xsl:otherwise>
                        </xsl:choose>
                    </img>
                </a>
            </td>
            <td  style="padding-top: 3px; padding-bottom: 3px; width: {$width - 20}px; border-top:  #cccccc  1px solid;" class="hoo">
                <xsl:choose>
                    <xsl:when test="substring(/ShowPage/@config,4,1)='2'" />
                    <xsl:otherwise>
                        <xsl:attribute name="onmouseover">
                            <xsl:text>table_show('</xsl:text>
                            <xsl:value-of select="@id"/>
                            <xsl:text>','');</xsl:text>
                        </xsl:attribute>
                    </xsl:otherwise>
                </xsl:choose>
                <div style="margin: 2px; overflow: hidden; width: {$width - 20}px;">
                    <a class="under" style="text-decoration: none;" >
                        <xsl:apply-templates select="." mode="link"/>
                        <xsl:value-of select="sTitle"/>
                    </a>
                    <xsl:apply-templates select="." mode="Status"/>
                </div>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <table cellpadding="2" style="display: none;" id="tab{@id}" width="{$width -20}">
                    <tbody/>
                </table>
            </td>
        </tr>
    </xsl:template>
    <xsl:param name="lsTemplateSelected">
        <xsl:choose>
            <xsl:when test="count(/ShowPage/param[.='tree']) > 0">ajaxlist.xsl</xsl:when>
            <xsl:otherwise>ajaxcol.xsl</xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="width" select="220"/>
    <xsl:param name="gifClose" select="'DynClose.gif'" />
    <xsl:param name="gifOpen" select="'DynOpen.gif'" />
    <xsl:param name="gifProcessing" select="'Processing.gif'" />
    <xsl:param name="lsAutoexpand">
        <xsl:choose>
            <xsl:when test="$lsLanguage='zh-cn'">全部展开</xsl:when>
            <xsl:when test="$lsLanguage='de'">Alles zeigen</xsl:when>
            <xsl:otherwise>Show everything</xsl:otherwise>
        </xsl:choose>
    </xsl:param>
    <xsl:param name="config">
        <xsl:choose>
            <xsl:when test="count(/ShowPage/param[starts-with(.,'config')])">
                <xsl:value-of select="substring(/ShowPage/param[starts-with(.,'config')],7)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="/ShowPage/@config"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
</xsl:stylesheet>
