<!--                                                                  -->
<!--  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">
        <xsl:call-template name="publisherShow" />
        <xsl:call-template name="buttons" />
    </xsl:template>
  

    <xsl:template name="publisherShow">
        <div class="section" id="publisherShow">
            <xsl:call-template name="helpLink" />
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Publisher successfully updated!</xsl:with-param>
            </xsl:call-template>
			<fieldset>
				<legend><xsl:value-of select="$publisherType" /> Publisher</legend>
	            <xsl:call-template name="linkedPublishers" />
  	            <xsl:call-template name="column1Show" />
    	        <xsl:call-template name="column2Show" />
      	        <p class="bottomText">
        	        Last modified <xsl:value-of select="Form/Publisher/ModifiedDate" /><xsl:if test="normalize-space(Form/Publisher/ModifiedBy)"> by <xsl:value-of select="Form/Publisher/ModifiedBy" /></xsl:if>
      	        </p>
			</fieldset>
			<xsl:if test="Form/PayorList/Payor">
				<br />
				<xsl:call-template name="payorList" />
			</xsl:if>
			<br /><br />
        </div>
    </xsl:template>
    

  <xsl:template name="column1Show">
    <div class="column1">
      <table>
        <tr>
          <td class="leftCol">Publisher:</td>
          <td><xsl:value-of select="Form/Publisher/PublisherName" /><xsl:if test="/Root/Form/Publisher/IsAgency != 0">  [Agent] </xsl:if></td>
        </tr>
        <tr>
          <td class="leftCol">Client Account #:</td>
          <td><xsl:value-of select="Form/Publisher/ClientAccountID" /></td>
        </tr>
        <tr>
        	<td class="leftCol">Status:</td>
        	<td>
        		<xsl:choose>
        			<xsl:when test="Form/Publisher/Status = 0">Inactive</xsl:when>
        			<xsl:when test="Form/Publisher/Status = 2">On-hold</xsl:when>
        			<xsl:otherwise>Active</xsl:otherwise>
        		</xsl:choose>
        	</td>
        </tr>
        <tr><td colspan="2"><hr /></td></tr>
        <tr>
          <td class="leftCol">Address 1:</td>
          <td><xsl:value-of select="Form/Publisher/StreetAddress" /></td>
        </tr>
        <tr>
          <td class="leftCol">Address 2:</td>
          <td><xsl:value-of select="Form/Publisher/StreetAddress2" /></td>
        </tr>
        <tr>
          <td class="leftCol">Address 3:</td>
          <td><xsl:value-of select="Form/Publisher/StreetAddress3" /></td>
        </tr>        
        <tr>
          <td class="leftCol">City:</td>
          <td><xsl:value-of select="Form/Publisher/City" /></td>
        </tr>
        <tr>
          <td class="leftCol">State/Province:</td>
          <td><xsl:value-of select="Form/Publisher/StateProvince" /></td>
        </tr>
        <tr>
          <td class="leftCol">ZIP/Postal:</td>
          <td><xsl:value-of select="Form/Publisher/PostalCode" /></td>
        </tr>
        <tr>
          <td class="leftCol">Country:</td>
          <td><xsl:value-of select="Form/Publisher/CountryCode" /></td>
        </tr>
        <tr><td colspan="2"><hr /></td></tr>
        <tr>
          <td class="leftCol">E-mail:</td>
          <td><xsl:value-of select="Form/Publisher/Email" /></td>
        </tr>
        <tr>
          <td class="leftCol">Phone:</td>
          <td><xsl:value-of select="Form/Publisher/PhoneNumber" /></td>
        </tr>
        <tr>
          <td class="leftCol">Fax:</td>
          <td><xsl:value-of select="Form/Publisher/FaxNumber" /></td>
        </tr>
      </table>
    </div>
  </xsl:template>
  
  <xsl:template name="column2Show">
    <div class="column2"> 
      <table>
        <tr>
          <td class="leftCol">Publisher Type:</td>
          <td>
            <xsl:choose>
              <xsl:when test="Form/Publisher/IsAgency = 1">Agency</xsl:when>
              <xsl:when test="Form/Publisher/IsAdmin = 1">Administrator</xsl:when>
              <xsl:otherwise>Standard</xsl:otherwise>
            </xsl:choose>
          </td>
        </tr>
        <xsl:if test="/Root/Form/Publisher/IsAdmin = 0">
          <tr>
            <td class="leftCol">Admin:</td>
            <td><xsl:value-of select="Form/AdminList/Admin[PublisherID = /Root/Form/Publisher/AdminID]/PublisherName" /></td>
          </tr>
        </xsl:if>
        <xsl:if test="/Root/Form/Publisher/IsAgency = 0">
          <tr>
           <td class="leftCol">Agent:</td>
            <td><xsl:value-of select="Form/AgentList/Agent[AgentID = /Root/Form/Publisher/AgentID]/Name" /></td>
          </tr>
        </xsl:if>
        <tr><td colspan="2"><hr /></td></tr>
        <tr>
          <td class="leftCol">Tax ID:</td>
          <td><xsl:value-of select="Form/Publisher/TaxID" /></td>
        </tr>
        <tr>
          <td class="leftCol">Affiliation:</td>
          <td>
            <xsl:variable name="affiliateID"><xsl:value-of select="Form/Publisher/AffiliateID" /></xsl:variable>
            <xsl:value-of select="/Root/Form/AffiliateList/Affiliate[AffiliateID = $affiliateID]/Name" />
          </td>
        </tr>
        <tr class="labelTop">
          <td class="leftCol">Comments:</td>
          <td class="Publisher_Comments">
            <xsl:call-template name="replaceLineBreak">
              <xsl:with-param name="string" select="Form/Publisher/Comments"/>
            </xsl:call-template>
          </td>
        </tr>
      </table>
    </div>
  </xsl:template>


    <xsl:template name="payorList">  
        <fieldset id="payorViewTable">
            <legend>Payors</legend>
            <xsl:call-template name="payorListTable" />               
        </fieldset>
    </xsl:template>


    <xsl:template name="payorListTable">
        <xsl:variable name="accountCurrencyCode">
            <xsl:choose>
                <xsl:when test="$area = 'publisher'">USD</xsl:when>
                <xsl:when test="$area = 'ca_publisher'">CAD</xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="Client/Locale/CurrencyFormat/CurrencyCode" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>  
        
        <table class="textChart">
            <tbody>
                <tr>
                    <th>Payor</th>
                    <th>License Admin</th>
                    <th class="amount">License Count</th>
                    <th class="amount">Minimum Payment (<xsl:value-of select="$accountCurrencyCode" />)</th>
                    <th class="amount">
        	            Pending Transactions (<xsl:value-of select="$accountCurrencyCode" />) 
						<xsl:call-template name="helpIcon">
							<xsl:with-param name="tip">Sum of all non-committed transactions</xsl:with-param>
						</xsl:call-template>    
                    </th>
                    <th class="icon">Edit</th>
                </tr>             
 
                <xsl:choose>
                    <xsl:when test="Form/Publisher/IsAgency = 1">
                    
                        <xsl:for-each select="Form/PayorList/Payor[Direct = 1]">
                            <xsl:call-template name="directRow">
                                <xsl:with-param name="rowClass">row<xsl:value-of select="position() mod 2" /></xsl:with-param>
                            </xsl:call-template>
                        </xsl:for-each> 
                                           
                    </xsl:when>
                    <xsl:otherwise>
                             
                        <xsl:for-each select="Form/PayorList/Payor[Direct = 1 or HasAccount &gt; 0 or LicenseCount &gt; 0 or normalize-space(/Root/Form/PublisherAgentID) or normalize-space(/Root/Form/Publisher/AdminID)]">
        					
        					<!-- direct -->
                            <xsl:if test="Direct = 1">
                                <xsl:call-template name="directRow" />
                            </xsl:if>
                            
                            <!-- indirect -->
                            <xsl:if test="Indirect = 1">
                                <xsl:call-template name="indirectRow" />   
                            </xsl:if>
                                             
                        </xsl:for-each>
                        
                    </xsl:otherwise>
                </xsl:choose>
                
            </tbody>
        </table>  
   
    </xsl:template>


    <xsl:template name="directRow">       
        <xsl:variable name="payorID" select="PayorID" />
        <tr class="row{position() mod 2}">
            <td>
                <xsl:value-of select="Name" />
            </td>
            <td>
                <xsl:choose>
                  <xsl:when test="/Root/Form/Publisher/IsAgency = 1">Agency</xsl:when>
                  <xsl:when test="/Root/Form/Publisher/IsAdmin = 1">Administrator</xsl:when>
                  <xsl:otherwise>Direct</xsl:otherwise>
                </xsl:choose>                
            </td>
            <td class="amount">
                <xsl:choose>              
                    <xsl:when test="LicenseCount &gt; 0">
                        <a>
                            <xsl:attribute name="href">
                                <xsl:choose>
                                    <xsl:when test="$publisherDirect = 1">?c=list_licenses&amp;publisherID=<xsl:value-of select="/Root/Params/PublisherID" />&amp;payorID=<xsl:value-of select="$payorID" /></xsl:when>
                                    <xsl:otherwise>?c=list_direct_licenses&amp;publisherID=<xsl:value-of select="/Root/Params/PublisherID" />&amp;payorID=<xsl:value-of select="$payorID" /></xsl:otherwise>
                                </xsl:choose>
                            </xsl:attribute>
                            <xsl:value-of select="LicenseCount" />
                        </a>
                    </xsl:when>
                    <xsl:otherwise>0</xsl:otherwise>
                </xsl:choose>
            </td>
            <td class="amount">
				<xsl:if test="/Root/Form/Publisher/Account[PayorID = $payorID]">
                    <xsl:if test="normalize-space(/Root/Form/Publisher/Account[PayorID = $payorID]/MinPayment)"><xsl:value-of select="/Root/Form/Publisher/Account[PayorID = $payorID]/FinanceAccount/Balance/@currency_symbol" /></xsl:if>
                    <xsl:value-of select="/Root/Form/Publisher/Account[PayorID = $payorID]/MinPayment" />
				</xsl:if>
            </td>
            <td class="amount pendingCol">
                <xsl:value-of select="/Root/Form/Publisher/Account[PayorID = $payorID]/FinanceAccount/PendingBalance" />
            </td>
            <td class="icon">
                <a title="Edit" href="?PayorID={PayorID}&amp;c=edit_direct&amp;PublisherID={/Root/Form/Publisher/PublisherID}">
					<img src="/production/images/icons/office/Edit-(16x16).gif" height="16" width="16" />	
				</a>
            </td>
        </tr>    
    </xsl:template>
    
    
    <xsl:template name="indirectRow">
        <xsl:variable name="payorID" select="PayorID" />
        <tr class="row{position() mod 2}">
            <td>
                <xsl:value-of select="Name" />
            </td>
            <td>
                <xsl:choose>
                    <xsl:when test="normalize-space($indirectPublisherType)">
                        <xsl:value-of select="$indirectPublisherType" />
                    </xsl:when>
                    <xsl:otherwise>N/A</xsl:otherwise>
                </xsl:choose>                
            </td>
            <td class="amount">
                <xsl:choose>
                    <xsl:when test="LicenseCount &gt; 0">
                        <a href="?c=list_indirect_licenses&amp;publisherID={/Root/Params/PublisherID}&amp;payorID={$payorID}"><xsl:value-of select="LicenseCount" /></a>
                    </xsl:when>
                    <xsl:otherwise>0</xsl:otherwise>
                </xsl:choose>
            </td>
            <td class="amount">
                <xsl:choose>
                    <xsl:when test="normalize-space($indirectPublisherType)">
                        <i>See <xsl:value-of select="$indirectPublisherType" /></i>
                    </xsl:when>
                    <xsl:otherwise>N/A</xsl:otherwise>
                </xsl:choose>
            </td>
            <td class="amount pendingCol">
                <xsl:value-of select="PendingBalance" />
            </td>
            <td class="icon">
                <a title="Edit" href="?PayorID={PayorID}&amp;c=edit_indirect&amp;PublisherID={/Root/Form/Publisher/PublisherID}">
					<img src="/production/images/icons/office/Edit-(16x16).gif" height="16" width="16" />	
				</a>
            </td>
        </tr>       
    </xsl:template>
    

    <xsl:template name="submitButton">
        <input type="button" value="Edit Publisher" onClick="javascript:location.href='?PublisherID={Form/Publisher/PublisherID}&amp;c=edit'" />
    </xsl:template>


    <xsl:template name="cancelButton">
        <input type="button" name="Back" value="Back to Publishers" onClick="location.href='{$payeeHome}';" />
    </xsl:template>


</xsl:stylesheet>
