<%--
    Document   : pdsRationCardTypeMaster
    Created on : Jul 14, 2016, 12:22:27 PM
    Author     : 1320035
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="DataEntryBean.RationCardTypeHeaderBean"%>
<%@page import="DataEntryBean.RationCardTypeDetailsBean"%>
<%@page import="java.util.ArrayList"%>
<% try {
%>
<html>
    <head>
        <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>
        <title>Ration Card Type Enrollment</title>

    </head>
    <body  onload="noBack()">
        <script src="${pageContext.request.contextPath}/jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js"></script>

        <script type="text/javascript">


            function noBack()
            {
                window.history.forward();
            }

            function submitform(rationCardTypeForm)
            {

                if (checkCreateDiv(rationCardTypeForm))
                {

                    document.forms[0].handle_id.value = "Create";
                    document.forms[0].action='/PacsApplication/RationCardTypeServlet';
                    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
                    }
            }
            function checkCreateDiv(rationCardTypeForm)
            {

                if (rationCardTypeForm.cardType.value == ""||rationCardTypeForm.cardDescription.value == ""||rationCardTypeForm.status.value == "")
                {
                    alert("!! All fields must be filled !!");
                    // memberEnrollForm.custName.focus();
                    return false;
                }

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



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

                    try{
                        var productType = document.getElementById("productType"+i).value;

                        var productSubType = document.getElementById("productSubType"+i).value;

                        var quantiyUnit = document.getElementById("quantiyUnit"+i).value;

                        var quantity = document.getElementById("quantity"+i).value;
                        var eligibility = document.getElementById("eligibility"+i).value;
                        var frequency = document.getElementById("frequency"+i).value;



                        if (productType == "" || productSubType == "" || quantiyUnit == "" || quantity == "" ||eligibility==""||frequency=="") {

                            alert("Fill The Required Fields");
                            return false;
                        }


                    }
                    catch(e){

                    }


                }


                return true;
            }



            function updateForm(rationCardTypeForm)
            {
                if (checkUpdateDiv(rationCardTypeForm))
                {
                    document.forms[0].handle_id.value = "Update";
                    document.forms[0].action='/PacsApplication/RationCardTypeServlet';
                    rationCardTypeForm.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!=46){ //allow decimal entry      
                         if (unicode<48||unicode>57) //if not a number
                                        return false ;//disable key press
                        }
                }
            }


            function checkUpdateDiv(rationCardTypeForm)
            {

                if (rationCardTypeForm.cardTypeAmend.value == ""||rationCardTypeForm.cardDescriptionAmend.value == ""||rationCardTypeForm.statusAmend.value == "")
                {
                    alert("!! All fields must be filled !!");
                    // memberEnrollForm.custName.focus();
                    return false;
                }

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



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

                    try{
                        var productType = document.getElementById("productTypeAmend"+i).value;

                        var productSubType = document.getElementById("productSubTypeAmend"+i).value;

                        var quantiyUnit = document.getElementById("quantiyUnitAmend"+i).value;

                        var quantity = document.getElementById("quantityAmend"+i).value;
                        var eligibility = document.getElementById("eligibilityAmend"+i).value;
                        var frequency = document.getElementById("frequencyAmend"+i).value;



                        if (productType == "" || productSubType == "" || quantiyUnit == "" || quantity == "" ||eligibility==""||frequency=="") {

                            alert("Fill The Required Fields");
                            return false;
                        }


                    }
                    catch(e){

                    }


                }


                return true;

            }
            //LOV
            function popup_Card(width, height, cardTypeSearch,cardDescriptionSearch) {
                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 = "pdsRationCardTypeMaster.jsp";
                var  lovKey="cardDetails"
                popWin = open('/PacsApplication/CommonSearchInformationPdsLOV.jsp?cardTypeSearch=' + cardTypeSearch + '&cardDescriptionSearch=' + cardDescriptionSearch +'&screenName=' + screenName+'&lovKey='+lovKey, 'cardDetails', attr);
                popWin.focus();

            }
            function SearchProduct(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 = "pdsRationCardTypeMaster.jsp";
                var  lovKey="PdsProductSearch"
                popWin = open('/PacsApplication/CommonSearchInformationPdsLOV.jsp?screenName=' + screenName+'&lovKey='+lovKey+'&textIndex='+i , 'PdsProductSearch', attr);
                popWin.focus();

            }
            function SearchProduct_Amend(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 = "pdsRationCardTypeMaster.jsp";
                var  lovKey="PdsProductSearchAmend"
                popWin = open('/PacsApplication/CommonSearchInformationPdsLOV.jsp?screenName=' + screenName+'&lovKey='+lovKey+'&textIndex='+i , 'PdsProductSearchAmend', attr);
                popWin.focus();

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

            }


            function getSearch(rationCardTypeForm) {
                document.forms[0].handle_id.value = "Search";
                document.forms[0].action = '/PacsApplication/RationCardTypeServlet';
                document.forms[0].submit();

            }



        </script>



        <%     int count = 1;
             String error_msg = "";
             Object error = request.getAttribute("message");
             if (error != null) {
                 error_msg = error.toString();
             }
        %>
        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>

        <%
             Object rationCardTypeHeaderBeanObj = request.getAttribute("orationCardTypeHeaderBean");
             RationCardTypeHeaderBean OrationCardTypeHeaderBean = new RationCardTypeHeaderBean();
             if (rationCardTypeHeaderBeanObj != null) {
                 OrationCardTypeHeaderBean = (RationCardTypeHeaderBean) request.getAttribute("orationCardTypeHeaderBean");

             }

        %>
        <%
             Object alRationCardTypeDetailsBeanApendObj = request.getAttribute("alRationCardTypeDetailsBeanApend");
             ArrayList<RationCardTypeDetailsBean> alRationCardTypeDetailsBeanApend = new ArrayList<RationCardTypeDetailsBean>();
             RationCardTypeDetailsBean OrationCardTypeDetailsBean = new RationCardTypeDetailsBean();
             if (alRationCardTypeDetailsBeanApendObj != null) {
                 alRationCardTypeDetailsBeanApend = (ArrayList<RationCardTypeDetailsBean>) request.getAttribute("alRationCardTypeDetailsBeanApend");
             }
        %>

        <%
             String displayFlag = "";
             Object display = request.getAttribute("displayFlag");
             if (display != null) {
                 displayFlag = display.toString();
             }
        %>


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



        <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">RATION CARD TYPE CREATION</legend>
            <form name="rationCardTypeForm" method="post" action="RationCardTypeServlet" >

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

                <center><label style=" font-family: Berlin Sans FB; font-weight:  normal;">Operation Selection</label>
                    <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>
                <br>
                <br>

                <div id="create" style="display: none;">

                    <table>
                        <tbody>
                            <tr>
                                <td>Card Type: </td>
                                <td><input type="text" name="cardType" id="cardType"/></td>
                            </tr>
                            <tr>
                                <td>Card Description: </td>
                                <td> <input type="text" size="30" name="cardDescription" id="cardDescription"/></td>
                            </tr>

                            <tr>
                                <td>Status:</td>
                                <td> <select id="status" name="status">
                                        <option value="" disabled selected style="display:none;"  >--Select--</option>
                                        <option value="A">Active</option>
                                        <option value="I">Inactive</option>
                                    </select></td>
                            </tr>

                        <tbody>

                    </table>
                    <br><br>


                    <table id="order-list">
                        <thead class="CSSTableGenerator">
                            <tr>
                                <td></td>
                                <td>Product Type</td>
                                <td colspan="2">Product Sub Type</td>
                                <td>Quantity Unit</td>
                                <td>Eligible Quantity</td>
                                <td>Eligibility</td>
                                <td>Frequency</td>
                                <td>Sale Rate Per Unit</td>
                                <td>Expiry Date</td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><input type="checkbox" name="chckbox<%=count%>" id="chckbox<%=count%>" onclick="return checkboxTrue(<%=count%>)"/></td>
                                <td><input type="text" id="productType<%=count%>" name="productType<%=count%>" readonly onkeypress="return numbersonly(event)"/></td>
                                <td><input type="text" id="productSubType<%=count%>" name="productSubType<%=count%>" readonly onkeypress="return numbersonly(event)"/></td>
                                <td><input type="button" value="Search" id="search<%=count%>" name="search<%=count%>" onclick="SearchProduct(450,180,<%=count%>)" /></td>
                                <!--LOV-->
                                <td><input type="text" id="quantiyUnit<%=count%>" readonly name="quantityUnit<%=count%>" /></td>
                                <td><input type="text" id="quantity<%=count%>" name="quantity<%=count%>" onkeypress="return numbersonly(event)"/></td>
                                <td><select id="eligibility<%=count%>" name="eligibility<%=count%>">
                                        <option value="" disabled selected style="display:none;">--Select--</option>
                                        <option value="1">per head</option>
                                        <option value="2">per family</option>
                                    </select></td>
                                <td><select id="frequency<%=count%>" name="frequency<%=count%>">
                                        <option value="" disabled selected style="display:none;" >--Select--</option>
                                        <option value="W">Weekly</option>
                                        <option value="F">Fortnightly</option>
                                        <option value="M">Monthly</option>
                                    </select></td>
                                <td><input type="text" id="saleRatePerUnit<%=count%>" name="saleRatePerUnit<%=count%>" onkeypress="return numbersonly(event)"/></td>
                                <td><select id="expiryDate<%=count%>" name="expiryDate<%=count%>">
                                        <option value="" disabled selected style="display:none;" >--Select--</option>
                                        <option value="1" >1 month</option>
                                        <option value="2" >2 months</option>
                                        <option value="3" >3 months</option>
                                        <option value="4" >4 months</option>
                                        <option value="5" >5 months</option>
                                        <option value="6" >6 months</option>
                                        <option value="7" >7 months</option>
                                        <option value="8" >8 months</option>
                                        <option value="9" >9 months</option>
                                        <option value="10" >10 months</option>
                                        <option value="11" >11 months</option>
                                        <option value="12" >12 months</option>
                                        <option value="13" >Unlimited</option>
                                    </select></td>
                                <td style=" display: none"><input type="hidden" name="product_id<%=count%>" id="product_id<%=count%>"/></td>
                            </tr>
                        </tbody>
                    </table>
                    <br>
                    <br>
                    <br>

                    <center>
                        <input type="button" id="addRow" value="Add Row"/>
                        <input type="button" id="deleteRow" value="Delete Row"/>
                        <input type="button" value="Submit" onclick="javascript:submitform(rationCardTypeForm)">
                        <input type="button" value="Reset" onclick="ShowParent();" />
                    </center>


                </div>

                <div id="amend" style="display: none;">

                    <center>
                        <table>
                            <tr>
                                <td>Card Type: </td>
                                <td> <input type="text" name="cardTypeSearch" id="cardTypeSearch" /></td>
                                <td><input type="button"  value="Search" onclick="javascript:popup_Card(220, 180,document.rationCardTypeForm.cardTypeSearch.value, document.rationCardTypeForm.cardDescriptionSearch.value)" /></td>
                            </tr>
                            <tr>
                                <td>Card Type Description: </td>
                                <td><input type="text" name="cardDescriptionSearch" id="cardDescriptionSearch" /></td>

                                <td><input type="button"  value="Search" onclick="javascript:popup_Card(220, 180,document.rationCardTypeForm.cardTypeSearch.value, document.rationCardTypeForm.cardDescriptionSearch.value)" /></td>
                            </tr>
                        </table>
                        <br>
                        <input type="hidden" name="card_type_mst_id" id="card_type_mst_id">
                        <input type="button"  value="Submit" onclick="javascript:getSearch(rationCardTypeForm)" />
                    </center><br>
                </div>

                <%if (displayFlag.equalsIgnoreCase("Y")) {%>

                <div id="amend2" >

                    <table>
                        <tbody>
                            <tr>
                                <td>Card Type: </td>
                                <td> <input type="text" name="cardTypeAmend" id="cardTypeAmend" value="<%=blankNull(OrationCardTypeHeaderBean.getCardType())%>"/></td>

                            </tr>
                            <tr>
                                <td>Card Type Description: </td>
                                <td><input type="text" name="cardDescriptionAmend" id="cardDescriptionAmend" value="<%=blankNull(OrationCardTypeHeaderBean.getCardDescription())%>"/></td>

                            </tr>
                            <tr>
                                <td>Status:</td>
                                <td> <select id="statusAmend" name="statusAmend">
                                        <option value="" >--Select--</option>
                                        <option value="A" <%if (OrationCardTypeHeaderBean.getStatus().equals("A")) {%> selected <%}%>>Active</option>
                                        <option value="I" <%if (OrationCardTypeHeaderBean.getStatus().equals("I")) {%> selected <%}%>>Inactive</option>
                                    </select></td>


                            </tr>
                        </tbody>
                    </table>

                    <input type="hidden"  id="cardMstIdAmend" name="cardMstIdAmend" value="<%=blankNull(OrationCardTypeHeaderBean.getCardMstIdAmend())%>" />

                    <br><br>



                    <table id="order-list-Amend">
                        <thead class="CSSTableGenerator">
                            <tr>
                                <td></td>
                                <td>Product Type</td>
                                <td colspan="2">Product Sub Type</td>
                                <td>Quantity Unit</td>
                                <td>Eligible Quantity</td>
                                <td>Eligibility</td>
                                <td>Frequency</td>
                                <td>Sale Rate Per Unit</td>
                                <td>Expiry Date</td>
                            </tr>
                        </thead>
                        <tbody>
                            <%
                                OrationCardTypeDetailsBean = new RationCardTypeDetailsBean();
                                count = 0;
                                for (int i = 0; i < alRationCardTypeDetailsBeanApend.size(); i++) {
                                    OrationCardTypeDetailsBean = alRationCardTypeDetailsBeanApend.get(i);
                                    count++;
                            %>
                            <tr>
                                <td><input type="checkbox" <%if (!OrationCardTypeDetailsBean.getLedgerQty_remaining().equalsIgnoreCase("0")) {%>disabled<%}%> name="chckboxAmend<%=count%>" id="chckboxAmend<%=count%>" onclick="return checkboxTrueAmend(<%=count%>)" value="<%=blankNull(OrationCardTypeDetailsBean.getDetailId())%>"/></td>
                                <td><input type="text" disabled id="productTypeAmend<%=count%>" name="productTypeAmend<%=count%>" value="<%=blankNull(OrationCardTypeDetailsBean.getProductType())%>" onkeypress="return numbersonly(event)"/></td>
                                <td><input type="text" disabled id="productSubTypeAmend<%=count%>" name="productSubTypeAmend<%=count%>" value="<%=blankNull(OrationCardTypeDetailsBean.getProductSubType())%>" onkeypress="return numbersonly(event)"/></td>
                                <td><input type="button" disabled="true" value="Search" id="search<%=count%>" name="search<%=count%>" onclick="SearchProduct_Amend(450,180,<%=count%>);" /></td>
                                <!--LOV-->
                                <td><input type="text" disabled id="quantiyUnitAmend<%=count%>" name="quantityUnitAmend<%=count%>" value="<%=blankNull(OrationCardTypeDetailsBean.getQuantityUnit())%>"/></td>
                                <td><input type="text"  id="quantityAmend<%=count%>" name="quantityAmend<%=count%>" value="<%=blankNull(OrationCardTypeDetailsBean.getQuantity())%>" onkeypress="return numbersonly(event)" /></td>

                                <td><select id="eligibilityAmend<%=count%>" name="eligibilityAmend<%=count%>">
                                        <option value="" disabled selected style="display:none;">--Select--</option>
                                        <option value="1" <%if (OrationCardTypeDetailsBean.getEligibility().equals("1")) {%> selected <%}%>>per head</option>
                                        <option value="2" <%if (OrationCardTypeDetailsBean.getEligibility().equals("2")) {%> selected <%}%>>per family</option>
                                    </select></td>
                                <td><select id="frequencyAmend<%=count%>" name="frequencyAmend<%=count%>">
                                        <option value="" >--Select--</option>
                                        <option value="W" <%if (OrationCardTypeDetailsBean.getFrequency().equals("W")) {%> selected <%}%>>Weekly</option>
                                        <option value="F" <%if (OrationCardTypeDetailsBean.getFrequency().equals("F")) {%> selected <%}%>>Fortnightly</option>
                                        <option value="M" <%if (OrationCardTypeDetailsBean.getFrequency().equals("M")) {%> selected <%}%>>Monthly</option>
                                    </select></td>
                                <td><input type="text" id="saleRatePerUnitAmend<%=count%>" name="saleRatePerUnitAmend<%=count%>" value="<%=blankNull(OrationCardTypeDetailsBean.getSaleRatePerUnit())%>" onkeypress="return numbersonly(event)"/></td>

                                <td><select id="expiryDateAmend<%=count%>" name="expiryDateAmend<%=count%>">
                                        <option value="" >--Select--</option>
                                        <option value="1" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("1")) {%> selected <%}%>>1 month</option>
                                        <option value="2" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("2")) {%> selected <%}%>>2 months</option>
                                        <option value="3" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("3")) {%> selected <%}%>>3 months</option>
                                        <option value="4" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("4")) {%> selected <%}%>>4 months</option>
                                        <option value="5" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("5")) {%> selected <%}%>>5 months</option>
                                        <option value="6" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("6")) {%> selected <%}%>>6 months</option>
                                        <option value="7" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("7")) {%> selected <%}%>>7 months</option>
                                        <option value="8" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("8")) {%> selected <%}%>>8 months</option>
                                        <option value="9" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("9")) {%> selected <%}%>>9 months</option>
                                        <option value="10" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("10")) {%> selected <%}%>>10 months</option>
                                        <option value="11" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("11")) {%> selected <%}%>>11 months</option>
                                        <option value="12" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("12")) {%> selected <%}%>>12 months</option>
                                        <option value="13" <%if (OrationCardTypeDetailsBean.getExpiryDate().equals("13")) {%> selected <%}%>>Unlimited</option>
                                    </select></td>

                                <td style="display:none"><input type="hidden" name="rowStatus<%=count%>" id="rowStatus<%=count%>" value="A"/></td>
                                <td style="display:none"><input type="hidden" name="detailIDAmend<%=count%>" id="detailIDAmend<%=count%>" value="<%=blankNull(OrationCardTypeDetailsBean.getDetailId())%>" /></td>
                                <td style="display:none"><input type="hidden" name="product_id_Amend<%=count%>" id="product_id_Amend<%=count%>" value="<%=blankNull(OrationCardTypeDetailsBean.getProduct_id())%>"/></td>
                            </tr>
                            <%}%>
                        </tbody>
                    </table>
                    <br>
                    <br>
                    <br>
                    <label style="text-align: left; font-weight: normal">Cannot Delete Product which has Balance Quantity</label>
                    <center>
                        <input type="button" id="addRowAmend" value="Add Row"/>
                        <input type="button" id="deleteRowAmend" value="Delete Row"/>
                        <input type="button" value="Submit" onclick="javascript:updateForm(rationCardTypeForm)">
                        <input type="button" value="Reset" onclick="ShowParent();" />

                    </center>
                </div>
                <%}%>


                <input type="hidden" name="handle_id" value="" />
                <input type="hidden" name="rowCounter" id="rowCounter" value="<%=count%>">
                <input type="hidden" name="rowCounterDeleteAmend" id="rowCounterDeleteAmend" value="<%=count%>">
                <input type="hidden" name="rowCounterDelete" id="rowCounterDelete" value="<%=count%>">
                <input type="hidden" name="chkboxCounter" id="chkboxCounter" value="0"/>
                <input type="hidden" name="deletedRows" id="deletedRows" value=""/>

                <script>
                    $("#addRow").click(function(){

                        var counter = $("#rowCounter").val();
                        counter++;
                        $('#order-list tr:last').after('<tr><td><input type="checkbox" name="chckbox'+counter+'" id="chckbox'+counter+'" onclick="return checkboxTrue('+counter+')"/></td><td><input type="text" id="productType'+counter+'" readonly name="productType'+counter+'" onkeypress="return numbersonly(event)"/></td><td><input type="text" id="productSubType'+counter+'" readonly name="productSubType'+counter+'" onkeypress="return numbersonly(event)"/></td><td><input type="button" value="Search" id="search'+counter+'" name="search'+counter+'" onclick="SearchProduct(450,180,'+counter+')" /></td><td><input type="text" id="quantiyUnit'+counter+'" name="quantityUnit'+counter+'" /></td><td><input type="text" id="quantity'+counter+'" name="quantity'+counter+'"onkeypress="return numbersonly(event)"/></td><td><select id="eligibility'+counter+'" name="eligibility'+counter+'"><option value="" disabled selected style="display:none;">--Select--</option><option value="1">per head</option><option value="2">per family</option></select></td><td><select id="frequency'+counter+'" name="frequency'+counter+'"><option value="" >--Select--</option><option value="W">Weekly</option><option value="F">Fortnightly</option><option value="M">Monthly</option></select></td><td><input type="text" id="saleRatePerUnit'+counter+'" name="saleRatePerUnit'+counter+'" onkeypress="return numbersonly(event)"/></td><td><select id="expiryDate'+counter+'" name="expiryDate'+counter+'"><option value="" >--Select--</option><option value="1" >1 month</option><option value="2" >2 months</option><option value="3" >3 months</option><option value="4" >4 months</option><option value="5" >5 months</option><option value="6" >6 months</option><option value="7" >7 months</option><option value="8" >8 months</option><option value="9" >9 months</option><option value="10" >10 months</option><option value="11" >11 months</option><option value="12" >12 months</option><option value="13" >Unlimited</option></select></td><td style="display:none"><input type="hidden" name="product_id'+counter+'" id="product_id'+counter+'"/></td></tr>');
                        $("#rowCounter").val(counter);
                        $("#rowCounterDelete").val(counter);

                    });



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

                        var len = ($("#order-list tr").length)-1;
                        var counter = $("#rowCounterDelete").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();
                            $("#rowCounterDelete").val(counter);
                            chkboxCounter=0;
                            $("#chkboxCounter").val(chkboxCounter);

                        }

                    });



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

                        var counter = $("#rowCounter").val();
                        counter++;
                        $('#order-list-Amend tr:last').after('<tr><td><input type="checkbox" name="chckboxAmend'+counter+'" id="chckboxAmend'+counter+'" onclick="return checkboxTrueAmend('+counter+')"/></td><td><input type="text" id="productTypeAmend'+counter+'" readonly name="productTypeAmend'+counter+'" onkeypress="return numbersonly(event)"/></td><td><input type="text" id="productSubTypeAmend'+counter+'" readonly name="productSubTypeAmend'+counter+'" onkeypress="return numbersonly(event)"/></td><td><input type="button" value="Search" id="search'+counter+'" name="search'+counter+'" onclick="SearchProduct_Amend(450,180,'+counter+');" /></td><td><input type="text" id="quantiyUnitAmend'+counter+'" name="quantiyUnitAmend'+counter+'" /></td><td><input type="text" id="quantityAmend'+counter+'" name="quantityAmend'+counter+'"onkeypress="return numbersonly(event)"/></td><td><select id="eligibilityAmend'+counter+'" name="eligibilityAmend'+counter+'"><option value="" disabled selected style="display:none;">--Select--</option><option value="1">per head</option><option value="2">per family</option></select></td><td><select id="frequencyAmend'+counter+'" name="frequencyAmend'+counter+'"><option value="" >--Select--</option><option value="W">Weekly</option><option value="F">Fortnightly</option><option value="M">Monthly</option></select></td><td><input type="text" id="saleRatePerUnitAmend'+counter+'" name="saleRatePerUnitAmend'+counter+'" onkeypress="return numbersonly(event)"/></td><td><select id="expiryDateAmend'+counter+'" name="expiryDateAmend'+counter+'"><option value="" >--Select--</option><option value="1" >1 month</option><option value="2" >2 months</option><option value="3" >3 months</option><option value="4" >4 months</option><option value="5" >5 months</option><option value="6" >6 months</option><option value="7" >7 months</option><option value="8" >8 months</option><option value="9" >9 months</option><option value="10" >10 months</option><option value="11" >11 months</option><option value="12" >12 months</option><option value="13" >Unlimited</option></select></td><td style="display :none"><input type="hidden" name="product_id_Amend'+counter+'" id="product_id_Amend'+counter+'"/></td><td style="display :none"><input type="hidden" name="rowStatus' + counter + '" id="rowStatus' + counter + '" value="N"/></td><td style="display :none"><input type="hidden" name="detailIDAmend' + counter + '" id="detailIDAmend' + counter + '" value="" /></td></tr>');
                        $("#rowCounter").val(counter);
                        $("#rowCounterDeleteAmend").val(counter);

                    });



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


                        var len = ($("#order-list-Amend tr").length)-1;
                        var counter = $("#rowCounterDeleteAmend").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;
                            }


                            var selchbox = [];        // array that will store the value of selected checkboxes

                            selchbox= getSelectedChbox(rationCardTypeForm);
                            $("#deletedRows").val(selchbox);

                            $('input:checkbox:checked').closest('tr').remove();
                            $("#rowCounterDeleteAmend").val(counterDelete);
                            chkboxCounter=0;
                            $("#chkboxCounter").val(chkboxCounter);

                        }

                    });

                    function checkboxTrueAmend(i){

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

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

                        else{

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

                    }


                    function getSelectedChbox(rationCardTypeForm) {

                        var selchbox = [];        // array that will store the value of selected checkboxes

                        // gets all the input tags in frm, and their number
                        var inpfields = rationCardTypeForm.getElementsByTagName('input');
                        var nr_inpfields = inpfields.length;

                        // traverse the inpfields elements, and adds the value of selected (checked) checkbox in selchbox
                        for(var i=0; i<nr_inpfields; i++) {
                            if(inpfields[i].type == 'checkbox' && inpfields[i].checked == true){
                                if  (inpfields[i].value!=null || inpfields[i].value!="" ){

                                    selchbox.push(inpfields[i].value);

                                }

                            }

                        }

                        return selchbox;
                    }

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

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