<%
/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
%>

<%
String[] modifiedSections = StringUtil.split(ParamUtil.getString(request, "modifiedSections"));

for (int i = 0; i < categoryNames.length; i++) {
	String category = categoryNames[i];
	String[] sections = categorySections[i];

	if (sections.length > 0) {
%>

		<div class="menu-group">
			<h3><liferay-ui:message key="<%= category %>" /></h3>

			<ul>

				<%
				String errorSection = (String)request.getAttribute("errorSection");

				if (Validator.isNotNull(errorSection)) {
					curSection = StringPool.BLANK;
				}

				for (String section : sections) {
					String sectionId = _getSectionId(section);

					Boolean show = (Boolean)request.getAttribute(WebKeys.FORM_NAVIGATOR_SECTION_SHOW + sectionId);

					if ((show != null) && !show.booleanValue()) {
						continue;
					}

					boolean error = false;

					if (sectionId.equals(errorSection)) {
						error = true;

						curSection = section;
					}

					String cssClass = StringPool.BLANK;

					if (curSection.equals(section) || curSection.equals(sectionId)) {
						cssClass += "selected";
					}

					if (ArrayUtil.contains(modifiedSections, sectionId)) {
						cssClass += " section-modified";
					}

					if (error) {
						cssClass += " section-error";
					}
				%>

					<li class="<%= cssClass %>">
						<a href="#<%= sectionId %>" id="<%= sectionId %>Link">

						<liferay-ui:message key="<%= section %>" />

						<span class="modified-notice"> (<liferay-ui:message key="modified" />) </span>

						<c:if test="<%= error %>">
							<span class="error-notice"> (<liferay-ui:message key="error" />) </span>
						</c:if>

						</a>
					</li>

				<%
				}
				%>

			</ul>
		</div>

<%
	}
}
%>

<aui:script use="liferay-enterprise-admin">
	var <portlet:namespace />formNavigator = new Liferay.EnterpriseAdmin.FormNavigator(
		{
			container: '#<portlet:namespace />sectionsContainer',
			defaultModifiedSections: <%= JS.toScript(modifiedSections) %>,
			modifiedSections: '<portlet:namespace />modifiedSections'
		}
	);

	<%
	String errorSection = (String)request.getAttribute("errorSection");
	%>

	<c:if test="<%= Validator.isNotNull(errorSection) %>">
		<portlet:namespace />formNavigator._revealSection('#<%= errorSection %>', '');
	</c:if>
</aui:script>

<%!
private String _getSectionId(String name) {
	return TextFormatter.format(name, TextFormatter.M);
}

private String _getSectionJsp(String name) {
	return TextFormatter.format(name, TextFormatter.N);
}
%>