<%-- 
/**
  * Copyright (c) 2004 Red Hat, 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 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.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  * USA
  *
  * Component of: Red Hat Application Server
  * 
  * Initial Developers: Aizaz Ahmed
  *                     Vivek Lakshmanan
  *                     Andrew Overholt
  *                     Matthew Wringe
  *
  */
--%>

<%@ page contentType="text/html"
         import="olstore.util.WebUtils"
         import="java.lang.Integer"
%>
<%-- Parameters this form expects are:
        - formPrefix
        - prefix + numOfFields
        - prefix + numOfCols
        - prefix + Columni for every i
        - prefix + ColumnSizei for every i
     The fields are referred to as prefix + Field + row + "_" + col
--%>

<!-- Generate the form -- >
<%
    String prefix = (String) WebUtils.getValue ( "formPrefix", request );
    String numStr = (String) WebUtils.getValue ( prefix + "numOfFields", request );
    if ( WebUtils.isEmpty ( numStr ) ) { numStr = "5"; }
    int num = Integer.parseInt ( numStr );
    String numColsStr = (String) WebUtils.getValue ( prefix + "numOfCols", request );
    if ( WebUtils.isEmpty ( numColsStr ) ) { numStr = "1"; }
    int cols = Integer.parseInt ( numColsStr );
%>

    <!-- The form must be opened and closed in the caller jsp, because
         they must add the fields specific to the object being created -->
    <SCRIPT LANGUAGE="JavaScript" SRC="../general/validate.js">
    </SCRIPT>

    <table class="fields"><tr class="header"><td></td>
<%
    for ( int i =1 ; i <= cols ; i++ ) {
%>
        <td class="bodyText"><%=WebUtils.getValue(prefix + "Column" + i, request)%></td>
<%  } %>
    </tr>

<%
    for ( int row = 1 ; row <= num ; row++ ) {
        %><tr><td><%=row%>) </td><%
        for ( int col = 1 ; col <= cols ; col ++ ) {
            String fieldName = prefix+"Field"+row+"_"+col;
            String value = (String) WebUtils.getValue(fieldName, request );
            if ( value == null ) {
                value = "";
            }
            String colSize = WebUtils.getValue ( prefix + "ColumnSize" + col, request );
%>
            <td> <input name="<%=fieldName%>" type="text" size="<%=colSize%>" value="<%=value%>" ></td>
	    <div id="ValEmptyTF<%=fieldName%>"></div>
<%      }
        %></tr><%
    }
    String saveFormPrefix = WebUtils.getValue ( "saveFormPrefix", request );
%>
    </table>
    <input type="hidden" name=<%= prefix + "commitType" %> value="no" visible="false" >
	<div>
    Total number of fields: <input name=<%= prefix + "numOfFields"%> type="text" size="2" value="<%=num%>" >
</div>
    <div id="ValNumOut<%=prefix + "numOfFields"%>" style="visibility:hidden;" class="validation"> Please Enter a Number !</div>

    <input name="update" type="submit" value="Update" onClick="this.form.<%= WebUtils.isEmpty ( saveFormPrefix ) ? prefix + "commitType": saveFormPrefix + "commitType"%>.value='edit'" >

<%
    String noSaveButton = WebUtils.getValue ( prefix + "noSaveButton", request );
    if ( WebUtils.isEmpty ( noSaveButton ) || ! noSaveButton.equals("true") ) {
%>
        <input name="commit"
               type="submit"
               value="Save"
               onClick="this.form.<%=prefix+"commitType"%>.value='commit'; return(validateForm(this.form))" >
<%  } %>
