<?xml version="1.0"?>

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

<xsl:import href="main.xsl"/>

<xsl:param name="success"/>
<xsl:param name="errorField"/>
<xsl:param name="mail" select="true()"/>
<xsl:param name="nameText"/>
<xsl:param name="emailText"/>
<xsl:param name="subjectText"/>
<xsl:param name="messageText"/>

<xsl:template match="content" mode="head">
	<xsl:if test="not($error='' or $errorField='')">
		<xsl:call-template name="script-generator">
			<xsl:with-param name="code">
				<xsl:text>
				onload = function()
				{ document.forms[0].</xsl:text>
				<xsl:value-of select="$errorField"/>
				<xsl:text>.select();
				}</xsl:text>
			</xsl:with-param>
		</xsl:call-template>
	</xsl:if>
</xsl:template>

<xsl:template match="content">
	<xsl:choose>
		<xsl:when test="$success='true'">
			<p id="success">Your message has been sent.</p>
		</xsl:when>
		<xsl:otherwise>
			<xsl:if test="not($error)">
				<p>
					<xsl:text>Fill out the form below to send me an email, and I will be in touch shortly. If you would like to encrypt your message, here is </xsl:text>
					<a title="My PGP public key">
						<xsl:attribute name="href">
							<xsl:call-template name="target-handler">
								<xsl:with-param name="target">/contact/key/</xsl:with-param>
							</xsl:call-template>
						</xsl:attribute>
						<xsl:text>my public key</xsl:text>
					</a>
					<xsl:text>.</xsl:text>
				</p>
			</xsl:if>

			<xsl:if test="not($mail)">
				<p>
					<xsl:text>In order to prevent spam, a cookie with your session </xsl:text>
					<acronym title="identifier">ID</acronym>
					<xsl:text> needs to be set. Please enable cookies in your browser and </xsl:text>
					<a title="Start another email after enabling cookies">
						<xsl:attribute name="href">
							<xsl:call-template name="target-handler">
								<xsl:with-param name="target">/contact/</xsl:with-param>
							</xsl:call-template>
						</xsl:attribute>

						<xsl:text>start over</xsl:text>
					</a>
					<xsl:text>.</xsl:text>
				</p>
			</xsl:if>

			<xsl:if test="$mail">
				<form id="mail" method="post">
					<xsl:attribute name="action">
						<xsl:call-template name="target-handler">
							<xsl:with-param name="target">/contact/</xsl:with-param>
						</xsl:call-template>
					</xsl:attribute>

					<fieldset>
						<legend>Message Information</legend>
						<dl>
							<xsl:apply-templates/>					
						</dl>
					</fieldset>
					<div>
						<input class="button" id="submitButton" type="submit" value="send" />
					</div>
				</form>
			</xsl:if>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="field[@title]">
<xsl:variable name="first-letter" select="substring(@title, 1, 1)"/>

	<dt>
		<span class="access">
			<xsl:call-template name="capitalizor">
				<xsl:with-param name="text" select="$first-letter"/>
			</xsl:call-template>
		</span>
		<xsl:value-of select="substring(@title, 2)"/>	
	</dt>
	<dd>
		<xsl:choose>
			<xsl:when test="@type='textarea'">
				<textarea name="{@title}" accesskey="{$first-letter}" cols="{@width}" rows="{@rows}">
					<xsl:if test="not($messageText='')">
						<xsl:value-of select="$messageText"/>
					</xsl:if>
				</textarea>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="val">
					<xsl:choose>
						<xsl:when test="@title='name' and not($nameText='')">
							<xsl:value-of select="$nameText"/>
						</xsl:when>
						<xsl:when test="@title='email' and not($emailText='')">
							<xsl:value-of select="$emailText"/>
						</xsl:when>
						<xsl:when test="@title='subject' and not($subjectText='')">
							<xsl:value-of select="$subjectText"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text></xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>

				<input type="text" name="{@title}" accesskey="{$first-letter}" maxlength="{@maxlen}" value="{$val}"/>
			</xsl:otherwise>
		</xsl:choose>
	</dd>
</xsl:template>
<!--
<xsl:template name="title-generator">
<xsl:param name="markup" select="true()"/>

<xsl:variable name="msgText">
	<xsl:choose>
		<xsl:when test="not($error='')">Problem With Your Message</xsl:when>
		<xsl:when test="$success='true'">Thank You</xsl:when>
	</xsl:choose>
</xsl:variable>

	<xsl:choose>
		<xsl:when test="$markup and $msgText=''">
			<span id="local">Contact</span>
		</xsl:when>
		<xsl:otherwise>Contact</xsl:otherwise>
	</xsl:choose>
	
	<xsl:if test="not($msgText='')">
		<xsl:choose>
			<xsl:when test="$markup">
				<span class="separator">
					<xsl:value-of select="$separator"/>
				</span>
				<span id="local">
					<xsl:value-of select="$msgText"/>
				</span>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$separator"/>
				<xsl:value-of select="$msgText"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:if>
</xsl:template>
-->
</xsl:stylesheet>
