<%@ page import="org.thdl.lex.*,org.thdl.lex.component.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sess" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="str" uri="http://jakarta.apache.org/taglibs/string-1.0" %>
<!--metaForm.jsf-->

<c:choose>
	<c:when test="${ ! empty param.formMode && param.formMode == 'insert'}">
		<c:set var="updateMode" value="${ false }" />		
		<c:set var="language" value="${ sessionScope.preferences.language }" />
		<c:set var="dialect" value="${ sessionScope.preferences.dialect }" />
		<c:set var="source" value="${ sessionScope.preferences.source }" />
		<c:set var="projectSubject" value="${ sessionScope.preferences.projectSubject }" />
		<c:set var="script" value="${ sessionScope.preferences.script }" />
		<%-- <c:set var="precedence" value="1" /> --%>
		<c:set var="note" value="${ sessionScope.preferences.note }" />
	</c:when>
	<c:when test="${ ! empty param.formMode && param.formMode == 'update'}">
		<c:set var="updateMode" value="${ true }" />		
		<c:set var="language" value="${ component.language }" />
		<c:set var="dialect" value="${ component.dialect }" />
		<c:set var="source" value="${ component.source }" />
		<c:set var="projectSubject" value="${ component.modifiedByProjSub }" />
		<c:set var="script" value="${ component.script }" />
		<%-- <c:set var="precedence" value="${ component.precedence }" /> --%>
		<c:set var="note" value="${ component.note }" />
	</c:when>
	<c:otherwise>
		<c:set var="updateMode" value="${ false }" />		
		<c:set var="language" value="ERROR" />
		<c:set var="dialect" value="ERROR" />
		<c:set var="source" value="ERROR" />
		<c:set var="projectSubject" value="ERROR" />
		<c:set var="script" value="ERROR" />
		<%-- <c:set var="precedence" value="ERROR" /> --%>
		<c:set var="note" value="ERROR" />
	</c:otherwise>
</c:choose>
<c:if test="${ component.translationOf > 0 }">
	<c:set var="translateMode" value="${ true }" />
	<c:set var="originalNote" value="Original Metadata Note: ${ note } <br /> Translation " />
	<c:set var="note" value="" />
</c:if>

<c:if test="${ translateMode }">
<c:out value='<input type="hidden" name="translationOf" value="${ component.translationOf }" />'escapeXml="false" />
</c:if>

<c:if test="${ ! updateMode && param.cmd != 'annotate' && param.cmd != 'getTranslationForm' }">
<p>
Analysis: <br />
<textarea name="analyticalNote" rows="8" cols="90"></textarea>
</p>
</c:if>

<!--Add Token-->
<c:out value='<input type="hidden" name="token" value="${ sessionScope.token }" />' escapeXml="false" />

<c:choose>
<c:when test="${ ! sessionScope.preferences.useDefaultLanguage || updateMode }">
<p>
Language: 
<select name="language">
	<c:set var="sel" value="" />
	<c:if test="${ 0 == language }">
		<c:set var="sel" value="selected='selected'" />
	</c:if>
	<c:out value="<option value='0' ${sel}>none</option>" escapeXml="false" /> 
		<c:forEach var="prefLangs" items="${ sessionScope.preferences.languageSet }">
		<c:set var="sel" value="" />		
		<c:if test="${ language == prefLangs }">
			<c:set var="sel" value="selected='selected'" />
		</c:if>
		<c:out value='<option value="${ prefLangs }" ${ sel }>${ applicationScope.flatData.languages[ prefLangs ] }</option>' escapeXml="false" />
	</c:forEach>
	<%-- <option disabled="disabled" value="">----------------</option> --%>
	<c:forEach var="langs" items="${ applicationScope.flatData.languages }">
		<c:set var="printOption" value="${ true }" />
		<c:forEach var="prefLangs" items="${ sessionScope.preferences.languageSet }">
			<c:if test="${ prefLangs == langs.key }">
				<c:set var="printOption" value="${ false }" />
			</c:if>
		</c:forEach>
		<c:if test="${ printOption }">
			<c:set var="sel" value="" />		
			<c:if test="${ langs.key == language }">
				<c:set var="sel" value="selected='selected'" />
			</c:if>
			<c:out value='<option value="${ langs.key }" ${sel}>${ langs.value }</option>' escapeXml="false" />
		</c:if>
	</c:forEach>
</select>
</p>
</c:when>
<c:otherwise>
	<c:out value='<input type="hidden" name="language" value="${ sessionScope.preferences.language }" />' escapeXml='false' /> 
</c:otherwise>
</c:choose>

<c:choose>
<c:when test="${ ! sessionScope.preferences.useDefaultScript || updateMode }">
<p>
Script: 
<select name="script">
	<c:set var="sel" value="" />
	<c:if test="${ 0 == script }">
		<c:set var="sel" value="selected='selected'" />
	</c:if>
	<c:out value="<option value='0' ${sel}>none</option>" escapeXml="false" /> 
<c:forEach var="prefScripts" items="${ sessionScope.preferences.scriptSet }">
		<c:set var="sel" value="" />		
		<c:if test="${ script == prefScripts }">
			<c:set var="sel" value="selected='selected'" />
		</c:if>
<c:out value='<option value="${ prefScripts }" ${ sel }>${ applicationScope.flatData.scripts[ prefScripts ] }</option>' escapeXml="false" />
</c:forEach>
<option disabled="disabled" value="">----------------</option>
<c:forEach var="scripts" items="${ applicationScope.flatData.scripts }">
	<c:set var="printOption" value="${ true }" />
	<c:forEach var="prefScripts" items="${ sessionScope.preferences.scriptSet }">
		<c:if test="${ prefScripts == scripts.key }">
			<c:set var="printOption" value="${ false }" />
		</c:if>
	</c:forEach>
<c:if test="${ printOption }">
			<c:set var="sel" value="" />		
			<c:if test="${ scripts.key == script }">
				<c:set var="sel" value="selected='selected'" />
			</c:if>
<c:out value='<option value="${ scripts.key }"  ${ sel }>${ scripts.value }</option>' escapeXml="false" />
</c:if>
</c:forEach>
</select>

</p>
</c:when>
<c:otherwise>
	<c:out value='<input type="hidden" name="script" value="${ sessionScope.preferences.script }" />' escapeXml='false' /> 
</c:otherwise>
</c:choose>

<c:choose>
<c:when test="${ ! sessionScope.preferences.useDefaultDialect || updateMode }">
<%-- <c:if test="${ ! translateMode }"> --%>
<p>
Dialect: 
<select name="dialect">
	<c:set var="sel" value="" />
	<c:if test="${ 0 == dialect }">
		<c:set var="sel" value="selected='selected'" />
	</c:if>
	<c:out value="<option value='0' ${sel}>none</option>" escapeXml="false" /> 
<c:forEach var="prefDials" items="${ sessionScope.preferences.dialectSet }">
		<c:set var="sel" value="" />		
		<c:if test="${ dialect == prefDials }">
			<c:set var="sel" value="selected='selected'" />
		</c:if>
<c:out value='<option value="${ prefDials }" ${ sel }>${ applicationScope.flatData.majorDialectFamilies[ prefDials ] }</option>' escapeXml="false" />
</c:forEach>
	<option disabled="disabled" value="">----------------</option>
<c:forEach var="dials" items="${ applicationScope.flatData.majorDialectFamilies }">
	<c:set var="printOption" value="${ true }" />
	<c:forEach var="prefDials" items="${ sessionScope.preferences.dialectSet }">
		<c:if test="${ prefDials == dials.key }">
			<c:set var="printOption" value="${ false }" />
		</c:if>
	</c:forEach>
<c:if test="${ printOption }">
			<c:set var="sel" value="" />		
			<c:if test="${ dials.key == dialect }">
				<c:set var="sel" value="selected='selected'" />
			</c:if>
<c:out value='<option value="${ dials.key }"  ${ sel }>${ dials.value }</option>' escapeXml="false" />
</c:if>
</c:forEach>
</select>
</p>
</c:when>
<c:otherwise>
	<c:out value='<input type="hidden" name="dialect" value="${ sessionScope.preferences.dialect }" />' escapeXml='false' /> 
</c:otherwise>
</c:choose>

<c:choose>
<c:when test="${ ! sessionScope.preferences.useDefaultSource  || updateMode }">
<p>
Source: 
<select name="source">
	<c:set var="sel" value="" />
	<c:if test="${ 0 == source }">
		<c:set var="sel" value="selected='selected'" />
	</c:if>
	<c:out value="<option value='0' ${sel}>none</option>" escapeXml="false" /> 
<c:forEach var="prefSources" items="${ sessionScope.preferences.sourceSet }">
		<c:set var="sel" value="" />		
		<c:if test="${ source == prefSources }">
			<c:set var="sel" value="selected='selected'" />
		</c:if>
<c:out value='<option value="${ prefSources }" ${ sel }>${ applicationScope.flatData.sources[ prefSources ] }</option>' escapeXml="false" />
</c:forEach>
<option disabled="disabled" value="">----------------</option>
<c:forEach var="srcs" items="${ applicationScope.flatData.sources }">
	<c:set var="printOption" value="${ true }" />
	<c:forEach var="prefSources" items="${ sessionScope.preferences.sourceSet }">
		<c:if test="${ prefSources == srcs.key }">
			<c:set var="printOption" value="${ false }" />
		</c:if>
	</c:forEach>
<c:if test="${ printOption }">
			<c:set var="sel" value="" />		
			<c:if test="${ srcs.key == source }">
				<c:set var="sel" value="selected='selected'" />
			</c:if>
<c:out value='<option value="${ srcs.key }"  ${ sel }>${ srcs.value }</option>' escapeXml="false" />
</c:if>
</c:forEach>
</select>
</p>
</c:when>
<c:otherwise>
	<c:out value='<input type="hidden" name="source" value="${ sessionScope.preferences.source }" />' escapeXml='false' /> 
</c:otherwise>
</c:choose>

<c:choose>
<c:when test="${ ! sessionScope.preferences.useDefaultProjSub  || updateMode }">
<p>
Project/Subject: 
<select name="projectSubject" style="width: 80%;">
	<c:set var="sel" value="" />
	<c:if test="${ 0 == projectSubject }">
		<c:set var="sel" value="selected='selected'" />
	</c:if>
	<c:out value="<option value='0' ${sel}>none</option>" escapeXml="false" /> 
<c:forEach var="prefProjSub" items="${ sessionScope.preferences.projectSubjectSet }">
		<c:set var="sel" value="" />		
		<c:if test="${ projectSubject == prefProjSub }">
			<c:set var="sel" value="selected='selected'" />
		</c:if>
<c:out value='<option value="${ prefProjSub }" ${ sel }>${ applicationScope.flatData.projectSubjects[ prefProjSub ] }</option>' escapeXml="false" />
</c:forEach>
<option disabled="disabled" value="">----------------</option>
<c:forEach var="projSubs" items="${ applicationScope.flatData.projectSubjects }">
	<c:set var="printOption" value="${ true }" />
	<c:forEach var="prefProjSub" items="${ sessionScope.preferences.projectSubjectSet }">
		<c:if test="${ prefProjSub == projSubs.key }">
			<c:set var="printOption" value="${ false }" />
		</c:if>
	</c:forEach>
<c:if test="${ printOption }">
	<c:set var="sel" value="" />		
	<c:if test="${ projSubs.key == projectSubject }">
		<c:set var="sel" value="selected='selected'" />
	</c:if>
<c:out value='<option value="${ projSubs.key }"  ${ sel }>${ projSubs.value }</option>' escapeXml="false" />
</c:if>
</c:forEach>
</select>
</p>
</c:when>
<c:otherwise>
	<c:out value='<input type="hidden" name="projectSubject" value="${ sessionScope.preferences.projectSubject }" />' escapeXml='false' /> 
</c:otherwise>
</c:choose>

<c:choose>
<c:when test="${ ! sessionScope.preferences.useDefaultNote  || updateMode }">

<p>
<c:out value="${ originalNote }" escapeXml="false"/>
Metadata Note: <br />
<textarea name="note" rows="8" cols="90"><c:out value='${ note }' escapeXml='false' /></textarea> <br />
</p>
</c:when>
<c:otherwise>
	<c:out value='<input type="hidden" name="note" value="${ sessionScope.preferences.note }" />' escapeXml='false' /> 
</c:otherwise>
</c:choose>


