<?xml version="1.0" encoding="iso-8859-1"?>
<!--                Copyright (c) 2008, Lexmark International, Inc.
        THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY
           INFORMATION WHICH IS THE PROPERTY OF LEXMARK INTERNATIONAL, INC.
      ANY DISCLOSURE, USE, OR REPRODUCTION, WITHOUT WRITTEN AUTHORIZATION FROM
                 LEXMARK INTERNATIONAL, INC., IS STRICTLY PROHIBITED
-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>
  <!--==========================================================================
  =  Localization 
  ===========================================================================-->
  <!-- Resource path -->
  <xsl:variable name="resPath" select="/deviceDashboard/resourcePath" />
  
  <!-- Variable holding the localization document. -->
  <xsl:variable name="local_doc" select="document(concat($resPath, 'strings.xml'))" />

  <!-- Callable template for replacing a stringID with a localized string.
       params:
         stringID   The ID of the localized string.
  -->
  <xsl:template name="InsertLocalizedString">
    <xsl:param name="stringID" />
    <xsl:for-each select="$local_doc">
      <xsl:value-of select="key('StringLookup', $stringID)" />
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="InsertLocalizedNoHotKeyString">
    <xsl:param name="stringID" />
    <xsl:for-each select="$local_doc">
      <xsl:variable name="wholestring">
        <xsl:value-of select="key('StringLookup', $stringID)" />  
      </xsl:variable>
      <!--Get hotkey position from reource.xml-->
      <xsl:variable name="hotkeyposfromresource">
        <xsl:if test="string-length(substring-after($wholestring,'&amp;')) != 0">
          <xsl:value-of select="string-length(substring-before($wholestring,'&amp;')) + 1"/>
        </xsl:if>
        <xsl:if test="string-length(substring-after($wholestring,'&amp;')) = 0">
          <xsl:value-of select="string-length(substring-before($wholestring,'&amp;'))"/>
        </xsl:if>
      </xsl:variable>
      <xsl:if test="$hotkeyposfromresource != '0'"> <!--If hotkey is there-->
        <xsl:variable name="string1">
          <xsl:value-of select="substring($wholestring,1,$hotkeyposfromresource - 1)" />
        </xsl:variable>
        <xsl:variable name="string2">
          <xsl:value-of select="substring($wholestring,$hotkeyposfromresource + 1)" />
        </xsl:variable>
        <xsl:value-of select="concat($string1,$string2)" /> <!--If no hotkey-->
      </xsl:if>
      <xsl:if test="$hotkeyposfromresource = '0'">
        <xsl:value-of select="$wholestring" />
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

  
  <!-- Key for performing lookups on the string table -->
  <xsl:key name="StringLookup" match="StringTable/strings/string" use="@id" />

  <!-- readingOrder variable: should contain either 'rtl' or 'ltr' -->
  <xsl:variable name="readingOrder">
    <xsl:value-of select="$local_doc/StringTable/readingorder/@value"/>
  </xsl:variable>

  <!-- language ID -->
  <xsl:variable name="langID">
    <xsl:value-of select="$local_doc/StringTable/language/@id"/>
  </xsl:variable>

  <!-- alignWithReadingOrder variable: left for ltr, right for rtl -->
  <xsl:variable name="alignWithReadingOrder">
    <xsl:if test="$readingOrder = 'ltr'">
      <xsl:text>left</xsl:text>
    </xsl:if>
    <xsl:if test="$readingOrder = 'rtl'">
      <xsl:text>right</xsl:text>
    </xsl:if>
  </xsl:variable>

  <!-- alignAgainstReadingOrder variable: right for ltr, left for rtl -->
  <xsl:variable name="alignAgainstReadingOrder">
    <xsl:if test="$readingOrder = 'ltr'">
      <xsl:text>right</xsl:text>
    </xsl:if>
    <xsl:if test="$readingOrder = 'rtl'">
      <xsl:text>left</xsl:text>
    </xsl:if>
  </xsl:variable>

  <!-- imagePath variable: dependent on readingOrder -->
  <xsl:variable name="imagePath">
    <xsl:text>Images/</xsl:text>
    <xsl:value-of select="$readingOrder"/>
    <xsl:text>/</xsl:text>
  </xsl:variable>
  
  <!--==========================================================================
  =  Screen generation 
  ===========================================================================-->
  
  <!-- Config XML structure -->
  <xsl:template match="/deviceDashboard">
    <!-- Set up the basic HTML structure -->
    <html>
      <head>
        <title>
          <xsl:call-template name="InsertLocalizedString">
            <xsl:with-param name="stringID">DocTitle</xsl:with-param>
          </xsl:call-template>
        </title>
        <base>
          <xsl:attribute name="href">
            <xsl:value-of select="$resPath"/>
          </xsl:attribute>
        </base>
        <link type="text/css" rel="StyleSheet" href="dashboard.css" />
        <script type="text/javascript" src="dashboard.js"></script>
      </head>
      <!-- Disable drag & drop -->
      <body ondragstart="javascript:return false;" onload="javascript:this.focus();javascript:this.onloaded()">
        <!-- If an ogreIndex was specified, add an onload handler to show the 
             appropriate element. -->
        <xsl:if test="/deviceDashboard/ogreIndex">
          <xsl:attribute name="onload">
            <xsl:text>javascript:showOgreControl(</xsl:text>
            <xsl:value-of select="/deviceDashboard/ogreIndex"/>
            <xsl:text>);</xsl:text>
          </xsl:attribute>
        </xsl:if>
        <!-- Generate the actual layout -->
        <!-- Apply document level RTL / LTR -->
        <xsl:attribute name="dir">
          <xsl:value-of select="$readingOrder" />
        </xsl:attribute>
        <!-- Insert the header -->
        <xsl:apply-templates select="header"/>
        <!-- Insert the task areas -->
        <xsl:apply-templates select="content"/>
      </body>
    </html>
  </xsl:template>

  <!-- Header portion of the screen. -->
  <xsl:template match="header">
    <span class="header">
      <xsl:attribute name="style">
        <xsl:text>background-image:url(</xsl:text>
        <xsl:value-of select="$imagePath"/>
        <xsl:value-of select="@image"/>
        <xsl:text>);</xsl:text>
      </xsl:attribute>
    </span>
    <!-- Device image -->
    <xsl:variable name="imagename">
      <xsl:value-of select="../device/@image"/>
    </xsl:variable>
    <xsl:if test="$imagename != ''">
    <span>
      <xsl:attribute name="class">
        <xsl:text>device-</xsl:text>
        <xsl:value-of select="$readingOrder" />
      </xsl:attribute>
      <img>
        <xsl:attribute name="src">
          <xsl:value-of select="$imagePath"/>
          <xsl:value-of select="../device/@image"/>
        </xsl:attribute>
      </img>
    </span>  
    </xsl:if>
    <!-- Printer list -->
    <span>
      <xsl:attribute name="class">
        <xsl:text>printer-</xsl:text>
        <xsl:value-of select="$readingOrder" />
      </xsl:attribute>
      <xsl:apply-templates select="../printerList" />
    </span>
    <span id="breadtrail">
      <xsl:attribute name="class">
        <xsl:text>back-</xsl:text>
        <xsl:value-of select="$readingOrder" />
      </xsl:attribute>
      <xsl:call-template name="back-link">
      </xsl:call-template>
    </span>
  </xsl:template>

  <!-- Generate a combo box from the printer list, including the selected item and all necessary 
       javascript hooks. -->
  <xsl:template match="printerList">
    <select class="printer-select">
      <xsl:attribute name="onchange">
        <xsl:text>javascript:onPrinterSelected(this.options[this.selectedIndex].id);</xsl:text>
      </xsl:attribute>
      <xsl:for-each select="printer">
        <option>
          <xsl:attribute name="id">
            <xsl:value-of select="@id"/>
          </xsl:attribute>
          <xsl:if test="@selected">
            <xsl:attribute name="selected" />
          </xsl:if>
          <xsl:if test="$readingOrder = 'rtl'">
            <xsl:text>&#x202A;</xsl:text>
          </xsl:if>
          <xsl:variable name="printobjectlength">
            <xsl:value-of select="string-length(@name)"/>
          </xsl:variable>
          <xsl:choose>
            <xsl:when test="$printobjectlength >= 92">
              <xsl:variable name="newsubstring">
                <xsl:value-of select="substring(@name,1,88)"/>
              </xsl:variable>
              <xsl:value-of select="concat($newsubstring,'...')"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="@name"/>
            </xsl:otherwise>
          </xsl:choose>
        </option>
      </xsl:for-each>
    </select>
    <br />
  </xsl:template>
  
  <xsl:template match="task">
    <table class="content">
      <!-- Insert the primary task group (big buttons). -->
      <xsl:apply-templates mode="main-area" select="taskGroup[@priority=0]" />
      <!-- Vertical padding space. -->
      <div class="main-secondary-spacer"></div>
    </table>
  </xsl:template>
  <!-- Content portion of the screen. Includes all tasks. -->
  <xsl:template match="content">
    <div class="content">
      <!-- Insert the primary task group (big buttons). <xsl:with-param name="stringID"><xsl:value-of select="@name"/></xsl:with-param>
      <xsl:apply-templates mode="main-area" select="taskGroup[@mainscreen=0]" />-->
      <div class="main-secondary-spacer"></div>
      <table style="width:100%;" cellspacing="0">
        <xsl:variable name="testvar">
          <xsl:value-of select="count(taskGroup[@priority=0])"/>
        </xsl:variable>
        <!--<xsl:value-of select="$testvar"/>-->
        <xsl:for-each select="taskGroup[@priority=0]">
          <!--<td><xsl:value-of select="@name"/></td>-->
          <xsl:variable name="pos" select="position() mod 2"/>
          <xsl:choose>
            <xsl:when test="$pos != 1">
              <td>
                <xsl:call-template name="screen-button">
                  <xsl:with-param name="tasks">
                    <xsl:value-of select="."/>
                  </xsl:with-param>
                </xsl:call-template>
              </td>
              <tr>
                <td class="main-secondary-spacer"></td>
              </tr>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="@name != 'BlankPagedeName' and @name != 'DowloadPageName'">
                <td>
                  <xsl:call-template name="screen-button"></xsl:call-template>
                </td>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:if test="@name = 'BlankPagedeName'">
                    <td>
                      <xsl:call-template name="blank-page"></xsl:call-template>
                    </td>
                  </xsl:if>
                  <xsl:if test="@name = 'DowloadPageName'">
                    <td>
                      <xsl:call-template name="download-page"></xsl:call-template>
                    </td>
                  </xsl:if>
                </xsl:otherwise>
              </xsl:choose>
              
            </xsl:otherwise>
            
          </xsl:choose>
        </xsl:for-each>
        <xsl:for-each select="taskGroup[@priority=1]">
          <xsl:variable name="pos" select="(position() + $testvar) mod 2"/>
          <td valign="top">
            <xsl:call-template name="task-button"></xsl:call-template>
          </td>
          <xsl:if test="$pos = 0">
            <tr>
              <td class="main-secondary-spacer"></td>
            </tr>
          </xsl:if>
        </xsl:for-each>
      </table>
    </div>
  </xsl:template>

  <!-- Content portion of the screen. Includes all tasks. -->
  <xsl:template match="task | taskGroup" mode="screenbutton">
    <xsl:call-template name="screen-button"></xsl:call-template>
  </xsl:template>
 
  <!--SECTION FOR BREAD TRAIL. -->
  <xsl:template match="breadtrail">
    <table cellspacing="0" cellpadding="0">
      <tr>
        <td class="link-column">
          <xsl:call-template name="back-link">
          </xsl:call-template>
        </td>
        <td class="link-column-spacer"></td>
        <td class="link-column">
          <xsl:call-template name="InsertLocalizedString">
            <xsl:with-param name="stringID"><xsl:value-of select="@category"/></xsl:with-param>
          </xsl:call-template>
        </td>
      </tr>
    </table>
  </xsl:template>
  
  <xsl:template name="back-link">
    <table cellspacing="0" cellpadding="0">
      <tr>
        <td>
     <a>
      <xsl:attribute name="href">
        <xsl:text>javascript:onBackClick();</xsl:text>
      </xsl:attribute>
       <xsl:call-template name="InsertLocalizedString">
         <xsl:with-param name="stringID"><xsl:value-of select="back-link/@name"/></xsl:with-param>
      </xsl:call-template>
     </a>
        </td>
        <td class="bread-spacer"></td>
        <td><xsl:text>|</xsl:text></td>
        <td class="bread-spacer"></td>
        <td id="breadcategory" class="link-column">
          <xsl:call-template name="InsertLocalizedString">
            <xsl:with-param name="stringID"><xsl:value-of select="back-link/@category"/></xsl:with-param>
          </xsl:call-template>
        </td>
      </tr>
      </table>
  </xsl:template>
  
  <xsl:template match="task" mode="main-area">
    <!-- Title text & secondary tasks (links) -->
    
    <!-- Up to two rows of big buttons-->
    <table style="width:100%;" cellspacing="0">
      <tr>
        <xsl:call-template name="task-link" /> 
      </tr>
      <tr class="rbb-vertical-separator">
        <td></td>
      </tr>
      <!-- <tr>
        <xsl:apply-templates select="task[@priority=0] | taskGroup[@priority=0]" mode="task-button">
        <xsl:with-param name="row">1</xsl:with-param>
        </xsl:apply-templates>
        </tr> -->
    </table>
  </xsl:template>

  <!-- Links for the upper right of the main task area.-->
  <xsl:template match="task" mode="primary-group-task-link">
    <td style="vertical-align:baseline;" class="primary-group-task-link">
      <nobr>
        <xsl:call-template name="task-link" />
      </nobr>
    </td>
    <!-- Spacer, placed after all but the last link -->
    <xsl:if test="position() != last()">
      <td style="vertical-align:text-bottom;">
        <div class="pgtl-separator"></div>
      </td>
    </xsl:if>
  </xsl:template>

  <!-- Task link, including javascript hooks and an optional icon. 
       params: 
         showIcon  'no' to hide the icon, anything else to show it. Defaults to 'no'
  -->
  <xsl:template name="task-link">
    <xsl:param name="showIcon">no</xsl:param>
    <xsl:param name="maxwidth"></xsl:param>
    <a class="test">
      <xsl:variable name="strname">
        <xsl:call-template name="InsertLocalizedNoHotKeyString">
          <xsl:with-param name="stringID">
            <xsl:value-of select="@name"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:variable>
      <xsl:attribute name="Title">
        <xsl:value-of select="$strname"/>
      </xsl:attribute>
      <xsl:attribute name="href">
        <xsl:text>javascript:onTaskClick('</xsl:text>
        <xsl:value-of select="@id"/>
        <xsl:text>');</xsl:text>
      </xsl:attribute>
      <xsl:if test="$showIcon != 'no' and @image">
        <img>
          <xsl:attribute name="src">
            <xsl:value-of select="$imagePath"/>
            <xsl:value-of select="@image"/>
          </xsl:attribute>
          <xsl:attribute name="class">
            <xsl:text>task-link-image-</xsl:text>
            <xsl:value-of select="$readingOrder"/>
          </xsl:attribute>
        </img>
      </xsl:if>
      <xsl:variable name="strlength">
        <xsl:value-of select="string-length($strname)"/>
      </xsl:variable>
      <xsl:variable name="maxstrlength">
        <xsl:value-of select="$maxwidth - 3"/>
      </xsl:variable>
      
      <xsl:choose>
        <xsl:when test="$strlength > $maxwidth">
          <xsl:variable name="newsubstring">
            <xsl:value-of select="substring($strname,1,$maxstrlength)"/>
          </xsl:variable>
          <xsl:value-of select="concat($newsubstring,'...')"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$strname"/>
        </xsl:otherwise>
      </xsl:choose>
    </a>
  </xsl:template>
  
  <!-- A row of big buttons.
       params: 
         row          The current row number - used to calculate which tasks to show.
         tasksPerRow  The number of tasks to show per row. Defaults to 2.
  -->
  <xsl:template match="task | taskGroup" mode="task-button">
    <xsl:param name="row" />
    <xsl:param name="tasksPerRow">2</xsl:param>
    <xsl:variable name="min" select="$row * $tasksPerRow"/>
    <xsl:variable name="max" select="($row + 1) * $tasksPerRow"/>
    <xsl:if test="(position() &gt; $min) and (position() &lt;= $max)">
      <td class="rbb-column">
        <xsl:choose>
          <xsl:when test="name() = 'task'">
            <xsl:call-template name="task-button" />           
          </xsl:when>
        </xsl:choose>
      </td>
      <!-- Spacer, placed after all but the last button -->
      <xsl:if test="position() != (($row + 1) * $tasksPerRow)">
        <td class="rbb-separator"></td>
      </xsl:if>
    </xsl:if>
  </xsl:template>

  <!-- A big button. Includes all javascript hooks for behavior.
       params: 
         isMenu   'no' indicates a task button, anything else indicates this is
                  a menu button. Defaults to 'no'
  -->
  <xsl:template name="task-button">
    <xsl:param name="isMenu">no</xsl:param>
    <button>
      <xsl:variable name="ButtonName">
        <xsl:call-template name="InsertLocalizedString">
          <xsl:with-param name="stringID">
            <xsl:value-of select="@name"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:variable>
      <!--Get hotkey position from reource.xml-->
      <xsl:variable name="hotkeyposfromresource">
        <xsl:if test="string-length(substring-after($ButtonName,'&amp;')) != 0">
          <xsl:value-of select="string-length(substring-before($ButtonName,'&amp;')) + 1"/>
        </xsl:if>
        <xsl:if test="string-length(substring-after($ButtonName,'&amp;')) = 0">
          <xsl:value-of select="string-length(substring-before($ButtonName,'&amp;'))"/>
        </xsl:if>
      </xsl:variable>
      <xsl:if test="$hotkeyposfromresource != '0'">
        <xsl:attribute name="ACCESSKEY">
          <xsl:value-of select="substring($ButtonName,$hotkeyposfromresource+1,1)"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:attribute name="class">
        <xsl:text>rbb </xsl:text>
        <!-- Add class 'text-rtl' or 'text-ltr' -->
        <xsl:value-of select="concat('text-', $readingOrder)"/>
        <xsl:if test="@enabled != 'true'">
          <xsl:text> rbb-disabled</xsl:text>
        </xsl:if>
      </xsl:attribute>
      <xsl:attribute name="style">
        <xsl:text>background-image:url(</xsl:text>
        <xsl:value-of select="$imagePath"/>
        <xsl:text>rbb324.jpg);</xsl:text>
      </xsl:attribute>
      <xsl:if test="@enabled != 'true'">
        <!-- Apply the 'disabled' attribute to prevent clicks and alter the 
             appearance of the button. -->
        <xsl:attribute name="disabled"/>
      </xsl:if>
      <xsl:attribute name="id">
        <xsl:value-of select="generate-id(.)"/>
      </xsl:attribute>
      <xsl:attribute name="onmouseover">
        <xsl:text>onRbbMouseOver('</xsl:text>
        <xsl:value-of select="generate-id(.)"/>
        <xsl:text>');</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="onmouseout">
        <xsl:text>onRbbMouseOut('</xsl:text>
        <xsl:value-of select="generate-id(.)"/>
        <xsl:text>');</xsl:text>
      </xsl:attribute>
      <xsl:choose>
        <xsl:when test="$isMenu = 'no'">
          <!-- Regular buttons get the standard onTaskClick handler -->
          <xsl:attribute name="onclick">
            <xsl:text>javascript:onTaskClick('</xsl:text>
            <xsl:value-of select="task/@id"/>
            <xsl:text>');document.body.focus();</xsl:text>
          </xsl:attribute>
        </xsl:when>
      </xsl:choose>
      <img>
        <xsl:attribute name="class">
          <xsl:value-of select="$readingOrder"/>
        </xsl:attribute>
        <xsl:attribute name="src">
          <xsl:value-of select="$imagePath"/>
          <xsl:value-of select="@image"/>
        </xsl:attribute>
      </img>
      <nobr>
        <span>
          <xsl:if test="$hotkeyposfromresource != '0'">
            <!--If there is a hotkey for this button-->
            <xsl:value-of select="substring($ButtonName,1,$hotkeyposfromresource - 1)"/>
            <U>
              <xsl:value-of select="substring($ButtonName,$hotkeyposfromresource + 1,1)"/>
            </U>
            <xsl:value-of select="substring($ButtonName,$hotkeyposfromresource + 2)"/>
          </xsl:if>
          <xsl:if test="$hotkeyposfromresource = '0'">
            <!--If there is no hotkey for this button-->
            <xsl:value-of select="$ButtonName"/>
          </xsl:if>
        </span>
      </nobr>
      <small>
        <xsl:call-template name="InsertLocalizedString">
          <xsl:with-param name="stringID"><xsl:value-of select="@description"/></xsl:with-param>
        </xsl:call-template>
      </small>
    </button>
  </xsl:template>


  <xsl:template name="screen-button">
    <xsl:param name="isMenu">no</xsl:param>
    <xsl:param name="tasks"/>    
    <button>      
      <xsl:variable name="ButtonName">
        <xsl:call-template name="InsertLocalizedString">
          <xsl:with-param name="stringID">
            <xsl:value-of select="@name"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:variable>
      <!--Get hotkey position from reource.xml-->
      <xsl:variable name="hotkeyposfromresource">
        <xsl:if test="string-length(substring-after($ButtonName,'&amp;')) != 0">
          <xsl:value-of select="string-length(substring-before($ButtonName,'&amp;')) + 1"/>
        </xsl:if>
        <xsl:if test="string-length(substring-after($ButtonName,'&amp;')) = 0">
          <xsl:value-of select="string-length(substring-before($ButtonName,'&amp;'))"/>
        </xsl:if>
      </xsl:variable>
      <xsl:if test="$hotkeyposfromresource != '0'">
        <xsl:attribute name="ACCESSKEY">
          <xsl:value-of select="substring($ButtonName,$hotkeyposfromresource+1,1)"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:attribute name="class">
        <xsl:text>rbb </xsl:text>
        <!-- Add class 'text-rtl' or 'text-ltr' -->
        <xsl:value-of select="concat('text-', $readingOrder)"/>
        <xsl:if test="@enabled != 'true'">
          <xsl:text> rbb-disabled</xsl:text>
        </xsl:if>
      </xsl:attribute>
      <xsl:attribute name="style">
        <xsl:text>background-image:url(</xsl:text>
        <xsl:value-of select="$imagePath"/>
        <xsl:text>rbb324.jpg);</xsl:text>
      </xsl:attribute>
      <xsl:if test="@enabled != 'true'">
        <!-- Apply the 'disabled' attribute to prevent clicks and alter the 
          appearance of the button. -->
        <xsl:attribute name="disabled"/>
      </xsl:if>
      <xsl:attribute name="id">
        <xsl:value-of select="generate-id(.)"/>
      </xsl:attribute>
      <xsl:attribute name="onmouseover">
        <xsl:text>onRbbMouseOver('</xsl:text>
        <xsl:value-of select="generate-id(.)"/>
        <xsl:text>');</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="onmouseout">
        <xsl:text>onRbbMouseOut('</xsl:text>
        <xsl:value-of select="generate-id(.)"/>
        <xsl:text>');</xsl:text>
      </xsl:attribute>
      <xsl:choose>
        <xsl:when test="$isMenu = 'no'">
          <!-- Regular buttons get the standard onTaskClick handler -->
          <xsl:attribute name="onclick">
           <xsl:text>onScreenClick('</xsl:text>
            <xsl:value-of select="@name"/>
            <xsl:text>','</xsl:text>
            <xsl:call-template name="InsertLocalizedString">
              <xsl:with-param name="stringID"><xsl:value-of select="@category"/></xsl:with-param>
            </xsl:call-template>
            <xsl:text>');</xsl:text>                   
          </xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <!-- Menu buttons get the showMenu handler for click events -->
          <xsl:attribute name="onclick">
            <xsl:text>javascript:showMenu('</xsl:text>
            <xsl:value-of select="generate-id(.)"/>
            <xsl:text>');</xsl:text>
          </xsl:attribute>
          <!-- Menu buttons also get the drop down arrow -->
          <div>
            <xsl:attribute name="class">
              <xsl:value-of select="concat('arrow-', $readingOrder)"/>
            </xsl:attribute>
            <img>
              <xsl:attribute name="src">
                <xsl:value-of select="$imagePath"/>
                <xsl:text>dnarrow.jpg</xsl:text>
              </xsl:attribute>
            </img>
          </div>
          <!-- Register this menu button for use with Ogre -->
          <xsl:call-template name="ogre-registration">
            <xsl:with-param name="id" select="generate-id(.)"/>
            <xsl:with-param name="func_name">showMenu</xsl:with-param>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
      <img>
        <xsl:attribute name="class">
          <xsl:value-of select="$readingOrder"/>
        </xsl:attribute>
        <xsl:attribute name="src">
          <xsl:value-of select="$imagePath"/>
          <xsl:value-of select="@image"/>
        </xsl:attribute>
      </img>
      <nobr>
        <span>
          <xsl:if test="$hotkeyposfromresource != '0'">
            <!--If there is a hotkey for this button-->
            <xsl:value-of select="substring($ButtonName,1,$hotkeyposfromresource - 1)"/>
            <U>
              <xsl:value-of select="substring($ButtonName,$hotkeyposfromresource + 1,1)"/>
            </U>
            <xsl:value-of select="substring($ButtonName,$hotkeyposfromresource + 2)"/>
          </xsl:if>
          <xsl:if test="$hotkeyposfromresource = '0'">
            <!--If there is no hotkey for this button-->
            <xsl:value-of select="$ButtonName"/>
          </xsl:if>
        </span>
      </nobr>
      <small>
        <xsl:call-template name="InsertLocalizedString">
          <xsl:with-param name="stringID"><xsl:value-of select="@description"/></xsl:with-param>
        </xsl:call-template>
      </small>
    </button>
    <br></br>
    <table cellspacing="0">
      <tr>
        <xsl:variable name="category" select="@category"/>
        <xsl:variable name="groupname" select="@name"/>
        <xsl:variable name="taskcount" select="count(task)"/>    
        <xsl:for-each select="task">
          <xsl:variable name="pos" select="position()"/>
          <xsl:choose>
             <xsl:when test="$pos = 1">
              <td class="main-screen-link">
                <xsl:call-template name="task-link">
                   <xsl:with-param name="maxwidth">50</xsl:with-param>
                </xsl:call-template>
                <xsl:choose>
                  <xsl:when test="$pos != $taskcount">
                    <xsl:value-of select="'|'"/>
                  </xsl:when>
                </xsl:choose>
              </td>
             </xsl:when>
             <xsl:when test="$pos = 2">
               <td class="main-screen-link">
                 <xsl:variable name="lastlinkname">
                   <xsl:call-template name="InsertLocalizedNoHotKeyString">
                      <xsl:with-param name="stringID">
                          <xsl:value-of select="../task[1]/@name"/>
                      </xsl:with-param>
                   </xsl:call-template>
                 </xsl:variable>
                 <xsl:variable name="currentlinkname">
                   <xsl:call-template name="InsertLocalizedNoHotKeyString">
                      <xsl:with-param name="stringID">
                         <xsl:value-of select="@name"/>
                      </xsl:with-param>
                   </xsl:call-template>
                 </xsl:variable>
                    
                 <xsl:choose>
                    <xsl:when test="$pos != $taskcount"> <!--Check if more than 2 tasks are there in the group-->
                        <xsl:choose>
                            <xsl:when test="50 - (string-length($lastlinkname) + string-length($currentlinkname)) > 0"> <!--Draw the second link only if we can accommodate-->
                              <xsl:call-template name="task-link">
                                <xsl:with-param name="maxwidth">50 - string-length($lastlinkname)</xsl:with-param>
                              </xsl:call-template>
                              <xsl:value-of select="'|'"/>
                            </xsl:when>                                                  
                        </xsl:choose>
 
                       <!--We always need the More link as we have more than 2 tasks-->                       
                        <xsl:call-template name="MoreLink">
                          <xsl:with-param name="category">
                            <xsl:value-of select="$category"/>
                          </xsl:with-param>
                          <xsl:with-param name="groupname">
                            <xsl:value-of select="$groupname"/>
                          </xsl:with-param>
                        </xsl:call-template>
                        
                   </xsl:when>
                   
                   <xsl:otherwise> <!--Only two tasks are there in the group-->
                      <xsl:choose>  
                        <xsl:when test="50 - (string-length($lastlinkname) + string-length($currentlinkname)) > 0">
                           <xsl:call-template name="task-link">
                               <xsl:with-param name="maxwidth">50 - string-length($lastlinkname)</xsl:with-param>
                           </xsl:call-template>                   
                        </xsl:when>
                        <xsl:otherwise> <!--We need the More link though only two tasks are there as we could not accommodate the second link-->
                           <!--<xsl:value-of select="'|'"/>-->
                           <xsl:call-template name="MoreLink">
                              <xsl:with-param name="category">
                                <xsl:value-of select="$category"/>
                              </xsl:with-param>
                              <xsl:with-param name="groupname">
                                <xsl:value-of select="$groupname"/>
                              </xsl:with-param>
                           </xsl:call-template>
                        </xsl:otherwise>
                      </xsl:choose>
                   </xsl:otherwise>
                 </xsl:choose>
               </td>      
             </xsl:when>             
          </xsl:choose>
        </xsl:for-each>
      </tr>
    </table>
  </xsl:template>
  
  <!--blank-page template-->
  <xsl:template name="blank-page">
    <xsl:param name="isMenu">no</xsl:param>
    <xsl:param name="tasks"/>
    <FONT size="5">
      <xsl:call-template name="InsertLocalizedString">
        <xsl:with-param name="stringID">BlankPageDesc1</xsl:with-param>
      </xsl:call-template>
      <br/>
      <br/>
      <xsl:call-template name="InsertLocalizedString">
        <xsl:with-param name="stringID">BlankPageDesc2</xsl:with-param>
      </xsl:call-template>
      <br/>
      <br/>
      <xsl:call-template name="InsertLocalizedString">
        <xsl:with-param name="stringID">BlankPageDesc3OEM</xsl:with-param>
      </xsl:call-template>
      <xsl:text> </xsl:text>     
    </FONT>
  </xsl:template>
  

  <!--download-page template-->
  <xsl:template name="download-page">
    <xsl:param name="isMenu">no</xsl:param>
    <xsl:param name="tasks"/>
    <FONT size="5">
      <xsl:call-template name="InsertLocalizedString">
        <xsl:with-param name="stringID">DownloadPageDesc1</xsl:with-param>
      </xsl:call-template>
      <xsl:text> </xsl:text>
      <xsl:call-template name="task-link">
        <xsl:with-param name="maxwidth">50</xsl:with-param>
      </xsl:call-template>
      <xsl:text> </xsl:text>
      <xsl:call-template name="InsertLocalizedString">
        <xsl:with-param name="stringID">DownloadPageDesc2</xsl:with-param>
      </xsl:call-template>
      <br/>
      <br/>
      <xsl:call-template name="InsertLocalizedString">
        <xsl:with-param name="stringID">DownloadPageDesc3</xsl:with-param>
      </xsl:call-template>
      <br/>
      <br/>
      <xsl:call-template name="InsertLocalizedString">
        <xsl:with-param name="stringID">DownloadPageDesc4</xsl:with-param>
      </xsl:call-template>
    </FONT>
  </xsl:template>


  <xsl:template name="MoreLink">
    <xsl:param name="category"/>
    <xsl:param name="groupname"/>
    <xsl:param name="docpath1">
    <xsl:variable name="docPath" select="concat($resPath, 'strings.xml')" />
    <xsl:value-of select="translate($docPath,'\',',')"/>
    </xsl:param>
    <a>
      <xsl:attribute name="href">
        <xsl:text>javascript:OnLinkClick('</xsl:text>
        <xsl:value-of select="$groupname"/>
        <xsl:text>','</xsl:text>
        <xsl:value-of select="$category"/>
        <xsl:text>','</xsl:text>
        <xsl:value-of select="$docpath1"/>
        <xsl:text>');</xsl:text>
      </xsl:attribute>
      <xsl:call-template name="InsertLocalizedString">
        <xsl:with-param name="stringID">
          <xsl:text>More</xsl:text>
        </xsl:with-param>
      </xsl:call-template>
    </a>

  </xsl:template>
  
  <!-- Register a control ID for use with Ogre.
       params:
         id         The ID of the element to register
         func_name  The name of the function to register for that element.
  -->
  <xsl:template name="ogre-registration">
    <xsl:param name="id" />
    <xsl:param name="func_name" />
    <!-- Skip ogre registration if Ogre is not enabled -->
    <xsl:if test="/deviceDashboard/ogreIndex">
      <script type="text/javascript">
        <xsl:text>registerOgreControl('</xsl:text>
        <xsl:value-of select="$id"/>
        <xsl:text>', '</xsl:text>
        <xsl:value-of select="$func_name"/>
        <xsl:text>');</xsl:text>
      </script>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>