<%--
    Document   : accountCreation
    Created on : Mar 8, 2016, 1:20:58 PM
    Author     : Tcs Helpdesk10
--%>

<%@page import="LoginDb.DbHandler"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.sql.Connection"%>
<%@page import="DataEntryBean.AccountCreationBean"%>
<html>
    <head>
        <title>Account 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 submitform(accCreatForm)
            {

                if (checkDiv(accCreatForm))
                {
                   accCreatForm.submit();
                }
            }
            function checkDiv(accCreatForm)
            {

                if (accCreatForm.productCodeDetails.value == "")
                {
                    alert("Product Code must be filled.");
                    accCreatForm.productCodeDetails.focus();
                    return false; 
                }
                if (accCreatForm.inttCategory.value == "")
                {
                    alert("Interest Category must be filled.");
                    accCreatForm.inttCategory.focus();
                    return false;
                }
                if (accCreatForm.segmentCode.value == "")
                {
                    alert("Segment Code must be filled.");
                    accCreatForm.segmentCode.focus();
                    return false;
                }
                if (accCreatForm.cifNumber.value == "")
                {
                    alert("CIF Number must be filled.");
                    accCreatForm.cifNumber.focus();
                    return false;
                }
//                if (accCreatForm.cbsSavingsAccount.value == "")
//                {
//                    alert("!! All fields must be filled !!");
//                    accCreatForm.cbsSavingsAccount.focus();
//                    return false;
//                }
                if (accCreatForm.collateralType.value == "")
                {
                    alert("Collateral Type must be filled.");
                    accCreatForm.collateralType.focus();
                    return false;
                }
                if (accCreatForm.collateralType.value == "L")
                {
                    if (accCreatForm.landinAcres.value == "")
                    {
                        alert("Land in Acres must be filled.");
                        accCreatForm.landinAcres.focus();
                        return false;
                    }
                }
                if (accCreatForm.description.value == "")
                {
                    alert("Description  must be filled.");
                    accCreatForm.description.focus();
                    return false;
                }
                if (accCreatForm.currentValuation.value == "")
                {
                    alert("Current Valuation must be filled.");
                    accCreatForm.currentValuation.focus();
                    return false;
                }
                if (accCreatForm.safeLendingMargin.value == "")
                {
                    alert("Safe Lending Margin must be filled.");
                    accCreatForm.safeLendingMargin.focus();
                    return false;
                }               
                if (accCreatForm.limit.value == "")
                {
                        alert("Total Limit must be filled.");
                        accCreatForm.limit.focus();
                        return false;
                }   
                if (accCreatForm.limit_kind.value == "")
                {
                    alert("Limit in Kind must be filled.");
                    accCreatForm.limit_kind.focus();
                    return false;
                }
                if (accCreatForm.limitExpiryDate.value == "")
                {
                    alert("Loan Due Date must be filled.");
                    accCreatForm.limitExpiryDate.focus();
                    return false;
                }
                
                if (accCreatForm.activityCode.value == "")
                {
                    alert("Activity Code  must be filled.");
                    accCreatForm.activityCode.focus();
                    return false;
                }
                if (accCreatForm.customerType.value == "")
                {
                    alert("Customer Type must be filled.");
                    accCreatForm.customerType.focus();
                    return false;
                }
                if (accCreatForm.intRate.value == "")
                {
                    alert("Interest Rate must be filled.");
                    accCreatForm.intRate.focus();
                    return false;
                }
                if (accCreatForm.penIntRate.value == "")
                {
                    alert("Penal Interest Rate must be filled.");
                    accCreatForm.penIntRate.focus();
                    return false;
                }
                re = /^\d+$/; //this checks whether field contains digits
                if (!re.test(accCreatForm.cifNumber.value))
                {
                    alert("CIF number could only contain numbers.");
                    accCreatForm.cifNumber.focus();
                    return false;
                }
                re = /^\d+$/; //this checks whether field contains digits
//                if (!re.test(accCreatForm.cbsSavingsAccount.value))
//                {
//                    alert("!! CBS savings account could only contain numbers !!");
//                    accCreatForm.cbsSavingsAccount.focus();
//                    return false;
//                }

//                re = /^(?=.*\d)\d*(?:\.\d*)?$/; //this checks whether field contains digits
//                if (!re.test(accCreatForm.limit.value))
//                {
//                    alert("Limit should only contain numbers.");
//                    accCreatForm.limit.focus();
//                    return false;
//                }

                re = /^(?=.*\d)\d*(?:\.\d*)?$/; //this checks whether field contains digits
                if (!re.test(accCreatForm.limit_kind.value))
                {
                    alert("Limit should only contain numbers.");
                    accCreatForm.limit_kind.focus();
                    return false;
                }

                re = /^(?=.*\d)\d*(?:\.\d*)?$/; //this checks whether field contains digits
                if (!re.test(accCreatForm.currentValuation.value))
                {
                    alert("CurrentValuation could only contain numbers.");
                    accCreatForm.currentValuation.focus();
                    return false;
                }
                re = /^(?=.*\d)\d*(?:\.\d*)?$/; //this checks whether field contains digits
                if (!re.test(accCreatForm.safeLendingMargin.value))
                {
                    alert("SafeLendingMargin could only contain numbers.");
                    accCreatForm.safeLendingMargin.focus();
                    return false;
                }
//                if(Number(accCreatForm.limit.value) > Number(accCreatForm.maxLimit.value) && accCreatForm.inttCatDetails.value.substr(0,1) == "1"){
//                    alert("Limit cannot be greater than " + accCreatForm.maxLimit.value);
//                    accCreatForm.limit.focus();
//                    return false;
//                }
                return true;
            }

            function sendInfo() {

                document.forms[0].handle_id.value = document.accCreatForm.productCode.value;
                document.forms[0].action = "DynamicInttCategory.jsp";
                document.forms[0].submit();

            }

            function ShowParent()
            {
                document.forms[0].action = "accountCreation.jsp";
                document.forms[0].submit();
            }


            function popup_CIF(width, height, cifNumber) {
                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 = "accountCreation.jsp";
                var  lovKey="CifDetails"
                popWin = open('CommonSearchInformationLOV.jsp?cifNumber=' + cifNumber + '&screenName=' + screenName+'&lovKey='+lovKey, 'CifDetails', attr);
                popWin.focus();

            }
            function popup_productCode(width, height, productCodeDetails) {
                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 = "accountCreation.jsp";
                var  lovKey="productCodeSearch"
                popWin = open('CommonSearchInformationLOV.jsp?productCodeDetails=' + productCodeDetails + '&screenName=' + screenName+'&lovKey='+lovKey, 'productCodeSearch', attr);
                popWin.focus();

            }

            function checkNotMoreThanHundred(event)
            {
                var idCalled = event.target.id;
                if( document.getElementById(idCalled).value !="" && document.getElementById(idCalled).value > 100)
                {
                    alert("limit in kind can't be more than 100%")
                    document.getElementById(idCalled).value=null;
                    document.getElementById(idCalled).focus();
                    return false;
                }
            }

            $(document).ready(function() {                                                          
                  $('#landinAcres').change(function(){
                    if($('#landinAcres').val() == ""){
                        $('#limit').prop("disabled", true);
                        $('#limit').val('');
                    } else {
                        $('#limit').val(Math.round($('#landinAcres').val() * 100000));
                        $('#limit').prop("disabled", false);
                        $('#maxLimit').val(Math.round($('#landinAcres').val() * 100000));
                    }
                });                                     
            });            
            
            $(document).ready(function () {
                $('select#collateralType').change(function () {
                    var shouldEnable = $(this).val();
                    switch(shouldEnable)
                    {
                        case 'O':
                            $('#forLand').hide();                           
                            break;
                        case 'L':
                            $('#forLand').show();                            
                            break;    
                        default:                           
                            $('#forLand').show();
                            break;
                    }
                })
            });
            
            // 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();
                    }
        %>

        <jsp:include page="MenuHead.jsp" flush="true" />
        <br>

        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>

        <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">Account Creation</legend>

            <form name="accCreatForm" method="post" onsubmit="return checkDiv(this)" action="AccountCreationServlet">

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

                <div id="create" align="left">

                    <table>
                        <tr><td><hr></td></tr>
                        <tr><td><h3>Account Information :</h3></td></tr>
                        <tr>
                            <td><lable>Product Code<font color="red" >*</font>:</lable></td>
                        <td><input type="text" id="productCodeDetails" name="productCodeDetails" readonly></td>
                        <td><input type="button" name="productCodeSearch" id="productCodeSearch" value="Search" onclick="javascript:popup_productCode(220, 180, document.accCreatForm.productCodeDetails.value);"/></td>

                        </tr>
                        <tr>
                            <td><lable>Interest Category<font color="red" >*</font>:</lable></td>
                        <td><input type="text" id="inttCatDetails" name="inttCatDetails" readonly="true"></td>
                        </tr>

                        <tr>
                            <td><lable>Segment Code<font color="red" >*</font>:</lable></td>
                        <td>
                            <select id="segmentCode" name="segmentCode">
                                <option value="" disabled selected style="display:none;">--Select--</option>
                                <option value="0706">0706:INDIVIDUAL</option>
                                <option value="0306">0306:STAFF</option>
                                <option value="5003">5003:SENIOR CITIZEN</option>
                                <option value="5010">5010:SHG</option>
                                <option value="5000">5000:BANKS</option>
                                <option value="5009">5009:INSTITUTIONS</option>
                                <option value="5050">5050:OTHERS</option>
                                <option value="5007">5007:SOCIETY</option>
                                <option value="5011">5011:GOV/SEMI GOV</option>
                                <option value="5012">5012:PACS</option>
                                <option value="5013">5013:UCB</option>
                                <option value="5014">5014:SCB</option>
                                <option value="5015">5015:CCB</option>
                            </select>
                        </td>
                        </tr>
                        <tr>
                            <td><lable>CIF Number<font color="red" >*</font>:</lable></td>
                        <td><input type="text" id="cifNumber" name="cifNumber" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' ></td>
                        <td><input type="button" name="cifNumberSearch" id="cifNumberSearch" value="Search" onclick="javascript:popup_CIF(220, 180, document.accCreatForm.cifNumber.value);"/></td>
                        </tr>

                        <tr>
<!--                            <td><lable>Linked CBS Savings Account :</lable></td>-->
                        <td><input type="text" hidden id="cbsSavingsAccount" name="cbsSavingsAccount" readonly="true" value="" ></td>
                        </tr>

                        <tr><td><hr></td></tr>
                        <tr><td><h3>Collateral Information :</h3></td></tr>
                        <tr>
                            <td><lable>Collateral Type<font color="red" >*</font>:</lable></td>
                        <td>
                            <select id="collateralType" name="collateralType">
                                <option value="" disabled selected style="display:none;">--Select--</option>
                                <option value="L">Land</option>
                                <option value="O">Others</option>
                            </select>
                        </td>
                        </tr>
                        <tr id="forLand">
                            <td><lable>Land in Acres<font color="red" >*</font>:</lable></td>
                        <td><input type="text" id="landinAcres" name="landinAcres" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' ></td>
                        </tr>
                        <tr>
                            <td><lable>Description<font color="red" >*</font>:</lable></td>
                        <td><textarea id="description" name="description" style="width : 150px"></textarea></td>
                        </tr>
                        <tr>
                            <td><lable>Current Valuation (in Rs.)<font color="red" >*</font>:</lable></td>
                        <td><input type="text" id="currentValuation" name="currentValuation" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' /></td>
                        </tr>
                        <tr>
                            <td><lable>Safe Lending Margin<font color="red" >*</font>:</lable></td>
                        <td><input type="text" id="safeLendingMargin" name="safeLendingMargin" onfocusout="javascript:checkNotMoreThanHundred(event);" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /> %</td>
                        <%--<td><lable>%</lable></td>--%>
                        </tr>

                        <tr><td><hr></td></tr>
                        <tr><td><h3>Limit Information</h3></td></tr>

                        <tr id="forLimit">
                            <td><lable>Total Limit/Sanction Amount<font color="red" >*</font>:</lable></td>
                        <td><input type="text" id="limit" name="limit" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57'></td>
                        </tr>

                        <tr>
                            <td><lable>Limit in Kind<font color="red" >*</font>:</lable></td>
                        <td><input type="text" id="limit_kind" name="limit_kind" onfocusout="javascript:checkNotMoreThanHundred(event);" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57'> %</td>
                        <%--<td><lable>%</lable></td>--%>
                        </tr>

                        <tr>
                            <td><lable>Loan Due Date<font color="red" >*</font>:</lable></td>
                <td><input type="text" id="limitExpiryDate" name="limitExpiryDate" style="text-align:center;" readonly="true">&nbsp;<a href="#" onclick="return getCalendar(document.forms[0].limitExpiryDate);"><img src="img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a></td>
                        </tr>

                        <tr><td><hr></td></tr>
                        <tr><td><h3>Additional Information :</h3></td></tr>

                        <tr>
                            <td><lable>Activity Code<font color="red" >*</font>:</lable></td>
                        <td>
                            <select id="activityCode" name="activityCode">
                                <option value="" disabled selected style="display:none;">--Select--</option>
                                <option value="1">Direct Agriculture</option>
                                <option value="2">Indirect Agriculture</option>
                                <option value="3">Agricultural Service Units</option>
                                <option value="4">Farm Irrigation</option>
                                <option value="5">Fruits & Vegetables</option>
                            </select>
                        </td>
                        </tr>
                        <tr>
                            <td><lable>Customer Type<font color="red" >*</font>:</lable></td>
                        <td>
                            <select id="customerType" name="customerType">
                                <option value="" disabled selected style="display:none;">--Select--</option>
                                <option value="I">Individual</option>
                                <option value="C">Corporate</option>
                            </select>
                        </td>
                        </tr>

                        <tr><td><hr></td></tr>
                        <tr><td><h3>Interest Information:</h3></td></tr>
                        <tr>
                        <td><lable>Interest Rate<font color="red" >*</font>:</lable></td>
                        <td><input type="text" id="intRate" name="intRate" value="" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57'></td>
                        </tr>
                        <tr>
                        <td><lable>Penal Interest Rate<font color="red" >*</font>:</lable></td>
                        <td><input type="text" id="penIntRate" name="penIntRate" value="" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57'></td>
                        </tr>

                    </table>
                    <center>
                        <input type="button" value="Submit" onclick="javascript:submitform(accCreatForm)">
                        <input type="button" value="Reset" name="reset" onclick="ShowParent();" />
                    </center>
                    <tr><td><br></td></tr>
                    <tr><td><br></td></tr>
                    <label style=" font-family: Berlin Sans FB; font-weight:normal; "><font color="red" >*</font>All fields are mandatory</label>
                </div>
                <input type="hidden" name="handle_id" value="" />
                <input type="hidden" name="productCode" value="" />
                <input type="hidden" name="inttCategory" value="" />
                <input type="hidden" name="maxLimit" id="maxLimit" value="" />
            </form>
        </fieldset>
    </body>
</html>
