﻿<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" 
	version="1.0"
	omit-xml-declaration="yes"
	encoding="utf-8"
	standalone="no"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" 
	doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 
	indent="yes"
	/>
<xsl:param name="page"/>

<xsl:variable name="devise">EUR</xsl:variable>
<xsl:variable name="paypal_account">order@earnyourears.com</xsl:variable>
<xsl:variable name="item_name">order on earnyourears website </xsl:variable>
<xsl:variable name="shipping_fees_europa">2</xsl:variable>
<xsl:variable name="shipping_fees_others">3</xsl:variable>

<!--
<xsl:variable name="return">http://earnyourears.com/eye/index.php5?page=thanks</xsl:variable>
<xsl:variable name="cancel_return">http://earnyourears.com/eye/index.php5?page=buy</xsl:variable>
-->

<xsl:template match="/site/page">
    <!-- si le requète n'existe pas, on affiche la page d'index -->
  <xsl:if test="$page=''"><xsl:param name="page">index</xsl:param></xsl:if>
  <xsl:if test="$style=''"><xsl:param name="style">style.css</xsl:param></xsl:if>
  <xsl:if test="$page=@name">
  <html>
  <head>
    <title>earn your ears - <xsl:value-of select="@name"/></title>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="{$style}" media="screen" rel="Stylesheet" type="text/css"></link>
    <link rel="alternate" type="application/rss+xml" title="Flux RSS" href="http://earnyourears.com/eye/rss.php5" />
     <script type="text/javascript" src="./scripts/commande.js" />
    </head> 
  
<body>
<div id="container">
	<div id="menu">
			<p>
				<xsl:for-each select="/site/page[@menu!='no']">
					<a id="{@name}" href="?page={@name}">
						<xsl:if test="$page=@name">
							<xsl:attribute name="class">this</xsl:attribute>
						</xsl:if>
						<xsl:value-of select="@name"/>
					</a>
				</xsl:for-each>
			</p>
			<xsl:if test="$page!='index'">
				<blockquote id="logo_small"><a href="?page=index"><img src="./picture/eye_small.png"></img></a></blockquote>
			</xsl:if>
		<div class="spacer"></div>
	</div>
	
	<div id="content">
		<xsl:apply-templates />
		<xsl:if test="@name='index'">
			<div id="news">
				<p>last news (<a href="?page=read">read more</a>)</p>
				<xsl:apply-templates select="/site/page[@name='read']/listing/news[position() = last()]" mode="news" />
			</div>
		</xsl:if>
		<xsl:if test="@name='buy'">
			<div id="caddie">
				<xsl:apply-templates select="/site/page[@name='hear']/listing/category[@availability!='']" mode="caddie" />
			</div>
		</xsl:if>
		
	</div>
	<div id="foot">
		<p>myspace: <a href="http://www.myspace.com/earnyourears">earnyourears</a>; webdesign: <a href="http://aurele-origami.com">aurele duda</a></p>
		<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
		<script type="text/javascript">
			<xsl:text>_uacct = "UA-1150535-1";
			urchinTracker();
			</xsl:text>
		</script>
	</div>

</div>
    <!-- phpmyvisites -->
    <!-- phpmyvisites -->
<a href="http://www.phpmyvisites.net/" title="phpMyVisites | Open source web analytics"
onclick="window.open(this.href);return(false);"><script type="text/javascript">
<xsl:comment>
var a_vars = Array();
var pagename='<xsl:value-of select="@name" />';

var phpmyvisitesSite = 1;
var phpmyvisitesURL = "http://earnyourears.com/pmv2/phpmyvisites.php";
//</xsl:comment>
</script>
<script language="javascript" src="http://earnyourears.com/pmv2/phpmyvisites.js" type="text/javascript"></script>
<noscript><p>phpMyVisites | Open source web analytics
<img src="http://earnyourears.com/pmv2/phpmyvisites.php" alt="Statistics" style="border:0" />
</p></noscript></a>
<!-- /phpmyvisites --> 
	</body>
</html>
</xsl:if>
</xsl:template>

<xsl:template match="content">
    <xsl:copy-of select="*"/>
</xsl:template>

<xsl:template match="listing">
    <div id="listing">
    <table>
    <xsl:choose>
	<xsl:when test="news">
		<xsl:apply-templates>
			<xsl:sort select="@date" order="descending" data-type="number" />
		</xsl:apply-templates>
	</xsl:when>
	<xsl:otherwise>
		<xsl:apply-templates/>
	</xsl:otherwise>
    </xsl:choose>
    </table>
    </div>
</xsl:template>

<xsl:template match="category">
	<tr><td colspan="2">
		<xsl:value-of select="@name"/>
	</td></tr>
	<xsl:apply-templates match="audio"/>
</xsl:template>

<xsl:template match="project">
        <tr>
        <td>
            <blockquote>
                <xsl:value-of select="@id"/><br/><xsl:if test="image"><img alt="{@id}" src="./picture/{image[1]}"/></xsl:if>
            </blockquote>
        </td>
        <td>
            <blockquote>
        <p class="name">
		<xsl:value-of select="@name"/>
		<xsl:if test="@availability">
			<xsl:text> </xsl:text>
			<a href="?page=buy">(<xsl:value-of select="@availability" />)</a>
		</xsl:if>
	</p>
        <ul>
        <xsl:apply-templates select="audio" />
        </ul>
        <p class="descr"><xsl:copy-of select="descr"/></p>
        </blockquote>
        </td>
        </tr>
</xsl:template>

<xsl:template match="news">
        <tr><td>
	<table>
	<tr class="date"><a name="{@date}"/><td><xsl:value-of select="@display"/></td></tr>
	<tr><td><xsl:copy-of select="./*" /></td>
	</tr>
	</table>
	</td></tr>
</xsl:template>

<xsl:template match="news" mode="news">
	<table>
	<tr class="date"><td><xsl:value-of select="@display"/></td></tr>
	<tr><td><xsl:copy-of select="./*" /></td>
	</tr>
	</table>
</xsl:template>

<xsl:template match="audio">
    <li>
	<xsl:choose>
		<xsl:when test="@type='streaming'">
			<object type="application/x-shockwave-flash" 
				data="dewplayer.swf?son=http://earnyourears.free.fr/audio/{@id}.{@format}&amp;bgcolor=FFFFFF&amp;volume=60" width="200" height="20">
					<param name="movie" value="dewplayer.swf?son=http://earnyourears.free.fr/audio/{@id}.{@format}&amp;bgcolor=FFFFFF&amp;volume=60" />
			</object>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="@title"/> (<a class="dl" href="http://earnyourears.free.fr/audio/{@id}.{@format}">download</a>)
		</xsl:otherwise>
	</xsl:choose>
	<xsl:copy-of select="*"/>
	</li>
</xsl:template>


<xsl:template match="add" name="add">
	<p>
		<xsl:param name="input"/>
		<xsl:param name="number" select="8"/>
		<xsl:choose>
			<xsl:when test="not($number) or  not ($input)"/>
			<xsl:when test="$number = 1">
				<xsl:value-of select="$input"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:if test="$number mod 2">
					<xsl:value-of select="$input"/>
				</xsl:if>
				<xsl:call-template name="dup">
					<xsl:with-param name="input" select="concat($input,$input)"/>
					<xsl:with-param name="number" select="floor($number div 2)"/>
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</p>
</xsl:template>

<xsl:template match="category" name="caddie" mode="caddie">
	 <form id="shopping_card" name="shopping_card" action="https://www.paypal.com/en/cgi-bin/webscr" method="post">
			<input type="hidden" name="cmd" value="_xclick" />
			<input type="hidden" name="business" value="{$paypal_account}" />
			<input type="hidden" name="currency_code" value="{$devise}" />
		<table>
		<colgroup>
			<col width="15%" />
			<col width="55%" />
		</colgroup>
		<colgroup>
			<col width="10%" />
			<col width="10%" />
		</colgroup>
			<thead>
				<tr>
					<th></th><th></th><th>price</th><th>quantity</th><th>total</th>
				</tr>
			</thead>
			<tbody>
					<xsl:apply-templates select="project[@availability]" mode="caddie"/>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="4" align="right">Subtotal</td>
					<td ><input class="prix" name="totalamount" size="8" value="0" disabled="disabled" type="text" /><xsl:value-of select="$devise"/>
					<input name="amount" value="0.00" type="hidden" /> 
					</td>
				</tr>
				<tr>
					<td align="right" colspan="5">
						Shipping: 
						<input type="radio" selected="selected" name="shipping" value="{$shipping_fees_europa}" /> France and Europa (<xsl:value-of select="concat($shipping_fees_europa,' ',$devise)"/>) 
						<input type="radio" name="shipping" value="{$shipping_fees_others}" /> Others countries (<xsl:value-of select="concat($shipping_fees_others,' ',$devise)"/>)
					</td>
				</tr>
				<tr>
					<td align="right" colspan="5">
						<input type="hidden" name="item_name" value="{$item_name}" />
						<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Effectuez vos paiements via PayPal : une solution rapide, gratuite et sécurisée" />
					</td>
				</tr>
			</tfoot>
		</table>
    	</form>
</xsl:template>

<xsl:template match="project" name="caddie_item" mode="caddie">
<tr>
		<td><img src="./picture/{image[@type='buy']}"/></td>
		<td>
		<xsl:value-of select="@id"/><br />
			<xsl:value-of select="@name"/> 		
			<xsl:if test="@time">
				<xsl:text> (total time: </xsl:text>
				<xsl:value-of select="@time" />
				<xsl:text>)</xsl:text>
			</xsl:if>
			<xsl:if test="@comment">
				<blockquote class="warning">
					<xsl:value-of select="@comment"/>
				</blockquote>
			</xsl:if>
		</td>
		<td><input type="text" size="3" disabled="disabled" name="{concat('pu','_',position())}" value="{@price}" /></td>
		<td>
            <select>
                <xsl:attribute name="onchange" ><xsl:text>calculQ(this);</xsl:text></xsl:attribute>
                <xsl:attribute name="name" ><xsl:value-of select="concat('q','_',position())" /></xsl:attribute>
                <xsl:if test="@availability!='buy'">
                    <xsl:attribute name="disabled" value="disabled" />
                    <option value="{@availability}" selected="selected"><xsl:value-of select="@availability" /></option> 
                </xsl:if>
				<option value="0">0</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3">3</option>
				<option value="4">4</option>
				<option value="5">5</option>
			</select>
</td>
<td>
	<input disabled="disabled" type="text" size="4" name="{concat('amount','_',position())}" value="0" /><xsl:value-of select="$devise"/>
</td>
</tr>

</xsl:template>

</xsl:stylesheet> 

