﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template name="CommunityContainer">
        <xsl:param name="ContentHtml" select="'N/A'"></xsl:param>
        <xsl:param name="InstructionsHtml" select="'N/A'"></xsl:param>
        <xsl:param name="RelatedTemplatesHtml" select="'N/A'"></xsl:param>
        <xsl:param name="ItemID" select="normalize-space(AjaxRequest/Params/ItemID)"></xsl:param>
        <xsl:param name="CommunityGroupUser" select="'N/A'"></xsl:param>
        <xsl:param name="Authenticated" select="'N/A'"/>
        <xsl:param name ="TemplateURL" select ="'N/A'"/>
        <xsl:param name="TotalTemplates" select="'N/A'"></xsl:param>
        <xsl:param name="TotalPublications" select="'N/A'"></xsl:param>
        <xsl:param name="TotalDiscussions" select="'N/A'"></xsl:param>
        <xsl:param name="TotalContents" select="'N/A'"></xsl:param>
        <xsl:param name="Version" select="'N/A'"></xsl:param>
        <xsl:param name="MyCommunityHTML" select="'N/A'"></xsl:param>
        <xsl:param name="ItemName" select="'N/A'"></xsl:param>
        <xsl:param name="BlogPostsHTML" select="'N/A'"></xsl:param>
        <xsl:param name="ArticlesHTML" select="'N/A'"></xsl:param>
        <xsl:param name="VolumeLevel">
            <xsl:number value="-99"/>
        </xsl:param>
        <xsl:param name="PromoteKey" select="'N/A'"></xsl:param>
        <xsl:param name="HostName" select="'N/A'"></xsl:param>
        <xsl:param name="LoggedInUserID" select="'N/A'"></xsl:param>
        <xsl:param name="SocialSharePublishedYN" select="'N/A'"></xsl:param>
        <xsl:param name="CommunityPublishYN" select="'N/A'"></xsl:param>
        <xsl:param name="CommunityPublicYN" select="'N/A'"></xsl:param>
        <xsl:param name="CommunityAdminUser" select="'N/A'"></xsl:param>
        <xsl:param name="CommunityAdmin" select="'N/A'"></xsl:param>
        <xsl:param name="MBrandItemID" select="'N/A'"></xsl:param>
        <xsl:param name="ParentItemPublishYN" select="'N/A'"></xsl:param>
        <xsl:param name="ParentItemPublicYN" select="'N/A'"></xsl:param>
     
        <xsl:choose>
            <xsl:when test="Version != 2.0">
                <div id="divCommunity_Container">
                    <div id="divCommunity_HeaderBox" style="margin-bottom: 20px;margin-top:5px;">
                        <xsl:value-of select="$InstructionsHtml" disable-output-escaping="yes"/>
                    </div>

                    <div id="divCommunity_Operation" style="display: none; margin-bottom: 20px;"></div>

                    <div id="divOperations" style="display: none; margin-bottom: 20px; border: 0px solid #385D8A;">
                    </div>
                    <xsl:if test="($TotalTemplates &gt; 0 or $CommunityGroupUser = 'True')">
                        <div id="divCommunity_RelatedTemplates" style="margin-bottom: 20px;">
                            <xsl:value-of select="$RelatedTemplatesHtml" disable-output-escaping="yes"/>
                        </div>
                    </xsl:if>
                    <div id="divAds" align="center" style="padding-bottom: 10px;">
                    </div>
                    <script language="javascript" type="text/javascript">
                        getActiveAdForItem("<xsl:value-of select='$ItemID'/>", "divAds", "19");
                    </script>
                    <xsl:if test="$Authenticated = 'True' and ($TotalDiscussions &gt; 0 or $CommunityGroupUser = 'True')">
                        <div id="divCommunity_Discussions" style="margin-bottom: 20px;">
                            <img id="imgWaiting" src="{$TemplateURL}Web/Images/pre-loader.gif" style="vertical-align: middle;"></img>
                        </div>
                        <script language="javascript" type="text/javascript">
                            discussion_Load("<xsl:value-of select='$ItemID'/>", "divCommunity_Discussions");
                        </script>
                    </xsl:if>
                    <xsl:if test="($TotalContents &gt; 0 or $CommunityGroupUser = 'True')">
                        <div id="divCommunity_LearnIt" style="margin-bottom: 20px;">
                            <xsl:value-of select="$ContentHtml" disable-output-escaping="yes"/>
                        </div>
                    </xsl:if>
                </div>
            </xsl:when>
            <xsl:otherwise>
                <div id="CommunityContainerBody">
                    <xsl:choose>
                        <xsl:when test="$CommunityPublicYN = -1 and $VolumeLevel = 0">
                            <div class="labelGoalTitle marginTop20" style="color:red;">This is a private community.</div>
                        </xsl:when>
                        <xsl:when test="$CommunityPublicYN = -1 or $CommunityPublicYN = 1 or $CommunityPublicYN = 0">
                            <xsl:choose>
                                <xsl:when test="$CommunityPublicYN = 0 or $CommunityPublicYN = 1 or ($CommunityPublicYN = -1 and $VolumeLevel = 3)">
                                    <div style="margin:10px;">
                                        <table class="tableMaster" cellspacing="0" cellpadding="0">
                                            <xsl:call-template name="CommunityHeader">
                                                <xsl:with-param name="ItemName" select="$ItemName"></xsl:with-param>
                                            </xsl:call-template>
                                            <xsl:call-template name="CommunityFollowShareOptions">
                                                <xsl:with-param name="Authenticated" select="$Authenticated"></xsl:with-param>
                                                <xsl:with-param name="VolumeLevel" select="$VolumeLevel"></xsl:with-param>
                                                <xsl:with-param name="ItemID" select="$ItemID"></xsl:with-param>
                                                <xsl:with-param name="CommunityPublishYN" select="$CommunityPublishYN"></xsl:with-param>
                                                <xsl:with-param name="ParentItemPublishYN" select="$ParentItemPublishYN"></xsl:with-param>
                                                <xsl:with-param name="SocialSharePublishedYN" select="$SocialSharePublishedYN"></xsl:with-param>
                                                <xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
                                                <xsl:with-param name="PromoteKey" select="$PromoteKey"></xsl:with-param>
                                                <xsl:with-param name="LoggedInUserID" select="$LoggedInUserID"></xsl:with-param>
                                                <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                                <xsl:with-param name="ItemName" select="$ItemName"></xsl:with-param>
                                                <xsl:with-param name="CommunityAdminUser" select="$CommunityAdminUser"></xsl:with-param>
                                                <xsl:with-param name="CommunityAdmin" select="$CommunityAdmin"></xsl:with-param>
                                                <xsl:with-param name="MBrandItemID" select="$MBrandItemID"></xsl:with-param>
                                            </xsl:call-template>
                                        </table>
                                    </div>
                                    <xsl:if test="((
                                                        $LoggedInUserID &gt; 0 
                                                            and (($VolumeLevel = 3 and $CommunityPublicYN = 0)
                                                                    or $CommunityPublicYN = 1)
                                                    ) 
                                                    or 
                                                    ((($CommunityPublishYN = 1 and $LoggedInUserID &lt; 0) 
                                                        or ($VolumeLevel = 3 and $LoggedInUserID &gt; 0)))
                                                   )">
                                        <div id="divCommunity_Operation" style="display: none; margin-bottom: 20px;"></div>
                                        <div>
                                            <xsl:call-template name="CommunityBody">
                                                <xsl:with-param name="BlogPostsHTML" select="$BlogPostsHTML"></xsl:with-param>
                                                <xsl:with-param name="Authenticated" select="$Authenticated"></xsl:with-param>
                                                <xsl:with-param name="TotalDiscussions" select="$TotalDiscussions"></xsl:with-param>
                                                <xsl:with-param name="CommunityGroupUser" select="$CommunityGroupUser"></xsl:with-param>
                                                <xsl:with-param name="TemplateURL" select="$TemplateURL"></xsl:with-param>
                                                <xsl:with-param name="ItemID" select="$ItemID"></xsl:with-param>
                                                <xsl:with-param name="MyCommunityHTML" select="$MyCommunityHTML"></xsl:with-param>
                                                <xsl:with-param name="TotalTemplates" select="$TotalTemplates"></xsl:with-param>
                                                <xsl:with-param name="RelatedTemplatesHtml" select="$RelatedTemplatesHtml"></xsl:with-param>
                                                <xsl:with-param name="ArticlesHTML" select="$ArticlesHTML"></xsl:with-param>
                                            </xsl:call-template>
                                        </div>
                                    </xsl:if>
                                </xsl:when>
                            </xsl:choose>
                        </xsl:when>
                        <xsl:when test="($CommunityPublishYN = 0 or (not($CommunityPublishYN)) and $LoggedInUserID &lt; 0)">
                            <div id="divAuthenticationMessage">
                                <script language="javascript" type="text/javascript">
                                    DisplaySignUpPopUp('login', 'NonAuthCase', '');
                                </script>
                            </div>
                        </xsl:when>
                    </xsl:choose>
                </div>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


    <xsl:template name="CommunityHeader">
        <xsl:param name="ItemName" select="'N/A'"></xsl:param>

        <tr>
            <td width="100%" rowspan="2" class="verticallyMiddle">
                <span class="brandTopHeaderTitle">
                    Welcome to <xsl:value-of select="$ItemName"/>.
                </span>
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="CommunityFollowShareOptions">
        <xsl:param name="Authenticated" select="'N/A'"></xsl:param>
        <xsl:param name="VolumeLevel" select="'N/A'"></xsl:param>
        <xsl:param name="ItemID" select="'N/A'"></xsl:param>
        <xsl:param name="CommunityPublishYN" select="'N/A'"></xsl:param>
        <xsl:param name="ParentItemPublishYN" select="'N/A'"></xsl:param>
        <xsl:param name="SocialSharePublishedYN" select="'N/A'"></xsl:param>
        <xsl:param name="HostName" select="'N/A'"></xsl:param>
        <xsl:param name="PromoteKey" select="'N/A'"></xsl:param>
        <xsl:param name="LoggedInUserID" select="'N/A'"></xsl:param>
        <xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
        <xsl:param name="ItemName" select="'N/A'"></xsl:param>
        <xsl:param name="CommunityAdminUser" select="'N/A'"></xsl:param>
        <xsl:param name="CommunityAdmin" select="'N/A'"></xsl:param>
        <xsl:param name="MBrandItemID" select="'N/A'"></xsl:param>        
        <xsl:param name="ParentItemPublicYN" select="'N/A'"></xsl:param>

        <xsl:variable name="FloatPosition">
            <xsl:choose>
                <xsl:when test="$CommunityAdminUser = 1 or $CommunityAdmin/Role[RoleName = 'Community Admin']">
                    <xsl:text>left</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>right</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        
        
        
        <tr>
            <td class="textCenter verticallyMiddle" align="center">
                <div style="display:inline-block;width:330px;text-align:right;" class="marginBottom10">
                    <div style="display:inline-block;">                        
                        <xsl:choose>
                            <xsl:when test="$Authenticated = 'True'">
                                <xsl:choose>
                                    <xsl:when test="$VolumeLevel = 3">
                                        <div id="div_{$ItemID}_Following" style="display:block;padding-top:3px;"
                                            class="unFollowCommunity verticallyMiddle boxShadow"
                                            onclick="followCommunityBase('{$ItemID}', 'divCommunity_Operation', 'Community', 0);">Following !</div>
                                        <div id="div_{$ItemID}_Follow" style="display:none;padding-top:3px;"
                                            class="followCommunity verticallyMiddle boxShadow"
                                             onclick="followCommunityBase('{$ItemID}', 'divCommunity_Operation', 'Community', 3);">Follow Community</div>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <div id="div_{$ItemID}_Following" style="display:none;padding-top:3px;"
                                            class="unFollowCommunity verticallyMiddle boxShadow"
                                            onclick="followCommunityBase('{$ItemID}', 'divCommunity_Operation', 'Community', 0);">Following !</div>
                                        <div id="div_{$ItemID}_Follow" style="display:block;padding-top:3px;"
                                            class="followCommunity verticallyMiddle boxShadow"
                                             onclick="followCommunityBase('{$ItemID}', 'divCommunity_Operation', 'Community', 3);">Follow Community</div>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:when>
                        </xsl:choose>
                    </div>
                    <xsl:if test="$CommunityAdminUser = 1 or $CommunityAdmin/Role[RoleName = 'Community Admin']">                      
                            <img src="{$TemplateURL}Web/Images/Ver_2_0/icon-Followers.jpg" alt="Add Admin" class="onMouseOver"
                            title="Add Followers" border="0" width="32" height="32" align="absmiddle"
                            onClick="loadCommunityFollowersPopup('{$ItemID}');"/>
                    </xsl:if>

                    <xsl:if test="$CommunityAdminUser = 1 or $CommunityAdmin/Role[RoleName = 'Community Admin']">
                        <img src="{$TemplateURL}Web/Images/Ver_2_0/padlock.png" alt="Add Admin" class="onMouseOver"
                             title="Add Admin" border="0" width="32" height="32" align="absmiddle"
                             onClick="AddAdminToCommunity('{$ItemID}','{$MBrandItemID}');"/>
                    </xsl:if>
                

                <xsl:if test="(($CommunityPublishYN = 1 or $ParentItemPublishYN = 1) and $SocialSharePublishedYN = 'True') or (($ParentItemPublishYN = 1 or $CommunityPublishYN = 1) and not($SocialSharePublishedYN))">
                    <div class="marginTop10" style="text-align:right;">
                        <table  cellspacing="0" cellpadding="0" style="display:inline-block;">
                            <tr>
                                <td class="verticallyMiddle">

                                    <a id="linkFacebook" target="_blank" class="decorationNone"
                                          href="http://www.facebook.com/share.php?u=http://{normalize-space($HostName)}/{normalize-space($PromoteKey)}?Ref=FB-U{normalize-space($LoggedInUserID)}">
                                        <img src="{$TemplateURL}Web/Images/Ver_2_0/BT_facebook_60.png" alt="Follow us on Facebook!"
                                             hspace="3" border="0" width="30" height="30" align="absmiddle"/>
                                    </a>
                                </td>
                                <td class="verticallyMiddle">
                                    <a id="linkTwitter" target="_blank" class="decorationNone"
                                          href="http://twitter.com/intent/tweet?status={$ItemName}+on+LifeSpace+http://{normalize-space($HostName)}/{normalize-space($PromoteKey)}?Ref=TW-U{normalize-space($LoggedInUserID)}">
                                        <img src="{$TemplateURL}Web/Images/Ver_2_0/BT_twitter_60.png" alt="Follow us on Twitter!"
                                             hspace="3" border="0" width="30" height="30" align="absmiddle"/>
                                    </a>
                                </td>
                                <td class="verticallyMiddle" endurl="http://{normalize-space($HostName)}/{normalize-space($PromoteKey)}?REF=PLUS-U{normalize-space($LoggedInUserID)}">
                                    <div class="g-plusone" data-size="standard" data-count="false"
                                         data-href="http://{normalize-space($HostName)}/{normalize-space($PromoteKey)}?REF=PLUS-U{normalize-space($LoggedInUserID)}"></div>
                                </td>
                                <td class="verticallyMiddle">
                                    <xsl:choose>
                                        <xsl:when test="$Authenticated = 'True'">
                                            <a class="link" onClick='return EmailUserInvitation_Load("{$PromoteKey}","divCommunity_Operation",{$ItemID},"community");'>
                                                <img src="{$TemplateURL}Web/Images/Ver_2_0/Email_Icon.png" style="border: 0px none;"
                                                     width="30" height="30" align="absmiddle"></img>
                                            </a>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <a class="link" onclick="DisplaySignUpPopUp('signup','emailinvitationcommunity','{$ItemID}');">
                                                <input type="hidden" id="emailInvitation_{$ItemID}_PromoteKey" value="{$PromoteKey}"></input>
                                                <img src="{$TemplateURL}Web/Images/Ver_2_0/Email_Icon.png" style="border: 0px none;"
                                                     width="30" height="30" align="absmiddle"></img>
                                            </a>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </td>
                            </tr>
                        </table>
                    </div>
                </xsl:if>

                </div>
            </td>
        </tr>
    </xsl:template>


    <xsl:template name="CommunityBody">
        <xsl:param name="BlogPostsHTML" select="'N/A'"></xsl:param>
        <xsl:param name="Authenticated" select="'N/A'"></xsl:param>
        <xsl:param name="TotalDiscussions" select="'N/A'"></xsl:param>
        <xsl:param name="CommunityGroupUser" select="'N/A'"></xsl:param>
        <xsl:param name="TemplateURL" select="'N/A'"></xsl:param>
        <xsl:param name="ItemID" select="'N/A'"></xsl:param>
        <xsl:param name="MyCommunityHTML" select="'N/A'"></xsl:param>
        <xsl:param name="TotalTemplates" select="'N/A'"></xsl:param>
        <xsl:param name="RelatedTemplatesHtml" select="'N/A'"></xsl:param>
        <xsl:param name="ArticlesHTML" select="'N/A'"></xsl:param>


        <table class="tableMaster" cellpadding="0" cellspacing="0">
            <tr>
                <td width="65%">
                    <div id="divCommunity_LearnIt" style="margin:10px;background-color:White;">
                        <xsl:value-of select="$BlogPostsHTML" disable-output-escaping="yes"/>
                    </div>

                    <!--<xsl:if test="$Authenticated = 'True' and ($TotalDiscussions &gt; 0 or $CommunityGroupUser = 'True')">-->
                    <xsl:if test="$Authenticated = 'True'">
                        <div id="divCommunity_Discussions" style="margin:10px;background-color:White;">
                            <img id="imgWaiting" src="{$TemplateURL}Web/Images/pre-loader.gif" style="vertical-align: middle;"></img>
                        </div>
                        <script language="javascript" type="text/javascript">
                            discussion_Load("<xsl:value-of select='$ItemID'/>", "divCommunity_Discussions");
                        </script>
                    </xsl:if>
                </td>
                <td width="35%">
                    <div id="divMyCommunities" style="margin:10px;background-color:White;">
                        <xsl:if test="$Authenticated = 'True'">
                            <xsl:value-of select ="$MyCommunityHTML" disable-output-escaping ="yes"/>
                        </xsl:if>
                    </div>
                    <xsl:if test="($TotalTemplates &gt; 0 or $CommunityGroupUser = 'True')">
                        <div id="divCommunity_RelatedTemplates" style="margin:10px;background-color:White;">
                            <xsl:value-of select="$RelatedTemplatesHtml" disable-output-escaping="yes"/>
                        </div>
                    </xsl:if>
                    <div id="divArticles" style="margin:10px;background-color:White;">
                        <xsl:value-of select ="$ArticlesHTML" disable-output-escaping ="yes"/>
                    </div>
                </td>
            </tr>
        </table>
    </xsl:template>
</xsl:stylesheet>
