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

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<html>
    <head>
        <title>Customer Enrollment</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 ShowParent()
            {
                    document.forms[0].action = "${pageContext.request.contextPath}/Trading_JSP/CustomerEnrollment.jsp";
                    document.forms[0].submit();
            }

            function submitform(CustomerEnrollmentForm)
            {
                if (checkCreateDiv(CustomerEnrollmentForm))
                {
                    document.forms[0].handle_id.value = "Create";
                    document.forms[0].action = '/PacsApplication/TradingCustomerEnrollmentServlet';
                    CustomerEnrollmentForm.submit();
                }

            }
            function checkCreateDiv(CustomerEnrollmentForm)
            {
                if (CustomerEnrollmentForm.checkOption1.value == "")
                {
                    alert("Please select Member Status.");
                    CustomerEnrollmentForm.checkOption1.focus();
                    return false;
                }
//                if (CustomerEnrollmentForm.cif_no.value == "")
//                {
//                    alert("CIF number cannot be blank.");
//                    CustomerEnrollmentForm.cif_no.focus();
//                    return false;
//                }
                if (CustomerEnrollmentForm.name.value == "")
                {
                    alert("Customer Name must be filled.");
                    CustomerEnrollmentForm.name.focus();
                    return false;
                }
                if (CustomerEnrollmentForm.address.value == "")
                {
                    alert("Address must be filled.");
                    CustomerEnrollmentForm.address.focus();
                    return false;
                }
                if (CustomerEnrollmentForm.contactperson.value == "")
                {
                    alert("Contact Person must be filled.");
                    CustomerEnrollmentForm.contactperson.focus();
                    return false;
                }
                if (CustomerEnrollmentForm.phone.value == "")
                {
                    alert("Phone number must be filled.");
                    CustomerEnrollmentForm.phone.focus();
                    return false;
                }                
                return true;
            }

            function updateform(CustomerEnrollmentForm)
            {                             
                if (checkUpdateDiv(CustomerEnrollmentForm))
                {

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

                }
            }
            function checkUpdateDiv(CustomerEnrollmentForm)
            {                
                if (CustomerEnrollmentForm.namesearch.value == "")
                {
                    alert("Name must be filled.");
                    CustomerEnrollmentForm.namesearch.focus();
                    return false;
                }
                if (CustomerEnrollmentForm.addressAmend.value == "")
                {
                    alert("Address must be filled.");
                    CustomerEnrollmentForm.addressAmend.focus();
                    return false;
                }
                if (CustomerEnrollmentForm.contactpersonAmend.value == "")
                {
                    alert("Contact Person must be filled.");
                    CustomerEnrollmentForm.contactpersonAmend.focus();
                    return false;
                }
                if (CustomerEnrollmentForm.phoneAmend.value == "")
                {
                    alert("Phone number must be filled.");
                    CustomerEnrollmentForm.phoneAmend.focus();
                    return false;
                }
                if (CustomerEnrollmentForm.cif_noAmend.value == "")
                {
                    alert("CIF number cannot be blank.");
                    CustomerEnrollmentForm.cif_noAmend.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';
                }
            }

            function checkop1()
            {
                if (document.getElementById("checkOption1").value == "Y")
                {
                    document.getElementById('cif').style.display = 'block';
                }
                if (document.getElementById("checkOption1").value == "N")
                {
                    document.getElementById('cif').style.display = 'none';
                }
            }
            
            function searchCustomer(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 = "customer.jsp";
                var lovKey = "CustomerDetails";

                popWin = open('/PacsApplication/CommonSearchInformationTradingLOV.jsp?customername=' + name + '&screenName=' + screenName + '&lovKey=' + lovKey, 'CustomerDetails', attr);
                popWin.focus();

            }

            function searchCif(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 = "customer.jsp";
                var lovKey = "CifDetails";

                popWin = open('/PacsApplication/CommonSearchInformationTradingLOV.jsp?screenName=' + screenName + '&lovKey=' + lovKey + '&cifNumber=' + cifNumber , 'CifDetails', attr);
                popWin.focus();

            }


            function getDetails()
            {
                if (CustomerEnrollmentForm.namesearch.value == "")
                {
                    alert("Customer Name must be filled.");
                    CustomerEnrollmentForm.namesearch.focus();
                    return false;
                }
                
                document.forms[0].handle_id.value = "Search";
                document.forms[0].action = '/PacsApplication/TradingCustomerEnrollmentServlet';
                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 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;
            }
        %>
        <%          int count = 1;
                    String error_msg = "";
                    Object error = request.getAttribute("message");
                    if (error != null) {
                        error_msg = error.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">Customer Enrollment</legend>
            <form name="CustomerEnrollmentForm" method="post" action="TradingCustomerEnrollmentServlet">

                <%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>
                        <tr>
                            <td>Member Status<font color="red" >*</font>:</td>
                            <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
                            <td>
                                <select id="checkOption1" name="checkOption1" >
                                    <option value="" disabled selected style="display:none;" > --Select-- </option>
                                    <option value="Y" >Member</option>
                                    <option value="N" >Non-Member</option>
                                </select>
                            </td>
                        </tr>
                    </table>

<!--                    <div id="cif">
                        <table>
                            <td>CIF Number:</td>
                            <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
                            <td></td><td></td><td></td><td></td><td></td><td></td>
                            <td><input type="text" name="cif_no" id="cif_no" value="" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                            <td><input type="button" value="Search" onclick="javascript:searchCif(620, 380,document.forms[0].cif_no.value)" /></td>
                        </table>
                    </div>-->
                    <table>
                        <tbody>
                           <tr id="cif">
                            <td>CIF Number:</td>                                                        
                            <td><input type="text" name="cif_no" id="cif_no" value="" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                            <td><input type="button" value="Search" onclick="javascript:searchCif(620, 380,document.forms[0].cif_no.value)" /></td>
                            </tr>
                            <tr>
                                <td>Customer Name<font color="red" >*</font>:</td>
                                <td><input type="text" name="name" id="name" value="" onpaste="return false;" onkeypress='return (event.charCode >= 65 && event.charCode <= 90) || (event.charCode == 32)' /></td>
                            </tr>
                            <tr>
                                <td>Address<font color="red" >*</font>:</td>
                                <td><textarea name="address"  id="address" value="" ></textarea></td>
                            </tr>
                            <tr>
                                <td>Contact Person<font color="red" >*</font>:</td>
                                <td><input type="text" name="contactperson" id="contactperson" value="" /></td>
                            </tr>
                            <tr>
                                <td>Phone Number<font color="red" >*</font>:</td>
                                <td><input type="text" name="phone" id="phone" value="" maxlength="10" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                            </tr>
                            <tr>
                                <td>GSTIN Number:</td>
                                <td><input type="text" name="gstin" id="gstin" value="" maxlength="20" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 90 && event.charCode != 64' /></td>
                            </tr>
                            <tr><td><br></td></tr>
                            <tr><td><br></td></tr>
                            <tr><td><label style="font-weight:  normal;"><font color="red" >*</font>All fields are mandatory</label></td></tr>

                        </tbody>
                    </table>

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

                <div id="amend" style="display: none;">
                    <table>
                        <tbody>
                        <lable style=" font-family: Berlin Sans FB; font-weight:  normal;" >Enter Customer Name<font color="red" >*</font>: </lable>
                        &nbsp;
                        <input type="text" name="namesearch" id="namesearch" onpaste="return false;" onkeypress='return (event.charCode >= 65 && event.charCode <= 90) || (event.charCode == 32)' />
                        <input type="button" name="customerSearch" id="customerSearch" value="Search" onclick="javascript:searchCustomer(620, 380, document.CustomerEnrollmentForm.namesearch.value)"/>                                                
                    
                        <tr>
                            <td>Member Status:</td>                             
                            <td><select id="checkOption1Amend" name="checkOption1Amend" >
                                    <option value="Y" >Member</option>
                                    <option value="N" >Non-Member</option>
                                </select>
                            </td>
                        </tr>                    
                                                        
                            <td>CIF Number:</td>
                            <td><input type="text" readonly="readonly" name="cif_noAmend" id="cif_noAmend" value="" style="text-align:right;"  /></td>
                                                                                                                                       
                            <tr>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
                                <td>Address:</td>
                                <td><input type="text" name="addressAmend" id="addressAmend" value="" /></td>
                            </tr>
                            <tr>
                                <td>Contact Person:</td>
                                <td><input type="text" name="contactpersonAmend" id="contactpersonAmend" value="" /></td>
                            </tr>
                            <tr>
                                <td>Phone Number:</td>
                                <td><input type="text" name="phoneAmend" id="phoneAmend" value="" maxlength="10" onkeypress="return numbersonly(event)" style="text-align:right;"  /></td>
                            </tr>
                            <tr>
                                <td>GSTIN Number:</td>
                                <td><input type="text" name="gstinAmend" id="gstinAmend" value="" maxlength="20" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 90 && event.charCode != 64' /></td>
                            </tr>

                            <tr><td><br></td></tr>
                            <tr><td><br></td></tr>
                            <tr><td><label style="font-weight:  normal;"><font color="red" >*</font>All fields are mandatory</label></td></tr>
                        </tbody>
                    </table><br><br>

                    <br><br>

                    <center>
                        <input type="button" value="Update" onclick="javascript:updateform(CustomerEnrollmentForm)">
                        <input type="reset" value="Reset" name="reset" onclick="ShowParent();"/>
                    </center>

                </div>  

                <input type="hidden" name="handle_id" value="" />              
            </form>

        </fieldset>

    </body>
</html>

