<%-- 
    Document   : popupGoldLoanDetails
    Created on : Dec 21, 2021, 4:45:36 PM
    Author     : 1242938
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Fill-up Gold Details</title>
        <link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/ButtonAndText.css" />
        <script src="${pageContext.request.contextPath}/jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js"></script>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css" />
        <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>
        <script src="${pageContext.request.contextPath}/js/Calendar.js"></script>

    </head>
    <body style="background-image: url('/PacsApplication/img/download.jpg');">
        <%
                    int count = 1;
        %>
        <form name="goldDetails" action="">
            <center>
                <table id="order-list2" border="2" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px">
                    <thead class="CSSTableGenerator" >
                        <tr>
                            <td></td>
                            <td>Bond No</td>
                            <td>Gross Weight</td>
                            <td>Net Weight</td>                            

                        </tr>
                    </thead>
                    <tbody>
                        <tr class="tRowGold">
                            <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;" name="bond<%=count%>" id="bond<%=count%>" maxlength="15"/></td>
                            <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="grossW<%=count%>" id="grossW<%=count%>" maxlength="15" onkeypress='return event.charCode >= 46 && event.charCode <= 57' /></td>
                            <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" name="netW<%=count%>" id="netW<%=count%>" maxlength="15" onkeypress='return event.charCode >= 46 && event.charCode <= 57' /></td>

                        </tr>
                    </tbody>
                </table>
                <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()"></td>
                        
                    </tr>
                </table>
            </center>
            <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">
        </form>
        <script type="text/javascript">
            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-list2 tr:last').after('<tr class="tRowGold"><td><input type="checkbox" name="chckbox' + x + '" id="chckbox' + x + '" onclick="checkboxTrue(' + x + ');"/></td>  \n\
                <td><input  type="text" maxlength="15" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;"  name="bond' + x + '" id="bond' + x + '"/></td>\n\
                <td><input  type="text" maxlength="15" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;"  name="grossW' + x + '" id="grossW' + x + '"/></td>\n\
                <td><input  type="text" maxlength="15" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;"  name="netW' + x + '" id="netW' + x + '"/></td>\n\
                </tr>');

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


            });


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

                var len = ($("#order-list2 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);
                }

            });

            function submitform(){
                if(validateNscDetails()){
                    
                    var totRow = document.getElementById("rowCounter").value;
                    var x=0;
                    var totsec=0;

                    var mindate = '01/01/2099';
                    var init = mindate.split("/")
                    var initDate = new Date(init[2], init[1] - 1, init[0])
                    //alert(totRow);
                    for(x=1;x<=totRow;x++){
                        //alert(window.opener.document.getElementById('productCodeDetails').value);
                        //alert(x);
                        var iFrame = window.opener.document.getElementById('order-list2');
                        var newDivInParent = window.opener.document.createElement('tr');
                        newDivInParent.setAttribute("Id", "goldDetails"+x);
                        iFrame.appendChild(newDivInParent);
                        var bond = document.getElementById("bond"+x).value;
                        var grossW = document.getElementById("grossW"+x).value;                        
                        var netW = document.getElementById("netW"+x).value;  
                        //totsec=Number(totsec)+Number(netW);

                        opener.document.getElementById('goldDetails'+x).innerHTML = '<tr class="tRowGold">\<td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" readonly name="bond' + x + '" id="bond' + x + '" value="' + bond + '"/></td>\n\<td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" readonly name="grossW' + x + '" id="grossW' + x + '" value="' + grossW + '"/></td>\n\<td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" readonly name="netW' + x + '" id="netW' + x + '" value="' + netW + '"/></td>\n\</tr>';

                        /*opener.document.$('#order-list tr:last').after('<tr class="tRow">\<td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" readonly name="ref' + x + '" id="ref' + x + '"/></td>\n\
                        <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" readonly name="amt' + x + '" id="amt' + x + '"/></td>\n\
                        <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" readonly name="openDt' + x + '" id="openDt' + x + '"/></td>\n\
                        <td><input  type="text" style="width: 100%;padding: 5px;margin: 0px;border: 1px solid #CCC;" readonly name="expDt' + x + '" id="expDt' + x + '"/></td>\n\
                        </tr>');*/
                    }
                  //  window.opener.document.getElementById('bond').value=bond;
                  //  window.opener.document.getElementById('netW').value=totsec;
                    window.opener.document.getElementById('rowCounter').value=totRow;
                    window.opener.document.getElementById('mat_dt').value=mindate;
                    window.opener.$('#gold').show();
                    self.close();

                }
            }

            function validateNscDetails(){
                var totRow = document.getElementById("rowCounter").value;
                var x=0;
                for(x=1;x<=totRow;x++){
                    if(document.getElementById("bond"+x).value == ""){
                        alert("Bond number cannot be empty");
                        document.getElementById("bond"+x).focus();
                        return false;
                    }
                    if(document.getElementById("grossW"+x).value == ""){
                        alert("Gross Weight cannot be empty");
                        document.getElementById("grossW"+x).focus();
                        return false;
                    }
                    if(document.getElementById("netW"+x).value == ""){
                        alert("Net Weight cannot be empty");
                        document.getElementById("netW"+x).focus();
                        return false;
                    }
                    
//                    re = /^\d+$/;
//                    if (!re.test(document.getElementById("grossW"+x).value))
//                    {
//                        alert("Amount could only contain numbers !!");
//                        document.getElementById("grossW"+x).focus();
//                        return false;
//                    }
                
                }
                return true;
            }
        </script>
    </body>
</html>
