<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
    <xsl:output method="html" indent="no" doctype-system="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" encoding="utf-8" />

    <xsl:include href="/app/tools/rps/templates/global.xsl" />
    <xsl:include href="shared.xsl" />

    <xsl:template name="pickLayout">
        <script type="text/javascript" src="/production/javascript/validatePublisher.js?v=1" />
        <form name="publisherEdit" id="publisherEdit" method="post" action="{$area}">
            <xsl:call-template name="publisherEdit" />
            <xsl:call-template name="buttons" />
        </form>
    </xsl:template>


    <xsl:template name="publisherEdit">
        <div class="section">
            <xsl:call-template name="helpLink" />
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Publisher successfully created!</xsl:with-param>
            </xsl:call-template>
            <xsl:if test="Params/_inline">
                <input type="hidden" name="_inline" value="1" />
            </xsl:if>
            <input type="hidden" name="formSubmit" value="1" />
            <input type="hidden" name="c" value="edit" />
            <input type="hidden" name="saveAsDefault" id="saveAsDefault" />
            <input type="hidden" name="ReturnTo" id="ReturnTo" value="" />
            <xsl:if test="normalize-space(Form/Publisher/PublisherID)">
                <input type="hidden" name="PublisherID" value="{Form/Publisher/PublisherID}" />
            </xsl:if>

     		<xsl:call-template name="openRunStatusMessage" />
            <xsl:call-template name="linkedPublishers" />
            <p class="formHeader">Enter publisher information here.</p>
            <hr />
            <xsl:call-template name="errorMessageGeneral" />
            <xsl:call-template name="column1Edit" />
            <xsl:call-template name="column2Edit" />
			<br class="superBreak" />
			<br />
        </div>
    </xsl:template>

    <xsl:template name="column1Edit">
        <div class="column1">
            <table>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_PublisherName">*Publisher:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/PublisherName</xsl:with-param>
                            <xsl:with-param name="displayName">Publisher</xsl:with-param>
                        </xsl:call-template>
                        <input type="text" class="publisherNameField" name="Form_Publisher_PublisherName" id="Form_Publisher_PublisherName" value="{Form/Publisher/PublisherName}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </td>
                </tr>
                <tr>
                    <td class="leftCol" nowrap="nowrap"><label for="Form_Publisher_ClientAccountID">Client Account #:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/ClientAccountID</xsl:with-param>
                            <xsl:with-param name="displayName">Client Account #</xsl:with-param>
                        </xsl:call-template>
                        <input type="text" class="clientAccountIDField" name="Form_Publisher_ClientAccountID" id="Form_Publisher_ClientAccountID" value="{Form/Publisher/ClientAccountID}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </td>
                </tr>
				<tr>
					<td class="leftCol"><label for="Form_Publisher_Status">Status:</label></td>
					<td>
						<select name="Form_Publisher_Status" id="Form_Publisher_Status">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
							<option value="1">
								Active
							</option>
							<option value="0">
								<xsl:if test="Form/Publisher/Status = 0">
									<xsl:attribute name="selected">selected</xsl:attribute>
								</xsl:if>
								Inactive
							</option>
							<option value="2">
								<xsl:if test="Form/Publisher/Status = 2">
									<xsl:attribute name="selected">selected</xsl:attribute>
								</xsl:if>
								On-hold
							</option>
						</select>
					</td>
				</tr>
                <tr><td colspan="2"><hr /></td></tr>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_StreetAddress">Address 1:</label></td>
                    <td>
                        <input type="text" name="Form_Publisher_StreetAddress" id="Form_Publisher_StreetAddress" value="{Form/Publisher/StreetAddress}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>                    
                    </td>
                </tr>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_StreetAddress2">Address 2:</label></td>
                    <td>
                        <input type="text" name="Form_Publisher_StreetAddress2" id="Form_Publisher_StreetAddress2" value="{Form/Publisher/StreetAddress2}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>                    
                    </td>
                </tr>  
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_StreetAddress3">Address 3:</label></td>
                    <td>
                        <input type="text" name="Form_Publisher_StreetAddress3" id="Form_Publisher_StreetAddress3" value="{Form/Publisher/StreetAddress3}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>                    
                    </td>
                </tr>                                   
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_City">City:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/City</xsl:with-param>
                            <xsl:with-param name="displayName">City</xsl:with-param>
                        </xsl:call-template>
                        <input type="text" name="Form_Publisher_City" id="Form_Publisher_City" value="{Form/Publisher/City}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </td>
                </tr>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_StateProvince">State/Province:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/StateProvince</xsl:with-param>
                            <xsl:with-param name="displayName"></xsl:with-param>
                        </xsl:call-template>
                        <input type="text" name="Form_Publisher_StateProvince" id="Form_Publisher_StateProvince" value="{Form/Publisher/StateProvince}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </td>
                </tr>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_PostalCode">ZIP/Postal:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/PostalCode</xsl:with-param>
                            <xsl:with-param name="displayName">Zip/Postal</xsl:with-param>
                        </xsl:call-template>
                        <input type="text" class="zipField" name="Form_Publisher_PostalCode" id="Form_Publisher_PostalCode" value="{Form/Publisher/PostalCode}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </td>
                </tr>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_CountryCode">Country:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/CountryCode</xsl:with-param>
                            <xsl:with-param name="displayName">Country</xsl:with-param>
                        </xsl:call-template>
                        <select name="Form_Publisher_CountryCode">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                            <option value="">Choose...</option>
                            <xsl:for-each select="Form/CountryList/Country">
                                <option value="{CountryCode}">
                                    <xsl:if test="CountryCode = /Root/Form/Publisher/CountryCode">
                                        <xsl:attribute name="selected">selected</xsl:attribute>
                                    </xsl:if>
                                    <xsl:value-of select="Name" />
                                </option>
                            </xsl:for-each>
                        </select>
                    </td>
                </tr>
                <tr><td colspan="2"><hr /></td></tr>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_Email">E-mail:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/Email</xsl:with-param>
                            <xsl:with-param name="displayName">E-mail</xsl:with-param>
                        </xsl:call-template>
                        <input type="text" class="emailField" name="Form_Publisher_Email" id="Form_Publisher_Email" value="{Form/Publisher/Email}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </td>
                </tr>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_PhoneNumber">Phone:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/PhoneNumber</xsl:with-param>
                            <xsl:with-param name="displayName">Phone</xsl:with-param>
                        </xsl:call-template>
                        <input type="text" class="phoneField" name="Form_Publisher_PhoneNumber" id="Form_Publisher_PhoneNumber" value="{Form/Publisher/PhoneNumber}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </td>
                </tr>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_FaxNumber">Fax:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/FaxNumber</xsl:with-param>
                            <xsl:with-param name="displayName">FaxNumber</xsl:with-param>
                        </xsl:call-template>
                        <input type="text" class="phoneField" name="Form_Publisher_FaxNumber" id="Form_Publisher_FaxNumber" value="{Form/Publisher/FaxNumber}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <br />*Required field
                    </td>
                </tr>
            </table>
        </div>
    </xsl:template>


    <xsl:template name="column2Edit">
        <xsl:variable name="linkedPublishers" select="Form/Publisher/AgentFor + Form/Publisher/AdminFor" />
        <input type="hidden" name="initialType" id="initialType">
            <xsl:attribute name="value">
                <xsl:choose>
                    <xsl:when test="Form/Publisher/IsAdmin = 1">admin</xsl:when>
                    <xsl:when test="Form/Publisher/IsAgency = 1">agency</xsl:when>
                    <xsl:otherwise>standard</xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
        </input>
        <input type="hidden" name="Form_Publisher_IsAgency" id="Form_Publisher_IsAgency" value="{Form/Publisher/IsAgency}" />
        <input type="hidden" name="Form_Publisher_IsAdmin" id="Form_Publisher_IsAdmin" value="{Form/Publisher/IsAdmin}" />
        <div class="column2">
            <table>
                <tr>
                    <td class="leftCol">Publisher Type:</td>
                    <td>
                        <select name="Publisher_Type">
                            <xsl:attribute name="onChange">checkPublisherType(this.value);<xsl:if test="$linkedPublishers &gt; 0"> checkInitialType(this.value); </xsl:if> </xsl:attribute>
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                            <option value="standard">Standard</option>
                            <option value="admin">
                                <xsl:if test="Form/Publisher/IsAdmin = 1">
                                    <xsl:attribute name="selected">selected</xsl:attribute>
                                </xsl:if>
                                Administrator
                            </option>
                            <option value="agency">
                                <xsl:if test="Form/Publisher/IsAgency = 1">
                                    <xsl:attribute name="selected">selected</xsl:attribute>
                                </xsl:if>
                                Agency
                            </option>
                        </select>
                        <xsl:if test="$linkedPublishers &gt; 0">
                            &#160;<input type="checkbox" name="Form_Publisher_UpdateAttachedPublishers" value="1" id="Form_Publisher_UpdateAttachedPublishers" checked="checked">
                                <xsl:if test="$openRuns = 1">
                                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                                </xsl:if>
                            </input>
                            <xsl:call-template name="helpIcon">
                                <xsl:with-param name="tip">
                                    The system will attempt to update the linked Publisher<xsl:if test="$linkedPublishers &gt; 1">s</xsl:if> if this box is checked.
                                </xsl:with-param>
                                <xsl:with-param name="hidden">1</xsl:with-param>
                                <xsl:with-param name="id">linkedPublishersHelp</xsl:with-param>
                                <xsl:with-param name="hide">Form_Publisher_StatementTypeID</xsl:with-param>
                            </xsl:call-template>
                        </xsl:if>
                    </td>
                </tr>
                <tr>
                    <td class="leftCol">
                        <label for="Form_Publisher_AdminID" id="adminLabel">
                            Admin:
                        </label>
                    </td>
                    <td>
						<xsl:call-template name="inlineError">
							<xsl:with-param name="path">Form/Publisher/AdminID</xsl:with-param>
							<xsl:with-param name="displayName">Admin</xsl:with-param>
						</xsl:call-template>
						<select name="Form_Publisher_AdminID" id="Form_Publisher_AdminID">
							<xsl:if test="Form/Publisher/IsAgency = 1 or Form/Publisher/IsAdmin = 1 or $openRuns = 1">
								<xsl:attribute name="disabled">disabled</xsl:attribute>
							</xsl:if>
							<option value="">Choose...</option>
							<xsl:for-each select="Form/AdminList/Admin[PublisherID != /Root/Form/Publisher/PublisherID]">
								<option value="{PublisherID}">
									<xsl:if test="/Root/Form/Publisher/AdminID = PublisherID and /Root/Form/Publisher/IsAdmin != 1 and /Root/Form/Publisher/IsAgency != 1">
										<xsl:attribute name="selected">selected</xsl:attribute>
									</xsl:if>
									<xsl:value-of select="substring(PublisherName,1,35)" /><xsl:if test="substring(PublisherName,36,1)">...</xsl:if><xsl:if test="AgentID &gt; 0"> (HFA)</xsl:if>
								</option>
							</xsl:for-each>
						</select>
					</td>
                </tr>
                <tr>
                    <td class="leftCol">
                        <label for="Form_Publisher_AgentID" id="agentLabel">
                            Agent:
                        </label>
                    </td>
                    <td>
						<xsl:call-template name="inlineError">
							<xsl:with-param name="path">Form/Publisher/AgentID</xsl:with-param>
							<xsl:with-param name="displayName">Agent</xsl:with-param>
						</xsl:call-template>
						<select name="Form_Publisher_AgentID" id="Form_Publisher_AgentID">
							<xsl:if test="Form/Publisher/IsAgency = 1 or $openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
							<option value="">Choose...</option>
							<xsl:for-each select="Form/AgentList/Agent[AgentID != /Root/Form/Publisher/PublisherID]">
								<option value="{AgentID}">
									<xsl:if test="/Root/Form/Publisher/AgentID = AgentID and /Root/Form/Publisher/IsAgency != 1">
										<xsl:attribute name="selected">selected</xsl:attribute>
									</xsl:if>
									<xsl:value-of select="Name" />
								</option>
							</xsl:for-each>
						</select>
					</td>
				</tr>
				<tr><td colspan="2"><hr /></td></tr>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_TaxID">Tax ID:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/TaxID</xsl:with-param>
                            <xsl:with-param name="displayName">Tax ID</xsl:with-param>
                        </xsl:call-template>
                        <input type="text" name="Form_Publisher_TaxID" id="Form_Publisher_TaxID" value="{Form/Publisher/TaxID}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </td>
                </tr>
                <tr>
                    <td class="leftCol"><label for="Form_Publisher_AffiliateID">Affiliation:</label></td>
                    <td>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/Publisher/AffiliateID</xsl:with-param>
                            <xsl:with-param name="displayName">Affiliation</xsl:with-param>
                        </xsl:call-template>
                        <select name="Form_Publisher_AffiliateID">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                            <option value="">Choose...</option>
                            <xsl:for-each select="Form/AffiliateList/Affiliate">
                                <option value="{AffiliateID}">
                                    <xsl:if test="AffiliateID = /Root/Form/Publisher/AffiliateID">
                                        <xsl:attribute name="selected">selected</xsl:attribute>
                                    </xsl:if>
                                    <xsl:value-of select="Name" />
                                </option>
                            </xsl:for-each>
                        </select>
                    </td>
                </tr>
                <tr class="labelTop">
                    <td class="leftCol">Comments:</td>
                    <td>
                        <textarea rows="6" cols="40" name="Form_Publisher_Comments">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="Form/Publisher/Comments" />
                        </textarea>
                    </td>
                </tr>
            </table>
        </div>
    </xsl:template>


    <xsl:template name="submitButton">
        <input name="submitButton" type="submit" id="submitButton">
            <xsl:if test="$openRuns = 1">
                <xsl:attribute name="disabled">disabled</xsl:attribute>
            </xsl:if>
            <xsl:attribute name="value">
                <xsl:if test="normalize-space(Form/Publisher/PublisherID)">Update</xsl:if>
                <xsl:if test="not(normalize-space(Form/Publisher/PublisherID))">Create</xsl:if>
            </xsl:attribute>
        </input>
    </xsl:template>


    <xsl:template name="cancelButton">
        <xsl:if test="not(normalize-space(Form/Publisher/PublisherID))">
            <input name="submitButton" id="addAnotherButton" type="submit" value="Create and Add Another" onClick="modifyFieldValue('ReturnTo','?c=edit&amp;msg=success|form_submit_success')">
                <xsl:if test="$openRuns = 1">
                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                </xsl:if>
            </input>
        </xsl:if>
        <xsl:if test="Params/PublisherID">
            <input type="button" value="Return to Publisher" onClick="location.href='?PublisherID={Params/PublisherID}&amp;c=show'" />
        </xsl:if>
        <xsl:if test="not(Params/PublisherID)">
            <input type="button" value="Back to Publishers" onClick="location.href='{$payeeHome}'" />
        </xsl:if>
    </xsl:template>


</xsl:stylesheet>
