<%@ 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/displaytag-12.tld" prefix="display" %>
<%@ taglib uri="http://ajaxtags.org/tags/ajax" prefix="ajax" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.ampiere.search.ComponentBean" %>
<%@ page import="com.ampiere.dto.CodeValue" %>
<%@ page import="com.ampiere.util.AmpiereUtil" %>
<%
com.ampiere.web.struts.search.InfoLookupForm myForm = (com.ampiere.web.struts.search.InfoLookupForm)session.getAttribute("searchInfoFormAssignment");
java.lang.String lookupID = "";
if (myForm != null) { lookupID = myForm.getLookupID(); }
com.ampiere.search.Info infoLookup = (com.ampiere.search.Info)session.getAttribute("infoLookup" + lookupID);
%>
<jsp:include page="/ampiere/jsp/common/includeYAHOOUI.jsp" flush="true" /> 
<html>
<head>
<title><bean:write name="searchInfoFormAssignment" 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/ajax/js/prototype-1.4.0.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/ampiere/ajax/js/scriptaculous.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/ampiere/ajax/js/overlibmws.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/ampiere/ajax/js/ajaxtags-1.2-beta1.js"></script>
<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>
<script type="text/javascript" src="${pageContext.request.contextPath}/ampiere/js/search.js"></script>
<%!
String getColTitle(Object obj, int idx) {
	if (obj == null) { return "&nbsp;"; } else { String s = AmpiereUtil.sanitizing(((com.ampiere.search.ColBean)obj).getColTitle(idx)); if (s == null || "".equals(s) || " ".equals(s)) { return "&nbsp;"; } else { return s; } }
}
String getColData(Object obj, int idx) {
	if (obj == null) { return "&nbsp;"; } else { Object o = (((com.ampiere.search.ColBean)obj).getColData(idx)); if (o == null) { return "&nbsp;"; } else { String s = AmpiereUtil.sanitizing(o.toString()); if (s == null || "".equals(s) || " ".equals(s)) { return "&nbsp;"; } else { return s; } } }
}
String getColStyle(Object obj, int idx) {
	if (obj == null) { return ""; } else { Object o = (((com.ampiere.search.ColBean)obj).getStyle(idx)); if (o == null) { return ""; } else { return AmpiereUtil.sanitizing((String)o); } }
}
String getLookupIcon(String columnName) {
	String iconName = "PickOpen16.gif";
	if (columnName != null && columnName.length() > 0) {
		if (columnName.indexOf("Locator") >= 0)
			iconName = "Location16.gif";
		else if (columnName.indexOf("Account") >= 0)
			iconName = "Account16.gif";
		else if (columnName.indexOf("BPartner") >= 0)
			iconName = "BPartner16.png";
		else if (columnName.indexOf("Product") >= 0)
			iconName = "Product16.gif";
	}
	return iconName;
}
String getLookupValue(int flag, Object content) {
	if (content == null) {
		return "";
	}

	if (content instanceof String) {
		String pp[] = (AmpiereUtil.sanitizing((String)content)).split(":");
		if (pp != null && pp.length == 2) {
			if (flag == 0) {
				return pp[0];
			} else if (flag == 1) {
				return pp[1];
			} else if (flag == 2) {
				return (AmpiereUtil.sanitizing((String)content));
			}
		}
	}

	return "";
}
%>

<script type="text/javascript">
var paraMonths = <bean:write name="searchInfoFormAssignment" property="months" filter="false"/>;
var paraShortMonths = <bean:write name="searchInfoFormAssignment" property="shortMonths" filter="false"/>;
var paraWeeks = <bean:write name="searchInfoFormAssignment" property="weeks" filter="false"/>;
var paraShortWeeks = <bean:write name="searchInfoFormAssignment" property="shortWeeks" filter="false"/>;
var paraDateFormat = <bean:write name="searchInfoFormAssignment" property="dateFormat" filter="false"/>;
var paraInvalidDateMsg = <bean:write name="searchInfoFormAssignment" property="invalidDateMsg" filter="false"/>;

function updateLooupField(changedFieldId, lookupFieldId) {
	if (changedFieldId == null || lookupFieldId == null) {
		return;
	}

	var changedFieldD = document.getElementById(changedFieldId + "D");
	var changedFieldF = document.getElementById(changedFieldId + "F");
	var lookupField = document.getElementById(lookupFieldId);
	if (changedFieldD != null && changedFieldF != null && lookupField != null) {
		lookupField.value = (changedFieldD.value + ":" + changedFieldF.value);
	}
}
</script>
</head>

<body id="popup" <% if ("1".equals(request.getAttribute("doQuery"))) { %> onload="doQuery();" <% } %> onunload="closeMyChildren();">

	<table width="100%" >
	<tr>
	<td>
<div id="header">
		<h1><bean:write name="searchInfoFormAssignment" property="title"/></h1>
</div>
	</td>
    <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">
    <html:form styleId="infoLookupForm" style="margin:0;" target="_self" action="/ampiere/InfoLookupSearchAction.do" enctype="application/x-www-form-urlencoded" focus="lookup1">
    	<html:hidden name="searchInfoFormAssignment" property="windowNo"/>
    	<html:hidden name="searchInfoFormAssignment" property="columnName"/>
    	<html:hidden name="searchInfoFormAssignment" property="column_ID"/>
    	<html:hidden name="searchInfoFormAssignment" property="searchWhere" value=""/>
    	<html:hidden name="searchInfoFormAssignment" property="lookupID"/>
        <table class="popupInfoTable" cellspacing="5" cellpadding="0">
        <tr>
        <td align="center">
			<table border="0" width="100%" cellspacing="3" cellpadding="0">
			<tr>
<%
			ArrayList componentList = null;
			if (infoLookup != null) {
				componentList = infoLookup.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;
					String align = AmpiereUtil.sanitizing(componentBean.getAlign());
					int colSpan = componentBean.getColSpan();
					String label = AmpiereUtil.sanitizing(componentBean.getLabel());
					int width = componentBean.getWidth();
					Object content = componentBean.getContent();
					String toolTipText = AmpiereUtil.sanitizing(componentBean.getToolTipText());
					switch (componentBean.getType()) {
					case ComponentBean.TYPE_LABEL:
%>
    					<td nowrap="nowrap" align="<%= align %>" colspan="<%= colSpan %>"><%= label %></td>
<%
						break;
					case ComponentBean.TYPE_NUMBER:
					case ComponentBean.TYPE_TEXT:
%>
						<td align="<%= align %>" colspan="<%= colSpan %>"><input type="text" id="lookup<%= Integer.toString(i) %>" style="width:<%= width %>px" value="<%= AmpiereUtil.sanitizing((String)content)%>"/></td>
<%
						break;
					case ComponentBean.TYPE_SELECT:
						ArrayList selectListBean = (ArrayList)content;
%>
						<td align="<%= align %>" colspan="<%= colSpan %>">
						<select id="lookup<%= Integer.toString(i) %>" style="width:<%= width %>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 (label != null && label.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_CHECKBOX:
%>
						<td align="<%= align %>" colspan="<%= colSpan %>">
						<input type="checkbox" id="lookup<%= Integer.toString(i) %>" name="lookup<%= Integer.toString(i) %>" value="<%= AmpiereUtil.sanitizing((String)content) %>" <% if ("Y".equalsIgnoreCase((String)content)) { %>checked <% } %> onclick="checkboxChanged(this);" ><%= label %>
						</td>
<%
						break;
					case ComponentBean.TYPE_BR:
%>
					    </tr>
					    <tr>
<%
						break;
					case ComponentBean.TYPE_DATE:
%>
						<td align="<%= align %>" colspan="<%= colSpan %>">
							<input type="text" id="lookup<%= Integer.toString(i) %>" name="lookup<%= Integer.toString(i) %>" style="width:<%= width %>px" value="<%= AmpiereUtil.sanitizing((String)content)%>" onchange="checkDateValidation(this, paraInvalidDateMsg);"/>
							<img src="${pageContext.request.contextPath}/ampiere/images/Calendar16.png" id="$recDate$toggle" class="popupButton" name="$recDate$toggle"
											onclick="recDate_onclick_function('lookup<%= Integer.toString(i) %>', 'infoLookupForm', paraMonths, paraShortMonths, paraWeeks, paraShortWeeks, paraDateFormat);"/>
					    </td>
<%
						break;
					case ComponentBean.TYPE_LOOKUP:
%>
						<td align="<%= align %>" colspan="<%= colSpan %>">
						<input id="<%= label %>D" value="<%= getLookupValue(0, content) %>" name="<%= label %>D" onchange="updateLooupField('<%= label %>', 'lookup<%= Integer.toString(i) %>');" type="hidden"/>
						<input id="lookup<%= Integer.toString(i) %>" value="<%= getLookupValue(2, content) %>" type="hidden"/>
						<input id="<%= label %>F" value="<%= getLookupValue(1, content) %>" style="width:<%= width %>px" name="<%= label %>F" type="text"/>
						<img id="<%= label %>B" title="<%= toolTipText %>" class="popupButton" 
						 		name="<%= label %>" src="${pageContext.request.contextPath}/ampiere/images/<%= getLookupIcon(label) %>" 
						 		onclick="startLookup('<%= label %>', <bean:write name="searchInfoFormAssignment" property="windowNo"/>, 
						 					<bean:write name="searchInfoFormAssignment" property="column_ID"/>,'<%= label %>', 'N', null);return false;"/>
					    </td>
<%
						break;
					}
				}
			} else {
%>
				<script type="text/javascript">
				var componentNum = 0;
				</script>
				<%
			}
%>
			</tr>
			</table>
        </td>
        </tr>
        <tr>
            <td class="button-box align-right" scope="row">
            <html:button property="search" onclick="doQuery();"><bean:write name="searchInfoFormAssignment" property="searchBtnTitle"/></html:button>
            </td>
        </tr>
        </table>
    </html:form>



</div>

<!-- displayTagFrame -->
    <ajax:displayTag id="displayTagFrame" ajaxFlag="displayAjax">
      <display:table id="oneObject" name="searchResultAssignment" class="displaytag" pagesize="10" scope="session"
        defaultsort="2" defaultorder="ascending" export="true" excludedParams="ajax" sort="list" cellpadding="0" cellspacing="0">
        <display:column title="<%=getColTitle(oneObject, 0)%>" media="html" class="align-center" sortable="false">
            <input type="radio" id="radioSelect" name="radioSelect" value="<bean:write name='oneObject' property='colId'/>________<bean:write name='oneObject' property='colName'/>" ondblclick="updateInfo('<bean:write name="searchInfoFormAssignment" property="columnName"/>');return false;"/>
        </display:column>
<%
		ArrayList columnAttrList = null;
		if (infoLookup != null) {
			columnAttrList = infoLookup.getColumnAttrList();
		}
		if (columnAttrList != null) {
			for (int ii = 1; ii < columnAttrList.size(); ii++) {
				int colAttr = ((Integer)columnAttrList.get(ii)).intValue();
				if (colAttr == 1) {
%>
        			<display:column style="<%= getColStyle(oneObject, ii) %>" title="<%="&nbsp;" + getColTitle(oneObject, ii) + "&nbsp;"%>" sortable="true" headerClass="sortable" ><%= getColData(oneObject, ii)%></display:column>
<%
				} else {
%>
        			<display:column style="<%= getColStyle(oneObject, ii) %>" title="<%= getColTitle(oneObject, ii) %>" ><%=getColData(oneObject, ii)%></display:column>
<%
				}
			}
		}
%>
      </display:table>
    </ajax:displayTag>

<!-- body-footer -->
<div class="bottomMenuRight">
<table>
	<tr>
	<td>
    <font color="#EE0000"><i><bean:write name='searchInfoFormAssignment' property='largeRecords'/></i></font>
    </td>
	<td class="lbl" style="padding-right:5px;">
	<input id="ok" type="image" src="${pageContext.request.contextPath}/ampiere/images/Ok32.png" onclick="updateInfo('<bean:write name="searchInfoFormAssignment" property="columnName"/>');return false;" alt="<bean:write name='searchInfoFormAssignment' 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='searchInfoFormAssignment' property='closeBtnTitle'/>"/>
	<span>キャンセル</span>	
    </td>
    </tr>
    </table>
</div>
<!-- /body-footer -->
</div>
<!-- /body -->
</body>
</html>
