<%--
    Document   : kycCreation
    Created on : Mar 18, 2016, 12:19:23 PM
    Author     : TCS
--%>

<%@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.UUID" %>
<%String uuid = UUID.randomUUID().toString();%>
<% try {
%>

<html>
    <head>

        <title>Deposit KYC 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>
        <style>
            #image-holder{
                position: absolute;
                top:265;
                right: 425;
                left: 550;
                bottom:376;
                width: auto;

            }

        </style>
        <script type="text/javascript">
            (function($) {
                $.fn.ajaxfileupload = function(options) {
                    var settings = {
                        params: {},
                        action: '',
                        onStart: function() { },
                        onComplete: function(response) { },
                        onCancel: function() { },
                        validate_extensions : true,
                        valid_extensions : ['jpg'],
                        submit_button : null
                    };

                    var uploading_file = false;

                    if ( options ) {
                        $.extend( settings, options );
                    }


                    // 'this' is a jQuery collection of one or more (hopefully)
                    //  file elements, but doesn't check for this yet
                    return this.each(function() {
                        var $element = $(this);

                        // Skip elements that are already setup. May replace this
                        //  with uninit() later, to allow updating that settings
                        if($element.data('ajaxUploader-setup') === true) return;

                        $element.change(function()
                        {
                            // since a new image was selected, reset the marker
                            uploading_file = false;

                            // only update the file from here if we haven't assigned a submit button
                            if (settings.submit_button == null)
                            {
                                upload_file();
                            }
                        });

                        if (settings.submit_button == null)
                        {
                            // do nothing
                        } else
                        {
                            settings.submit_button.click(function(e)
                            {
                                // Prevent non-AJAXy submit
                                e.preventDefault();

                                // only attempt to upload file if we're not uploading
                                if (!uploading_file)
                                {
                                    upload_file();
                                }
                            });
                        }

                        var upload_file = function()
                        {
                            if($element.val() == '') return settings.onCancel.apply($element, [settings.params]);

                            // make sure extension is valid
                            var ext = $element.val().split('.').pop().toLowerCase();
                            if(true === settings.validate_extensions && $.inArray(ext, settings.valid_extensions) == -1)
                            {
                                // Pass back to the user
                                settings.onComplete.apply($element, [{status: false, message: 'The select file type is invalid. File must be ' + settings.valid_extensions.join(', ') + '.'}, settings.params]);
                            } else
                            {
                                uploading_file = true;

                                // Creates the form, extra inputs and iframe used to
                                //  submit / upload the file
                                wrapElement($element);

                                // Call user-supplied (or default) onStart(), setting
                                //  it's this context to the file DOM element
                                var ret = settings.onStart.apply($element, [settings.params]);

                                // let onStart have the option to cancel the upload
                                if(ret !== false)
                                {
                                    $element.parent('form').submit(function(e) { e.stopPropagation(); }).submit();
                                } else {
                                    uploading_file = false;
                                }
                            }
                        };

                        // Mark this element as setup
                        $element.data('ajaxUploader-setup', true);

                        /*
          // Internal handler that tries to parse the response
          //  and clean up after ourselves.
                         */
                        var handleResponse = function(loadedFrame, element) {
                            var response, responseStr = $(loadedFrame).contents().text();
                            try {
                                //response = $.parseJSON($.trim(responseStr));
                                response = JSON.parse(responseStr);
                            } catch(e) {
                                response = responseStr;
                            }

                            if(response.status ==1){
                                $(response.file_info).each(function(){
                                    var saved_file_name = this.target;
                                    var file_name_input = '<input type="hidden" class="image_name" name="image_names[]" value="' +saved_file_name+ '" />';
                                    document.form[0].append(file_name_input);
                                })
                            }

                            // Tear-down the wrapper form
                            element.siblings().remove();
                            element.unwrap();

                            uploading_file = false;

                            // Pass back to the user
                            settings.onComplete.apply(element, [ {
                                    status : true,
                                    message : 'Your file has been uploaded!'
                                }, settings.params ]);
                        };

                        /*
          // Wraps element in a <form> tag, and inserts hidden inputs for each
          //  key:value pair in settings.params so they can be sent along with
          //  the upload. Then, creates an iframe that the whole thing is
          //  uploaded through.
                         */
                        var wrapElement = function(element) {
                            // Create an iframe to submit through, using a semi-unique ID
                            var frame_id = 'ajaxUploader-iframe-' + Math.round(new Date().getTime() / 1000)
                            $('body').after('<iframe width="0" height="0" style="display:none;" name="'+frame_id+'" id="'+frame_id+'"/>');
                            $('#'+frame_id).get(0).onload = function() {
                                handleResponse(this, element);
                            };

                            // Wrap it in a form
                            element.wrap(function() {
                                return '<form action="' + settings.action + '" method="POST" enctype="multipart/form-data" target="'+frame_id+'" />'
                            })
                            // Insert <input type='hidden'>'s for each param
                            .before(function() {
                                var key, html = '';
                                for(key in settings.params) {
                                    var paramVal = settings.params[key];
                                    if (typeof paramVal === 'function') {
                                        paramVal = paramVal();
                                    }
                                    html += '<input type="hidden" name="' + key + '" value="' + paramVal + '" />';
                                }
                                return html;
                            });
                        }
                    });
                }
            })( jQuery )
        </script>
        <script lang="Javascript">
            $(document).ready(function() {
                $('#file').ajaxfileupload({
                    'action' : '/PacsApplication/UploadFile',
                    'onComplete' : function(response) {
                        $('#upload').hide();
                        $('#message').show();

                        var statusVal = JSON.stringify(response.status);

                        if(statusVal == "false")
                        {
                            $("#message").html("<font color='red'>"+JSON.stringify(response.message)+"</font>");
                        }
                        if(statusVal == "true")
                        {
                            $("#message").html("<font color='green'>"+JSON.stringify(response.message)+"</font>");
                        }
                    },
                    'onStart' : function() {
                        $('#upload').show();
                        $('#message').hide();
                    }
                });
                $('#sigUpld').ajaxfileupload({
                    'action' : '/PacsApplication/SigUploadFile',
                    'onComplete' : function(response) {
                        $('#sigupload').hide();
                        $('#sigmessage').show();

                        var statusVal = JSON.stringify(response.status);

                        if(statusVal == "false")
                        {
                            $("#sigmessage").html("<font color='red'>"+JSON.stringify(response.message)+"</font>");
                        }
                        if(statusVal == "true")
                        {
                            $("#sigmessage").html("<font color='green'>"+JSON.stringify(response.message)+"</font>");
                        }
                    },
                    'onStart' : function() {
                        $('#sigupload').show();
                        $('#sigmessage').hide();
                    }
                });      
            });

$(document).on("DOMNodeInserted",function(){
    //alert('1q2');
    $('.upldId').ajaxfileupload({
                    'action' : '/PacsApplication/UploadIdFile',
                    //url: '/PacsApplication/UploadIdFile',
                    //data: { 'name': $("#document_mst_id1").val() },
                    //dataType: 'html',
                    'onComplete' : function(response) {
                        var id = $(this).attr('id');

                        //alert(id[id.length -1]);
                        var rowno = id[id.length -1];
                        $('#idUpload'+ rowno).hide();
                        $('#message'+ rowno).show();
                        $('#upldFlag'+ rowno).val('1');
                        var statusVal = JSON.stringify(response.status);

                        if(statusVal == "false")
                        {
                            $("#message" + rowno).html("<font color='red'>"+JSON.stringify(response.message)+"</font>");
                        }
                        if(statusVal == "true")
                        {
                            $("#message" + rowno).html("<font color='green'>"+JSON.stringify(response.message)+"</font>");
                        }
                    },
                    'onStart' : function() {
                        var id = $(this).attr('id');
                        var rowno = id[id.length -1];
                        $('#upload' + rowno).show();
                        $('#message' + rowno).hide();
                    }
                });
});

 
        </script>
    </head>
    <body  onload="noBack()">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }
            function checkDiv(kycCreateForm)
            {


                if (kycCreateForm.title.value == "")
                {
                    alert("Title must be filled.");
                    kycCreateForm.title.focus();
                    return false;
                }
                if (kycCreateForm.fName.value == "")
                {
                    alert("First Name must be filled.");
                    kycCreateForm.fName.focus();
                    return false;
                }
                if (kycCreateForm.lName.value == "")
                {
                    alert("Last Name must be filled.");
                    kycCreateForm.lName.focus();
                    return false;
                }
                if (kycCreateForm.motherName.value == "")
                {
                    alert("Mother's Name must be filled.");
                    kycCreateForm.motherName.focus();
                    return false;
                }
                if (kycCreateForm.add1.value == "")
                {
                    alert("Address Line1 must be filled.");
                    kycCreateForm.add1.focus();
                    return false;
                }
                if (kycCreateForm.add3.value == "")
                {
                    alert("Address Line3 must be filled.");
                    kycCreateForm.add3.focus();
                    return false;
                } 
                if (kycCreateForm.pin.value == "")
                {
                    alert(" PIN Code must be filled.");
                    kycCreateForm.pin.focus();
                    return false;
                }
                if (kycCreateForm.distname.value == "")
                {
                    alert("District must be filled.");
                    kycCreateForm.distname.focus();
                    return false;
                }

                if (kycCreateForm.farmerType.value == "")
                {
                    alert("Farmer Type must be filled.");
                    kycCreateForm.farmerType.focus();
                    return false;
                }
                if (kycCreateForm.gender.value == "Not")
                {
                    alert("Gender must be filled.");
                    kycCreateForm.gender.focus();
                    return false;
                }
                if (kycCreateForm.religion.value == "")
                {
                    alert("Religion must be filled.");
                    kycCreateForm.religion.focus();
                    return false;
                }
                if (kycCreateForm.caste.value == "")
                {
                    alert("Caste must be filled.");
                    kycCreateForm.caste.focus();
                    return false;
                }

                if (kycCreateForm.dob.value == "")
                {
                    alert("Date Of Birth must be filled.");
                    kycCreateForm.dob.focus();
                    return false;
                }

                if (kycCreateForm.mNumber.value != "")
                {

                    if (kycCreateForm.mNumber.value.length != 10)
                    {
                        alert("Mobile Number Details must contain 10 digit.");
                        kycCreateForm.mNumber.focus();
                        return false;
                    }
                }
                var aa = $('#dbDate').val();
                var chkdate = document.getElementById("dob").value;
                var edate = chkdate.split("/");
                var spdate = new Date(aa.substring(6,10),aa.substring(3,5) - 1,aa.substring(0, 2));
                var sdd = spdate.getDate();
                var smm = spdate.getMonth();
                var syyyy = spdate.getFullYear()-0;
                var today = new Date(syyyy,smm,sdd).getTime();
                var e_date = new Date(edate[2],edate[1]-1,edate[0]).getTime();
                
                if(e_date > today)
                {
                    alert("Please provide appropriate Date of Birth.");
                    return false;
                }

                var counter = document.forms[0].rowCounter.value;

                try{
                    for (var i = 1; i <= counter; i++) {

                        var document_mst_id = document.getElementById("document_mst_id" + i).value;
                        var idIssueAt = document.getElementById("idIssueAt" + i).value;
                        var idNumber = document.getElementById("idNumber" + i).value;
                        var idIssueDate = document.getElementById("idIssueDate" + i).value;


                        if (document_mst_id == "" || idIssueAt == "" || idNumber == "" || idIssueDate =="") {
                            alert("KYC Document ID details must be filled.");
                            return false;
                        }

                        var a = $('#dbDate').val();
                        var chkdate = document.getElementById("idIssueDate" + i).value;
                        var edate = chkdate.split("/");
                        var spdate = new Date(a.substring(6,10),a.substring(3,5) - 1,a.substring(0, 2));
                        var sdd = spdate.getDate();
                        var smm = spdate.getMonth();
                        var syyyy = spdate.getFullYear()-0;
                        var today = new Date(syyyy,smm,sdd).getTime();
                        var e_date = new Date(edate[2],edate[1]-1,edate[0]).getTime();
                        if(e_date > today)
                        {
                            alert("Please provide appropriate Date of ID Issue.");
                            return false;
                        }

                    }
                }catch(e){

                }

                return true;
            }

            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;
            }

            // 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("KCC")) {%>
        <jsp:include page="/MenuHead.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.");
            }

            }
        %>


        <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 (KYC) Details Creation</legend>
            <form action="" method="post" name="kycCreateForm">

                <br>

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

                <div id="create" align="left" >
                    <table>
                        <tbody>
                            <tr>
                                <td>Select Photograph:</td>
                                <td><input type="file" name="file" id="file" />
                                    <div id="upload" style="display: none;">Uploading..</div>
                                    <div id="message"></div>
                                </td>
                            </tr>
                            <tr>
                                <td>Select Signature:</td>
                                <td><input type="file" name="sigUpld" id="sigUpld" />
                                    <div id="sigupload" style="display: none;">Uploading..</div>
                                    <div id="sigmessage"></div>
                                </td>
                            </tr>                            
                            <tr>
                                <td>Customer Type: </td>
                                <td>
                                    <select name="cType"  id="cType" style="width: 260px">
                                        <OPTION value="">      -- Select --     </OPTION>
                                        <option value="PERSONAL">PERSONAL</option>
                                        <option VALUE="NON-PERSONAL">NON-PERSONAL</option>

                                    </select>
                                </td>
                            </tr>


                            <tr>
                                <td>Title:<font color="red">*</font></td>
                                <td>
                                    <select name="title"  id="title">
                                        <OPTION value="">      -- Select --     </OPTION>
                                        <option value="Mr.">Mr.</option>
                                        <option value="Mrs.">Mrs.</option>
                                        <option value="M/S.">M/S.</option>


                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>First Name:<font color="red">*</font></td>
                                <td><input type="text" name="fName" style="width: 260px" id="fName" onpaste="return false;" onkeypress='return event.charCode >= 65 && event.charCode <= 90' /></td>
                            
                                <td>Middle Name: </td>
                                <td><input type="text" name="mName" style="width: 260px" id="mName" onpaste="return false;" onkeypress='return event.charCode >= 65 && event.charCode <= 90' /></td>
                            
                                <td>Last Name:<font color="red">*</font></td>
                                <td><input type="text" name="lName" style="width: 260px" id="lName" onpaste="return false;" onkeypress='return event.charCode >= 65 && event.charCode <= 90' /></td>
                            </tr>
                            <tr>
                                <td>Guardian Name/ Husband Name: </td>
                                <td><input type="text" name="gName" style="width: 260px" id="gName"  /></td>
                                
                                <td>Mother's Name<font color="red">*</font>: </td>
                                <td><input type="text" name="motherName" style="width: 260px" id="motherName"  /></td>
                            </tr>
                            <tr>
                                <td>Address Line1:<font color="red">*</font></td>
                                <td><textarea name="add1" id="add1" ></textarea></td>
                                <td>Address Line2:</td>
                                <td><textarea name="add2" id="add2"></textarea></td>
                                <td>Address Line3:<font color="red">*</font></td>
                                <td><textarea name="add3" id="add3"></textarea></td>                                
                            </tr>
                            <tr>
                                <td>Block: </td>
                                <td><input type="text" name="block" id="block" /></td>   
                                
                                <td>PIN Code:<font color="red">*</font> </td>
                                <td><input type="text" name="pin" id="pin" maxlength="6" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td> 
                                
                                <td>Area/Ward: </td>
                                <td><input type="text" name="ward" id="ward" /></td>  
                            </tr>

                            <tr>
                                <td>District:<font color="red">*</font></td>
                                <td><input type="text" name="distname" style="width: 260px" id="distname" /></td>
                                <td>City/Town: </td>
                                <td><input type="text" name="city" id="city" /></td>

                                <td>State: </td>
                                <td><input type="text" name="statename" id="statename" /></td>
                            </tr>
                            <tr>
                                <td>Date Of Birth:<font color="red">*</font></td>
                                <td>
                                    <input  type="text" id="dob" name="dob" readonly style="text-align:center" />&nbsp;<a href="#" onclick="return getCalendar(document.forms[0].dob);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a>
                                    <%--<input type="date" id="dob" name="dob">--%>
                                </td>
                                <td>Membership No: </td>
                                <td><input type="text" id="mem_no" name="mem_no" /></td>
                                <td>Farmer Type:<font color="red">*</font> </td>
                                <td><select id="farmerType" name="farmerType">
                                        <option value="" selected disabled>-- Select --</option>
                                        <option value="S">Small/Marginal</option>
                                        <option value="O">Other</option>
                                    </select></td>
                            </tr>
                            <tr>
                                <td>Gender:<font color="red">*</font></td>
                                <td><select id="gender" name="gender">
                                        <option value="Not">-- Select --</option>
                                        <option value="M">Male</option>
                                        <option value="F">Female</option>
                                        <option value="O">Other</option>
                                    </select></td>
                                    <td>Religion:<font color="red">*</font></td>
                                    <td><select id="religion" name="religion">
                                            <option value="" disabled selected>-- Select --</option>
                                            <option value="1">Hindu</option>
                                            <option value="2">Muslim</option>
                                            <option value="3">Christian</option>
                                            <option value="4">Sikh</option>
                                            <option value="5">Jain</option>
                                            <option value="6">Buddhist</option>
                                            <option value="7">Parsi</option>
                                            <option value="8">Others</option>
                                        </select>
                                    </td>
                                    <td>Caste:<font color="red">*</font></td>
                                    <td><select id="caste" name="caste">
                                            <option value="" selected disabled> --Select-- </option>
                                            <option value="1">General</option>
                                            <option value="2">SC</option>
                                            <option value="3">ST</option>
                                            <option value="4">Others</option>
                                        </select>
                                    </td>
                            </tr>
                            <tr>
                                <td>Mobile Number: </td>
                                <td><input type="text" maxlength=10 name="mNumber" id="mNumber" class="mobile" style="text-align:right;" /></td>

                                 <td>Email Id: </td>
                                <td><input  type="text" name="emailId"  id="emailId"/></td>
                            </tr>
<!--                            <tr><td>Mother Bank CIF: </td><td><input type="text" style="text-align:right;" maxlength="11" name="bankCIF" id="bankCIF" onkeypress='return event.charCode >= 48 && event.charCode <= 57' ></td></tr>-->
                            <tr><td>Alive/Dead: </td><td><select id="lstatus" name="lstatus">
                                        <option value="" selected disabled> --Select-- </option>
                                        <option value="A">Alive</option>
                                        <option value="D">Dead</option>
                                        </select></td></tr>
                            <tr id="showdate"><td>Date of Death: </td><td><input  type="text" style="text-align:center;" id="doDeath" name="doDeath"  />&nbsp;<a href="#" onclick="return getCalendar(document.forms[0].doDeath);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a></td></tr>

                        </tbody>
                    </table>
                                <br><br>
                    <div id="image-holder" style="display:none;">
                        <table>
                            <tr>
                                <td>
                                    <img id="blah" src="#" alt="Invalid image" width="140" height="150" border="1px" style="display:none;" /></td>
                                <td valign="bottom">
                                    <img id="blahsig" src="#" alt="Invalid image" width="180" height="100" border="1px" style="display:none;"/></td>
                            </tr>
                        </table>
                    </div>

                    <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">ID Type</td>
                                    <td>Score </td>
                                    <td>ID Number </td>
                                    <td>ID Issued At</td>
                                    <td colspan="2">ID Issue Date </td>
                                    <td>ID Scan Image</td>

                                </tr>
                            </thead>
                            <tbody>
                                <tr class="tRow">
                                    <td><input type="checkbox" name="chckbox<%=count%>" id="chckbox<%=count%>" onclick="checkboxTrue(<%=count%>);" /></td>

                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" readonly name="idType<%=count%>" id="idType<%=count%>"/></td>

                                    <td><input type="button" class="changeTotalScoreButton"  style="margin-right:-30px" name="SearchAsset<%=count%>" id="SearchAsset<%=count%>" value="Select ID"  onclick="SearchAsset(280,240,<%=count%>);" /></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" size="5" readonly class="IDScore" name="Score<%=count%>" id="Score<%=count%>"/></td>
                                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" maxlength="28" name="idNumber<%=count%>" id="idNumber<%=count%>"/></td>
                                    <td><input type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" maxlength="20"  name="idIssueAt<%=count%>" id="idIssueAt<%=count%>"/></td>
                                    <td><input type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" size="8" id="idIssueDate<%=count%>" name="idIssueDate<%=count%>" readonly="true"></td>
                                    <td><a href="#" onclick="return getCalendar(document.forms[0].idIssueDate<%=count%>);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" style="display:block;"  height="100%" width="20" /></a></td>

                                    <td><input type="file" class="upldId" name="file<%=count%>" id="file<%=count%>" value ="" />
                                    <div id="idUpload<%=count%>" style="display: none;">Uploading..</div>
                                    <div id="message<%=count%>"></div>
                                </td>
                                <td style="display:none;"><input type="hidden" name="upldFlag<%=count%>" id="upldFlag<%=count%>" value="0" /></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>
                            <tr >
                                <td><B>Total ID Score</B></td>
                                <td></td><td></td>
                                <td><input type="text" size="4" style="text-align: center;font-weight: bold;" readonly  name="grandTotal" id="grandTotal" value="0"/></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(kycCreateForm)"></td>
                                <td><input type="button" value="Reset" onclick="ShowParent();" /></td>
                                
                            </tr>
                        </table>
                    </center>
                    
                    <tr><td><br></td></tr>
                    <tr><td><label><font color="red" >*</font> marked fields are mandatory.</label></td></tr>
                </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="dbDate" id="dbDate" value="<%=sysDt%>" />
                <input type="hidden" name="nameOfFile" id="nameOfFile" value="">
                <input type="hidden" name="nameOfsigFile" id="nameOfsigFile" value="">
                <input type="hidden" id="test" value =""/>
            </form>
            <script>
                var x=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 + ');"/></td>  \n\
                    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" readonly name="idType' + x + '" id="idType' + x + '"/></td>\n\
    <td><input type="button" class="changeTotalScoreButton" style="margin-right:-30px" name="SearchAsset' + x + '" id="SearchAsset' + x + '" value="Select ID"  onclick="SearchAsset(280,240,'+x+')" /></td> \n\
    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" readonly size="5" class="IDScore" name="Score' + x + '" id="Score' + x + '" value=""/></td>\n\
    <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" maxlength="28" name="idNumber' + x + '" id="idNumber' + x + '" value=""/></td>\n\\n\
    <td><input type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" maxlength="20" name="idIssueAt' + x + '" id="idIssueAt' + x + '" value=""/></td>\n\
    <td><input type="text" size="8" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" id="idIssueDate' + x + '" name="idIssueDate' + x + '" readonly="true"></td>\n\                                            \n\
    <td><a href="#" onclick="return getCalendar(document.forms[0].idIssueDate' + x + ');"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" style="display:block;"  height="100%" width="20" /></a></td>\n\
    <td><input type="file" class="upldId" name="file' + x + '" id="file' + x + '" /><div id="idUpload' + x + '" style="display: none;">Uploading..</div><div id="message' + x + '"></div></td>\n\
    <td style="display:none"><input type="hidden" name="upldFlag' + x + '" id="upldFlag' + x + '" value="0" /></td>\n\
<td style="display:none"><input type="hidden"  name="document_mst_id' + x + '" id="document_mst_id' + x + '"/>               </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;
                        for (var i = 1; i <= x; 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 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 submitform(kycCreateForm)
            {

                if (document.getElementById("file").value != "" )
                {
                    if (!hasExtension('file', ['.jpg', '.JPG']) ) {
                        alert("Invalid Photo! Please select valid JPG/JPEG Photograph.");
                        return false;
                    }
                    var photo = document.getElementById("file");
                    var size1 = parseFloat(photo.files[0].size / 1024).toFixed(2);                    
                    if ( size1 > 50 )
                        {
                            alert("Please upload Photograph within 50 KB by size!");
                            return false;
                        }
                }                                   
                if (document.getElementById("sigUpld").value != "" ) 
                {
                    if (!hasExtension('sigUpld', ['.jpg', '.JPG']) ) {
                        alert("Invalid Photo! Please select valid JPG/JPEG Signature.");
                        return false;
                    }
                    var signature = document.getElementById("sigUpld");
                    var size2 = parseFloat(signature.files[0].size / 1024).toFixed(2);
                    if ( size2 > 30 )
                        {
                            alert("Please upload Signature within 30 KB by size!");
                            return false;
                        }
                }
               // var counter = ($("#order-list tr").length)-1;
               // alert("counter:"+counter);

                var browse1= $("#file1").val();
                var browse2= $("#file2").val();
                var browse3= $("#file3").val();
                var browse4= $("#file4").val();
                var browse5= $("#file5").val();
                //alert("browse5"+browse5);

                //if (counter >= 5 ) {
                if (browse5 != "" && browse5 != undefined)
                {
                    if (!hasExtension('file5', ['.jpg', '.JPG']) ) {
                        alert("Invalid Photo! Please select valid JPG/JPEG ID Scan Image.");
                        return false;
                    }
                    else
                        {
                    var photo = document.getElementById("file5");
                    var size1 = parseFloat(photo.files[0].size / 1024).toFixed(2);
                    if ( size1 > 50 )
                        {
                            alert("Please upload ID Scan Image within 50 KB by size!");
                            return false;
                        }
                    }
                }
                //if (counter >= 4 ) {
                if (browse4 != "" && browse4 != undefined)
                {
                    if (!hasExtension('file4', ['.jpg', '.JPG']) ) {
                        alert("Invalid Photo! Please select valid JPG/JPEG ID Scan Image.");
                        return false;
                    }
                    else
                        {
                    var photo = document.getElementById("file4");
                    var size1 = parseFloat(photo.files[0].size / 1024).toFixed(2);
                    if ( size1 > 50 )
                        {
                            alert("Please upload ID Scan Image within 50 KB by size!");
                            return false;
                        }
                    }
                }
                //if (counter >= 3 ) {
                if (browse3 != "" && browse3 != undefined)
                {
                    if (!hasExtension('file3', ['.jpg', '.JPG']) ) {
                        alert("Invalid Photo! Please select valid JPG/JPEG ID Scan Image.");
                        return false;
                    }
                    else
                        {
                    var photo = document.getElementById("file3");
                    var size1 = parseFloat(photo.files[0].size / 1024).toFixed(2);
                    if ( size1 > 50 )
                        {
                            alert("Please upload ID Scan Image within 50 KB by size!");
                            return false;
                        }
                    }
                }
                //if (counter >= 2 ) {
                if (browse2 != "" && browse2 != undefined)
                {
                 if (!hasExtension('file2', ['.jpg', '.JPG']) ) {
                        alert("Invalid Photo! Please select valid JPG/JPEG ID Scan Image.");
                        return false;
                    }
                    else
                        {
                    var photo = document.getElementById("file2");
                    var size1 = parseFloat(photo.files[0].size / 1024).toFixed(2);
                    if ( size1 > 50 )
                        {
                            alert("Please upload ID Scan Image within 50 KB by size!");
                            return false;
                        }
                        }
                }
                //if (counter >= 1 ) {
                //if (document.getElementById("file1").value != "" || $("#file1").val() )
                if (browse1 != "" && browse1 != undefined)
                {
                    if (!hasExtension('file1', ['.jpg', '.JPG']) ) {
                        alert("Invalid Photo! Please select valid JPG/JPEG ID Scan Image.");
                        return false;
                    }
                    else
                        {
                    var photo = document.getElementById("file1");
                    var size1 = parseFloat(photo.files[0].size / 1024).toFixed(2);
                    if ( size1 > 50 )
                        {
                            alert("Please upload ID Scan Image within 50 KB by size!");
                            return false;
                        }
                        }
                }                
                if (checkDiv(kycCreateForm))
                {
                    if(checkDuplicateID()){
                        checkIDScore();
                        if($('#message').text().indexOf("Your file has been uploaded!") >= 0){
                            $('#nameOfFile').val($('#file').val());
                        }
                        if($('#sigmessage').text().indexOf("Your file has been uploaded!") >= 0){
                            $('#nameOfsigFile').val($('#sigUpld').val());
                        }
                        document.kycCreateForm.handle_id.value = "Create";
                        document.kycCreateForm.action = '/PacsApplication/DepositKYCCreationServlet';
                        document.kycCreateForm.submit();
                    }
                }                
            }
            
            function ShowParent(    )
            {
                document.forms[0].action="${pageContext.request.contextPath}/Deposit/DepositKYCCreation.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) {
                
            }
%>
