<%--
    Document   : Godown
    Created on : Apr 20, 2016, 3:16:34 PM
    Author     : 590685
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="DataEntryBean.GodownBean"%>

<% try {
%>
<html>
    <head>
        <title>Godown</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="${pageContext.request.contextPath}/js/Calendar.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico?pacs=<%=((new java.util.Date()).getTime())%>" type="image/x-icon" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/styles.css?pacs=<%=((new java.util.Date()).getTime())%>"/>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/ButtonAndText.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/info.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/chromejs/chrome.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/js/iFrame_killer.js"></script>
    </head>
    <body onload="noBack()">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }

            function submitform(GodownForm)
            {
                if (checkCreateDiv(GodownForm))
                {
                    document.forms[0].handle_id.value = "Create";
                    document.forms[0].action = '/PacsApplication/GodownServlet';
                    // document.forms[0].submit();
                    GodownForm.submit();
                }
            }
            function ShowParent()
            {
                document.forms[0].action = "Godown.jsp";
                document.forms[0].submit();
            }
            function checkCreateDiv(GodownForm)
            {
               if (GodownForm.name.value == "")
                {
                    alert("Godown Name field must be filled.");
                    GodownForm.name.focus();
                    return false;
                }
                if (GodownForm.address.value == "")
                {
                    alert("Address field must be filled.");
                    GodownForm.address.focus();
                    return false;
                }
                if (GodownForm.phone.value == "")
                {
                    alert("Phone number field must be filled.");
                    GodownForm.phone.focus();
                    return false;
                }
                if (GodownForm.contactperson.value == "")
                {
                    alert("Contact Person field must be filled.");
                    GodownForm.contactperson.focus();
                    return false;
                }                
                if (GodownForm.capacity.value == "")
                {
                    alert("Capacity field must be filled.");
                    GodownForm.capacity.focus();
                    return false;
                }
                return true;
            }

            function updateform(GodownForm)
            {
                if (checkUpdateDiv(GodownForm))
                {
                    document.forms[0].handle_id.value = "Update";
                    document.forms[0].action = '/PacsApplication/GodownServlet';
                    GodownForm.submit();

                }
            }
            function checkUpdateDiv(GodownForm)
            {

                if (GodownForm.nameAmend.value == "")
                {
                    alert("Godown Name must be filled.");
                    GodownForm.nameAmend.focus();
                    return false;
                }
                if (GodownForm.addressAmend.value == "")
                {
                    alert("Address must be filled.");
                    GodownForm.addressAmend.focus();
                    return false;
                }
                if (GodownForm.phoneAmend.value == "")
                {
                    alert("Phone Number must be filled.");
                    GodownForm.phoneAmend.focus();
                    return false;
                }
                if (GodownForm.contactpersonAmend.value == "")
                {
                    alert("Contact Person must be filled.");
                    GodownForm.contactpersonAmend.focus();
                    return false;
                }                
                if (GodownForm.capacityAmend.value == "")
                {
                    alert("Total Capacity must be filled.");
                    GodownForm.capacityAmend.focus();
                    return false;
                }
                if (GodownForm.avcapacityAmend.value == "")
                {
                    alert("Available Capacity must be filled.");
                    GodownForm.avcapacityAmend.focus();
                    return false;
                }

                return true;
            }

            function checkop()
            {
                if (document.getElementById("checkOption").value == "create")
                {
                    document.getElementById('create').style.display = 'block';
                    document.getElementById('amend').style.display = 'none';
                    document.getElementById('amend2').style.display = 'none';


                }
                if (document.getElementById("checkOption").value == "amend")
                {
                    document.getElementById('create').style.display = 'none';
                    document.getElementById('amend').style.display = 'block';
                    document.getElementById('amend2').style.display = 'none';


                }
                /*if (document.getElementById("checkOption").value == "active")
                {
                    document.getElementById('create').style.display = 'none';
                    document.getElementById('amend').style.display = 'none';
                    document.getElementById('active').style.display = 'block';
                    document.getElementById('amend2').style.display = 'none';

                }
                if (document.getElementById("checkOption").value == "deactive")
                {
                    document.getElementById('create').style.display = 'none';
                    document.getElementById('amend').style.display = 'none';
                    document.getElementById('active').style.display = 'none';
                    document.getElementById('amend2').style.display = 'none';

                }*/

            }

            function searchGodown(width, height, name) {

                if (window.innerWidth) {
                    LeftPosition = (window.innerWidth - width) / 2;
                    TopPosition = ((window.innerHeight - height) / 2) - 20;
                }
                else {
                    LeftPosition = (parseInt(window.screen.width) - width) / 2;
                    TopPosition = ((parseInt(window.screen.height) - height) / 2) - 20;
                }
                attr = 'resizable=yes,scrollbars=yes,width=' + width + ',height=' +
                    height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
                    TopPosition + '';
                var screenName = "Godown.jsp";
                var lovKey = "godownDetails"
                popWin = open('/PacsApplication/CommonSearchInformationTradingLOV.jsp?&screenName=' + screenName + '&lovKey=' + lovKey+ '&Godowname=' + name , 'godownDetails', attr);
                popWin.focus();

            }

            function getDetails() {

                document.forms[0].handle_id.value = "Search";
                document.forms[0].action = '/PacsApplication/GodownServlet';
                document.forms[0].submit();

            }

            function numbersonly(e){
                    var unicode=e.charCode? e.charCode : e.keyCode
                    if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
                            if (unicode<48||unicode>57) //if not a number
                                    return false //disable key press
                    }
            }
            
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });

        </script>
        <%
                    String error_msg = "";
                    Object error = request.getAttribute("message");
                    if (error != null) {
                        error_msg = error.toString();
                    }
        %>

        <%
                    String displayFlag = "";
                    Object display = request.getAttribute("displayFlag");
                    if (display != null) {
                        displayFlag = display.toString();
                    }
        %>
        <jsp:include page="MenuHead_TRADING.jsp" flush="true" />
        <br>
        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>

        <%
                    Object GodownBeanObj = request.getAttribute("GodownBeanObj");
                    GodownBean oGodownBean = new GodownBean();
                    if (GodownBeanObj != null) {
                        oGodownBean = (GodownBean) request.getAttribute("GodownBeanObj");

                    }
        %>
        <fieldset style="border-color: black; background-image: url('/PacsApplication/img/download.jpg'); border-width: 3px">

            <legend style="padding: 8px; border-radius: 20px; background-color: #006600; color: white">Godown</legend>
            <form name="GodownForm" method="post" action="GodownServlet">

                <%if (!error_msg.equalsIgnoreCase("")) {%>
                <center><div class="info" id="errorMessage"><center><%= error_msg%></center></div></center>
                <% }%>

                <br>
                <br>
                <center><lable style=" font-family: Berlin Sans FB; font-weight:  normal;">Operation Selection:</lable>
                    <select id="checkOption" onchange="checkop()" name="checkOption" >
                        <option value="" disabled selected style="display:none;" >--select--</option>
                        <option value="create" >Create</option>
                        <option value="amend" >Amend</option>
                    </select>
                </center>
                <div id="create" style="display:none;">
                    <table>
                        <tbody>


                            <tr>
                                <td>Godown Name<font color="red" >*</font>:</td>
                                <td><input type="text" name="name" id="name" value="" /></td>
                            </tr>
                            <tr>
                                <td>Address<font color="red" >*</font>:</td>
                                <td><textarea name="address"  id="address"  ></textarea></td>
                            </tr>

                            <tr>
                                <td>Phone Number<font color="red" >*</font>:</td>
                                <td><input name="phone" id="phone" value="" maxlength="10" onkeypress="return numbersonly(event)" style="text-align:right"/></td>
                            </tr>
                            <tr>
                                <td>Contact Person<font color="red" >*</font>:</td>
                                <td><input type="text" name="contactperson" id="contactperson" value="" /></td>
                            </tr>
                            <tr>
                                <td>Capacity<font color="red" >*</font>:</td>
                                <td><input type="text" name="capacity" id="capacity" value="" onkeypress="return numbersonly(event)" style="text-align:right"/></td>
                            </tr>


                        </tbody>
                    </table><br><br>

                    <center>
                        <input type="button" value="Submit" onclick="javascript:submitform(GodownForm)"/>
                        <input type="reset" value="Reset" name="reset" onclick="javascript:ShowParent()" />
                    </center>
                </div>
                <br><br>

                <div id="amend" style="display: none;">
                    <center>
                        <lable style=" font-family: Berlin Sans FB; font-weight:  normal;" >Enter Godown Name: </lable>
                        <input type="text" name="nameSearch" id="nameSearch"/>
                        <input type="button"  value="Search" onclick="javascript:searchGodown(220, 180, document.GodownForm.nameSearch.value)" />
                        <input type="button"  value="Submit" onclick="javascript:getDetails()" />
                    </center>
                    <br><br>
                </div>

                <%if (displayFlag.equalsIgnoreCase("Y")) {%>
                <div id="amend2" >

                    <table>
                        <tbody>

                            <tr>
                                <td>Godown Name:<font color="red" >*</font>  &nbsp;</td>
                                <td><input type="text" name="nameAmend" id="nameAmend" value="<%=blankNull(oGodownBean.getName())%>" /></td>
                            </tr>
                            <tr>
                                <td>Address:<font color="red" >*</font>  &nbsp;</td>
                                <td><textarea name="addressAmend" id="adaddressAmend"><%=blankNull(oGodownBean.getAddress())%></textarea><td>
                            </tr>

                            <tr>
                                <td>Phone Number:<font color="red" >*</font>  &nbsp;</td>
                                <td><input type="text" name="phoneAmend" id="phoneAmend" maxlength="10" onkeypress="return numbersonly(event)" value="<%=blankNull(oGodownBean.getPhone())%>" style="text-align:right" /></td>
                            </tr>
                            <tr>
                                <td>Contact Person:<font color="red" >*</font>  &nbsp;</td>
                                <td><input type="text" name="contactpersonAmend" id="contactpersonAmend" value="<%=blankNull(oGodownBean.getContactperson())%>" /></td>
                            </tr>
                            <tr>
                                <td>Total Capacity:<font color="red" >*</font>  &nbsp;</td>
                                <td><input type="text" name="capacityAmend" id="capacityAmend" onkeypress="return numbersonly(event)" value="<%=blankNull(oGodownBean.getCapacity())%>" style="text-align:right"/></td>
                            </tr>

                            <tr>
                                <td>Available Capacity:<font color="red" >*</font>  &nbsp;</td>
                                <td><input type="text" name="avcapacityAmend" id="avcapacityAmend"  onkeypress="return numbersonly(event)" value="<%=blankNull(oGodownBean.getAvcapacity())%>" style="text-align:right" /></td>
                            </tr>

                            <tr><td><br></td></tr>
                            <tr><td><br></td></tr>
                            <tr><td><label><font color="red" >*</font> marked fields are mandatory.</label></td></tr>
                        </tbody>
                    </table><br><br>

                    <br><br>
                   <center>
                        <input type="button" value="Update" onclick="javascript:updateform(GodownForm)">
                    </center>

                </div>
                <% }%>


                <input type="hidden" name="handle_id" value="" />
                <input type="hidden" name="godown_id" id="godown_id" value="<%=blankNull(oGodownBean.getGodown_id())%>"/>
            </form>

        </fieldset>

    </body>
</html>
<% 	} catch (Exception e) {
                
            }
%>
