﻿<?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 ="CommunityItemID">
            <xsl:value-of select ="normalize-space(AddCommunity/SelectedCommunityItemID)"/>
        </xsl:variable>
        <xsl:variable name="ContentItemID">
            <xsl:value-of select="normalize-space(AddCommunity/Content/ItemID)"/>
        </xsl:variable>
        <xsl:variable name="DisplayFormatID">
            <xsl:value-of select="normalize-space(AddCommunity/Content/DisplayFormatID)"/>
        </xsl:variable>
        <xsl:variable name="StatusID">
            <xsl:value-of select="normalize-space(AddCommunity/Content/StatusID)"/>
        </xsl:variable>
        <xsl:variable name="Role">
            <xsl:value-of select="normalize-space(AddCommunity/Content/Role)"/>
        </xsl:variable>
        <xsl:variable name="BrandCommunity" select="normalize-space(AddCommunity/BrandCommunity)"/>
        <xsl:variable name="Mode" select="normalize-space(AddCommunity/Mode)"></xsl:variable>
        <xsl:variable name="BrandID" select="normalize-space(AddCommunity/BrandID)"></xsl:variable>
        <xsl:variable name="OriginNew" select="normalize-space(AddCommunity/Origin)"></xsl:variable>
        <xsl:variable name="OwnerBrandID" select="AddCommunity/Output/Communities/Community/OwnerBrandID"></xsl:variable>
        <xsl:variable name="TemplateDetailID">
            <xsl:value-of select="normalize-space(AddCommunity/TemplateDetailID)"/>
        </xsl:variable>

        <xsl:variable name="TemplateID">
            <xsl:value-of select="normalize-space(AddCommunity/TemplateID)"/>
        </xsl:variable>

        <xsl:variable name="TopicName">
            <xsl:value-of select="normalize-space(AddCommunity/TopicName)"/>
        </xsl:variable>

        <xsl:variable name="TemplateMode">
            <xsl:value-of select="normalize-space(AddCommunity/Mode)"/>
        </xsl:variable>


        <center>
            <table class="tableMaster" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td style="padding-left: 5px;" rowspan="14"></td>
                    <td>
                        <div id ="divResult"></div>
                    </td>
                </tr>
                <xsl:choose>
                    <xsl:when test="($BrandID) and $TemplateMode = ''">
                        <tr>
                            <td colspan="2">
                                <div id="divClose" align="right" style="margin:5px; text-align:right;">
                                    <span onclick="return ClientPortal_LoadClinetCommunityData('Article','{$BrandID}','divClientPortalOperations_Container');" class="link">[ X ]</span>
                                </div>
                            </td>
                        </tr>
                    </xsl:when>
                    <xsl:when test="$TemplateMode != ''">
                        <!--<tr>
                            <td colspan="2">
                                <div id="divClose" align="right" style="margin:5px; text-align:right;">
                                    <span onclick="ClientPortal_CloseAddNewTemplateItemBox('div_{$TemplateDetailID}_AddNewItem',
                                                            'div_{$TemplateDetailID}_AddNewAction', 'div_{$TemplateDetailID}_AddNewItemButton','{$TemplateDetailID}');" 
                                          class="link">[ X ]</span>
                                </div>
                            </td>
                        </tr>-->
                    </xsl:when>
                    <xsl:otherwise>
                        <tr>
                            <td colspan="2">
                                <div id="divClose" align="right" style="margin:5px; text-align:right; display: none;">
                                    <span onclick="hideDiv();" class="link">[ X ]</span>
                                </div>
                            </td>
                        </tr>
                    </xsl:otherwise>
                </xsl:choose>
                <tr>
                    <td>
                        <span class="labelFormFields lineHeight">Content URL</span>
                    </td>
                    <td>
                        <input id="txtContentURL" type="text" value="{normalize-space(AddCommunity/Content/ContentURL)}"
                               class="wideText" tabindex="1" maxlength="150"/>&#xa0;
                        <input id="btnAttach" value="Attach" type="button" class="button" onClick='return attachUrl();'></input>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <xsl:if test="normalize-space(AddCommunity/Content/ImageURL) != ''">
                            <div id ="divAttachURL" style="border: 1px solid #385D8A; display: block; width: 100%;">
                                <img src="{normalize-space(AddCommunity/Content/ImageURL)}" width="150px"></img>
                            </div>
                        </xsl:if>
                        <xsl:if test="normalize-space(AddCommunity/Content/ImageURL) = ''">
                            <div id ="divAttachURL" style="border: 1px solid #385D8A; display: none; width: 100%;">
                                <img src="{normalize-space(AddCommunity/Content/ImageURL)}" width="150px"></img>
                            </div>
                        </xsl:if>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span class="labelFormFields lineHeight">Image URL</span>
                    </td>
                    <td>
                        <input type="text" id="txtContentImageURL" class="wideText" maxlength="250"
                               value="{normalize-space(AddCommunity/Content/ImageURL)}"/>&#xa0;
                        <span class="link" onClick="return RemoveContentImage('txtContentImageURL');">[ X ]</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span class="labelFormFields lineHeight">Content Name</span>
                    </td>
                    <td>
                        <input id="txtContentName" type="text"
                               value="{normalize-space(AddCommunity/Content/ContentName)}"
                               class="wideText" tabindex="7" maxlength="75"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span class="labelFormFields lineHeight">Content Memo</span>
                    </td>
                    <td>
                        <textarea id="txtContentMemo" rows="4" class="wideText" tabindex="8">
                            <xsl:value-of select="AddCommunity/Content/ContentMemo"/>
                        </textarea>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span class="labelFormFields lineHeight">Tags</span>
                    </td>
                    <td>
                        <xsl:if test ="$CommunityItemID != 0">
                            <xsl:for-each select="AddCommunity/Output/Communities/Community">
                                <xsl:if test ="$CommunityItemID = CommunityItemID">
                                    <xsl:choose>
                                        <xsl:when test="$BrandCommunity = 1">
                                            <input id="txtTags" type="text" class="wideText" tabindex="9" maxlength="150" value="{CommunityName/.}">
                                            </input>
                                            <div style="display:none;">
                                                <input id="txtHiddenTags" type="text" maxlength="150" value="{CommunityName/.}">
                                                </input>
                                            </div>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <input id="txtTags" type="text" class="wideText" tabindex="9" maxlength="150" 
                                                   value="{Lifespace/.}, {Section/.}, {CommunityName/.}">
                                            </input>
                                            <div style="display:none;">
                                                <input id="txtHiddenTags" type="text" maxlength="150"
                                                        value="{Lifespace/.}, {Section/.}, {CommunityName/.}">
                                                </input>
                                            </div>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:if>
                            </xsl:for-each>
                        </xsl:if>
                        <xsl:if test ="$CommunityItemID = 0">
                            <input id="txtTags" type="text" class="wideText" tabindex="9" maxlength="150">
                            </input>
                            <div style="display:none;">
                                <input id="txtHiddenTags" type="text" maxlength="150">
                                </input>
                            </div>
                        </xsl:if>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span class="labelFormFields lineHeight">Type</span>
                    </td>
                    <td>
                        <select id="ddlContentType" name="ContentType" class="dropdown" tabindex="3">
                            <xsl:for-each select="AddCommunity/ContentType/Type">
                                <xsl:if test="Name != ../../Content/Type">
                                    <option value="{ID/.}">
                                        <xsl:value-of select="normalize-space(Name/.)"/>
                                    </option>
                                </xsl:if>

                                <xsl:if test="Name = ../../Content/Type">
                                    <option value="{ID/.}" selected="selected">
                                        <xsl:value-of select="normalize-space(Name/.)"/>
                                    </option>
                                </xsl:if>
                            </xsl:for-each>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span class="labelFormFields lineHeight">Format</span>
                    </td>
                    <td>
                        <select id="ddlContentFormat" name="ContentFormat" class="dropdown" tabindex="4">
                            <xsl:for-each select="AddCommunity/ContentFormat/Format">
                                <xsl:if test="Name != ../../Content/Format">
                                    <option value="{ID/.}">
                                        <xsl:value-of select="normalize-space(Name/.)"/>
                                    </option>
                                </xsl:if>

                                <xsl:if test="Name = ../../Content/Format">
                                    <option value="{ID/.}" selected="selected">
                                        <xsl:value-of select="normalize-space(Name/.)"/>
                                    </option>
                                </xsl:if>
                            </xsl:for-each>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span class="labelFormFields lineHeight">Community</span>
                    </td>
                    <td>
                        <select id="ddlCommunity" name="community" class="dropdown" tabindex="2">
                            <xsl:choose>
                                <xsl:when test="$CommunityItemID = 0">
                                    <option value="" selected="selected">
                                    </option>
                                </xsl:when>
                            </xsl:choose>

                            <xsl:choose>
                                <xsl:when test="$BrandCommunity = 1">
                                    <option value="{$CommunityItemID}" selected="selected" >
                                        <xsl:value-of
                                            select="normalize-space(AddCommunity/Output/Communities/Community[CommunityItemID = $CommunityItemID]/CommunityName/.)"/>
                                    </option>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:for-each select="AddCommunity/Output/Communities/Community">
                                        <xsl:if test ="$CommunityItemID = CommunityItemID">
                                            <option value="{CommunityItemID/.}" selected="selected" >
                                                <xsl:value-of select="normalize-space(CommunityName/.)"/>
                                            </option>
                                        </xsl:if>
                                        <xsl:if test ="$CommunityItemID != CommunityItemID">
                                            <option value="{CommunityItemID/.}">
                                                <xsl:value-of select="normalize-space(CommunityName/.)"/>
                                            </option>
                                        </xsl:if>
                                    </xsl:for-each>
                                </xsl:otherwise>
                            </xsl:choose>


                        </select>
                        <span id ="span_item_ErrorMessage" class="labelError" style="display:none;">*</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span class="labelFormFields lineHeight">Display Format</span>
                    </td>
                    <td>
                        <select id="ddlContentDisplayFormat" name="ContentDisplayFormat" class="dropdown" tabindex="5">
                            <xsl:for-each select="AddCommunity/DisplayFormat/Format">
                                <xsl:if test ="$DisplayFormatID != ''">
                                    <xsl:if test="normalize-space(ID/.) = $DisplayFormatID">
                                        <option value="{ID/.}" selected="selected">
                                            <xsl:value-of select="normalize-space(FormatText/.)"/>
                                        </option>
                                    </xsl:if>
                                    <xsl:if test="normalize-space(ID/.) != $DisplayFormatID">
                                        <option value="{ID/.}">
                                            <xsl:value-of select="normalize-space(FormatText/.)"/>
                                        </option>
                                    </xsl:if>
                                </xsl:if>
                                <xsl:if test ="$DisplayFormatID = ''">
                                    <xsl:if test="FormatText != 'ContentBar'">
                                        <option value="{ID/.}">
                                            <xsl:value-of select="normalize-space(FormatText/.)"/>
                                        </option>
                                    </xsl:if>

                                    <xsl:if test="FormatText = 'ContentBar'">
                                        <option value="{ID/.}" selected="selected">
                                            <xsl:value-of select="normalize-space(FormatText/.)"/>
                                        </option>
                                    </xsl:if>
                                </xsl:if>
                            </xsl:for-each>
                        </select>
                    </td>
                </tr>
                <xsl:if test ="$Role = 'Admin'">
                    <tr>
                        <td>
                            <span class="labelFormFields lineHeight">Status</span>
                        </td>
                        <td>
                            <select id="ddlContentStatus" name="ContentStatus" class="dropdown" tabindex="6">
                                <xsl:for-each select="AddCommunity/ContentStatus/Status">
                                    <xsl:choose>
                                        <xsl:when test="$StatusID != ''">
                                            <xsl:if test="normalize-space(ID/.) = $StatusID">
                                                <option value="{ID/.}" selected="selected">
                                                    <xsl:value-of select="normalize-space(StatusText/.)"/>
                                                </option>
                                            </xsl:if>
                                            <xsl:if test="normalize-space(ID/.) != $StatusID">
                                                <option value="{ID/.}">
                                                    <xsl:value-of select="normalize-space(StatusText/.)"/>
                                                </option>
                                            </xsl:if>
                                        </xsl:when>
                                        <xsl:when test="$BrandCommunity = 1">
                                            <xsl:if test="StatusText != 'Active'">
                                                <option value="{ID/.}">
                                                    <xsl:value-of select="normalize-space(StatusText/.)"/>
                                                </option>
                                            </xsl:if>
                                            <xsl:if test="StatusText = 'Active'">
                                                <option value="{ID/.}" selected="selected">
                                                    <xsl:value-of select="normalize-space(StatusText/.)"/>
                                                </option>
                                            </xsl:if>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:if test="StatusText != 'Pending'">
                                                <option value="{ID/.}">
                                                    <xsl:value-of select="normalize-space(StatusText/.)"/>
                                                </option>
                                            </xsl:if>
                                            <xsl:if test="StatusText = 'Pending'">
                                                <option value="{ID/.}" selected="selected">
                                                    <xsl:value-of select="normalize-space(StatusText/.)"/>
                                                </option>
                                            </xsl:if>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:for-each>
                            </select>
                        </td>
                    </tr>
                </xsl:if>
                <tr>
                    <td style="padding-top: 10px; padding-bottom: 10px;">
                        <input type="hidden" id="txtHiddenMode" value="{$Mode}"></input>
                        <xsl:if test ="$ContentItemID = 0">
                            <xsl:if test ="$Role = 'Admin'">
                                <a onClick = 'Community_Save(
                                                      "ddlCommunity",
                                                      "ddlContentType",
                                                      "ddlContentFormat",
                                                      "txtContentURL",
                                                      "txtContentName",
                                                      "txtContentMemo",
                                                      "txtTags",
                                                      "imgAttach",
                                                      "divResult",
                                                      "ddlContentDisplayFormat",
                                                      "ddlContentStatus",
                                                      "span_item_ErrorMessage",
                                                      "{$BrandID}","{$TemplateID}","{$TemplateDetailID}","{$TopicName}","{$TemplateMode}"
                                                      );'
                                  
                                   class="button" tabindex="10">&#xa0;Save&#xa0;</a>
                            </xsl:if>
                            <xsl:if test ="$Role != 'Admin'">
                                <a onClick = 'Community_Save(
                                                      "ddlCommunity",
                                                      "ddlContentType",
                                                      "ddlContentFormat",
                                                      "txtContentURL",
                                                      "txtContentName",
                                                      "txtContentMemo",
                                                      "txtTags",
                                                      "imgAttach",
                                                      "divResult",
                                                      "ddlContentDisplayFormat",
                                                      "ddlContentStatus",
                                                      "span_item_ErrorMessage",
                                                      "{$BrandID}","{$TemplateID}","{$TemplateDetailID}","{$TopicName}","{$TemplateMode}"
                                                      );'
                                   
                                   class="button" tabindex="10">&#xa0;Save&#xa0;</a>
                            </xsl:if>
                        </xsl:if>
                        <xsl:if test ="$ContentItemID > 0">
                            <a onClick = 'return Community_Update(
                                                      "{normalize-space(AddCommunity/Content/ItemID)}",
                                                      "ddlCommunity",
                                                      "ddlContentType",
                                                      "ddlContentFormat",
                                                      "txtContentURL",
                                                      "txtContentName",
                                                      "txtContentMemo",
                                                      "txtTags",
                                                      "imgAttach",       
                                                      "divResult",
                                                      "ddlContentDisplayFormat",
                                                      "ddlContentStatus"
                                                      );' class="button" tabindex="10">&#xa0;Update&#xa0;</a>
                        </xsl:if>
                    </td>
                    <!--<td style="padding-top: 10px; padding-bottom: 10px;">
                        <xsl:if test="$OriginNew = 'AddContentInTemplate'">
                            <a class="button"
                               onclick="CloseAddNewContentBox();">
                                &#xa0;Cancel&#xa0;
                            </a>
                        </xsl:if>
                    </td>-->

                </tr>
            </table>
        </center>
    </xsl:template>
</xsl:stylesheet>
