<%--
    Document   : LoanInquiry
    Created on : Oct 19, 2016, 3:11:52 PM
    Author     : 986137
--%>

<%@page import="LoginDb.DbHandler"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.ArrayList"%>
<%@page import="DataEntryBean.EnquiryBean"%>
<%@page import="java.util.Date"%>


<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="${pageContext.request.contextPath}/jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js"></script>
        <script src="${pageContext.request.contextPath}/js/Calendar.js"></script>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css" />
        <title>Add/Edit SMS-Email Services</title>
        <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())%>" />
        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico?pacs=<%=((new java.util.Date()).getTime())%>" type="image/x-icon" />
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
                if($('#smsService').prop('checked') == true){
                    $('#mob_no').attr('readonly',false);
                    $('#miss_call').attr('disabled',false);
                }
                if($('#mailservice').prop('checked') == true){
                    $('#mail_id').attr('readonly',false);
                }
            }
            function ShowParent()
            {
                    document.forms[0].action="${pageContext.request.contextPath}/Deposit/EditServices.jsp";
                    document.forms[0].submit();
            }

           function accountsubmitform(editServicesForm)
            {
                 <%--if( ($('#smsService').prop('checked') == false) && $('#mailservice').prop('checked') == false && $('#deactivate').prop('checked') == false ){
                        alert('You must select at least one service to proceed');
                        $('#smsService').focus();
                        return false;
                    }--%>
                    if($('#acNo').val() == "" && $('#displayFlag').val() != "Y"){
                        alert('Please search the a/c number before proceeding');
                        $('#accountNo').focus(); 
                        return false;
                    }
                    if($('#change').val() == "N" && $('#displayFlag').val() == "Y"){
	                        alert('Please modify atleast one service before proceeding');
	                        return false;
	                    }
                    if($('#smsService').prop('checked') == true){
                        var filter = /^[0-9]{10}$/;
                        var mob = $('#mob_no').val();
                        //alert(mob);
                        if($('#mob_no').val() == ""){
                            alert('Enter mobile no for SMS service');
                            $('#mob_no').focus();
                            return false;
                        }
                        else if(!filter.test(mob)){
                            alert("Please put 10 digit mobile number");
                            $('#mob_no').focus();
                            return false;
                        }
                    }
                    if($('#smsService').prop('checked') == false){
                       // sms_flag=0;
                        document.forms[0].action = '/PacsApplication/ModifyServicesServlet';
                        document.forms[0].submit();
                    }
                    if($('#mailservice').prop('checked') == true){
                         var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
                         var mail = $('#mail_id').val();

                        if($('#mail_id').val() == ""){
                            alert('Enter Email Id for MAIL service');
                            $('#mail_id').focus();
                            return false;
                        }
                        else if(!filter.test(mail)){
                            alert('Enter valid Email Id for MAIL service');
                            $('#mail_id').focus();
                            return false;
                        }
                    }
                document.forms[0].action = '/PacsApplication/ModifyServicesServlet';
                document.forms[0].submit();   
            }
            
            function popup_accNo(width, height, accNo) {
                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 = "EditServices.jsp";
                var lovKey = "FetchAccountList"
                popWin = open('/PacsApplication/CommonSearchInformationLOV.jsp?accNo=' + accNo + '&screenName=' + screenName + '&lovKey=' + lovKey  , 'FetchAccountList', attr);
                popWin.focus();
            }

            function smsCheckBoxFunc(){
                $('#change').val("Y");
                if($('#smsService').prop('checked') == true){
                    //alert('checked');
                    $('#mob_no').attr('readonly',false);
                    $('#miss_call').attr('disabled',false);
                }else {
                    <%--$('#mob_no').attr('readonly',true);
                    $('#mob_no').val("");--%>
                    $('#miss_call').attr('disabled',true);
                    document.getElementById('sms_flag').value="0";
                }
            }

            function misscallCheckBoxFunc() {
	                $('#change').val("Y");
	            }

            function mailCheckBoxFunc(){
                $('#change').val("Y");
                if($('#mailservice').prop('checked') == true){
                    $('#mail_id').attr('readonly',false);
                }
                else{
                    $('#mail_id').attr('readonly',true);
                    $('#mail_id').val("");
                }

            }
            
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
            
        </script>
    </head>
    <body  onload="noBack()">


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

        <jsp:include page="MenuHead_Deposit.jsp" flush="true" />
        <br>
        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>

        <%
                    String error_msg = "";
                    Object error = request.getAttribute("message");
                    if (error != null) {
                        error_msg = error.toString();
                    }
        %>

      


        <fieldset style="border-color: black; background-image: url('/PacsApplication/img/download.jpg'); border-width: 3px">
            <legend style="padding: 8px; border-radius: 20px; background-color: #006600; color: white">Add/Edit SMS-Email Services</legend>
            <form id="editServicesForm" name="editServicesForm" method="post" action="">


                <%if (!error_msg.equalsIgnoreCase("")) {%>
                <center><div class="info" id="errorMessage"><center><%= error_msg%></center></div></center>
                <% }%>
                <br>
                <br>
            <input type="hidden" value="EditServices" name="screenName" />
            <%if (!(displayFlag.equalsIgnoreCase("Y"))) {%>
                <div id="filterDiv" >
                    <center>
                       <table>
                           <tr>
                              <td style="text-align: right">Account Number<font color="red" >*</font>: </td>
                              <td><input type="text"  maxlength="17" name="accountNo" id="accountNo" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' value="<%= blankNull(((String)request.getAttribute("acc_no")))%>"/></td>
                              <td><input type="button" value="Search" onclick="javascript:popup_accNo(420, 180, document.editServicesForm.accountNo.value)"/></td>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                           </tr>
                       </table>
                    </center>
                           
                   </div><br><br>
              <%}%>
                            
             <%if (displayFlag.equalsIgnoreCase("Y")) {%>
                  <center>
                     <div id="displayDiv" >             
                        <table>
                           <tr>
                              <td style="text-align: right">Account No: </td>
                              <td><input type="text"  maxlength="17" name="accountNo" id="accountNo_read"  value="<%= blankNull(((String)request.getAttribute("acc_no")))%>" readonly/></td>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                           </tr>
                           <tr> <td>&nbsp;</td></tr>
                           <tr><td style="text-align: right">Select Services: </td></tr>
                           <tr>
                               <td><input type ="checkbox" name ="smsService" id="smsService" onclick="smsCheckBoxFunc()" value ="SMS" <%=("1".equals((String)request.getAttribute("sms_flag"))?"checked":"")%>>SMS</td>
                               <td><input type="text"  maxlength="10" name="mob_no" id="mob_no" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' readonly value="<%= blankNull(((String)request.getAttribute("mob_no")))%>" placeholder="Enter Mobile No"/></td>
                           </tr>
                           <tr> <td>&nbsp;</td></tr>
                           <tr>
                               <td><input type ="checkbox" name="mailservice" id="mailservice" onclick="mailCheckBoxFunc()" value ="MAIL" <%=("1".equals((String)request.getAttribute("email_flag"))?"checked":"")%>>MAIL</td>
                               <td><input type="text"  maxlength="50" name="mail_id" id="mail_id" readonly  value="<%= blankNull(((String)request.getAttribute("mail_id")))%>" placeholder="Enter Email Id"/></td>
                           </tr>
                           <tr> <td>&nbsp;</td></tr>
                           <tr>
                               <td><input type ="checkbox" name ="miss_call" id="miss_call" disabled="true" onclick="misscallCheckBoxFunc()" value ="MISSED CALL" <%=("1".equals((String)request.getAttribute("misdcl_flag"))?"checked":"")%>>MISS CALL</td>
                           </tr>
                           <tr> <td>&nbsp;</td></tr>                            
                        </table>
                     </div>
                  </center>
             <%}%>
                  <center>
                     <input type="button" value="Submit" onclick="javascript:accountsubmitform(editServicesForm)">
                     <input type="button" value="Reset" name="reset" onclick="ShowParent();" />
                  </center>
                  <input type="hidden" id="acNo" name="acNo" value=""/>
                  <input type="hidden" id="displayFlag" name="displayFlag" value="<%=displayFlag%>"/>
                  <input type="hidden" id="change" name="change" value="N"/>
        </form>
    </fieldset>
  </body>
</html>
