<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:strip-space elements="*"/>
	<xsl:output method="html" indent="yes" encoding="utf-8"/>

	<xsl:template match="DELEGATED-CONTENT">
		<xsl:param name="additionalContent" />
		<xsl:param name="status" />

		<script type="text/javascript" src="/js/SSO/UserSelection.js?{$version}.{$build}"/>
		
		<table width="100%"  border="0">
			<tr>
				<td align="center">
					<table align="center" width="40%">
						<tr><td>
							<div style="width:100%;" border="0">
								<xsl:if test="$status">
									<xsl:apply-templates select="$status" mode="admin">
										<xsl:with-param name="controlStyle">padding: 10px;</xsl:with-param>
									</xsl:apply-templates>
								</xsl:if>
							</div>
						</td></tr>
						<tr><td>
							<fieldset class="sb-toolbar-fieldset" style="padding-left:10px">
								<legend class="sb-label-toolbar-title"><xsl:value-of select="/SITEBUILDER-PAGE/LOCALE/SELECT-ACCOUNT" /></legend>
								<form name="loginForm" action="{@ACTION}" method="post" id="loginForm" onsubmit="javascript:return validateForm();">
									<xsl:apply-templates select="$additionalContent" />
									<xsl:variable name="dropdown" select="CONTROL[@NAME='name']" />
									<xsl:if test="$dropdown and $dropdown/@COUNT > 0">
										<div style="padding-top: 10px;"></div>
										<xsl:call-template name="USER-SELECTION" />
									</xsl:if>

									<div id="enterAccountForm" style="width:100%;padding:10px;padding-left:0px">
										<xsl:if test="$dropdown and $dropdown/@COUNT > 0">
											<xsl:attribute name="style">width:100%;display:none;padding: 10px;padding-left:0px</xsl:attribute>
										</xsl:if>
										<xsl:call-template name="USER-LOGIN" />
									</div>
									<!-- input image needed for work default submit via Enter -->
									<input type="image" style="border-width: 0px; height: 0px; width: 0px;"/>
								</form>
							</fieldset>
						</td></tr>
						<tr><td>
							<table width="100%">
								<tr>
									<td align="right" style="padding: 10px;padding-top:0px">
										<xsl:apply-templates select="CONTROL[@TYPE='BUTTON']">
											<xsl:with-param name="class">sb-login-control-button</xsl:with-param>
											<xsl:with-param name="action">javascript:validateForm();</xsl:with-param>
										</xsl:apply-templates>
									</td>
								</tr>
							</table>
						</td></tr>
					</table>
				</td>
			</tr>
		</table>
	</xsl:template>

	<xsl:template name="USER-LOGIN">
	
		<table cellpadding="0" cellspacing="0" border="0" class="control-title-input">
			<tr>
				<td class="title-block">
					<xsl:apply-templates select="CONTROL[@NAME='user_name']" mode="label"/>
				</td>
				<td class="input-block">
					<xsl:apply-templates select="CONTROL[@NAME='user_name']" mode="control"/>
				</td>
			</tr>
			<tr>
				<td class="title-block">
					<xsl:apply-templates select="CONTROL[@NAME='user_password']" mode="label"/>
				</td>
				<td class="input-block">
					<xsl:apply-templates select="CONTROL[@NAME='user_password']" mode="control">
						<xsl:with-param name="type">password</xsl:with-param>
					</xsl:apply-templates>
				</td>
			</tr>
			<tr>
				<td class="title-block">
					<xsl:apply-templates select="CONTROL[@TYPE='COMBO-BOX']" mode="label"/>
				</td>
				<td class="input-block">
					<xsl:apply-templates select="CONTROL[@TYPE='COMBO-BOX']" mode="control"/>
				</td>
			</tr>
		</table>

		<a class="sb-login-description">
			<xsl:attribute name='href'><xsl:value-of select="$baseUrl"/>/ForgetPassword</xsl:attribute>
			<xsl:value-of select="FORGOT-PASSWORD/@TITLE"/>
		</a>
					
	</xsl:template>

	<xsl:template name="USER-SELECTION">
		<script type="text/javascript">
			function onSubmitClick() {
				$('selectionForm').submit();
			}

			function onCancelClick() {
				disableForm();
				onSubmitClick();
			}

			function disableForm() {
				$('confirmed').disabled = true;
				$('name').disabled = true;
			}

			function onUserSelectionChange(source) {
				$('enterAccountForm').style.display = source.value == "ANOTHERACCOUNT" ? "block" : "none";
				return true;
			}
		</script>

		<xsl:value-of select="@DESCRIPTION"/> <!-- select an account under which you ... -->
		<div style="width: 0; height: 5px;"><span></span></div>		
		
		<table cellpadding="0" cellspacing="0" border="0" class="control-title-input">
			<tr>
				<td class="title-block"><xsl:apply-templates select="CONTROL[@NAME='name']" mode="label"/></td>
				<td class="input-block">
					<table cellpadding="0" cellspacing="0" border="0" class="control-input-title">
						<xsl:for-each select="CONTROL[@NAME='name']/CONTROL[@TYPE='RADIO-OPTION']">
							<tr>
								<td class="input-block" style="padding-bottom: 0;">
									<xsl:apply-templates select="." mode="control">
										<xsl:with-param name="id" select="@ID"/>
									<xsl:with-param name="onclick">javascript:onUserSelectionChange(this);</xsl:with-param>
									</xsl:apply-templates>
								</td>
								<td class="title-block" style="padding-bottom: 0;">
									<xsl:apply-templates select="." mode="label"/>
								</td>
							</tr>
						</xsl:for-each>
					</table>
				</td>
			</tr>
		</table>
					
	</xsl:template>
	
</xsl:stylesheet>
