﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:import href="CategoriesControl.xslt"/>
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:variable name="BrandID" select="AjaxRequest/Params/BrandID"></xsl:variable>
        <xsl:variable name="Origin" select="AjaxRequest/Params/Origin"></xsl:variable>
        <xsl:variable name="ItemID" select="AjaxRequest/Params/ItemID"></xsl:variable>
        <xsl:variable name="TemplateURL" select="AjaxRequest/TemplateURL"></xsl:variable>
        <xsl:variable name="HostName" select="AjaxRequest/HostName"></xsl:variable>
        <xsl:variable name="UserID" select="AjaxRequest/UserID"></xsl:variable>
        <xsl:variable name="GoalOpenControlXML" select="AjaxRequest/GoalOpenControlXML/."></xsl:variable>
        <xsl:variable name="GoalNotesFormatXML" select="AjaxRequest/GoalNotesFormatXML/."></xsl:variable>
        <xsl:variable name="NumberGoalPermissionXML" select="AjaxRequest/NumberGoalPermission/."></xsl:variable>
        <xsl:variable name="PortalDefaultImageURL" select="AjaxRequest/Lifespace/ImageURL"></xsl:variable>


        <div id="divAddTemplate">
            <input id="templateImagePath" type="hidden" value=""></input>

            <table class="tableMaster" cellpedding="2" cellspacing="5">
                <xsl:choose>
                    <xsl:when test="$Origin='Update'">
                        <xsl:variable name="Item" select="AjaxRequest/TemplateData/Item/ItemName"></xsl:variable>
                        <xsl:variable name="Description" select="normalize-space(AjaxRequest/TemplateData/Item/Description)"></xsl:variable>
                        <xsl:variable name="Waiver" select="AjaxRequest/TemplateData/Item/Waiver"></xsl:variable>
                        <xsl:variable name="Type" select="AjaxRequest/TemplateData/Item/Type"></xsl:variable>
                        <xsl:variable name="ImageUrl" select="AjaxRequest/TemplateData/Item/ImageURL"></xsl:variable>
                        <xsl:variable name="PublicYN" select="AjaxRequest/TemplateData/Item/PublicYN"></xsl:variable>
                        <xsl:variable name="PublishedYN" select="AjaxRequest/TemplateData/Item/PublishedYN"></xsl:variable>
                        <xsl:variable name="TempStatus" select="AjaxRequest/TemplateData/Item/Status"></xsl:variable>
                        <xsl:variable name="SuccessKey" select="AjaxRequest/TemplateData/Item/SuccessKey"></xsl:variable>
                        <tr style="display:none;">
                            <td>
                                <span>File Upload</span>
                            </td>
                            <td>
                                <input type="file" id="txtFile" style="width:100%;"></input>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span>Name</span>
                            </td>
                            <td>
                                <input type="textbox" id="txtName" style="width:100%;" value="{$Item}"></input>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span>Description</span>
                            </td>
                            <td>
                                <textarea rows="3" id="txtDescription"  class="textAreaBox">
                                    <xsl:value-of select="$Description"/>
                                </textarea>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span>WaiverID</span>
                            </td>
                            <td>
                                <input type="textbox" id="txtWaiver" style="width:100%;" value="{$Waiver}"></input>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span>TypeID</span>
                            </td>
                            <td>
                                <input type="textbox" id="txtType" style="width:100%;" value="{$Type}"></input>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span>Brand</span>
                            </td>
                            <td>
                                <select id="ddlBrand" class="smallDropDown" style="width:125px;">
                                    <xsl:for-each select="AjaxRequest/Brands/Brand">
                                        <xsl:choose>
                                            <xsl:when test="BrandID = $BrandID">
                                                <option value="{BrandID}" selected="selected">
                                                    <xsl:value-of select="BrandKey"/>
                                                </option>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <option value="{BrandID}">
                                                    <xsl:value-of select="BrandKey"/>
                                                </option>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:for-each>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span>Goal Type</span>
                            </td>
                            <td>
                                <input id="rdb_{$ItemID}_PersonalGoal" type="radio" name="GoalType" checked="checked"
                                        onclick="document.getElementById('span_OpenTo_Text').style.display='none';
                                                 document.getElementById('opt_OpenTo').style.display='none';
                                                 document.getElementById('tr_NumbersEnteredBy').style.display='none';">
                                    <span class="publicationSummary marginRight10">Personal Goal</span>
                                </input>
                                <input id="rdb_{$ItemID}_GroupChallenge" type="radio" name="GoalType" style="display:none;"
                                       onclick="document.getElementById('span_OpenTo_Text').style.display='inline';
                                                document.getElementById('opt_OpenTo').style.display='inline';
                                                document.getElementById('tr_NumbersEnteredBy').style.display='inline';">
                                    <span class="publicationSummary" style="display:none;">Group Challenge</span>
                                </input>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span>Measure Success</span>
                            </td>
                            <td>
                                <select id="ddlSuccessKey" class="smallDropDown" style="width:125px;">
                                    <xsl:choose>
                                        <xsl:when test ="$SuccessKey = 'Number'">
                                            <option value="Action">Completing Actions</option>
                                            <option value="Number" selected="selected">By Numbers and Metrics</option>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <option value="Action" selected="selected">Completing Actions</option>
                                            <option value="Number">By Numbers and Metrics</option>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span>PublicYN</span>
                            </td>
                            <td>
                                <select id="ddlPublicYN" class="smallDropDown" style="width:125px;">

                                    <xsl:choose>
                                        <xsl:when test="$PublicYN='True'">
                                            <option value="1" selected="selected">Yes</option>
                                            <option value="0">No</option>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <option value="1">Yes</option>
                                            <option value="0" selected="selected">No</option>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>PublishedYN</td>
                            <td>
                                <select id="ddlPublishedYN" class="smallDropDown" style="width:125px;">
                                    <xsl:choose>
                                        <xsl:when test="$PublishedYN='True'">
                                            <option value="1" selected="selected">Yes</option>
                                            <option value="0">No</option>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <option value="1">Yes</option>
                                            <option value="0" selected="selected">No</option>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span>Status</span>
                            </td>
                            <td>
                                <select id="ddlStatus" class="smallDropDown" style="width:125px;">
                                    <xsl:for-each select="AjaxRequest/Template/TemplateStatus">
                                        <xsl:choose>
                                            <xsl:when test="StatusID=$TempStatus">
                                                <option value="{StatusID}" selected="selected">
                                                    <xsl:value-of select="Status"/>
                                                </option>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <option value="{StatusID}">
                                                    <xsl:value-of select="Status"/>
                                                </option>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:for-each>
                                </select>
                            </td>
                        </tr>

                        <tr id="tr_NumbersEnteredBy" style="display:none;">
                            <td>
                                <span>Numbers Entered By</span>
                            </td>
                            <td>
                                <select id="ddl_NumbersEnteredBy" class="smallDropDown" style="width:125px;">
                                    <option value="-99">-Select-</option>
                                    <xsl:for-each select="$NumberGoalPermissionXML/Permission">
                                        <option value="{ID}">
                                            <xsl:value-of select="NumbersEnteredBy"/>
                                        </option>
                                    </xsl:for-each>
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <td>
                                <span>Category Keys</span>
                            </td>
                            <td>
                                <div id="divCategoryXml">
                                    <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="UpdateTemplateCategoriesDisplay" select="$UpdateTemplateCategoriesDisplay"></xsl:with-param>
                                        <xsl:with-param name="EditTemplateDisplay" select="$EditTemplateDisplay"></xsl:with-param>
                                    </xsl:call-template>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>

                            </td>
                            <td>
                                <xsl:choose>
                                    <xsl:when test="$ImageUrl != ''">
                                        <div id="div_TemplateLogo" style="height:100px;" class="onMouseOver"
                                     onClick="ImageUploader_PopupCenter('http://{$HostName}/upload/uploadimage.aspx?guid=Template&amp;cropRatio=2&amp;requiredHeight=100&amp;requiredWidth=100&amp;requiredFileName=Logo&amp;Key=UploadPathItems&amp;TemplateID={$ItemID}',
                                                                'Upload_Image','530','390','{$ItemID}','UploadTemplateImage','div_TemplateLogo');">
                                            <img id="img_TemplateImage_{$UserID}" src="{$ImageUrl}" height="100" width="100" style="cursor:pointer;"
                                                 onmouseover="this.className='grayOut';document.getElementById('span_imageText').style.display ='block';"
                                                 onmouseout="this.setAttribute('class','');document.getElementById('span_imageText').style.display ='none';"></img>
                                            <span id="span_imageText" style="display:none;position:relative;top:-70px;margin-left:25px;" class="labelLifespaceItem"
                                                 onmouseover="document.getElementById('img_TemplateImage_{$UserID}').className='grayOut';document.getElementById('span_imageText').style.display ='block';"
                                                    onmouseout="document.getElementById('img_TemplateImage_{$UserID}').setAttribute('class','');document.getElementById('span_imageText').style.display ='none';">
                                                Change <br/> Photo
                                            </span>
                                        </div>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <div id="div_TemplateLogo" style="height:100px;" class="onMouseOver"
                                      onClick="ImageUploader_PopupCenter('http://{$HostName}/upload/uploadimage.aspx?guid=Template&amp;cropRatio=2&amp;requiredHeight=100&amp;requiredWidth=100&amp;requiredFileName=Logo&amp;Key=UploadPathItems&amp;TemplateID={$ItemID}',
                                                                'Upload_Image','530','390','{$ItemID}','UploadTemplateImage','div_TemplateLogo');">
                                            <img id="img_TemplateImage_{$UserID}" src="{$TemplateURL}Web/Images/Lifespace LLC.jpg" height="100" width="100" style="cursor:pointer;"
                                          
                                                 onmouseover="this.className='grayOut';document.getElementById('span_imageText').style.display ='block';"
                                                 onmouseout="this.setAttribute('class','');document.getElementById('span_imageText').style.display ='none';"></img>

                                            <span id="span_imageText" style="display:none;position:relative;top:-70px;color:gray;margin-left:25px;" class="labelLifespaceItem"
                                                 onmouseover="document.getElementById('img_TemplateImage_{$UserID}').className='grayOut';document.getElementById('span_imageText').style.display ='block';"
                                                    onmouseout="document.getElementById('img_TemplateImage_{$UserID}').setAttribute('class','');document.getElementById('span_imageText').style.display ='none';">
                                                Change <br/> Photo
                                            </span>
                                        </div>
                                    </xsl:otherwise>
                                </xsl:choose>

                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div>
                                    <span style="margin-right:15px;">
                                        <input class="anchorButton"
                                               onclick="return ClientPortal_UpdateTemplateData('{$ItemID}', 'txtFile', 'txtName', 'txtDescription', 
                                                                                                'txtWaiver', 'txtImageURL', 'txtType', 'ddlBrand', 
                                                                                                'ddlPublicYN', 'ddlPublishedYN', 'ddlStatus', 'divCategoryXml',
                                                                                                'ddlSuccessKey');"
                                               type="button" id="btnSave" value="Update"></input>
                                    </span>
                                    <span>
                                        <input class="anchorButton"
                                               onclick="clientPortal_LoadTemplateDetail('{$ItemID}','divMyServicesTemplateData','{$BrandID}');" type="button" id="btnCancel" value="Cancel"></input>
                                    </span>
                                </div>
                            </td>
                        </tr>
                    </xsl:when>
                    <xsl:otherwise>
                        <tr>
                            <td width="20%">
                                <span class="packageTitle">Name</span>
                            </td>
                            <td width="80%">
                                <input type="textbox" id="txtName" style="width:100%;"></input>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="packageTitle">Description</span>
                            </td>
                            <td>
                                <textarea id="txtDescription"  class="textAreaBox" type="text"
                                          onFocus="removeWhiteSpace('txtDescription');">
                                </textarea>
                            </td>
                        </tr>

                        <tr>
                            <td>
                                <span class="packageTitle">PublicYN</span>
                            </td>
                            <td>
                                <select id="ddlPublicYN" class="smallDropDown" style="width:125px;">
                                    <option value="-99" selected="selected">Select</option>
                                    <option value="1">Yes</option>
                                    <option value="0">No</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="packageTitle">Goal Type</span>
                            </td>
                            <td>
                                <input id="rdb_{$ItemID}_PersonalGoal" type="radio" name="GoalType" checked="checked"
                                       onclick="document.getElementById('tr_OpenTo').style.display='none';
                                                document.getElementById('tr_NotesFormat').style.display='none';                                    
                                                document.getElementById('tr_JoinDeadline').style.display='none';
                                                ">
                                    <span class="publicationSummary marginRight10">Personal Goal</span>
                                </input>
                                <input id="rdb_{$ItemID}_GroupChallenge" type="radio" name="GoalType" style="display:none;"
                                       onclick="document.getElementById('tr_OpenTo').style.display='table-row';
                                                document.getElementById('tr_NotesFormat').style.display='table-row';                                   
                                                document.getElementById('tr_JoinDeadline').style.display='table-row';
                                               ">
                                    <span class="publicationSummary" style="display:none;">Group Challenge</span>
                                </input>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="packageTitle">Measure Success</span>
                            </td>
                            <td>
                                <select id="ddlSuccessKey" class="smallDropDown" style="width:125px;">
                                    <option value="Action" selected="selected">Completing Actions</option>
                                    <option value="Number">By Numbers and Metrics</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="packageTitle">Status</span>
                            </td>
                            <td>
                                <select id="ddlStatus" class="smallDropDown" style="width:125px;">
                                    <option value="-99" selected="selected">Select</option>
                                    <xsl:for-each select="AjaxRequest/Template/TemplateStatus">
                                        <option value="{StatusID}">
                                            <xsl:value-of select="Status"/>
                                        </option>
                                    </xsl:for-each>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="packageTitle">Link to:</span>
                            </td>
                            <td>
                                <select id="ddlLifespace" class="smallDropDown" style="width:125px;">
                                    <xsl:for-each select="AjaxRequest/Lifespace/LifespaceName">
                                        <xsl:choose>
                                            <xsl:when  test="Item = 'Fitness'">
                                                <option value="{ItemID}" selected="selected">
                                                    <xsl:value-of select="Item"/>
                                                </option>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <option value="{ItemID}">
                                                    <xsl:value-of select="Item"/>
                                                </option>
                                            </xsl:otherwise>
                                        </xsl:choose>

                                    </xsl:for-each>
                                    <option selected="selected">
                                        <xsl:value-of select="AjaxRequest/Lifespace/Brand/CompanyName"/>
                                    </option>
                                </select>
                            </td>
                        </tr>
                        <tr id="tr_numbersEnteredBy" style="display:none;">
                            <td>
                                <span class="packageTitle">Numbers Entered By:</span>
                            </td>
                            <td>
                                <select id="ddl_NumbersEnteredBy" class="smallDropDown" style="width:125px;">
                                    <option value="-99">-Select-</option>
                                    <xsl:for-each select="$NumberGoalPermissionXML/Permission">
                                        <option value="{ID}">
                                            <xsl:value-of select="NumbersEnteredBy"/>
                                        </option>
                                    </xsl:for-each>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>

                            </td>
                            <td>
                                <div id="div_TemplateLogo" style="height:100px;" class="onMouseOver"
                                     onClick="ImageUploader_PopupCenter('http://{$HostName}/upload/uploadimage.aspx?guid=TempItemsTemplate&amp;cropRatio=2&amp;requiredHeight=100&amp;requiredWidth=100&amp;requiredFileName=Logo&amp;Key=UploadPathTempLocation&amp;UserID={$UserID}',
                                                                'Upload_Image','530','390','0','UploadTemplateLogo','div_TemplateLogo');">
                                    <img id="img_TemplateImage_{$UserID}" src="{$PortalDefaultImageURL}"
                                         onload="setWidthAndHeightImage(this, 120);" style="cursor:pointer;"
                                         onmouseover="this.className='grayOut';document.getElementById('span_imageText').style.display ='block';"
                                         onmouseout="this.setAttribute('class','');document.getElementById('span_imageText').style.display ='none';"></img>

                                    <span id="span_imageText" style="display:none;position:relative;top:-70px;color:gray;margin-left:25px;" class="labelLifespaceItem"
                                          onmouseover="document.getElementById('img_TemplateImage_{$UserID}').className='grayOut';document.getElementById('span_imageText').style.display ='block';"
                                          onmouseout="document.getElementById('img_TemplateImage_{$UserID}').setAttribute('class','');document.getElementById('span_imageText').style.display ='none';">
                                        Change <br/> Photo
                                    </span>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="onMouseOver divBrowseGradient spanBrowseGradientTextGray"
                                     onclick="return SaveTemplateFromPortal('txtName','txtDescription',
                                                                                        'txtImageURL', 'ddlStatus',
                                                                                        'ddlPublicYN', '{$BrandID}', 'ddlLifespace',
                                                                                        'ddlSuccessKey','templateImagePath');"
                                     onmouseout="document.getElementById('img_Submit').src='{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png';"
                                     onmouseover="document.getElementById('img_Submit').src='{$TemplateURL}Web/Images/Ver_2_0/icon_add_over.png';"
                                     style="width:80px;line-height:30px;">
                                    <img id="img_Submit" class="marginRight5" align="absmiddle" style="padding-left:8px;"
                                         src="{$TemplateURL}Web/Images/Ver_2_0/icon_Add.png"/>
                                    <span id="span_Save">SAVE</span>
                                </div>
                            </td>
                            <td>
                                <div class="verticallyMiddle onMouseOver divBrowseGradient spanBrowseGradientTextGray"
                                    onclick="return LoadCoachInfoWizard('LoadMyServices','{$BrandID}','divClientPortalOperations_Container','-99');"
                                    onmouseout="document.getElementById('img_Cancel').src='{$TemplateURL}Web/Images/Ver_2_0/BT_x.png';"
                                    onmouseover="document.getElementById('img_Cancel').src='{$TemplateURL}Web/Images/Ver_2_0/BT_x_hover.png';"
                                    style="width:80px;line-height:30px;">
                                    <img id="img_Cancel" class="marginRight5" align="absmiddle" style="padding-left:8px;"
                                         src="{$TemplateURL}Web/Images/Ver_2_0/BT_x.png"/>
                                    <span id="span_Cancel">CANCEL</span>
                                </div>

                            </td>

                        </tr>
                    </xsl:otherwise>
                </xsl:choose>
            </table>
        </div>
    </xsl:template>
</xsl:stylesheet>
