﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:variable name="Origin" select="AjaxRequest/Params/Origin"></xsl:variable>      
        <xsl:variable name="EditTemplateDisplay">
            <xsl:choose>
                <xsl:when test="count(AjaxRequest/CategoryControl/SelectedCategoryList/Item) &gt; 0">
                    <xsl:text>display:block</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>display:none</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <xsl:variable name="UpdateTemplateCategoriesDisplay">
            <xsl:choose>
                <xsl:when test="count(AjaxRequest/CategoryControl/SelectedCategoryList/Item) &gt; 0">
                    <xsl:text>display:none</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>display:block</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:call-template name="CategoryControl">
            <xsl:with-param name="Origin" select="$Origin"></xsl:with-param>
            <xsl:with-param name="UpdateTemplateCategoriesDisplay" select="$UpdateTemplateCategoriesDisplay"></xsl:with-param>
            <xsl:with-param name="EditTemplateDisplay" select="$EditTemplateDisplay"></xsl:with-param>
        </xsl:call-template>
        
    </xsl:template>

    <xsl:template name="CategoryControl">     
        <xsl:param name="UpdateTemplateCategoriesDisplay" select="'N/A'"></xsl:param>
        <xsl:param name="EditTemplateDisplay" select="'N/A'"></xsl:param>
        <xsl:param name="Origin" select="'N/A'"></xsl:param>
        
        <xsl:choose>
            <xsl:when test="$Origin = 'AddBrandTemplate'">
                <div id="divBrandCategories" style="display:block;">
                    <table class="tableMaster" cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td>
                                <select id="listLeftCategoryKeys" size="15" style="width:320px; margin-top:10px;" >
                                    <!--<xsl:for-each select="AjaxRequest/CategoryControl/CategoryList/Item">
                                        <xsl:variable name="CategoryItemID" select="ID"></xsl:variable>
                                    </xsl:for-each>-->
                                </select>
                            </td>
                            <td width="5%" style="padding-left:4px;">
                                <div>
                                    <input type="button" class="button" value="&gt;" onclick="publication_MoveCategoryKeysList(this)"></input>
                                </div>&#xa0;
                                <div>
                                    <input type="button" class="button" value="X" onclick="publication_MoveCategoryKeysList(this)"></input>
                                </div>
                            </td>
                            <td  width="65%">
                                <select id="listRightCategoryKeys" size="15" style="width:280px; margin-top:4px;">
                                    <xsl:for-each select="AjaxRequest/CategoryList/Item">
                                        <option style="font-family: Calibri, Verdana, Arial; font-size: 8pt; line-height: 1.5em;"
                                                value="{normalize-space(ID)}">
                                            <xsl:value-of select="normalize-space(Name/.)"/>
                                        </option>
                                    </xsl:for-each>
                                </select>
                            </td>
                        </tr>
                    </table>
                </div>
            </xsl:when>
            <xsl:otherwise>
                <div>
                    <div id="divEditTemplateCategories" class="link" style="{$EditTemplateDisplay}">

                        <xsl:for-each select="AjaxRequest/CategoryControl/SelectedCategoryList/Item">
                            <div id="div_{ItemCategoryID}_CategoryItem">
                                <table  border='1' cellspacing='0' cellpadding='0'>
                                    <tr>
                                        <td>
                                            <span style="margin:5px" class="label">
                                                <xsl:value-of select="Name"/>&#xa0;
                                            </span>
                                        </td>
                                        <td>
                                            <span style="margin:5px;" class="link"
                                                  onClick='deleteCategories("{normalize-space(ItemCategoryID)}", 
                                                                    "div_{ItemCategoryID}_CategoryItem",
                                                                    "{normalize-space(ID)}");'>
                                                &#xa0;X&#xa0;
                                            </span>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </xsl:for-each>

                        <div onClick="return flipToUpdateTemplateCategories('divEditTemplateCategories', 'divUpdateTemplateCategories');">
                            Edit...
                        </div>

                    </div>
                    <div id="divUpdateTemplateCategories" style="{$UpdateTemplateCategoriesDisplay}">
                        <table class="tableMaster" cellpadding="0" cellspacing="0" border="0">
                            <tr>
                                <td>
                                    <select id="listLeftCategoryKeys" size="15" >
                                        <xsl:for-each select="AjaxRequest/CategoryControl/CategoryList/Item">
                                            <xsl:variable name="CategoryItemID" select="ID"></xsl:variable>
                                            <xsl:if test="count(../../../SelectedCategoryList/Item
                                                                [normalize-space(ID) = $CategoryItemID]) = 0">

                                                <option style="font-family: Calibri, Verdana, Arial; font-size: 8pt; line-height: 1.5em;" value="{ID/.}">
                                                    <xsl:value-of select="normalize-space(Name/.)"/>
                                                </option>
                                            </xsl:if>
                                        </xsl:for-each>
                                    </select>
                                </td>
                                <td width="5%" style="padding-left:4px;">
                                    <div>
                                        <input type="button" class="button" value="&gt;" onclick="publication_MoveCategoryKeysList(this)"></input>
                                    </div>&#xa0;
                                    <div>
                                        <input type="button" class="button" value="X" onclick="publication_MoveCategoryKeysList(this)"></input>
                                    </div>
                                </td>
                                <td width="65%">
                                    <select id="listRightCategoryKeys" size="15" style="width:100%;" >
                                        <xsl:for-each select="AjaxRequest/CategoryControl/SelectedCategoryList/Item">
                                            <option style="font-family: Calibri, Verdana, Arial; font-size: 8pt; line-height: 1.5em;" value="{ID/.}">
                                                <xsl:value-of select="normalize-space(Name/.)"/>
                                            </option>
                                        </xsl:for-each>
                                    </select>
                                </td>
                                <!--<td width="5%">
                        </td>-->
                            </tr>
                        </table>
                    </div>
                </div>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
</xsl:stylesheet>
