<%@ 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" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.ampiere.util.AmpiereUtil" %>
<jsp:include page="/ampiere/jsp/common/includeYAHOOUI.jsp" flush="true" /> 
<html>
<head>
<title><bean:write name="buttonActionForm" property="title"/></title>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/ampiere/css/import_popup.css"/>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/ampiere/css/window.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/ampiere/js/window.js"></script>
<style type="text/css">
<!--
.popupInfoTable {
	padding-top: 3px;
	padding-bottom: 3px;
}
-->
</style>
<script type="text/javascript">
var selectIndex = 0;
var valueArray = null;
var descArray = null;

// Change description
function changeActionCombo(index) {
	var desc = document.getElementById("description");
	if (desc != null) {
		if (descArray != null && descArray.length > index) {
			desc.value = descArray[index];
		} else {
			desc.value = "";
		}
	}

	selectIndex = index;
}
// Start process
function startProcess(isBatch) {
	if (! checkParent(window)) {
        window.close();
		return;
	}

    if (window.opener.top.WWindow) {
    	var buttonObj = (window.opener.top.WWindow.document.getElementById("DocAction"));
		var processIdObj = document.getElementById("Process_ID");
		if (buttonObj != null && processIdObj != null) {
			var actionComboObj = document.getElementById("actionCombo");
			if (valueArray != null && actionComboObj != null) {
				var selectValue = valueArray[actionComboObj.value];
				processButton(buttonObj, processIdObj.value, isBatch, selectValue);
			}
/*
			if (valueArray != null && selectIndex >= 0 && valueArray.length > selectIndex) {
				var selectValue = valueArray[selectIndex];
				processButton(buttonObj, processIdObj.value, isBatch, selectValue);
			}
*/
		}
	}

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

<% com.ampiere.grid.ed.WDocAction wDocAction = (com.ampiere.grid.ed.WDocAction)request.getAttribute("wDocAction"); %>

<%
boolean closeMe = true;
if (wDocAction != null) {
	ArrayList actionCombo = (ArrayList)wDocAction.getActionCombo();
	if (actionCombo != null && actionCombo.size() > 0) {
		closeMe = false;
	}
}
%>

<body id="popup">

<div>
<html:hidden name="buttonActionForm" property="windowNo"/>
<html:hidden name="buttonActionForm" property="columnName"/>
<html:hidden styleId="Process_ID" name="buttonActionForm" property="processId"/>
</div>


<div id="header">
		<h1><bean:write name="buttonActionForm" property="title"/></h1>
</div>

<div id="body">

<%
String batchButton = null;
if (wDocAction != null) {
	ArrayList actionCombo = (ArrayList)wDocAction.getActionCombo();
	String actionComboDescSel = AmpiereUtil.sanitizing((String)wDocAction.getActionComboDescSelected());
	if (actionCombo != null && actionCombo.size() > 0) {
		batchButton = wDocAction.getBatchButton();
%>
<script type="text/javascript">
valueArray = <%= wDocAction.getActionComboValueArray() %>;
descArray = <%= wDocAction.getActionComboDescArray() %>;
</script>

<!-- body -->


<!-- popupInfoTable -->
<table class="popupInfoTable">
<tr>
	<th nowrap="nowrap" valign="middle" align="right"><%= wDocAction.getActionLabel() %>
	</th>
	<td class="align-right">
		<select id="actionCombo" onchange="changeActionCombo(this.value);">
<%
		for (int ii = 0; ii < actionCombo.size(); ii++) {
			String comboValue = AmpiereUtil.sanitizing((String)actionCombo.get(ii));
			if (comboValue != null && comboValue.equals(wDocAction.getActionComboSelected())) {
%>
				<option value="<%= ii %>" selected="selected"><%= comboValue %></option>
<%
			} else {
%>
				<option value="<%= ii %>"><%= comboValue %></option>
<%
			}
		}
%>
		</select>
	</td>
	</tr>

	<tr>
	<td colspan="2" align="right" valign="middle" nowrap="nowrap">
	<textarea id="description" readonly="readonly" cols="40" rows="3"><%= (actionComboDescSel != null ? actionComboDescSel : "") %>
	</textarea>
	</td>
	</tr>
	</table>
<%
	}
}

if (batchButton == null) {
%>
<center><font color="#FF0000"><i><b>DocAction - No Options.</b></i></font></center>
<%
}
%>
<!-- bottomMenu -->
<div class="bottomMenuBoth">
<table>
<tr>
<%
	if (batchButton != null) {
%>
	<td class="left"><input type="image" src="${pageContext.request.contextPath}/ampiere/images/Process32.png" onClick="startProcess('true');" alt="<%= batchButton %>" />
	</td>
<%
	}else{ //clmg 2009/02/24
%>
	<td class="left">&nbsp;</td>
<%		
	}
%>
	<td class="right">
	<input id="ok" type="image" src="${pageContext.request.contextPath}/ampiere/images/Ok32.png" onclick="startProcess('false');" alt="<bean:write name='buttonActionForm' 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='buttonActionForm' property='closeBtnTitle'/>"/>
	<span>キャンセル</span>
</td>
</tr>
</table>
</div>
<!-- /bottomMenu -->

</div>
<!-- /body -->

<!-- footer -->
<!-- /footer -->

</body>
</html>
