<%--
    Document   : Investment_Creation
    Created on : Oct 31, 2017, 12:27:10 PM
    Author     : 981898
--%>


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.SQLException"%>
<%@page import="LoginDb.DbHandler"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.ArrayList"%>
<%@page import="DataEntryBean.InvestmentCreationBean"%>


<%@page import="java.util.UUID" %>
<%String uuid = UUID.randomUUID().toString();%>
<% try {
%>


<html>
    <head>

        <title>Investment Creation</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 checkDuplicateID(){
                var arr = [];
                $("#order-list tbody tr").each(function(){
                    arr.push($(this).find("td:nth-child(5) input").val());

                });

                for (var i = 0; i < arr.length; i++)
                {
                    for (var j = 0; j < arr.length; j++)
                    {
                        if (i != j)
                        {
                            if (arr[i] == arr[j])
                            {
                                alert("Please do not repeat ID Number.");
                                return false;
                            }
                        }
                    }
                }

                arr = [];
                return true;
            }

            function checkOp()
            {

                    //alert("IN");
                  if(document.getElementById("opt").value=="create")
                      {
                          document.getElementById("create").style.display='block';
                          document.getElementById("amend").style.display='none';
                      }
                  else
                      {
                          document.getElementById("create").style.display='none';
                          document.getElementById("amend").style.display='block';
                          document.getElementById("amendSearch").style.display='table-row';

                      }
            }

            function searchGL(width, height,x)
            {
                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 = "Investment_Creation.jsp";
                var  lovKey=    "searchGl";
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationLOV.jsp?screenName=' + screenName+'&lovKey='+lovKey+'&acNo='+x , 'GLSearch', attr);
                popWin.focus();
            }


            function searchGLAmend(width, height,x)
            {
                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 = "Investment_Creation.jsp";
                var  lovKey=    "searchGlAmend";
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationLOV.jsp?screenName=' + screenName+'&lovKey='+lovKey+'&acNo='+x , 'GLSearch', attr);
                popWin.focus();
            }

            function searchBank(width, height,i)
            {
                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 = "Investment_Creation.jsp";
                var  lovKey=    "searchBank";
                var bk_nm=document.getElementById("bankName"+i).value;
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationLOV.jsp?screenName=' + screenName+'&lovKey='+lovKey+'&index='+i+'&bank_name='+bk_nm, 'GLSearch', attr);
                popWin.focus();
            }

            function searchBankAmend(width, height,i)
            {
                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 = "Investment_Creation.jsp";
                var  lovKey=    "searchBankAmend";
                var bk_nm=document.getElementById("bankNameAmend"+i).value;
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationLOV.jsp?screenName=' + screenName+'&lovKey='+lovKey+'&index='+i+'&bank_name='+bk_nm, 'GLSearch', attr);
                popWin.focus();
            }

             function numbersonly(txt,e){

                    var unicode=e.charCode? e.charCode : e.keyCode

                //alert(unicode);
                if(unicode==46)
                {if (txt.value.indexOf('.') === -1) {
                        return true;
                    } else {
                        return false;
                    }
                } else if(unicode!=8){

                             /*if(unicode==45)
                                 {
                                     return true;
                                 }*/
                    //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 ModuleName = new String();

             ModuleName = (String) session.getAttribute("moduleName");
        %>

        <%if (ModuleName.equalsIgnoreCase("Deposit")) {%>
        <jsp:include page="/Deposit/MenuHead_Deposit.jsp" flush="true" />
        <%} else if (ModuleName.equalsIgnoreCase("Loan")) {%>
        <jsp:include page="/Loan/MenuHead_Loan.jsp" flush="true" />
        <%}else if (ModuleName.equalsIgnoreCase("SpecialBothKcc")) {%>
        <jsp:include page="/MenuHead.jsp" flush="true" />
        <%}else if (ModuleName.equalsIgnoreCase("SpecialBothDep")) {%>
        <jsp:include page="/Deposit/MenuHead_Deposit.jsp" flush="true" />
        <%}else if (ModuleName.equalsIgnoreCase("SpecialBoth")) {%>
        <jsp:include page="/Deposit/MenuHead_Deposit.jsp" flush="true" />
        <%}%>
        <br>

        <%
             int count = 1;
             String error_msg = "";
             Object error = request.getAttribute("message");
             if (error != null) {
                 error_msg = error.toString();
             }
             String sysDt = new String();
             Connection connection = null;
             ResultSet rs = null;
             Statement statement = null;
             connection = DbHandler.getDBConnection();
             try {
                 statement = connection.createStatement();
                 rs = statement.executeQuery("select to_char(SYSTEM_DATE,'DD/MM/YYYY') from system_date");
                 while (rs.next()) {
                     sysDt = rs.getString(1);
                 }
                // statement.close();
                // connection.close();
             }  catch (Exception e) {
                System.out.println("Error occurred during processing.");
            } finally {
                try {
                    if(statement !=null)
                        statement.close();
                    if (connection != null)
                    connection.close();

            } catch (Exception e) {               
               System.out.println("Error Occurred during connection close.");
            }

            }
        %>

        <%
             String displayFlag = "";
             Object display = request.getAttribute("displayFlag");
             if (display != null) {
                 displayFlag = display.toString();
             }
         %>
         <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>
        <%
             String gl_number="";
             String bal="";
             String op="";
             Object alInvestmentCreationBeanObj = request.getAttribute("oInvestmentCreationBeanObj");
             ArrayList<InvestmentCreationBean> alInvestmentCreationDetailBean2 = new ArrayList<InvestmentCreationBean>();
             if (alInvestmentCreationBeanObj != null) {
                 alInvestmentCreationDetailBean2 = (ArrayList<InvestmentCreationBean>) request.getAttribute("alInvestmentCreationDetailBean2");
                 gl_number=request.getAttribute("GL_Account").toString();
                 bal=request.getAttribute("balance").toString();
                 op=request.getAttribute("Option").toString();

             }
        %>

        <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">Investment Creation</legend>
            <form action="" method="post" name="investmentCreateForm">

                <br>

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

                <div>
                    <center>
                    <table>
                    <tr>
                                <td>Select Option:</td>
                                <td><select id="opt" name="opt" onchange="checkOp()">
                                        <option value="Not" selected disabled> --Select-- </option>
                                        <option value="create">Create</option>
                                        <option value="amend"<%if(displayFlag=="Y"){if(op.equalsIgnoreCase("Amend")){%>selected<%}}%>>Amend</option>
                                    </select></td>

                    </tr>
                    </table>
                    </center>
                </div>

                <div id="create" align="left" style="display: none">
                    <center>
                    <table>
                        <tbody>
                            <tr>
                                <td>GL Account<font color="red" >*</font>: </td>
                                <td><input type="text" name="glName" id="glName" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                                <td><input type="button" id="gl_btn" name="gl_btn" value="Search" onclick="javascript:searchGL(750,320,document.getElementById('glName').value)"/></td>
                            </tr>
                            <tr>
                                <td>Balance: </td>
                                <td><input type="text" name="glBal" id="glBal" readonly style="text-align:right;" /></td>
                            </tr>

                    </tbody>
                    </table>
                   </center>
                    <center>
                        <table id="order-list" border="2" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px">
                            <thead class="CSSTableGenerator" >
                                <tr>
                                    <td></td>
                                    <td colspan="2">Bank Name</td>
                                    <td>Branch Name</td>
                                    <td>A/c Number</td>
                                    <td>Amount</td>
                                    <td>Maturity Amount</td>
                                    <td>Interest Rate</td>
                                    <td colspan="2">A/c Open Date</td>
                                    <td colspan="2">A/c Maturity Date</td>
                                    <td>Active</td>

                                </tr>
                            </thead>
                            <tbody>
                                <tr class="tRow">
                                    <td><input type="checkbox" name="chckbox<%=count%>" id="chckbox<%=count%>" name="chckbox<%=count%>" onclick="checkboxTrue(<%=count%>);" checked/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="bankName<%=count%>" id="bankName<%=count%>" /></td>
                                    <td><input  type="button" name="bankNameBtn<%=count%>" id="bankNameBtn<%=count%>" value="Search" onclick="javascript:searchBank(420,320,<%=count%>)"/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="branchName<%=count%>" id="branchName<%=count%>" readonly/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="accountNo<%=count%>" id="accountNo<%=count%>" onKeyPress="return numbersonly(this, event)"/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="amount<%=count%>" id="amount<%=count%>" onKeyPress="return numbersonly(this, event)"/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="maturityAmount<%=count%>" id="maturityAmount<%=count%>" onKeyPress="return numbersonly(this, event)"/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="interestRate<%=count%>" id="interestRate<%=count%>" onKeyPress="return numbersonly(this, event)"/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="acOpenDate<%=count%>" id="acOpenDate<%=count%>" size="8" readonly/></td>
                                    <td><a href="#" onclick="return getCalendar(document.forms[0].acOpenDate<%=count%>);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" style="display:block;"  height="100%" width="20" /></a></td>
                                    <td><input type="text" style="text-align:center;" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" size="8" id="acMatDate<%=count%>" name="acMatDate<%=count%>" readonly="true"></td>
                                    <td><a href="#" onclick="return getCalendar(document.forms[0].acMatDate<%=count%>);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" style="display:block;"  height="100%" width="20" /></a></td>
                                    <td><select id="active<%=count%>" name="active<%=count%>"><option value="" selected disabled>--- Select ---</option><option value="Yes">Yes</option><option value="No">No</option></select></td>
                                    <td style="display:none;"><input type="hidden"  name="document_mst_id<%=count%>" id="document_mst_id<%=count%>"/></td>
 
                                </tr>
                            </tbody>
                        </table>
                    </center>
                    <center>
                        <table >
                            <tr><td></td></tr>
                            <tr><td></td></tr>
                            <tr><td></td></tr>
                            <tr><td></td></tr>
                            </table></center>
                    <br><br><br>
                    <center>
                        <table>
                            <tr>
                                <td><input type="button" id="addRow" value="Add Row"/></td>
                                <%--<td><input type="button" id="deleteRow" value="Delete Row"/></td> --%>
                                <td><input type="button" value="Submit" onclick="javascript:submitform(investmentCreateForm)"></td>
                                <td><input type="button" value="Reset" onclick="ShowParent();" /></td>
                            </tr>
                        </table>
                    </center>
                    <br>
                </div>

                <div id="amend" align="left" style="display: none">
                    <center>
                    <table>
                        <tbody>
                            <tr>
                                <td>GL Account<font color="red" >*</font>: </td>
                                <td><input type="text" name="glNameAmend" id="glNameAmend" <%if(displayFlag=="Y"){%>value="<%=blankNull(gl_number)%>"<%}%> style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                                <td><input type="button" id="gl_btnAmend" name="gl_btnAmend" value="Search" onclick="javascript:searchGLAmend(750,320,document.getElementById('glNameAmend').value)"/></td>
                             </tr>
                            <tr>
                                <td>Balance: </td>
                                <td><input type="text" name="glBalAmend" id="glBalAmend"  <%if(displayFlag=="Y"){%>value="<%=blankNull(bal)%>"<%}%> readonly style="text-align:right;"  /></td>
                            </tr>
                            
                            <%if(displayFlag==""){%>
                            <tr id="amendSearch" style="display: none">
                                <td></td>
                                <td>
                                    <input type="button" id="searchAmend" name="searchAmend" value="Search" onclick="javascript:fetchform(investmentCreateForm)" />
                                </td>
                            </tr>
                            <%}%>

                    </tbody>
                    </table>
                   </center>
                    <center>
                        <br><br><br>
                        <%if(displayFlag=="Y"){%>
                        <table id="order-list2" border="2" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px">
                            <thead class="CSSTableGenerator" >
                                <tr>
                                    <td></td>
                                    <td colspan="2">Bank Name</td>
                                    <td>Branch Name</td>
                                    <td>A/c Number</td>
                                    <td>Amount</td>
                                    <td>Maturity Amount</td>
                                    <td>Interest Rate</td>
                                    <td colspan="2">A/c Open Date</td>
                                    <td colspan="2">A/c Maturity Date</td>
                                    <td>Active</td>

                                </tr>
                            </thead>

                            <%
                                    InvestmentCreationBean oInvestmentCreationBean = new InvestmentCreationBean();
                                    count = 0;

                                    for (int i = 0; i < alInvestmentCreationDetailBean2.size(); i++) {
                                        oInvestmentCreationBean = alInvestmentCreationDetailBean2.get(i);
                                        count++;
                            %>

                            <tbody>
                                <tr class="tRow">
                                    <td><input type="checkbox" name="chckboxAmend<%=count%>" id="chckboxAmend<%=count%>" onclick="checkboxAmendTrue(<%=count%>);" checked/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="bankNameAmend<%=count%>" id="bankNameAmend<%=count%>" value="<%=blankNull(oInvestmentCreationBean.getBank_name())%>" /></td>
                                    <td><input  type="button" name="bankNameAmendBtn<%=count%>" id="bankNameAmendBtn<%=count%>" value="Search" onclick="javascript:searchBankAmend(420,320,<%=count%>)"/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="branchNameAmend<%=count%>" id="branchNameAmend<%=count%>" value="<%=blankNull(oInvestmentCreationBean.getBranch_name())%>" readonly /></td>
                                    <td><input  type="text"  style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="accountNoAmend<%=count%>" id="accountNoAmend<%=count%>" onKeyPress="return numbersonly(this, event)" value="<%=blankNull(oInvestmentCreationBean.getAcno())%>" readonly/></td>
                                    <td><input  type="text"  style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="amountAmend<%=count%>" id="amountAmend<%=count%>" onKeyPress="return numbersonly(this, event)" value="<%=blankNull(oInvestmentCreationBean.getAmt())%>"/></td>
                                    <td><input  type="text"  style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="maturityAmountAmend<%=count%>" id="maturityAmountAmend<%=count%>" onKeyPress="return numbersonly(this, event)" value="<%=blankNull(oInvestmentCreationBean.getMat_amt())%>"/></td>
                                    <td><input  type="text"  style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="interestRateAmend<%=count%>" id="interestRateAmend<%=count%>" onKeyPress="return numbersonly(this, event)" value="<%=blankNull(oInvestmentCreationBean.getInt_rate())%>"/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="acOpenDateAmend<%=count%>" id="acOpenDateAmend<%=count%>" size="8" readonly value="<%=blankNull((oInvestmentCreationBean.getAc_opn_dt()))%>"/></td>
                                    <td><a href="#" onclick="return getCalendar(document.forms[0].acOpenDateAmend<%=count%>);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" style="display:block;"  height="100%" width="20" /></a></td>
                                    <td><input type="text" style="text-align:center;"  style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" size="8" id="acMatDateAmend<%=count%>" name="acMatDateAmend<%=count%>" readonly="true" value="<%=blankNull(oInvestmentCreationBean.getMat_dt())%>"></td>
                                    <td><a href="#" onclick="return getCalendar(document.forms[0].acMatDateAmend<%=count%>);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" style="display:block;"  height="100%" width="20" /></a></td>
                                    <td><select id="activeAmend<%=count%>" name="activeAmend<%=count%>"><option value="" selected disabled> --Select-- </option><option value="Yes" <%if(oInvestmentCreationBean.getActive_flag().equalsIgnoreCase("Yes")){%> selected <%}%> >Yes</option><option value="No" <%if(oInvestmentCreationBean.getActive_flag().equalsIgnoreCase("No")){%> selected <%}%> >No</option></select></td>
                                    <td style="display:none;"><input type="hidden"  name="document_mst_idAmend<%=count%>" id="document_mst_idAmend<%=count%>"/></td>

                                </tr>
                            </tbody>
                            <%}%>
                        </table>
                        <br><br><br>
                    <center>
                        <table>
                            <tr>
                                <td><input type="button" id="addRowAmend" value="Add Row"/></td>
                                <%--<td><input type="button" id="deleteRowAmend" value="Delete Row"/></td>--%>
                                <td><input type="button" value="Update" onclick="javascript:updateform(investmentCreateForm)"></td>
                                <td><input type="button" value="Reset" onclick="ShowParent();" /></td>
                            </tr>
                        </table>
                    </center>
                        <%}%>
                    </center>
                    <center>
                        <table >
                            <tr><td></td></tr>
                            <tr><td></td></tr>
                            <tr><td></td></tr>
                            <tr><td></td></tr>
                            </table></center>
                    
                    <br>

                </div>



                <input type="hidden" name="handle_id" value="" />
                <input type="hidden" name="rowCounterDeleteCreate" id="rowCounterDeleteCreate" value="<%=count%>">
                <input type="hidden" name="rowCounter" id="rowCounter" value="<%=count%>">
                <input type="hidden" name="chkboxCounter" id="chkboxCounter" value="0"/>
                <input type="hidden" name="all_rowsAdded" id="all_rowsAdded" value="1">

                <input type="hidden" name="rowCounterDeleteCreateAmend" id="rowCounterDeleteCreateAmend" value="<%=count%>">
                <input type="hidden" name="rowCounterAmend" id="rowCounterAmend" value="<%=count%>">
                <input type="hidden" name="chkboxCounterAmend" id="chkboxCounterAmend" value="0"/>
                <input type="hidden" name="all_rowsAddedAmend" id="all_rowsAddedAmend" value="1">
                <input type="hidden" name="hidden_gl_no" id="hidden_gl_no" <%if(displayFlag=="Y"){%>value="<%=blankNull(gl_number)%>"<%}%> />
                <input type="hidden" name="hidden_gl_amt" id="hidden_gl_amt" <%if(displayFlag=="Y"){%>value="<%=blankNull(bal)%>"<%}%> />
            </form>

             <%
                if(op.equalsIgnoreCase("Amend"))
                    {%>
                    <script>
                        //alert("OK");
                        document.getElementById("opt").value='amend';
                        document.getElementById("amend").style.display='block';
                    </script>
                    <%}
        %>

            <script>
                var x=1;
                var y=1;
                function checkboxTrue(i){

                    if(document.getElementById("chckbox"+i).checked==true){

                        var counter = $("#chkboxCounter").val();
                        counter++;
                        $("#chkboxCounter").val(counter);

                    }

                    else{

                        var counter = $("#chkboxCounter").val();
                        counter--;
                        $("#chkboxCounter").val(counter);
                    }

                }

                $("#addRow").click(function () {
                    x=x+1;
                    $("#all_rowsAdded").val(x);
                    var counter = $("#rowCounter").val();
                    counter++;
                    $('#order-list tr:last').after('<tr class="tRow"><td><input type="checkbox" name="chckbox'+ x +'" id="chckbox'+ x +'" onclick="checkboxTrue('+ x +');" checked/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="bankName'+ x +'" id="bankName'+ x +'" /></td>\n\\n\
                                    <td><input  type="button" name="bankNameBtn'+ x +'" id="bankNameBtn'+ x +'" value="Search" onclick="javascript:searchBank(420,320,'+ x +')"/></td>\n\\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="branchName'+ x +'" id="branchName'+ x +'" readonly/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" onKeyPress="return numbersonly(this, event)" name="accountNo'+ x +'" id="accountNo'+ x +'"/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" onKeyPress="return numbersonly(this, event)" name="amount'+ x +'" id="amount'+ x +'"/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" onKeyPress="return numbersonly(this, event)" name="maturityAmount'+ x +'" id="maturityAmount'+ x +'"/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" onKeyPress="return numbersonly(this, event)" name="interestRate'+ x +'" id="interestRate'+ x +'"/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="acOpenDate'+ x +'" id="acOpenDate'+ x +'" size="8" readonly/></td>\n\
                                    <td><a href="#" onclick="return getCalendar(document.forms[0].acOpenDate'+ x +');"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" style="display:block;"  height="100%" width="20" /></a></td>\n\
                                    <td><input type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" size="8" id="acMatDate'+ x +'" name="acMatDate'+ x +'" readonly="true"></td>\n\
                                    <td><a href="#" onclick="return getCalendar(document.forms[0].acMatDate'+ x +');"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" style="display:block;"  height="100%" width="20" /></a></td>\n\
                                    <td><select id="active'+ x +'" name="active'+ x +'"><option value="" selected disabled>--- Select ---</option><option value="Yes">Yes</option><option value="No">No</option></select></td>\n\
                                    <td style="display:none;"><input type="hidden"  name="document_mst_id'+ x +'" id="document_mst_id'+ x +'"/></td>               </tr>');

                    $("#rowCounter").val(counter);
                    counter = $("#rowCounterDeleteCreate").val();
                    counter++;
                    $("#rowCounterDeleteCreate").val(counter);


                });


                $( "#deleteRow" ).click(function() {

                    var len = ($("#order-list tr").length)-1;
                    var counter = $("#rowCounterDeleteCreate").val();

                    var chkboxCounter=$("#chkboxCounter").val();

                    var counterDelete=counter-chkboxCounter;

                    if (counterDelete==0){

                        alert("All rows cannot be deleted");
                    }
                    else{

                        if (len ==chkboxCounter) {
                            alert("All rows can not be deleted");
                            return false;
                        }

                        $('input:checkbox:checked').closest('tr').remove();
                        $("#rowCounterDeleteCreate").val(counterDelete);

                        chkboxCounter=0;
                        $("#chkboxCounter").val(chkboxCounter);
                        var total = 0;
                        var test;

                }

            });

  /*=========================================================================================================================== */

            function checkboxAmendTrue(i){

                    if(document.getElementById("chckboxAmend"+i).checked==true){

                        var counterAmend = $("#chkboxCounterAmend").val();
                        counterAmend++;
                        $("#chkboxCounterAmend").val(counterAmend);

                    }

                    else{

                        var counterAmend = $("#chkboxCounterAmend").val();
                        counterAmend--;
                        $("#chkboxCounterAmend").val(counterAmend);
                    }

                    //alert("ChkBoxCounterAmend="+counterAmend);

                }

                $("#addRowAmend").click(function () {
                    //x=x+1;
                    x=parseInt($("#rowCounterDeleteCreateAmend").val());
                    x=x+1;
                    $("#all_rowsAddedAmend").val(x);
                    var counterAmend = $("#rowCounterAmend").val();
                    counterAmend++;
                    $('#order-list2 tr:last').after('<tr class="tRow"><td><input type="checkbox" name="chckboxAmend'+ x +'" id="chckboxAmend'+ x +'" onclick="checkboxAmendTrue('+ x +');" checked/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="bankNameAmend'+ x +'" id="bankNameAmend'+ x +'"/></td>\n\\n\
                                    <td><input  type="button" name="bankNameAmendBtn'+ x +'" id="bankNameAmendBtn'+ x +'" value="Search" onclick="javascript:searchBankAmend(420,320,'+ x +')"/></td>\n\\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="branchNameAmend'+ x +'" id="branchNameAmend'+ x +'" readonly/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" onKeyPress="return numbersonly(this, event)" name="accountNoAmend'+ x +'" id="accountNoAmend'+ x +'"/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" onKeyPress="return numbersonly(this, event)" name="amountAmend'+ x +'" id="amountAmend'+ x +'"/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" onKeyPress="return numbersonly(this, event)" name="maturityAmountAmend'+ x +'" id="maturityAmountAmend'+ x +'"/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" onKeyPress="return numbersonly(this, event)" name="interestRateAmend'+ x +'" id="interestRateAmend'+ x +'"/></td>\n\
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="acOpenDateAmend'+ x +'" id="acOpenDateAmend'+ x +'" size="8" readonly/></td>\n\
                                    <td><a href="#" onclick="return getCalendar(document.forms[0].acOpenDateAmend'+ x +');"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" style="display:block;"  height="100%" width="20" /></a></td>\n\
                                    <td><input type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" size="8" id="acMatDateAmend'+ x +'" name="acMatDateAmend'+ x +'" readonly="true"></td>\n\
                                    <td><a href="#" onclick="return getCalendar(document.forms[0].acMatDateAmend'+ x +');"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" style="display:block;"  height="100%" width="20" /></a></td>\n\
                                    <td><select id="activeAmend'+ x +'" name="activeAmend'+ x +'"><option value="" selected disabled>--- Select ---</option><option value="Yes" >Yes</option><option value="No" >No</option></select></td>\n\
                                    <td style="display:none;"><input type="hidden"  name="document_mst_idAmend'+ x +'" id="document_mst_idAmend'+ x +'"/></td>                </tr>');

                                    //alert(x);
                    $("#rowCounterAmend").val(counterAmend);
                    counterAmend = $("#rowCounterDeleteCreateAmend").val();
                    counterAmend++;
                    $("#rowCounterDeleteCreateAmend").val(counterAmend);


                });


                $( "#deleteRowAmend" ).click(function() {

                    var len = ($("#order-list2 tr").length)-1;
                    //alert("Len="+len);
                    var counterAmend = $("#rowCounterDeleteCreateAmend").val();
                    //alert("CounterAmend="+counterAmend);

                    var chkboxCounterAmend=$("#chkboxCounterAmend").val();
                    //alert("chkboxCounterAmend="+chkboxCounterAmend);

                    var counterDeleteAmend=counterAmend-chkboxCounterAmend;

                    //alert("counterDeleteAmend=" + counterDeleteAmend);

                    if (counterDeleteAmend==0){

                        alert("All rows cannot be deleted.");
                    }
                    else{

                        if (len ==chkboxCounterAmend) {
                            alert("All rows can not be deleted");
                            return false;
                        }

                        $('input:checkbox:checked').closest('tr').remove();
                        $("#rowCounterDeleteCreateAmend").val(counterDeleteAmend);

                        chkboxCounterAmend=0;
                        $("#chkboxCounterAmend").val(chkboxCounterAmend);
                        var total = 0;
                        var test;

                }

            });

            function SearchAsset(width, height,i)
            {

                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 = "DepositKYCCreation.jsp";
                var  lovKey=    "IDTypeScoreSearch"
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationDepositLOV.jsp?screenName=' + screenName+'&lovKey='+lovKey+'&textIndex='+i , 'IDTypeScoreSearch', attr);
                popWin.focus();



            }

            jQuery('#order-list').on('change','.IDScore',
            function(){
                var counter = document.forms[0].all_rowsAdded.value;
                var total = 0;
                var test;
                for (var i = 1; i <= counter; i++) {
                    try{
                        var k = document.getElementById("Score" + i);
                        if(k !== null && k.value === ""){
                            test =0;
                        }
                        else
                            test=parseInt(document.getElementById("Score" + i).value);
                    }catch(err){
                        test=0;
                    }
                    total = parseInt(total) + test;
                    document.getElementById("grandTotal").value = total;
                }
                if(isNaN(document.getElementById("grandTotal").value)){
                    document.getElementById("grandTotal").value = 0;
                }
            });


            $( "body" ).click(function() {
                $( ".IDScore" ).change();
            });
            $('#order-list').on('click',':input.changeTotalScoreButton[type="button"]', function() {

                var counter = document.forms[0].all_rowsAdded.value;
                var total = 0;
                var test;
                for (var i = 1; i <= counter; i++) {
                    try{
                        var k = document.getElementById("Score" + i);
                        if(k !== null && k.value === ""){
                            test =0;
                        }
                        else
                            test=parseInt(document.getElementById("Score" + i).value);
                    }catch(err){
                        test=0;
                    }
                    total = parseInt(total) + test;
                    document.getElementById("grandTotal").value = total;
                }
                if(isNaN(document.getElementById("grandTotal").value)){
                    document.getElementById("grandTotal").value = 0;
                }
            });


            function checkDiv(investmentCreateForm)
            {
                var row_no=parseInt(document.getElementById("rowCounterDeleteCreate").value);
                var tot_amt=0.00;


                //alert(row_no);
                var i=0;


                for (i=1;i<=row_no;i++)
                    {

                        if(document.getElementById("chckbox"+i).checked==true)
                            {
                                if (document.getElementById("bankName"+i).value == "")
                                {
                                    alert("Bank Name must be filled.");
                                    document.getElementById("bankName"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("branchName"+i).value == "")
                                {
                                    alert(" Branch Name must be filled.");
                                    document.getElementById("branchName"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("accountNo"+i).value == "")
                                {
                                    alert("Account Number must be filled.");
                                    document.getElementById("accountNo"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("amount"+i).value == "")
                                {
                                    alert("Amount must be filled.");
                                    document.getElementById("amount"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("maturityAmount"+i).value == "")
                                {
                                    alert("Maturity Amount must be filled.");
                                    document.getElementById("maturityAmount"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("interestRate"+i).value == "")
                                {
                                    alert("Interest Rate must be filled");
                                    document.getElementById("interestRate"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("acOpenDate"+i).value == "")
                                {
                                    alert("Account Open Date must be filled.");
                                    document.getElementById("acOpenDate"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("acMatDate"+i).value == "")
                                {
                                    alert("Account Maturity Date must be filled.");
                                    document.getElementById("acMatDate"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("active"+i).value == "")
                                {
                                    alert("Active Flag must be filled.");
                                    document.getElementById("active"+i).focus();
                                    return false;
                                }

                              if(document.getElementById("active"+i).value=="Yes")
                                {
                                    tot_amt=tot_amt+parseFloat(document.getElementById("amount"+i).value);
                                }
                               //alert(tot_amt);
                               //alert("Out");


                            }
                    }
                            //alert(tot_amt);
//                            var gl_amt=Math.abs(parseFloat(document.getElementById("glBal").value));
//                            //alert(gl_amt);
//
//                            if(Number(tot_amt)>Number(gl_amt))
//                                {
//                                    alert("GL Amount and sum of Bank accounts must be equal. Also kindly ensure check box next to all the bank accounts are checked.");
//                                    return false;
//                                }
                            return true;
                    };







            function checkDivAmend(investmentCreateForm)
            {
                var row_no=parseInt(document.getElementById("rowCounterDeleteCreateAmend").value);
                var tot_amt=0;


                //alert(row_no);
                var i=0;


                for (i=1;i<=row_no;i++)
                    {

                        if(document.getElementById("chckboxAmend"+i).checked==true)
                            {
                                if (document.getElementById("bankNameAmend"+i).value == "")
                                {
                                    alert("Bank Name must be filled.");
                                    document.getElementById("bankNameAmend"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("branchNameAmend"+i).value == "")
                                {
                                    alert("Branch Name must be filled");
                                    document.getElementById("branchNameAmend"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("accountNoAmend"+i).value == "")
                                {
                                    alert("Account Number must be filled.");
                                    document.getElementById("accountNoAmend"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("amountAmend"+i).value == "")
                                {
                                    alert("Amount must be filled.");
                                    document.getElementById("amountAmend"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("maturityAmountAmend"+i).value == "")
                                {
                                    alert("Maturity Amount must be filled.");
                                    document.getElementById("maturityAmountAmend"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("interestRateAmend"+i).value == "")
                                {
                                    alert(" Interest Rate must be filled.");
                                    document.getElementById("interestRateAmend"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("acOpenDateAmend"+i).value == "")
                                {
                                    alert("Account Open Date must be filled");
                                    document.getElementById("acOpenDateAmend"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("acMatDateAmend"+i).value == "")
                                {
                                    alert("Account Maturity Date must be filled");
                                    document.getElementById("acMatDateAmend"+i).focus();
                                    return false;
                                }

                                if (document.getElementById("activeAmend"+i).value == "")
                                {
                                    alert("Active Flag must be filled.");
                                    document.getElementById("activeAmend"+i).focus();
                                    return false;
                                }

                                if(document.getElementById("activeAmend"+i).value=="Yes")
                                {
                                    tot_amt=tot_amt+parseFloat(document.getElementById("amountAmend"+i).value);
                                }
                               
                            }
                    }
                            var gl_amt=Math.abs(parseFloat(document.getElementById("hidden_gl_amt").value));

                            if(tot_amt>gl_amt)
                                {
                                    alert("Total amount cannot be greater than GL balance.");
                                    return false;
                                }
                            return true;

                };


            function fetchform(investmentCreateForm)
            {
                var gl_no=document.getElementById("glNameAmend").value;

                          if(gl_no!="")
                          {
                              document.investmentCreateForm.handle_id.value = "Search";
                              document.investmentCreateForm.action = '/PacsApplication/InvestmentCreationServlet';
                              document.investmentCreateForm.submit();
                          }
                          else
                              {
                                  alert(" Please Search the GL Account first before proceeding.");
                              }


            }

            function updateform(investmentCreateForm)
            {
                var gl_no=document.getElementById("hidden_gl_no").value;

                          if(gl_no!="")
                          {
                              if(checkDivAmend(investmentCreateForm))
                                  {
                                      document.investmentCreateForm.handle_id.value = "Update";
                                      document.investmentCreateForm.action = '/PacsApplication/InvestmentCreationServlet';
                                      document.investmentCreateForm.submit();
                                  }
                          }
                          else
                              {
                                  alert("Please Search the GL Account first before proceeding.");
                              }


            }

            function submitform(investmentCreateForm)
            {
                if($('#glName').val() == ""){
                    alert("GL Account cannot be blank.");
                    investmentCreateForm.glName.focus();
                    return false;
                }
                //if (kycCreateForm.file.value == "" || !$('#file').val()){
                //   alert("Please select Photograph to proceed!");
                //  return false;
                // }
                      if(checkDiv(investmentCreateForm))
                          {
                              document.investmentCreateForm.handle_id.value = "Create";
                              document.investmentCreateForm.action = '/PacsApplication/InvestmentCreationServlet';
                              document.investmentCreateForm.submit();
                          }
            }

            function ShowParent(    )
            {
                document.forms[0].action="${pageContext.request.contextPath}/investment_creation.jsp";
                document.forms[0].submit();
            }

            function checkIDScore(){
                $( ".IDScore" ).change();
                /*alert("ID Score checked");*/
            }

            $('div#create').on('keydown',':input.mobile[type="text"]', function() {

                if (event.shiftKey == true) {
                    event.preventDefault();
                }

                if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 46 ) {

                } else {
                    event.preventDefault();
                }



            });

            function readURL(input) {
                if (input.files && input.files[0]) {
                    var reader = new FileReader();

                    reader.onload = function (e) {
                        $('#blah').attr('src', e.target.result);
                    }
                    reader.readAsDataURL(input.files[0]);
                }
            }

            function sigreadURL(input) {
                if (input.files && input.files[0]) {
                    var reader = new FileReader();

                    reader.onload = function (e) {
                        $('#blahsig').attr('src', e.target.result);
                    }
                    reader.readAsDataURL(input.files[0]);
                }
            }

            $(document).ready(function() {
                $("#file").change(function(){
                    readURL(this);
                    $('#blah').show();
                    $('#image-holder').show();
                });
                $("#sigUpld").change(function(){
                    sigreadURL(this);
                    $('#blahsig').show();
                    $('#image-holder').show();
                });
            });

            function hasExtension(inputID, exts) {
                var fileName = document.getElementById(inputID).value;
                return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$')).test(fileName);
            }
            /*
            function callUploadSevlet(){
                document.kycCreateForm.encoding  ='multipart/form-data';
                document.kycCreateForm.action='${pageContext.request.contextPath}/DepositUploadImageSevlet';
                document.kycCreateForm.submit();
            }

            $("#uploadButton").click(function(){
                $.ajax({
                    url:'CheckUploadServlet',
                    data:{name:'abc'},
                    type:'get',
                    cache:false,
                    success:function(data){
                        alert(data);
                        $('#somediv').text(responseText);
                    },
                    error:function(){
                        alert('error check');
                    }
                });
            });

            $(document).ready(function() {
                $('#uploadButton').click(function() {
                    $.get('CheckUploadServlet', function(responseText) {
                        $('#somediv').text(responseText);
                    });
                });
            });
             */

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

