<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.ampiere.search.ComponentBean" %>
<%@ page import="com.ampiere.dto.CodeValue" %>
<%@ page import="com.ampiere.util.AmpiereUtil" %>
<jsp:include page="/ampiere/jsp/common/includeYAHOOUI.jsp" flush="true" /> 
<html>
<head>
<title><bean:write name="infoPattributeForm" property="title"/></title>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/ampiere/css/import.css" />
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/ampiere/css/window.css"/>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/ampiere/css/displaytag.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/ampiere/js/window.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/ampiere/js/DatePicker.js"></script>
<style type="text/css">
<!--
-->
</style>
<script type="text/javascript">
var paraMonths = <bean:write name="infoPattributeForm" property="months" filter="false"/>;
var paraShortMonths = <bean:write name="infoPattributeForm" property="shortMonths" filter="false"/>;
var paraWeeks = <bean:write name="infoPattributeForm" property="weeks" filter="false"/>;
var paraShortWeeks = <bean:write name="infoPattributeForm" property="shortWeeks" filter="false"/>;
var paraDateFormat = <bean:write name="infoPattributeForm" property="dateFormat" filter="false"/>;
var paraInvalidDateMsg = <bean:write name="infoPattributeForm" property="invalidDateMsg" filter="false"/>;

function pattributeSearch() {
	if (! checkParent(window)) {
		window.close();
		return;
	}

	if (window.opener.top.document.infoProductForm) {
		if (componentNum > 0) {
			var whereClause = "";
			var count = 0;
			for (var ii = 0; ii < componentNum; ii++) {
				var o = document.getElementById("pattribute" + ii);
				if (o != null && o.value != null && o.value != "") {
					whereClause += (ii + "," + o.value + ";");
					count++;
				}
			}

			if (whereClause != "" && count > 1) {
				window.opener.initProgress();
				window.opener.top.document.infoProductForm.paSearchFlag.value = "true";
				window.opener.top.document.infoProductForm.paSearchWhere.value = whereClause;
				window.opener.top.document.infoProductForm.submit();
			}	
		}
	}

    window.close();
	window.opener.focus();
}
</script>
</head>

<body id="popup" onunload="closeMyChildren();">
	<table width="100%" >
	<tr>
	<td>
<div id="header">
		<h1><bean:write name="infoPattributeForm" property="title"/></h1>
</div>
	<td valign="top" width="18">
    <div id="progressMsg" style="padding-top:1px;display:none;"><img src="${pageContext.request.contextPath}/ampiere/images/Loading-0.gif" /></div>
    </td>
    </tr>
	</table>

<!-- header -->


<!-- body -->
<div id="body" >
<div class="search-box">

	<form style="margin:0;" target="_self" id="pattributeForm" name="pattributeForm" enctype="application/x-www-form-urlencoded" focus="pattribute1">
	<table cellspacing="4" cellpadding="0" class="popupInfoTable">
	<tr>
<%
com.ampiere.search.InfoPAttribute infoPAttribute = (com.ampiere.search.InfoPAttribute)session.getAttribute("infoPAttribute");
ArrayList componentList = null;
if (infoPAttribute != null) {
	componentList = infoPAttribute.getComponentList();
}
if (componentList != null) {
%>
<script type="text/javascript">
var componentNum = <%= componentList.size() %>;
</script>
<%
	for (int i = 0; i < componentList.size(); i++) {
		ComponentBean componentBean = (ComponentBean)componentList.get(i);
		if (componentBean == null) continue;
		switch (componentBean.getType()) {
		case ComponentBean.TYPE_LABEL:
%>
    		<td align="<%= componentBean.getAlign() %>"><%= componentBean.getLabel() %></td>
<%
			break;
		case ComponentBean.TYPE_NUMBER:
		case ComponentBean.TYPE_TEXT:
%>
			<td align="<%= componentBean.getAlign() %>"><input type="text" id="pattribute<%= Integer.toString(i) %>" style="width:<%= componentBean.getWidth() %>px" value="<%= componentBean.getContent() %>"/></td>
<%
			break;
		case ComponentBean.TYPE_SELECT:
			ArrayList selectListBean = (ArrayList)componentBean.getContent();
%>
			<td align="<%= componentBean.getAlign() %>">
			<select id="pattribute<%= Integer.toString(i) %>" style="width:<%= componentBean.getWidth() %>px;">
<%
			if (selectListBean != null && selectListBean.size() > 0) {
				for (int ii = 0; ii < selectListBean.size(); ii++) {
					CodeValue pair = (CodeValue)selectListBean.get(ii);
					if (pair != null) {
						if (componentBean.getLabel() != null && componentBean.getLabel().equalsIgnoreCase(pair.getCode())) {
%>
							<option value="<%= pair.getCode() %>" selected="selected"><%= pair.getValue() %></option>
<%
						} else {
%>
							<option value="<%= pair.getCode() %>"><%= pair.getValue() %></option>
<%
						}
					}
				}
			}
%>
			</select>
			</td>
<%
			break;
		case ComponentBean.TYPE_BR:
%>
		    </tr>
		    <tr>
<%
			break;
		case ComponentBean.TYPE_DATE:
%>
			<td align="<%= componentBean.getAlign() %>">
				<input type="text" id="pattribute<%= Integer.toString(i) %>" name="pattribute<%= Integer.toString(i) %>" style="width:<%= componentBean.getWidth() %>px;" value="<%= componentBean.getContent()%>" onchange="checkDateValidation(this, paraInvalidDateMsg);"/>
				&nbsp;<img src="${pageContext.request.contextPath}/ampiere/images/Calendar16.png" id="$recDate$toggle" name="$recDate$toggle" class="popupButton" 
						onclick="recDate_onclick_function('pattribute<%= Integer.toString(i) %>', 'pattributeForm', paraMonths, paraShortMonths, paraWeeks, paraShortWeeks, paraDateFormat);"/>
		    </td>
<%
			break;
		}
	}
} else {
%>
<script type="text/javascript">
var componentNum = 0;
</script>
<%
}
%>
	</tr>
	</table>
	</form>



</div>

<!-- body-footer -->
<div class="bottomMenuRight">
<table>
	<tr>
	<td class="lbl" style="padding-right:5px;">
    	<input id="ok" type="image" src="${pageContext.request.contextPath}/ampiere/images/Ok32.png" onclick="pattributeSearch();" alt="<bean:write name='infoPattributeForm' property='submitBtnTitle'/>"/>
		<span>OK</span>
    	<input id="cancel" type="image" src="${pageContext.request.contextPath}/ampiere/images/Cancel32.png" onclick="window.close();return false;" alt="<bean:write name='infoPattributeForm' property='closeBtnTitle'/>"/>
		<span>キャンセル</span>
	    </td>
	</tr>
	</table>
</div>
<!-- /body-footer -->
</div>
<!-- /body -->
</body>
</html>
