<%@ 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="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="http://ajaxtags.org/tags/ajax" prefix="ajax" %>
<%@ page import="com.ampiere.util.AmpiereUtil" %>
<jsp:include page="/ampiere/jsp/common/includeYAHOOUI.jsp" flush="true" /> 
<html>
<head>
<title><bean:write name="createFromShipmentForm" 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>
<style type="text/css">
<!--
    #displayTagOverflow {
	    width: 760px;
    }
-->
</style>
<script type="text/javascript">
function initProgress() {
	Element.show('progressMsg');
}

function resetProgress() {
	Effect.Fade('progressMsg');
}

function submitShipment(obj, operationType) {
	var operationTypeObj = document.getElementById("operationType");
	if (operationTypeObj != null) {
		operationTypeObj.value = operationType;
	}
	if (obj != null) {
		obj.form.submit();
	}
}

function updateBPartner(obj) {
	submitShipment(obj, 1);
}

function orderChange(obj) {
	initProgress();

	submitShipment(obj, 2);
}

function invoiceChange(obj) {
	initProgress();

	submitShipment(obj, 3);
}

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

    var checkObjects = window.document.getElementsByName("checkSelect");
    var selectedIndexArray = "";
    if (checkObjects != null) {
        for (var i = 0; i < checkObjects.length; i++) {
            if (checkObjects[i] != null && checkObjects[i].checked) {
                selectedIndexArray += (checkObjects[i].value + ",");;
            }
        }
    }

	if (selectedIndexArray == "") {
        window.close();
	    window.opener.focus();
	} else {
		var selectedIndexObj = document.getElementById("selectedIndex");
		if (selectedIndexObj != null) {
			selectedIndexObj.value = selectedIndexArray;
		}
		submitShipment(obj, 4);
	}
}
</script>
</head>

<%!
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); } }
}
%>

<body id="popup" <% if ("close".equals(request.getAttribute("closeCreateFromShipment"))) { %> onload="window.close();" <% } %> onunload="closeMyChildren();">
<html:form style="margin:0;" target="_self" action="/ampiere/CreateFromShipmentAction.do" enctype="application/x-www-form-urlencoded" focus="bpartnerName">
<html:hidden name="createFromShipmentForm" property="windowNo"/>
<html:hidden name="createFromShipmentForm" property="columnName"/>
<html:hidden styleId="operationType" name="createFromShipmentForm" property="operation"/>
<html:hidden styleId="selectedIndex" name="createFromShipmentForm" property="selectedIndex"/>

	<table width="100%" >
	<tr>
	<td>
<div id="header">
		<h1><bean:write name="createFromShipmentForm" 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">
    <table class="popupInfoTable" cellspacing="4" cellpadding="0" border="0">
    <tr>
        <th scope="row"><bean:write name="createFromShipmentForm" property="bpartnerLabel"/></th>
		<td>
		<html:hidden styleId="C_BPartner_IDD" name="createFromShipmentForm" property="bpartnerID" onchange="updateBPartner(this);"/>
		<html:text styleId="C_BPartner_IDF" name="createFromShipmentForm" property="bpartnerName" style="width: 198px;"/>
		<img class="popupButton" src="${pageContext.request.contextPath}/ampiere/images/BPartner16.png" onclick="startLookup('C_BPartner_ID', <bean:write name='createFromShipmentForm' property='windowNo'/>, 3499, 'C_BPartner_ID', 'N',null);return false;"/>
	    </td>
        <th><bean:write name="createFromShipmentForm" property="orderLabel"/></th>
		<td>
			<html:select name="createFromShipmentForm" property="orderSelected" onchange="orderChange(this)" style="width: 220px;">
			<bean:define id="orderList" name="createFromShipmentForm" property="orderList"></bean:define>
			<html:options collection="orderList" property="code" labelProperty="value"/>
			</html:select>
        </td>
	</tr>
	<tr>
        <th scope="row"><bean:write name="createFromShipmentForm" property="locatorLabel"/></th>
		<td>
			<html:select name="createFromShipmentForm" property="locatorSelected" style="width: 220px;">
			<bean:define id="locatorList" name="createFromShipmentForm" property="locatorList"></bean:define>
			<html:options collection="locatorList" property="code" labelProperty="value"/>
			</html:select>
		</td>
        <th><bean:write name="createFromShipmentForm" property="invoiceLabel"/></th>
		<td>
			<html:select name="createFromShipmentForm" property="invoiceSelected" onchange="invoiceChange(this)" style="width: 220px;">
			<bean:define id="invoiceList" name="createFromShipmentForm" property="invoiceList"></bean:define>
			<html:options collection="invoiceList" property="code" labelProperty="value"/>
			</html:select>
        </td>
    </tr>
    </table>

<div>

<!-- displayTagFrame -->

    <ajax:displayTag id="displayTagFrame" ajaxFlag="displayAjax">
      <display:table id="oneObject" name="createFromShipmentResult" class="displaytag" scope="session"
        defaultsort="4" 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="checkbox" id="checkSelect" name="checkSelect" value="<bean:write name='oneObject' property='colId'/>"/>
        </display:column>
        <%-- Quantity --%>
        <display:column style="<%= getColStyle(oneObject, 1) %>" title="<%="&nbsp;&nbsp;" + getColTitle(oneObject, 1) + "&nbsp;&nbsp;"%>" sortable="true" headerClass="sortable"><%=getColData(oneObject, 1)%></display:column>
        <%-- UOM --%>
        <display:column style="<%= getColStyle(oneObject, 2) %>" title="<%="&nbsp;&nbsp;" + getColTitle(oneObject, 2) + "&nbsp;&nbsp;"%>" sortable="true" headerClass="sortable"><%=getColData(oneObject, 2)%></display:column>
        <%-- Product --%>
        <display:column style="<%= getColStyle(oneObject, 3) %>" title="<%="&nbsp;&nbsp;" + getColTitle(oneObject, 3) + "&nbsp;&nbsp;"%>" sortable="true" headerClass="sortable"><%=getColData(oneObject, 3)%></display:column>
        <%-- Order --%>
        <display:column style="<%= getColStyle(oneObject, 4) %>" title="<%="&nbsp;&nbsp;" + getColTitle(oneObject, 4) + "&nbsp;&nbsp;"%>" sortable="true" headerClass="sortable"><%=getColData(oneObject, 4)%></display:column>
        <%-- Shipment --%>
        <display:column style="<%= getColStyle(oneObject, 5) %>" title="<%= getColTitle(oneObject, 5) %>"><%=getColData(oneObject, 5)%></display:column>
        <%-- Invoice --%>
        <display:column style="<%= getColStyle(oneObject, 6) %>" title="<%= getColTitle(oneObject, 6) %>"><%=getColData(oneObject, 6)%></display:column>
      </display:table>
    </ajax:displayTag>

<!-- body-footer -->
<div class="bottomMenuRight">
<table>
	<tr>
	<td>
    <font color="#EE0000"><i><bean:write name='createFromShipmentForm' 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="doCreateFrom(this);return false;" alt="<bean:write name='createFromShipmentForm' 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='createFromShipmentForm' property='closeBtnTitle'/>"/>
	<span>キャンセル</span>
    </td>
    </tr>
    </table>
</div>
<!-- /body-footer -->
</div>
<!-- /body -->

</html:form>
</body>
</html>
