<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:import href="ajaxcol.xsl"/>
    <xsl:template match="ShowPage" mode="addstyle">
        <style type="text/css">
            td.form input[type=text] {width: 240px;}
            td.form select {padding: 1px 1px;}
            td.form table  {background-color: <xsl:value-of select="$pdcolor"/>; border-collapse: collapse;}
            td.form td {border: 1px white solid; padding: 3px;}
            a.glink {text-decoration: none;}
            table.googleresult h3 {margin-top: 3px; margin-bottom: 0px;font-size: 12pt; color: #1a0dab;}
            a.glink .cite {color: green; }
            a.glink:hover h3 {text-decoration: underline;}
            table.googleresult td {border: 3px white solid;}
        </style>
        <xsl:if test="count(Edit)=0 and Modus!='all'">
            <meta HTTP-EQUIV="REFRESH" content="0;url=info.aspx?f={@id}&amp;m=all&amp;device=IE40" />
            <script>
                <xsl:text>document.location.replace("info.aspx?f=</xsl:text>
                <xsl:value-of select="@id"/>
                <xsl:text>&amp;m=all&amp;device=IE40");</xsl:text>
            </script>
        </xsl:if>
    </xsl:template>
    <xsl:template match="ShowPage" mode="content">
        <xsl:choose>
            <xsl:when test="contains(@name,'.htm') or Modus='all'">
                <xsl:apply-templates select="." mode="google" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="." mode="keywords" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="ShowPage" mode="google">
        <table class="googleresult"  style="width: 680px;">
            <tbody>
                <xsl:apply-templates select="//Xtext//div[@id='resultStats']" mode="resultStats"/>
                <xsl:apply-templates select="//Xtext//div[@id='res']//a" mode="link" />
            </tbody>
        </table>
    </xsl:template>
    <xsl:template match="ShowPage" mode="Untergeordnet">
        <xsl:choose>
            <xsl:when test="Modus='all'" />
            <xsl:when test="contains(@name,'.htm')">
                <table border="0" cellspacing="0" cellpadding="0" width="680" id="untergeordnet">
                    <tbody>
                        <xsl:choose>
                            <xsl:when test="count(ListOption/@reverse)">
                                <xsl:apply-templates select="Subobj">
                                    <xsl:sort data-type="number" select="@sort" order="descending"/>
                                </xsl:apply-templates>
                            </xsl:when>
                            <xsl:when test="count(ListOption/@stitle)">
                                <xsl:apply-templates select="Subobj">
                                    <xsl:sort select="sTitle"/>
                                </xsl:apply-templates>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:apply-templates select="Subobj"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </tbody>
                </table>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="." mode="UnterCol" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="Subobj">
        <xsl:variable name="id" select="@id"/>
        <xsl:variable name="t1" select="substring-before(concat(sTitle,'.'),'.')"/>
        <xsl:variable name="t">
            <xsl:choose>
                <xsl:when test="$t1=''">[Unnamed]</xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$t1"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:choose>
            <xsl:when test="count(../Richtext//img[contains(@src,concat('?f=',$id))]) " />
            <xsl:when test="count(../Richtext//table[@class='ppt'])" />
            <xsl:when test="count(/ShowPage/ListOption/@max) and position() > /ShowPage/ListOption/@max"/>
            <xsl:when test="count(/ShowPage/Xtext//a//h3[starts-with(., $t)])"/>
            <xsl:when test="count(/ShowPage/Edit)=0 and /ShowPage/Modus!='all'" />
            <xsl:when test="/ShowPage/Modus='all'"/>
            <xsl:otherwise>
                <tr valign="top" id="l{@id}">
                    <td style="width: 23px; {$tdstyle}">
                        <xsl:choose>
                            <xsl:when test="sTemplate[.='Empty']">
                                <br/>
                            </xsl:when>
                            <xsl:otherwise>
                                <a target="{../Target}">
                                    <xsl:apply-templates select="." mode="link"/>
                                    <img border="0" width="20" height="16" alt="{$lsPageGif}" src="{../ImgDir}DynClose.gif"/>
                                </a>
                            </xsl:otherwise>
                        </xsl:choose>
                    </td>
                    <td class="under" style="{$tdstyle}">
                        <a target="{../Target}" style="text-decoration: none;">
                            <xsl:apply-templates select="." mode="link"/>
                            <xsl:value-of select="sTitle"/>
                        </a>
                        <xsl:apply-templates select="." mode="Status"/>
                    </td>
                </tr>

            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="a" mode="link">
        <xsl:variable name="t" select="h3"/>
        <xsl:choose>
            <xsl:when test="starts-with(@href,'http://webcache.googleusercontent.com/search?')"/>
            <xsl:when test="starts-with(@href,'https://webcache.googleusercontent.com/search?')"/>
            <xsl:when test="starts-with(@href,'https://translate.google.com/translate?')"/>
            <xsl:when test="count(/ShowPage/Edit)=0 and count(//Subobj[starts-with($t, substring-before(concat(sTitle,'.'),'.'))])=0"/>
            <xsl:when test="count(h3)=0"/>
            <xsl:when test=".!='' and @href != '' and @ping !=''">
                <tr>
                    <td colspan="2">
                        <div style="float: right;background0: red;">
                            <xsl:choose>
                                <xsl:when test="count(//Subobj[starts-with($t, substring-before(concat(sTitle,'.'),'.'))])">
                                    <a href="?f={//Subobj[starts-with($t, substring-before(concat(sTitle,'.'),'.'))]/@id}" target="_blank">
                                        <img src="{/ShowPage/ImgDir}document-xxl.png" border="0" style="heigh: 55px; width: 55px; margin-left: 10px; margin-top: 5px;"/>
                                    </a>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:variable name="dw" select="'55px'"/>
                                    <xsl:variable name="dh" select="'20px'"/>
                                    <div style="position: relative; display: inline-block; width: {$dw}; overflow: hidden;text-overflow: clip; margin-bottom: -3px;margin-left: 10px;">
                                        <form name="addform" method="post" enctype="multipart/form-data" style="width: {$dw}; text-overflow: clip; overflow:hidden;" 
                                            action="?f={/ShowPage/@id}&amp;m=create&amp;v=PrivateFile&amp;next=Super">
                                            <input type="file" name="sUpload" onchange="this.form.submit();" size="20" multiple="multiple" 
                                                   style="position: relative; width: {$dw};  height:{$dh};z-index: 200;-moz-opacity:0; filter:alpha(opacity: 0);  opacity: 0"/>
                                            <input type="button" value="Upload" 
                                                    style="position: relative; left: 0px; top: -15px; z-index:100; width: {$dw};height:{$dh};"/>
                                            <input type="hidden" name="sTitle" value="{h3}"/>
                                        </form>
                                    </div>                                    
                                </xsl:otherwise>
                            </xsl:choose>
                        </div>
                        <xsl:choose>
                            <xsl:when test="count(/ShowPage/Edit)">
                                <a href="{@href}" target="_blank" class="glink">
                                    <xsl:apply-templates select="h3|.//cite"/>
                                </a>
                            </xsl:when>
                            <xsl:otherwise>
                                <a href="{@href}" target="_blank" class="glink">
                                    <xsl:apply-templates select="h3|.//cite"/>
                                </a>
                            </xsl:otherwise>
                        </xsl:choose>


                        <br/>
                        <xsl:apply-templates select="../../div[@class='s']/div"/>
                    </td>
                    <!--
                    <td style="width: 45x;" >
                        <xsl:choose>
                            <xsl:when test="count(//Subobj[starts-with($t, substring-before(concat(sTitle,'.'),'.'))])">
                                <a href="?f={//Subobj[starts-with($t, substring-before(concat(sTitle,'.'),'.'))]/@id}" target="_blank">
                                    <img src="{/ShowPage/ImgDir}document-xxl.png" border="0" style="heigh: 45px; width: 45px;"/>
                                </a>
                            </xsl:when>
                        </xsl:choose>
                    </td>
                    -->
                </tr>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="cite">
        <span class="cite">
            <xsl:value-of select="."/>
        </span>
    </xsl:template>
    <xsl:param name="advsearch" select="'https://www.google.com/advanced_search?q='"/>
    <xsl:template match="div" mode="resultStats">
        <xsl:if test="count(/ShowPage/Edit)">
            <tr>
                <td colspan="2">
                    <a href="?f={/ShowPage/@id}&amp;v=PrivateFile" target="_blank">
                        <xsl:value-of select="."/>
                    </a>
                    <xsl:text> </xsl:text>
                    <xsl:apply-templates select="/ShowPage/Xtext//a[contains(@href,$advsearch)]" mode="query"/>
                </td>
            </tr>
        </xsl:if>
    </xsl:template>
    <xsl:template match="a" mode="query">
        <a href="https://www.google.com/search?q={substring-after(@href,$advsearch)}" target="_blank">
            <xsl:value-of select="substring-after(@href,$advsearch)"/>
        </a>
    </xsl:template>
    <xsl:template match="ShowPage" mode="keywords">
        <table cellspacing="0" cellpadding="0" border="0" width="100%">
            <tbody>
                <tr>
                    <td id="baseTD" colspan="2">
                        <xsl:apply-templates select="." mode="MainText" />
                    </td>
                </tr>
                <xsl:if test="count(/ShowPage/Edit)">

                    <tr>
                        <td class="form">
                            <form action="?f={@id}&amp;m=add" method="post" id="keywords">
                                <table border="0" cellspacing="1" class="list">
                                    <tbody>
                                        <xsl:apply-templates select="oGoogle" />
                                        <tr>
                                            <td>
                                                <input type="text" name="oGoogle_m" autofocus="autofocus" />
                                            </td>
                                            <td>
                                                <select name="oGoogle_s">
                                                    <option value="Option">Option</option>
                                                    <option value="Must">Must</option>
                                                    <option value="Switch">Switch</option>
                                                </select>
                                            </td>
                                            <td>
                                                <input type="hidden" name="f" value="{@id}"/>
                                                <input type="hidden" name="m" value="add" />
                                                <input type="hidden" name="oGoogle" />
                                                <input type="submit" value="OK"/>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </form>
                        </td>
                        <td class="form" style="text-align: right;">
                            <table class="list" border="0" cellspacing="1" align="right">
                                <tbody>
                                    <tr>
                                        <td style="white-space: nowrap; ">
                                            <div style="position: relative; display: inline-block; width: 250px; overflow: hidden;text-overflow: clip; margin-bottom: -3px;">
                                                <form name="addform" method="post" enctype="multipart/form-data" style="width: 250px; text-overflow: clip; overflow:hidden;" 
                                                    action="?f={/ShowPage/@id}&amp;m=create&amp;v=PrivateFile&amp;next=Super">
                                                    <input type="hidden" name="xTemplate" value="HAGsearch.xsl"/>
                                                    <input type="file" name="sUpload" multiple="multiple" onchange="this.form.submit();" size="20"
                                                           style="position: relative; width: 250px;  height:20px;z-index: 200;-moz-opacity:0; filter:alpha(opacity: 0);  opacity: 0"/>
                                                    <input type="button" value="Upload hit lists" 
                                                            style="position: relative; left: -250px; z-index:100; width: 250px;"/>
                                                </form>
                                            </div>
                                        </td>
                                    </tr>
                                    <xsl:if test="count(oGoogle)">
                                        <tr>
                                            <td>
                                                <form action="hagsearch.aspx" method="get" onsubmit="this.submit.disabled=true;">
                                                    <input type="hidden" name="f" value="{@id}"/>
                                                    <input type="submit" style="width: 250px;"  name="submit" 
                                                        value="Scan {(((count(oGoogle[@s='Option'])+1) div 2) * count(oGoogle[@s='Option']) +1) * (count(oGoogle[@s='Switch'])+1)} combinations" />
                                                </form>
                                            </td>
                                        </tr>
                                    </xsl:if>
                                    <xsl:if test="count(Subobj)">
                                        <tr>
                                            <td>
                                                <form action="?" method="get" onsubmit="this.submit.disabled=true;">
                                                    <input type="hidden" name="f" value="{@id}"/>
                                                    <input type="hidden" name="m" value="all" />
                                                    <input type="submit" style="width: 250px;"  name="submit" value="Show all results" />
                                                </form>
                                            </td>
                                        </tr>
                                    </xsl:if>
                                </tbody>
                            </table>
                        </td>

                    </tr>
                    <tr>
                        <td style="height: 10px;" />
                    </tr>
                    <xsl:apply-templates select="oSearchGroup">
                        <xsl:sort select="@id" order ="descending" data-type="number"/>
                    </xsl:apply-templates>
                </xsl:if>
            </tbody>
        </table>
    </xsl:template>
    <xsl:template match="oSearchGroup">
        <tr>
            <td id="oSG{@id}" class="form" colspan="2">
                <table class="list" border="0" cellspacing="1" style="width: 100%">
                    <tbody>
                        <xsl:apply-templates select="oSearch">
                            <xsl:sort select="@i" data-type="number" order="ascending"/>
                        </xsl:apply-templates>
                    </tbody>
                </table>

            </td>
        </tr>
        <tr>
            <td style="height: 10px;" />
        </tr>
    </xsl:template>
    <xsl:template match="oSearch">
        <tr>
            <td style="width: 100px;">
                <xsl:value-of select="@i"/>
            </td>
            <td style="width:500px;">
                <a href="https://www.google.com/search?q={.}&amp;num=100&amp;newwindows=1" target="_blank">
                    <xsl:value-of select="."/>
                </a>
            </td>
            <xsl:if test="position()=1">
                <td style="width:50px;" rowspan="{count(../oSearch)}" title="{../@s} {../@t}">
                    <a href="?f={/ShowPage/@id}&amp;m=remove&amp;ex={../@id}">
                        <img src="{/ShowPage/ImgDir}delete_s.gif" border="0" />
                    </a>
                </td>
            </xsl:if>
        </tr>

    </xsl:template>
    <xsl:template match="oGoogle">
        <tr>
            <td>
                <xsl:value-of select="."/>
            </td>
            <td>
                <xsl:value-of select="@s"/>
            </td>
            <td>
                <a href="?f={../@id}&amp;m=remove&amp;ex={@id}">
                    <img src="{../ImgDir}delete_s.gif" border="0" />
                </a>
            </td>
        </tr>
    </xsl:template>
    <xsl:param name="lsFooterEdit">true</xsl:param>
</xsl:stylesheet>

