<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
   <xsl:key name="getTeam" match="//TM" use="@id" />
   <xsl:key name="getDay" match="//day" use="@od" />


   <xsl:param name="display-view">1</xsl:param>

   <xsl:param name="data-level">0</xsl:param>
   
   <xsl:param name="fixSort">0</xsl:param>
   
   
   <xsl:param name="page-view">1</xsl:param>
   
   
   
   <xsl:param name="fix-SearchStr">1</xsl:param>
   <xsl:param name="this-fix">1</xsl:param>
   <xsl:param name="prev-fix">1</xsl:param>
   <xsl:param name="next-fix">1</xsl:param>


   <xsl:param name="tableSort1">10</xsl:param>
   <xsl:param name="tableSort2">7</xsl:param>
   <xsl:param name="tableSort3">9</xsl:param>


   
   <xsl:param name="row-highlight">white</xsl:param>
   <xsl:param name="row-normal">black</xsl:param>
   <xsl:param name="row-normal2">tomato</xsl:param>
   
   <xsl:template match="/">
      <xsl:choose>

         <xsl:when test="$display-view = 1">
<!-- FIXS table -->
<p>

            <xsl:apply-templates select="//LGES" mode="table" />
            </p>
         </xsl:when>

         <xsl:when test="$display-view = 2">
<!-- FIXS table -->

				<xsl:apply-templates select="//FIXLST" mode="combo-view" />  
         </xsl:when>

         <xsl:when test="$display-view = 3">

				<xsl:apply-templates select="//STATS" />  
         </xsl:when>

          <xsl:when test="$display-view = 21">
<!-- FIXS table -->
				<xsl:apply-templates select="//FIXLST"  mode="single-fix"/>  

				<xsl:variable name = "nFixLst">
				<FIXS>
						<xsl:apply-templates select="FIXLST[R[@h=$this-fix]]"  mode="combo-view"/>  
				</FIXS>
				
				</xsl:variable>

				<!--xsl:apply-templates select="msxsl:node-set($nFixLst)/FIXS" mode="single-fix" /-->  
         </xsl:when>
      
         <xsl:otherwise>
            <stuff>
            </stuff>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

<!-- Single Fixture  #################################################################################################### -->

   <xsl:template match="FIXLST" mode="single-fix">
   
      <table width="100%" cellspacing="0" cellpadding="0" border="0"  style="display:block">
  		<xsl:apply-templates select="FIX[@h=$this-fix]" mode="single-fix" />
      </table>
    </xsl:template>
    
   <xsl:template match="FIX" mode="single-fix">
<xsl:variable name = "gDay" select = "@d" />
<xsl:variable name = "Day" select = "key('getDay',$gDay)" />
<xsl:variable name = "Hid" select = "@h" />
<xsl:variable name = "HT" select = "key('getTeam',$Hid)" />
<xsl:variable name = "Aid" select = "@a" />
<xsl:variable name = "AT" select = "key('getTeam',$Aid)" />
        <tr>     
         	<td width="16px">         	
         	<xsl:if test = "$prev-fix != 0">
          		<IMG src="image/prev.gif" style="cursor:hand" onclick="select_fixture({$prev-fix},workhere2,fixtable2)" height="16px" width="16px"/>
        	</xsl:if>
        	</td>
 			<td width="351px" style="color:white;font-size:14pt;text-align:right"><xsl:value-of select="$HT/@nm" /></td>
 			<td width="6px"><IMG src="image/1pixel.gif" width="6px" height="1px"/></td>
  			<td width="351px" style="color:white;font-size:14pt"><xsl:value-of select="$AT/@nm" /></td>        	
            <td width="16px" style="text-align:right">
         	<IMG src="image/next.gif" style="cursor:hand" onclick="select_fixture({$next-fix},workhere2,fixtable2)" height="16px" width="16px"/>
         	</td>
 		</tr>
  		
 		<tr>
 			<td><xsl:value-of select="$prev-fix + 1" /></td>
          	<td class="Phonelist"   style="text-align:right">
		
 		   <xsl:apply-templates select="$HT/R" mode="fixturevisual" >
            	<xsl:sort select="position()" data-type="number" order="descending" />
            	<xsl:with-param name="max" select="@htx" />
            	<xsl:with-param name="cnt" select="count($HT/R)" />
            	<xsl:with-param name="iamhome" select="1" />
             	<xsl:with-param name="cellwidth" select="351" />
      					<xsl:with-param name="height" select="20" />
           </xsl:apply-templates>

 			</td>
 			<td></td>
 			<td>
 		   <xsl:apply-templates select="$AT/R" mode="fixturevisual" >
            	<xsl:with-param name="max" select="@atx" />
            	<xsl:with-param name="cnt" select="count($AT/R)" />
            	<xsl:with-param name="iamhome" select="0" />
             	<xsl:with-param name="cellwidth" select="351" />
      					<xsl:with-param name="height" select="20" />
           </xsl:apply-templates>
 			
 			</td>
  			<td><xsl:value-of select="@totv" /></td>
		</tr>


<!--tr><td colspan="4">
       		<table width="100%" cellspacing="0" cellpadding="0" border="0"  style="display:block">
         <xsl:apply-templates select="TM" mode="table" />
			</table>
</td>
</tr-->
	<tr>
		<td colspan="2">
      		<table width="100%" cellspacing="0" cellpadding="0" border="1"  style="display:block">
 			<xsl:apply-templates select="$HT" mode="single-fix" />
			</table>
		</td>
 			<td></td>
		<td colspan="2">
      		<table width="100%" cellspacing="0" cellpadding="0" border="1"  style="display:block">
 			<xsl:apply-templates select="$AT" mode="single-fix" />
			</table>
		</td>
	</tr>
    </xsl:template>
    

    <xsl:template match="TM" mode="single-fix">
<xsl:apply-templates select="R" mode="single-fix" />

    </xsl:template>
    
     <xsl:template match="R" mode="single-fix">     
	<tr>
		<td><xsl:value-of select="@v" /></td>
		<td><xsl:value-of select="@ds" /></td>
		<td><xsl:value-of select="@oc" /></td>
		<td><xsl:value-of select="@op" /></td>
		<td><xsl:value-of select="@f" /> - <xsl:value-of select="@g" /></td>
	</tr>

    </xsl:template>


<!-- Stats #################################################################################################### -->
   <xsl:template match="STATS">
    <DIV id="workhere1" class="workhere">
  	<xsl:apply-templates select="stat" mode="result-type"/>
  	</DIV>
   </xsl:template>
   
   
   
   
  <xsl:template match="stat"  mode="result-type">
   
  <table cellspacing="0" cellpadding="0" border="1" >  
  	<tr>
   		<td style="text-align:center;height:16px">.
   		</td>
   		<xsl:apply-templates select="."/>
   		<xsl:apply-templates select="stat"/>
   		
   	</tr> 
   	<tr>
    	<td style="text-align:right;height:28px">Played</td>
    </tr> 
   	<tr>
    	<td style="text-align:right;height:28px">Home Win</td>
    </tr> 
   	<tr>
    	<td style="text-align:right;height:28px">Drawn</td>
    </tr> 
   	<tr>
    	<td style="text-align:right;height:28px">Away Win</td>
    </tr> 
  	
   	
   </table>
   </xsl:template>
   
   
   
   
   <xsl:template match="stat">
    		<td rowspan="5">
    		<IMG src="image/1pixel.gif" width="2px" height="30" />
    		</td>
  		<td rowspan="5">

   <table cellspacing="0" cellpadding="0" border="0" >  
   <tr>
   	<td colspan="3"  style="text-align:center;height:16px"><xsl:value-of select="@nm" />
   	</td>
   	</tr> 
   <tr>
   		<td style="text-align:center;height:28px"><xsl:value-of select="@plyd" /></td>
   		<td style="text-align:center"></td>
   		<td style="text-align:center;height:28px"></td>
	</tr>

	<xsl:variable name = "hw" select = "format-number(@hw * 100 div @plyd,'0')" />   
	<tr>
   		<td style="text-align:center"><xsl:value-of select="@hw" /></td>
   		<td style="text-align:left;height:28px"><IMG src="image/wpix.gif" width="{$hw * 1.6}px" height="22" /></td>
   		<td style="text-align:center"><xsl:value-of select="$hw" />%</td>
	</tr>
	
	<xsl:variable name = "dr" select = "format-number(@dr * 100 div @plyd,'0')" />   
	<tr>
   		<td style="text-align:center"><xsl:value-of select="@dr" /></td>
   		<td style="text-align:left;height:28px;width:100px"><IMG src="image/dpix.gif" width="{$dr * 1.6}px" height="22" /></td>
   		<td style="text-align:center"><xsl:value-of select="$dr" />%</td>
	</tr>
	
	<xsl:variable name = "aw" select = "format-number(@aw * 100 div @plyd,'0')" />   
	<tr>
   		<td style="text-align:center"><xsl:value-of select="@aw" /></td>
   		<td style="text-align:left;height:28px"><IMG src="image/lpix.gif" width="{$aw * 1.6}px" height="22" /></td>
   		<td style="text-align:center"><xsl:value-of select="$aw" />%</td>
	</tr>
	
	</table>
	  		</td>
 
   </xsl:template>

<!-- Table #################################################################################################### -->
   <xsl:template match="LGES" mode="table">
       <xsl:param name="Results" />
  
  <DIV id="workhere1">          
 
   <table cellspacing="0" cellpadding="0" border="0" width="100%">
   
   <tr>
	<td align="center">
   <TABLE cellspacing="0" cellpadding="0" border="0" id="pagetab">  
    		<xsl:choose>
   			<xsl:when test="$page-view = 1">
  <TR>
	<TD id="tblge1" width="33%" class="datBtnSel">All</TD>
	<TD id="tblge2" onclick="PageChange(this,2)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)" class="datBtn">Home</TD>
	<TD id="tblge3" width="33%" onclick="PageChange(this,3)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)" class="datBtn">Away</TD>   
   </TR>
   			</xsl:when>
   			<xsl:when test="$page-view = 2">
  <TR>
	<TD id="tblge1" width="33%" onclick="PageChange(this,1)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)" class="datBtn">All</TD>
	<TD id="tblge2" class="datBtnSel">Home</TD>
	<TD id="tblge3" width="33%" onclick="PageChange(this,3)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)" class="datBtn">Away</TD>   
   </TR>
   			</xsl:when>
   		  
   			<xsl:otherwise>
    <TR>
	<TD id="tblge1" width="33%" onclick="PageChange(this,1)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)" class="datBtn">All</TD>
	<TD id="tblge2" onclick="PageChange(this,2)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)" class="datBtn">Home</TD>
	<TD id="tblge3" width="33%" class="datBtnSel">Away</TD>   
   </TR>
 			</xsl:otherwise>
   		</xsl:choose>  
    
    </TABLE>
  

 
   <table cellspacing="0" cellpadding="0" border="0" width="100%">
   
   <tr>
   	<td style="text-align:right;padding-right:20px">
   
   	<table cellspacing="0" cellpadding="0" border="0" style="font-sixe:XX-Small">
		<xsl:call-template name = "table-title-row" />
		<xsl:variable name = "unsorted">
		          <xsl:apply-templates select="TM" mode="table" >	
            	<xsl:with-param name="lge-num" select="number($page-view)" />
				</xsl:apply-templates>
		</xsl:variable>
		<xsl:apply-templates select="msxsl:node-set($unsorted)/tr" mode="sortthis" >
		      	<xsl:sort select="td[number($tableSort1)]" data-type="number" order="descending" />
		      	<xsl:sort select="td[number($tableSort2)]" data-type="number" order="descending" />
		      	<xsl:sort select="td[number($tableSort3)]" data-type="number" order="descending" />
		</xsl:apply-templates>
       <tr style="visibility:hidden">
       	<td class="Phonelist">99</td>
        	<td class="Phonelist">99</td>
 
        	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">100</td>
     	
       	</tr>
   	</table>
   	</td>
   	<td style="text-align:left;padding-left:20px">
   	<table cellspacing="0" cellpadding="0" border="0">
		<xsl:call-template name = "table-title-row" />
		<xsl:variable name = "unsorted1">
		          <xsl:apply-templates select="TM" mode="table" >	
            	<xsl:with-param name="lge-num" select="number($page-view + 3)" />
				</xsl:apply-templates>
		</xsl:variable>
		<xsl:apply-templates select="msxsl:node-set($unsorted1)/tr" mode="sortthis" >
		      	<xsl:sort select="td[number($tableSort1)]" data-type="number" order="descending" />
		      	<xsl:sort select="td[number($tableSort2)]" data-type="number" order="descending" />
		      	<xsl:sort select="td[number($tableSort3)]" data-type="number" order="descending" />
		</xsl:apply-templates>
       <tr style="visibility:hidden">
       	<td class="Phonelist">99</td>
        	<td class="Phonelist">99</td>
 
        	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">99</td>
       	<td class="Phonelist">100</td>
     	
       	</tr>
   	</table>
  	
   	</td>
   	</tr>
   	</table>
    	</td>
   	</tr>
   	</table>
  	 </DIV>
   </xsl:template>
   
   
 
   
   
   
    <xsl:template match="tr" mode="sortthis">
    	<tr id="R{td[2]}">
	    <xsl:if test = "@id &lt; 4">
	   		<xsl:attribute  name = "id" >L<xsl:value-of select="td[2]" /></xsl:attribute>
	   </xsl:if>

          <td class="Phonelist" onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            <xsl:value-of select="position()" />
         </td>
   		
   		<xsl:copy-of select = "td[position() != 1]"/>
    	</tr>
  </xsl:template>
  
 
   <xsl:template match="TM" mode="table">
      <xsl:param name="lge-num" />

      <tr id="{$lge-num}">
         <td class="Phonelist" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
         </td>
         <td class="Phonelist" style="text-align:right" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
            <xsl:value-of select="@nm" />
         </td>

        <xsl:call-template name="table">
            <xsl:with-param name="lge" select="RC[$lge-num]" />
         </xsl:call-template>
 
      </tr>
   </xsl:template>

   <xsl:template name="table">
      <xsl:param name="lge" />


      <td class="Phonelist" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
         <xsl:value-of select="$lge/@P" />
      </td>

      <td class="Phonelist" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
         <xsl:value-of select="$lge/@W" />
      </td>

      <td class="Phonelist" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
         <xsl:value-of select="$lge/@D" />
      </td>

      <td class="Phonelist" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
         <xsl:value-of select="$lge/@L" />
      </td>

      <td class="Phonelist" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
         <xsl:value-of select="$lge/@F" />
      </td>

      <td class="Phonelist" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
         <xsl:value-of select="$lge/@A" />
      </td>

      <td class="Phonelist" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
         <xsl:value-of select="$lge/@F - $lge/@A" />
      </td>

      <td class="Phonelist" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
         <xsl:value-of select="$lge/@pts" />
      </td>
      <td class="Phonelist" onmouseover="select_tablerow(this,'{$row-highlight}')" onmouseout="select_tablerow(this,'{$row-normal}')">
         <xsl:value-of select="$lge/@PC" />
      </td>

   </xsl:template>


    <xsl:template name="table-title-row">
      <tr>
         <td  class="datBtn" colspan="2" style="cursor:default">Team</td>

  
         <td class="datBtn" onclick="sort_thisTable(this,3)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)">
	    <xsl:if test = "$tableSort1 = 3">
	   		<xsl:attribute  name = "class" >datBtnSel</xsl:attribute>
	   </xsl:if>
        P</td>

         <td class="datBtn" onclick="sort_thisTable(this,4)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)">
	    <xsl:if test = "$tableSort1 = 4">
	   		<xsl:attribute  name = "class" >datBtnSel</xsl:attribute>
	   </xsl:if>
         W</td>

         <td class="datBtn" onclick="sort_thisTable(this,5)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)">
	    <xsl:if test = "$tableSort1 = 5">
	   		<xsl:attribute  name = "class" >datBtnSel</xsl:attribute>
	   </xsl:if>
         D</td>

         <td class="datBtn" onclick="sort_thisTable(this,6)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)">
	    <xsl:if test = "$tableSort1 = 6">
	   		<xsl:attribute  name = "class" >datBtnSel</xsl:attribute>
	   </xsl:if>
         L</td>

         <td class="datBtn" onclick="sort_thisTable(this,7)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)">
	    <xsl:if test = "$tableSort1 = 7">
	   		<xsl:attribute  name = "class" >datBtnSel</xsl:attribute>
	   </xsl:if>
         F</td>

         <td  class="datBtn" onclick="sort_thisTable(this,8)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)">
	    <xsl:if test = "$tableSort1 = 8">
	   		<xsl:attribute  name = "class" >datBtnSel</xsl:attribute>
	   </xsl:if>
         A</td>

         <td  class="datBtn" onclick="sort_thisTable(this,9)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)">
	    <xsl:if test = "$tableSort1 = 9">
	   		<xsl:attribute  name = "class" >datBtnSel</xsl:attribute>
	   </xsl:if>
         GD</td>

         <td  class="datBtn" onclick="sort_thisTable(this,10)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)">
	    <xsl:if test = "$tableSort1 = 10">
	   		<xsl:attribute  name = "class" >datBtnSel</xsl:attribute>
	   </xsl:if>
         Pts</td>

         <td  class="datBtn" onclick="sort_thisTable(this,11)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)">
         	    <xsl:if test = "$tableSort1 = 11">
	   		<xsl:attribute  name = "class" >datBtnSel</xsl:attribute>
	   </xsl:if>
%</td>

       </tr>
        </xsl:template>
  
<!--
#########################################################################################
-->

   <xsl:template match="FIXLST" mode="combo-view">
   <!--DIV id="pagetab"> 
   		
   		<xsl:choose>
   			<xsl:when test="$page-view = 1">
		<DIV id="fv1" onclick="PageChange(this,1)" style="left:2px" onmouseover="javascript:BtnHover(this)" onmouseout="javascript:BtnHover(this)" class="tabSel">As List</DIV>
		<DIV id="fv2" onclick="PageChange(this,2)" style="left:82px" onmouseover="javascript:BtnHover(this)" onmouseout="javascript:BtnHover(this)" class="tab">Visual</DIV>
   			</xsl:when>
   		  
   			<xsl:otherwise>
 		<DIV id="fv1" onclick="PageChange(this,1)" style="left:2px" onmouseover="javascript:BtnHover(this)" onmouseout="javascript:BtnHover(this)" class="tab">As List</DIV>
		<DIV id="fv2" onclick="PageChange(this,2)" style="left:82px" onmouseover="javascript:BtnHover(this)" onmouseout="javascript:BtnHover(this)" class="tabSel">Visual</DIV>
   			</xsl:otherwise>
   		</xsl:choose>  
   		
    </DIV-->

   <!--DIV id="workhere1" class="workhere" style="display:block">
   <xsl:if test = "$page-view = 2">
   		<xsl:attribute  name = "style" >display:none</xsl:attribute>
   </xsl:if>
      <table cellspacing="0" cellpadding="0" border="0" id="fixtable1" style="display:block">
         <tr>         
             <td width="10" style="display:none" >0</td>
           <td width="26" class="cap">Pos</td>
            <td width="30" class="cap">Dvn</td>
 
            <td width="100" class="cap">Date</td>

            <td width="36" class="cap">H</td>

            <td width="120" class="cap">Home Team</td>
            <td width="36" class="cap">D</td>

            <td width="120" class="cap">Away Team</td>

            <td width="36" class="cap">A</td>


            <td width="44" class="cap">VSc</td>
         </tr>

            <xsl:apply-templates select="FIX" mode="fixture" >
            <xsl:sort select="@totv" data-type="number" order="descending" />
         </xsl:apply-templates>
 
      </table>
 
   </DIV-->
   
   		<DIV id="workheresub" style="display:none">das</DIV>
  <DIV id="workhere2" class="workhere" style="display:block;top:0px">
   <!--xsl:if test = "$page-view = 1">
   		<xsl:attribute  name = "style" >display:none</xsl:attribute>
   </xsl:if-->
      <table cellspacing="0" cellpadding="0" border="0" id="fixtable2" style="display:block;">
         <tr>
                <td style="display:none" >0</td>
       
            <td class="datBtn" style="cursor:default">Pos</td>
            <td class="datBtn"    style="display:none" >Dvn</td>
            
            <xsl:choose>
         	<xsl:when test="$fixSort = 0">
              <td class="datBtn" onclick="sortFixLst(this,1)"  onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)"  colspan="2">Home Team</td>

            <td class="datBtn"  onclick="sortFixLst(this,2)"  onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)"  colspan="2">Away Team</td>

            <td class="datBtnSel"  onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)" >Sc</td>
            
           	
            	</xsl:when>
              
         	<xsl:when test="$fixSort = 1">
              <td class="datBtnSel"   onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)"  colspan="2">Home Team</td>

            <td class="datBtn"  onclick="sortFixLst(this,2)"  onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)"  colspan="2">Away Team</td>

            <td class="datBtn" onclick="sortFixLst(this,0)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)" >Sc</td>
            
           	
            	</xsl:when>
         	<xsl:when test="$fixSort = 2">
              <td class="datBtn" onclick="sortFixLst(this,1)"  onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)"  colspan="2">Home Team</td>

            <td class="datBtnSel"  onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)"  colspan="2">Away Team</td>

            <td class="datBtn"   onclick="sortFixLst(this,0)" onmouseover="javascript:datBtnHover(this)" onmouseout="javascript:datBtnHover(this)" >Sc</td>
            
           	
            	</xsl:when>
            </xsl:choose>
            
       </tr>

       <tr>
 <td colspan="7"><IMG scr="../../images/1pixel.gif" height="1" width="1"/>
 </td>
 </tr>
          
         <xsl:choose>
         	<xsl:when test="$fixSort = 0">
           <xsl:apply-templates select="FIX" mode="fixturevisual" >
            <xsl:sort select="@totv" data-type="number" order="descending" />
         </xsl:apply-templates>
         	</xsl:when>
           
         	<xsl:when test="$fixSort = 1">
           <xsl:apply-templates select="FIX" mode="fixturevisual" >
            <xsl:sort select="@htv" data-type="number" order="descending" />
         </xsl:apply-templates>
         	</xsl:when>
         	<xsl:when test="$fixSort = 2">
           <xsl:apply-templates select="FIX" mode="fixturevisual" >
            <xsl:sort select="@atv" data-type="number" order="descending" />
         </xsl:apply-templates>
         	</xsl:when>
         </xsl:choose>
         
         
          <tr  style="visibility:hidden">
                <td style="display:none" >0</td>
       
            <td class="Phonelist">Pos</td>
            <td class="Phonelist"  style="display:none">Dvn</td>
             <td width="256" class="Phonelist">&#160;</td>

            <td class="Phonelist">Home Team</td>

            <td class="Phonelist">Away Team</td>
             <td width="256" class="Phonelist">&#160;</td>

            <td class="Phonelist">Sc</td>
       </tr>
     </table>
 
   </DIV>
   

   </xsl:template>




<!-- Fixtures #################################################################################################### -->
 

   <xsl:template match="FIX" mode="fixture">

<xsl:variable name = "gDay" select = "@d" />
<xsl:variable name = "Day" select = "key('getDay',$gDay)" />
<xsl:variable name = "Hid" select = "@h" />
<xsl:variable name = "HT" select = "key('getTeam',$Hid)" />
<xsl:variable name = "Aid" select = "@a" />
<xsl:variable name = "AT" select = "key('getTeam',$Aid)" />

    <xsl:variable name="img" select="concat(translate(@r,'LDW','ldw'),'pix.gif')" />

      <tr style="cursor:hand" ondblclick="select_fixture({position()},workhere1,fixtable1)">
             <td width="10" style="display:none" ><xsl:value-of select="$HT/@id"/></td>
        <td class="Phonelist"  onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
        	<xsl:if test = "@r">        	
        	<xsl:attribute  name = "style" >background-image:url(image/<xsl:value-of select="$img" />)</xsl:attribute>
        	</xsl:if>
            <xsl:value-of select="position()"/>
         </td>
         <td class="Phonelist"  onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            <xsl:value-of select="$HT/@sid"/>
         </td>

         <td class="Phonelist"  onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            <xsl:value-of select="$Day/@d"/>
         </td>

         <td class="Phonelist"  onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            &#160;
         </td>


         <td class="Phonelist" style="text-align:right;padding-right:4px" onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            <xsl:value-of select="$HT/@nm" />
         </td>
         <td class="Phonelist"  onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            &#160;
         </td>

         <td class="Phonelist" style="text-align:left;padding-left:4px"  onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            <xsl:value-of select="$AT/@nm" />
         </td>

         <td class="Phonelist"  onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            &#160;
         </td>


         <td class="Phonelist"  onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            <xsl:value-of select="@totv" />
         </td>
      </tr>
   </xsl:template>


   <xsl:template match="FIX" mode="fixturevisual">

<xsl:variable name = "gDay" select = "@d" />
<xsl:variable name = "Day" select = "key('getDay',$gDay)" />
<xsl:variable name = "Hid" select = "@h" />
<xsl:variable name = "HT" select = "key('getTeam',$Hid)" />
<xsl:variable name = "Aid" select = "@a" />
<xsl:variable name = "AT" select = "key('getTeam',$Aid)" />

    <xsl:variable name="img" select="concat(translate(@r,'LDW','ldw'),'pix.gif')" />

      <tr style="cursor:hand" ondblclick="select_fixture({position()},workhere2,fixtable2)" id="fvrow{position()}">
              <td width="10" style="display:none" ><xsl:value-of select="$HT/@id"/></td>
        <td class="Phonelist"  onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">        	
        	<xsl:if test = "@r">        	
        	<xsl:attribute  name = "style" >background-image:url(image/<xsl:value-of select="$img" />)</xsl:attribute>
        	</xsl:if>
            <xsl:value-of select="position()"/>
         </td>
         <td class="Phonelist"  style="display:none">
            <xsl:value-of select="$HT/@sid"/>
         </td>

         <td class="Phonelist"   style="text-align:right" onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            <xsl:apply-templates select="$HT/R" mode="fixturevisual" >
            	<xsl:sort select="position()" data-type="number" order="descending" />
            	<xsl:with-param name="max" select="@htx" />
            	<xsl:with-param name="cnt" select="count($HT/R)" />
            	<xsl:with-param name="iamhome" select="1" />
             	<xsl:with-param name="cellwidth" select="256" />
           </xsl:apply-templates>
         </td>

         <td class="Phonelist" style="text-align:right;padding-right:4px" onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            <xsl:value-of select="$HT/@nm" />
         </td>

         <td class="Phonelist" style="text-align:left;padding-left:4px"  onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
            <xsl:value-of select="$AT/@nm" />
         </td>
         <td class="Phonelist" style="text-align:left" onmouseover="select_row(this,'{$row-highlight}')" onmouseout="select_row(this,'{$row-normal}')">
           <xsl:apply-templates select="$AT/R" mode="fixturevisual" >
            	<xsl:with-param name="max" select="@atx" />
           	<xsl:with-param name="cnt" select="count($AT/R)" />
            	<xsl:with-param name="iamhome" select="0" />
            	<xsl:with-param name="cellwidth" select="256" />
            </xsl:apply-templates>
         </td>
 

         <td class="Phonelist"   style="display:block">
            <xsl:value-of select="@totv" />
         </td>
      </tr>
   </xsl:template>

   <xsl:template match="R" mode="fixturevisual">
      <xsl:param name="max" />
      <xsl:param name="cnt" />
      <xsl:param name="iamhome" />
      <xsl:param name="cellwidth" />
    <xsl:param name="height">12</xsl:param>
		<xsl:variable name = "Opposition" select = "key('getTeam',@o)" />
     
      <xsl:variable name = "fwidth" select = "format-number(floor((($cellwidth - $cnt) * @fval div $max)+1),'0')" />
      <xsl:variable name = "vwidth" select = "format-number(floor((($cellwidth - $cnt) * @vval div $max)+1),'0')" />
      
      <xsl:variable name = "op" select = "concat(concat(concat(concat(concat(concat(concat($Opposition/@nm, ' ('),@f),' '),@g),') ['),@v),']')" />
     
      <xsl:choose>
      	<xsl:when test="$iamhome = 1">
      		
      		<xsl:choose>
      			<xsl:when test="@v = 'H'">      				
      				<xsl:call-template name = "vimg" >
      					<xsl:with-param name="oc" select="@r" />
      					<xsl:with-param name="width" select="$fwidth" />
      					<xsl:with-param name="op" select="$op" />
      					<xsl:with-param name="height" select="$height" />
      				</xsl:call-template>
      			</xsl:when>
      		  
      			<xsl:otherwise>
      				<xsl:call-template name = "vimg" >
      					<xsl:with-param name="oc" select="@r" />
      					<xsl:with-param name="width" select="$vwidth" />
      					<xsl:with-param name="op" select="$op" />
      					<xsl:with-param name="height" select="$height" />
      				</xsl:call-template>
      			</xsl:otherwise>
      		</xsl:choose>
      	
      	</xsl:when>
        
      	<xsl:otherwise>
       		<xsl:choose>
      			<xsl:when test="@v = 'H'">
      				<xsl:call-template name = "vimg" >
      					<xsl:with-param name="oc" select="@r" />
      					<xsl:with-param name="width" select="$vwidth" />
      					<xsl:with-param name="op" select="$op" />
      					<xsl:with-param name="height" select="$height" />
      				</xsl:call-template>
      			
      			</xsl:when>
      		  
      			<xsl:otherwise>
      				<xsl:call-template name = "vimg" >
      					<xsl:with-param name="oc" select="@r" />
      					<xsl:with-param name="width" select="$fwidth" />
      					<xsl:with-param name="op" select="$op" />
      					<xsl:with-param name="height" select="$height" />
      				</xsl:call-template>
      			</xsl:otherwise>
      		</xsl:choose>
     	 
      	</xsl:otherwise>
      </xsl:choose>
      
<!--xsl:value-of select="@vval" /-->
 	
   </xsl:template>
   
   
   <xsl:template name="vimg">
       <xsl:param name="oc" />
      <xsl:param name="width" />
    <xsl:param name="op" />
    <xsl:param name="height" />
    
    <xsl:variable name="img" select="concat(translate($oc,'LDW','ldw'),'pix.gif')" />
<IMG src="image/{$img}" height="{$height}px" width="{$width}px" alt="{$op}"/>

<IMG src="image/1pixel.gif" height="1px" width="1px"/>
  
   </xsl:template>
<!-- ############################################################################################################# -->













   
   



</xsl:stylesheet>


