<!DOCTYPE html>
<html>

<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<?php   include('include/common.php');?>  


<!-- new datatable js and css -->

        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.css"/>
<!-- <script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.js"></script> -->
 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.2.4/css/responsive.dataTables.min.css"/>
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.6.2/css/buttons.dataTables.min.css"/>

<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.js"></script>

<!-- https://code.jquery.com/jquery-3.5.1.js
https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js -->
<script type="text/javascript" src="https://cdn.datatables.net/responsive/2.2.4/js/dataTables.responsive.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.2/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.6.2/js/buttons.colVis.min.js"></script>


<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>

<!-- end new datatable js and css -->



 <script src="https://unpkg.com/gijgo@1.9.13/js/gijgo.min.js" type="text/javascript"></script>
    <link href="https://unpkg.com/gijgo@1.9.13/css/gijgo.min.css" rel="stylesheet" type="text/css" />
      
 



<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script> -->

<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css"> -->

<!-- Latest compiled and minified JavaScript -->
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script> -->

<!-- (Optional) Latest compiled and minified JavaScript translation files -->
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/i18n/defaults-*.min.js"></script> -->
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/@dashboardcode/bsmultiselect@0.5.58/dist/js/BsMultiSelect.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@dashboardcode/bsmultiselect@0.5.58/dist/js/BsMultiSelect.esm.min.js"></script>
 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@dashboardcode/bsmultiselect@0.5.58/dist/css/BsMultiSelect.min.css">

<?php
    //set default timezone for creater and updater
    date_default_timezone_set('Asia/Hong_Kong');


?>
</head>

<body  >

    <!-- admin javascript -->
     <script type="text/javascript">
      $( document ).ready(function() {


        $('#spinnermodal').on('shown.bs.modal', function(e) {
              $("#spinnermodal").modal("hide");
        });




        //add control
        $("#btnSubmit2").click(function(event) {
          var forcusitem="";
          var passCheck=true;

          var dataUrl= this.signaturePad.toDataURL();
           var dataUrl= this.signaturePad.toDataURL('image/png');
          window.open(dataUrl, "toDataURL() image", "width=600, height=200");
          // if($('#mobile').val().length !== 0){
          //   $("#mobile").addClass(" is-valid ");
          //   $("#mobile").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#mobile";
          //      $( '#mobile' ).empty().append('<p class="text-danger"  id="feedback">新增失敗。電話號碼的長度應為 7。</p>');
          //   }
          //   passCheck=false;
          //   $("#mobile").addClass(" is-invalid ");
          //   $("#mobile").removeClass(" is-valid ");
            
          //   passCheck=false;
          // }

          // if($('#code').val().length <=7 && $('#code').val().length!==0){

          //   // $("#code").addClass(" is-valid ");
          //   // $("#code").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#code";
          //   }
          //   $( '#warningmsg' ).empty().append('<p class="text-danger"  id="feedback">新增失敗。客戶編號的長度應為 7。</p>');
          //   passCheck=false;
          //  //  $("#code").addClass(" is-invalid ");
          //  // $("#code").removeClass(" is-valid ");
          // }


        //   if($('#inputadminname').val().length !== 0){
        //     $("#inputadminname").addClass(" is-valid ");
        //     $("#inputadminname").removeClass(" is-invalid ");
        //   }
        //   else{
        //     if(forcusitem.length===0){
        //        forcusitem="#inputadminname";
        //     }
        //     passCheck=false;
        //     $("#inputadminname").addClass(" is-invalid ");
        //    $("#inputadminname").removeClass(" is-valid ");
        //   }

          // if($('#password').val().length !== 0){
          //   $("#password").addClass(" is-valid ");
          //   $("#password").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#password";
          //   }
          //   passCheck=false;
          //   $("#password").addClass(" is-invalid ");
          //  $("#password").removeClass(" is-valid ");
          // }

          // if($('#confirm_password').val().length !== 0){
          //   $("#confirm_password").addClass(" is-valid ");
          //   $("#confirm_password").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#confirm_password";
          //   }
          //   passCheck=false;
          //   $("#confirm_password").addClass(" is-invalid ");
          //  $("#confirm_password").removeClass(" is-valid ");
          // }

          // if($('#confirm_password').val().length !== 0 || ($('#confirm_password').val()!==$('#password').val())){
          //   $("#confirm_password").addClass(" is-valid ");
          //   $("#confirm_password").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#confirm_password";
          //   }
          //   passCheck=false;
          //   $("#confirm_password").addClass(" is-invalid ");
          //  $("#confirm_password").removeClass(" is-valid ");
          // }

          

          //  if($('#chi_name').val().length !== 0){
          //   $("#chi_name").addClass(" is-valid ");
          //   $("#chi_name").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#chi_name";
          //   }
          //   passCheck=false;
          //   $("#chi_name").addClass(" is-invalid ");
          //  $("#chi_name").removeClass(" is-valid ");
          // }

          // if($('#eng_firstname').val().length !== 0){
          //   $("#eng_firstname").addClass(" is-valid ");
          //   $("#eng_firstname").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#eng_firstname";
          //   }
          //   passCheck=false;
          //   $("#eng_firstname").addClass(" is-invalid ");
          //  $("#eng_firstname").removeClass(" is-valid ");
          // }

          //  if($('#eng_lastname').val().length !== 0){
          //   $("#eng_lastname").addClass(" is-valid ");
          //   $("#eng_lastname").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#eng_lastname";
          //   }
          //   passCheck=false;
          //   $("#eng_lastname").addClass(" is-invalid ");
          //  $("#eng_lastname").removeClass(" is-valid ");
          // }


          //  if($('#role_name').val().length !== 0){
          //   $("#role_name").addClass(" is-valid ");
          //   $("#role_name").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#role_name";
          //   }
          //   passCheck=false;
          //   $("#role_name").addClass(" is-invalid ");
          //  $("#role_name").removeClass(" is-valid ");
          // }

          //  if($('#tenant_no').val().length !== 0){
          //   $("#tenant_no").addClass(" is-valid ");
          //   $("#tenant_no").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#tenant_no";
          //   }
          //   passCheck=false;
          //   $("#tenant_no").addClass(" is-invalid ");
          //  $("#tenant_no").removeClass(" is-valid ");
          // }

          //  if($('#income_type').val().length !== 0){
          //   $("#income_type").addClass(" is-valid ");
          //   $("#income_type").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#income_type";
          //   }
          //   passCheck=false;
          //   $("#income_type").addClass(" is-invalid ");
          //  $("#income_type").removeClass(" is-valid ");
          // }


          //  if($('#commission').val().length !== 0){
          //   $("#commission").addClass(" is-valid ");
          //   $("#commission").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#commission";
          //   }
          //   passCheck=false;
          //   $("#commission").addClass(" is-invalid ");
          //  $("#commission").removeClass(" is-valid ");
          // }

          // if($('#gender').val().length !== 0){
          //   $("#gender").addClass(" is-valid ");
          //   $("#gender").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#gender";
          //   }
          //   passCheck=false;
          //   $("#gender").addClass(" is-invalid ");
          //  $("#gender").removeClass(" is-valid ");
          // }




        //   alert("1");
          if(passCheck===false){
           
             $(forcusitem).focus();
          }


          if(passCheck===true){

          
          var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  // 'destUrl':'<?php echo base_url();?>/api/v1/frontend/add',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

            event.preventDefault();
            // var postUrl= '<?php echo base_url();?>' +'api/v1/tempbrcustomerend/add';
            // var postData ={
            //       'csrfToken' :'',
            //       'custname' : $('#name').val(),
            //       'tel' : $('#tel').val(),
            //       'email' : $('#email').val(),
            //       'wechat' : $('#wechat').val(),
            //       'birthday' : $('#birthday').val(),
            //       // 'selectedBox' :$('.css-checkbox:checked').val()
            //       'selectedBox' :selectBox1

            // }
            $checkedpurchase=0;
            if($('#need_purchase_service').is(':checked')){
                $checkedpurchase=1;
            }
            else
            {
              $checkedpurchase=0;
            }  

            var diseasearr = $('input[name=disease]:checked').map(function () {
  return this.value;
}).get();

            var postData ={
                'code':$('#code').val(),
                'display_name':$('#display_name').val(),
                // 'chi_name':$('#chi_name').val(),
                // 'eng_firstname':$('#eng_firstname').val(),
                // // 'inputadminname':$('#inputadminname').val(),
                // 'eng_lastname':$('#eng_lastname').val(),
                // 'gender':$('#gender').val(),
                'gender':$('input[name=gender]:checked').val(),
                'dob':$('#datepicker').val(),
                'mobile':$('#mobile').val(),
                'district_id':$('#area1').val(),
                'area_id':$('#level2').val(),
                'zone':$('#level3').val(),
                'address':$('#address').val(),
                'join_date':$('#datepicker2').val(),
                'shop_id':$('#first_registered_tenant_no').val(),
                'skin_improve':$('#skin_improve').val(),
                'body_improve':$('#body_improve').val(),
                'face_improve':$('#face_improve').val(),
                'referred_mobile':$('#referred_mobile').val(),
                'remark':$('#remark').val(),
                'need_purchase_service':$checkedpurchase,
                'service_id':$('#service_id').val(),
                'purchased_date':$('#purchased_date').val(),
                'purchased_qty':$('#purchased_qty').val(),
                'available_qty':$('#available_qty').val(),
                'remark2':$('#remark2').val(),
                'promotion_code':$('#promotion_code').val(),
                'first_registered_tenant_no':$('#first_registered_tenant_no').val(),  
                'concurrent_registered_tenant_no':$('#concurrent_registered_tenant_no').val(),  
                'level':$('#level').val(),  
                'isTemp':$('#isTemp').is(':checked') ? 1 : 0,
                'channelSelectID':$('#channelSelectID').val(), 
                'prefer_pic':$('#prefer_pic').val(), 
                'bodyoptionother_text':$('#bodyoptionother_text').val(), 
                'faceoptionother_text':$('#faceoptionother_text').val(), 



                // addedfield
                'id_number':$('#id_number').val(),  
                'career_name':$('#career_name').val(),   
                'age':$('#age').val(),   
                'body_height' :$('#body_height').val(), 
                'body_weight' :$('#body_weight').val(), 
                'married_status':$('#married_status').val(), 
                'child_num':$('#child_num').val(), 
                // 'disease':$('input[name=disease]:checked').val(), 
                'disease':$('input[name=disease]:checked').map(function () { return this.value;  }).get(),   
                'diseaseother': $('#diseaseother').val(), 
                'sensitivity' : $('#sensitivity').val(), 
                'surgery' : $('#surgery').val(), 
                'medicine' : $('#medicine').val(), 
                'allergy' : $('#allergy').val(), 
                'lifestyle':$('input[name=lifestyle]:checked').map(function () { return this.value;  }).get(),
                'habbit':$('input[name=habbit]:checked').map(function () { return this.value;  }).get(),
                'lighttheraphist':$('input[name=lighttheraphist]:checked').map(function () { return this.value;  }).get(),
                'otherlighttherapist': $('#otherlighttherapist').val(), 
                'botoxtherapist':$('input[name=botoxtherapist]:checked').map(function () { return this.value;  }).get(),
                // 'transtherapist':$('input[name=transtherapist]:checked').map(function () { return this.value;  }).get(),
                'transtherapist':$('input[name=transtherapist]:checked').map(function () { return this.value;  }).get(),
                'feeding':$('input[name=feeding]:checked').map(function () { return this.value;  }).get(),
                'beautytreat':$('input[name=beautytreat]:checked').map(function () { return this.value;  }).get(), 
                'paymentmethod':$('input[name=paymentmethod]:checked').map(function () { return this.value;  }).get(), 
                 'otherpayment' : $('#otherpayment').val(),  


                // end addedfield

                
            }
              postData.need_purchase_service=0;
            if($('#need_purchase_service').is(':checked')===true){
              postData.need_purchase_service=1;
              postData.service_id=$('#service_id').val();
              postData.purchased_date=$('#purchased_date').val();
              postData.purchased_price=$('#purchased_price').val();
              postData.purchased_qty=$('#purchased_qty').val();
              postData.available_qty=$('#available_qty').val();
            }  

            // alert($('#level2').val());
            $.ajax({
                  method: "POST",
                  url: postUrl,
                  dataType: "json",
                 data: postData,
                 success : function(data){

                // alert("posted");
                // // alert('formsubmit');
                // alert(data);
                
                // alert(data['recordstatus']);
                // alert(data['msg']);
                if(data['recordstatus']=="SUCCESS"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-primary" id="feedback">'+data['msg']+'</p>');
                    // setTimeout(function() {
                    //     location.reload();
                    // }, 3000);
                    setTimeout(function() {
                        location.href='/portable/formselection/'
                    }, 3000);
                    // location.reload();

                }
                  if(data['recordstatus']=="FAILURE"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-danger"  id="feedback">'+data['msg']+'</p>');
                //   $( '#modal-bodymsg' ).empty();
                //   $( '#modal-bodymsg' ).append( '<h5 class="text-center" style="color: #a03d49;">客戶不能增加。</h5> <h5 class="text-center" style="color: #a03d49;">請稍後再嘗試。</h5>' );
                //   $('#finishModal').modal('show');
                // }
                  // if (data.AJAX_SUCCESS==GlobalVariables.AJAX_SUCCESS){
                  //     window.location.href=GlobalVariables.destUrl;
                  // } else {
                  //     $('.alert').text("登入錯誤");
                  //    $('.alert').removeClass('hidden');
                  }
              }
            });  

            }//if(passCheck==true){
        });//$("#btnSubmit2").click(function(event) {

        //end add control


        //edit control
           $("#btnUpdate").click(function(event) {
          var forcusitem="";
          var passCheck=true;


          // if($('#code').val().length !== 0){
          //   $("#code").addClass(" is-valid ");
          //   $("#code").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#code";
          //   }
          //   passCheck=false;
          //   $("#code").addClass(" is-invalid ");
          //  $("#code").removeClass(" is-valid ");
          // }

           if($('#mobile').val().length !== 0){
            $("#mobile").addClass(" is-valid ");
            $("#mobile").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#mobile";
            }
            passCheck=false;
            $("#mobile").addClass(" is-invalid ");
           $("#mobile").removeClass(" is-valid ");
          }

          if($('#code').val().length <=7 && $('#code').val().length !== 0){

            // $("#code").addClass(" is-valid ");
            // $("#code").removeClass(" is-invalid ");
          }
          else{
            if(forcusitem.length===0){
               forcusitem="#code";
            }
            $( '#warningmsg' ).empty().append('<p class="text-danger"  id="feedback">更改失敗。客戶編號的長度應為 7。</p>');
            passCheck=false;
           //  $("#code").addClass(" is-invalid ");
           // $("#code").removeClass(" is-valid ");
          }



        //   if($('#inputadminname').val().length !== 0){
        //     $("#inputadminname").addClass(" is-valid ");
        //     $("#inputadminname").removeClass(" is-invalid ");
        //   }
        //   else{
        //     if(forcusitem.length===0){
        //        forcusitem="#inputadminname";
        //     }
        //     passCheck=false;
        //     $("#inputadminname").addClass(" is-invalid ");
        //    $("#inputadminname").removeClass(" is-valid ");
        //   }

          // if($('#password').val().length !== 0){
          //   $("#password").addClass(" is-valid ");
          //   $("#password").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#password";
          //   }
          //   passCheck=false;
          //   $("#password").addClass(" is-invalid ");
          //  $("#password").removeClass(" is-valid ");
          // }

          // if($('#confirm_password').val().length !== 0){
          //   $("#confirm_password").addClass(" is-valid ");
          //   $("#confirm_password").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#confirm_password";
          //   }
          //   passCheck=false;
          //   $("#confirm_password").addClass(" is-invalid ");
          //  $("#confirm_password").removeClass(" is-valid ");
          // }

          // if($('#confirm_password').val().length !== 0 || ($('#confirm_password').val()!==$('#password').val())){
          //   $("#confirm_password").addClass(" is-valid ");
          //   $("#confirm_password").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#confirm_password";
          //   }
          //   passCheck=false;
          //   $("#confirm_password").addClass(" is-invalid ");
          //  $("#confirm_password").removeClass(" is-valid ");
          // }

          

          //  if($('#chi_name').val().length !== 0){
          //   $("#chi_name").addClass(" is-valid ");
          //   $("#chi_name").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#chi_name";
          //   }
          //   passCheck=false;
          //   $("#chi_name").addClass(" is-invalid ");
          //  $("#chi_name").removeClass(" is-valid ");
          // }

          // if($('#eng_firstname').val().length !== 0){
          //   $("#eng_firstname").addClass(" is-valid ");
          //   $("#eng_firstname").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#eng_firstname";
          //   }
          //   passCheck=false;
          //   $("#eng_firstname").addClass(" is-invalid ");
          //  $("#eng_firstname").removeClass(" is-valid ");
          // }

          //  if($('#eng_lastname').val().length !== 0){
          //   $("#eng_lastname").addClass(" is-valid ");
          //   $("#eng_lastname").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#eng_lastname";
          //   }
          //   passCheck=false;
          //   $("#eng_lastname").addClass(" is-invalid ");
          //  $("#eng_lastname").removeClass(" is-valid ");
          // }


          //  if($('#role_name').val().length !== 0){
          //   $("#role_name").addClass(" is-valid ");
          //   $("#role_name").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#role_name";
          //   }
          //   passCheck=false;
          //   $("#role_name").addClass(" is-invalid ");
          //  $("#role_name").removeClass(" is-valid ");
          // }

          //  if($('#tenant_no').val().length !== 0){
          //   $("#tenant_no").addClass(" is-valid ");
          //   $("#tenant_no").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#tenant_no";
          //   }
          //   passCheck=false;
          //   $("#tenant_no").addClass(" is-invalid ");
          //  $("#tenant_no").removeClass(" is-valid ");
          // }

          //  if($('#income_type').val().length !== 0){
          //   $("#income_type").addClass(" is-valid ");
          //   $("#income_type").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#income_type";
          //   }
          //   passCheck=false;
          //   $("#income_type").addClass(" is-invalid ");
          //  $("#income_type").removeClass(" is-valid ");
          // }


          //  if($('#commission').val().length !== 0){
          //   $("#commission").addClass(" is-valid ");
          //   $("#commission").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#commission";
          //   }
          //   passCheck=false;
          //   $("#commission").addClass(" is-invalid ");
          //  $("#commission").removeClass(" is-valid ");
          // }

          // if($('#gender').val().length !== 0){
          //   $("#gender").addClass(" is-valid ");
          //   $("#gender").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#gender";
          //   }
          //   passCheck=false;
          //   $("#gender").addClass(" is-invalid ");
          //  $("#gender").removeClass(" is-valid ");
          // }


          if(passCheck===false){
           
             $(forcusitem).focus();
          }

        //   alert("1");
          if(passCheck==true){

          
          var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  // 'destUrl':'<?php echo base_url();?>/api/v1/frontend/add',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

            event.preventDefault();
            var postUrl= GlobalVariables.baseUrl +'api/v1/brcustomerend/update';
            // var postData ={
            //       'csrfToken' :'',
            //       'custname' : $('#name').val(),
            //       'tel' : $('#tel').val(),
            //       'email' : $('#email').val(),
            //       'wechat' : $('#wechat').val(),
            //       'birthday' : $('#birthday').val(),
            //       // 'selectedBox' :$('.css-checkbox:checked').val()
            //       'selectedBox' :selectBox1

            // }
            $checkedpurchase=0;
            if($('#need_purchase_service').is(':checked')){
                $checkedpurchase=1;
            }
            else
            {
              $checkedpurchase=0;
            }  


            var postData ={
                'code':$('#code').val(),
                'display_name':$('#display_name').val(),
                // 'chi_name':$('#chi_name').val(),
                // 'eng_firstname':$('#eng_firstname').val(),
                // 'inputadminname':$('#inputadminname').val(),
                // 'eng_lastname':$('#eng_lastname').val(),
                'gender':$('#gender').val(),
                'dob':$('#datepicker').val(),
                'mobile':$('#mobile').val(),
                'district_id':$('#area1').val(),
                'area_id':$('#level2').val(),
                'zone':$('#level3').val(),
                'address':$('#address').val(),
                'join_date':$('#datepicker2').val(),
                'shop_id':$('#first_registered_tenant_no').val(),
                'skin_improve':$('#skin_improve').val(),
                'referred_mobile':$('#referred_mobile').val(),
                'remark':$('#remark').val(),
                'oridistrict_id':$('#oridistrict_id').val(),
                'oriarea_id':$('#oriarea_id').val(),
                'orizone':$('#orizone').val(),
                'first_registered_tenant_no':$('#first_registered_tenant_no').val(),  
                'concurrent_registered_tenant_no':$('#concurrent_registered_tenant_no').val(), 
                'level':$('#level').val(),  
                'isTemp':$('#isTemp').is(':checked') ? 1 : 0,
                'channelSelectID':$('#channelSelectID').val(), 
                'body_improve':$('#body_improve').val(), 
                'bodyoptionother_text':$('#bodyoptionother_text').val(), 
                'face_improve':$('#face_improve').val(), 
                'faceoptionother_text':$('#faceoptionother_text').val(), 
                // 'need_purchase_service':$checkedpurchase,
                // 'service_id':$('#service_id').val(),
                // 'purchased_date':$('#purchased_date').val(),
                // 'purchased_qty':$('#purchased_qty').val(),
                // 'available_qty':$('#available_qty').val(),
                // 'remark2':$('#remark2').val(),
                'id':$('#id').val()

            }

            // alert($('#level2').val());
            $.ajax({
                  method: "POST",
                  url: postUrl,
                  dataType: "json",
                 data: postData,
                 success : function(data){

                // alert("posted");
                // // alert('formsubmit');
                // alert(data);
                
                // alert(data['recordstatus']);
                // alert(data['msg']);
                if(data['recordstatus']=="SUCCESS"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-primary" id="feedback">'+data['msg']+'</p>');
                    setTimeout(function() {
                        location.reload();
                    }, 3000);
                    // location.reload();

                }
                  if(data['recordstatus']=="FAILURE"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-danger"  id="feedback">'+data['msg']+'</p>');
                //   $( '#modal-bodymsg' ).empty();
                //   $( '#modal-bodymsg' ).append( '<h5 class="text-center" style="color: #a03d49;">客戶不能增加。</h5> <h5 class="text-center" style="color: #a03d49;">請稍後再嘗試。</h5>' );
                //   $('#finishModal').modal('show');
                // }
                  // if (data.AJAX_SUCCESS==GlobalVariables.AJAX_SUCCESS){
                  //     window.location.href=GlobalVariables.destUrl;
                  // } else {
                  //     $('.alert').text("登入錯誤");
                  //    $('.alert').removeClass('hidden');
                  }
              }
            });  

            }//if(passCheck==true){
        });//$("#btnUpdate").click(function(event) {

        
        //end edit control

        $("#btnBack").click(function(event){

          location.href='/portable/adminmain';
        });



         $( ".level1select" ).change(function() {
          // alert( "Handler for .change() called." );
          level1boxajax($(this).attr("id"),$(this).val());
        });
          
          $( ".level2select" ).change(function() {
          // alert( "Handler for .change() called." );
          level2boxajax($(this).attr("id"),$(this).val());
        });

          $( ".level3select" ).change(function() {
          // alert( "Handler for .change() called." );
          $('#address').val($("#area1 option:selected").text()+$(this).val());
        });
        

        });// $( document ).ready(function() {

         function level1boxajax($id,$value){
              var id = $id;
              // alert(id);
              var res = id.split("-");
              var fileid=res[0];
              var items=res[1];
              // alert("fileid"+fileid);
              // alert("items"+items);
              // var selectedid= $({"#".id}).val();
              var selectedid=$value;
              // alert(selectedid);
              var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  'destUrl':'<?php echo base_url();?>/api/v1/livingareaend/getSecondZone',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

              //empty lower select box

               var level2box = document.getElementById('level2');
                  // alert(city);
                   $(level2box).empty();     
   

              //end empty lower select box

              var postUrl= GlobalVariables.baseUrl +'/api/v1/livingareaend/getSecondZone';  
              //change select box option  
                 $.ajax({
                        type:'POST',
                        url:postUrl,
                        data:{'zone_id':selectedid},
                    success:function(data){
                      // alert('empty');
                      var obj = $.parseJSON(data);
                      // alert('empty2');
                    // var v = data.k; 

                   // the next thing you want to do 
                   // alert(fileid+'-'+items+'Level2');
                   // id='row' + id.toString();
                  // var findname=fileid.toString()+'-'+items.toString()+'-Level2';
                  // var city = document.getElementById(fileid+'-'.items+'Level2');
                  // var city = document.getElementById('5-1-Level2');
                  var level2box = document.getElementById('level2');
                  // alert(city);
                   $(level2box).empty();
                  //  $jsondata=json_decode($data);
                  // alert( obj.length);
                  // alert( obj[0]['name']);

                   //added empty select record  
                  $(level2box).append('<option  value=' + '> 請選擇居住範圍'  + '</option>');
                  
                  //end added empty select record    
                  

                  for (var i = 0; i < obj.length; i++) {

                  $(level2box).append('<option  value=' + obj[i].id + '>' + obj[i].chi_name + '</option>');
                  }
                  // alert(data);
                  // level3boxajax(fileid+'-'+items+'-Level3', obj[0].id);   
                  // alert('level3'+data);
              }
            });

          }
        //end level1boxajax

        //level2ajax
        function level2boxajax($id,$value){
              var id = $id;
              // alert(id);
              var res = id.split("-");
              var fileid=res[0];
              var items=res[1];
              // alert("fileid"+fileid);
              // alert("items"+items);
              // var selectedid= $({"#".id}).val();
              var selectedid=$value;
              // alert(selectedid);
              var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  'destUrl':'<?php echo base_url();?>/api/v1/livingareaend/getThirdZone',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

              //empty lower select box

               var level3box = document.getElementById('level3');
                  // alert(city);
                   $(level3box).empty();     
   

              //end empty lower select box

              var postUrl= GlobalVariables.baseUrl +'/api/v1/livingareaend/getThirdZone';  
              //change select box option  
                 $.ajax({
                        type:'POST',
                        url:postUrl,
                        data:{'zone_id':selectedid},
                    success:function(data){
                      // alert('empty');
                      var obj = $.parseJSON(data);
                      // alert('empty2');
                    // var v = data.k; 

                   // the next thing you want to do 
                   // alert(fileid+'-'+items+'Level2');
                   // id='row' + id.toString();
                  // var findname=fileid.toString()+'-'+items.toString()+'-Level2';
                  // var city = document.getElementById(fileid+'-'.items+'Level2');
                  // var city = document.getElementById('5-1-Level2');
                  var level3box = document.getElementById('level3');
                  // alert(city);
                   $(level3box).empty();
                  //  $jsondata=json_decode($data);
                  // alert( obj.length);
                  // alert( obj[0]['name']);

                   //added empty select record  
                  $(level3box).append('<option  value=' + '> 請選擇居住範圍'  + '</option>');
                  
                  //end added empty select record    
                  

                  for (var i = 0; i < obj.length; i++) {

                  $(level3box).append('<option  value=' + obj[i] + '>' + obj[i] + '</option>');
                  }
                  // alert(data);
                  // level3boxajax(fileid+'-'+items+'-Level3', obj[0].id);   
                  // alert('level3'+data);
              }
            });

          }

        //end level2ajax




      </script>
    


    <?php   include('include/header.php');?>
    <div class="wrapper" >
        
        <?php   //include('include/sidebar.php');?>
        <!-- loading modal -->
    <style>
      .bd-example-modal-lg .modal-dialog{
    display: table;
    position: relative;
    margin: 0 auto;
    top: calc(50% - 24px);
  }
  
  .bd-example-modal-lg .modal-dialog .modal-content{
    background-color: transparent;
    border: none;
  }
    </style>
    <div id="spinnermodal" class="modal fade bd-example-modal-lg" data-backdrop="static" data-keyboard="false" tabindex="-1">
    <div class="modal-dialog modal-sm">
        <div class="modal-content" style="width: 48px">
            <span class="fa fa-spinner fa-spin fa-3x"></span>
        </div>
    </div>
    <!-- <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        
      </div> -->
    </div>

<!-- end loading modal -->
        <!-- Page Content  -->
        <div id="content" style="background-color: #e4e4e4;">
          <!-- <h5>新增客戶</h5> -->
          <div class="title"><?php if($pagemethod=="add"){ 
                echo "<h5><a href='../adminmain' style='text-decaration:none;'>主頁</a> > <span style='color:#908d95;'>新客戶登記</span></h5>";
              }?>  
              <?php if($pagemethod=="edit"){ 
                echo "更改客戶";
              }?></div> 

         
            <!-- add button -->
            
            <!-- input form -->
            <form>

               <?php  

                 
                  if($pagemethod=="add"){  
                 
              } 
                if($pagemethod=="edit" || $pagemethod=="details"){ 
                  // echo $customerdetailsSkinImprove->skin_improve_ids;
                  // echo "<br>";

                   $str1="";
                  $str2="";
                  $pieces=array();
                  if(!empty($form2adetails->question)){
                    $str1 = substr($form2adetails->question, 1); 
                    $str2 = substr($str1, 0, -1); 
                    $pieces = explode(",", $str2);
                  }
              }
                ?>

            <!-- new customer form -->
              <div class="row" style="margin-top: 1vh;">
               
                <div class="card  bg-white o-hidden  ml-auto mr-auto py-3 " style="width: 95vw;border-radius: 1rem;" >
                   
                        <div class="card-body">
                            <!-- start card body -->


                       <!--      <div class="card-body-icon text-center">
                                
                                <img src="../assets/img/pen.png" style="width: 9vw; height: auto;">
                                
                            </div> -->
                            <div class="text-center " style="border-bottom: 1px solid #908d95;padding-bottom: 2vh;"><h3 class="mt-3" style="color: #908d95;">客 人 確 認 書</h3></div>

                            <!-- top row -->

<style>
                                :focus{
                                    outline:none;
                                  }
                              .radio{
                                -webkit-appearance:button;
    -moz-appearance:button;
    appearance:button;
    border:4px solid #ccc;
    border-top-color:#bbb;
    border-left-color:#bbb;
    background:#fff;
    width:50px;
    height:50px;
    border-radius:50%;
    display:table-cell;vertical-align:middle;
  }
  .radio:checked{
    border:20px solid #4099ff;
  }



  /* Base for label styling */
/*[type="checkbox"]:not(:checked),
[type="checkbox"]:checked {
  position: absolute;
  left: -9999px;
}
[type="checkbox"]:not(:checked) + label,
[type="checkbox"]:checked + label {
  position: relative;
  padding-left: 1.95em;
  cursor: pointer;
}
*/
/* checkbox aspect */
/*[type="checkbox"]:not(:checked) + label:before,
[type="checkbox"]:checked + label:before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 1.25em; height: 1.25em;
  border: 2px solid #ccc;
  background: #fff;
  border-radius: 4px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.1);
}*/
/* checked mark aspect */
/*[type="checkbox"]:not(:checked) + label:after,
[type="checkbox"]:checked + label:after {
  content: '\25CF\0020';
  position: absolute;*/
  /*top: .15em; left: .22em;*/
 /*  top: .24rem; left: .07rem;
  font-size: 1.2rem;
  line-height: 0.8;
  line-height: 0.8;
  color: #957c78;
  transition: all .2s;
  font-family: 'Lucida Sans Unicode', 'Arial Unicode MS', Arial;
}*/
/* checked mark aspect changes */
/*[type="checkbox"]:not(:checked) + label:after {
  opacity: 0;
  transform: scale(0);
}
[type="checkbox"]:checked + label:after {
  opacity: 1;
  transform: scale(1);
}*/
/* disabled checkbox */
/*[type="checkbox"]:disabled:not(:checked) + label:before,
[type="checkbox"]:disabled:checked + label:before {
  box-shadow: none;
  border-color: #bbb;
  background-color: #ddd;
}
[type="checkbox"]:disabled:checked + label:after {
  color: #999;
}
[type="checkbox"]:disabled + label {
  color: #aaa;
}*/
/* accessibility */
/*[type="checkbox"]:checked:focus + label:before,
[type="checkbox"]:not(:checked):focus + label:before {
  border: 2px solid #958778!important;
}*/

/* hover style just for information */
/*label:hover:before {
  border: 2px solid #4778d9!important;
}
*/


/*radio button*/
 input[type=radio].radio {
  display: none;
}
/* to hide the checkbox itself */
input[type=radio].radio + label:before {
  color: #958778;
  display: inline-block;
}
input[type=radio].radio + label:before {
  /*content: "✔";*/
  content: "\25CB";
      font-size: 1.25rem;
}
/* unchecked icon */
input[type=radio].radio + label:before {
  letter-spacing: 10px;
}
/* space between radio and label */
input[type=radio].radio:checked + label:before {
  /*content: "✔";*/
  content: "\25CF";
      font-size: 1.25rem;
}
/* checked icon */
input[type=radio].radio:checked + label:before {
  letter-spacing: 10px;
}



/*end radio button*/


  input[type=checkbox].radio {
  display: none;
}
/* to hide the checkbox itself */
input[type=checkbox].radio + label:before {
  color: #958778;
  display: inline-block;
}
input[type=checkbox].radio + label:before {
  /*content: "✔";*/
  content: "\25CB";
      font-size: 1.25rem;
}
/* unchecked icon */
input[type=checkbox].radio + label:before {
  letter-spacing: 10px;
}
/* space between checkbox and label */
input[type=checkbox].radio:checked + label:before {
  /*content: "✔";*/
  content: "\25CF";
      font-size: 1.25rem;
}
/* checked icon */
input[type=checkbox].radio:checked + label:before {
  letter-spacing: 10px;
}


                              </style>
                        <!-- common form data -->

                        <div class="form-group row" style="margin-top: 2vh;">
                        <div class="col-sm-12 col-md-12">
                        <h5 class="formfontcolor " style=" text-align: justify;">本人<u>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $customerdetails->display_name;?>&nbsp;&nbsp;&nbsp;&nbsp;</u>明白接受激光療程後,在治療位置的皮膚色素可能改變,主要是由
於激光的熱能對色素產生的作用,而且皮膚較乾,感覺微熱及表面出現微红現象,以上全部皆
是正常反應,可能持續數小時。 </h5>


                        </div>
                       </div>

                       <!-- new line 2 -->
                       <div class="form-group row" style="margin-top: 2vh;">
                        <div class="col-sm-12 col-md-12">
                        <h5 class="formfontcolor " style=" text-align: justify;">色素改變:治療位置皮膚色素可能改變。產生色素沉著或者色素減退的大多數皮膚類型在IV
和VI之間,或當治療位置或皮膚在治療前後3周前後受到日光暴曬。 </h5>


                        </div>
                       </div>

                       <!-- end new line 2 -->

                         <!-- new line 3 -->
                       <div class="form-group row" style="margin-top: 2vh;">
                        <div class="col-sm-12 col-md-12">
                        <h5 class="formfontcolor " style=" text-align: justify;">不適感:在發射雷射脈衝時,某些患者有不同程度的不適感,一些人覺得像被叮咬,其他則比
喻為橡皮圈彈的感覺,或術後持續一小時的燒灼感。 </h5>


                        </div>
                       </div>

                       <!-- end new line 3 -->
                       

                      <!-- new line 4 -->
                       <div class="form-group row" style="margin-top: 2vh;">
                        <div class="col-sm-12 col-md-12">
                        <h5 class="formfontcolor " style=" text-align: justify;">在治療後亦有可能出現一些不良反應,包括:皮膚出現持續紅斑、水泡、長期的併發症如色
素過深或過淺、结焦、腫及疤痕等。</h5>


                        </div>
                       </div>

                       <!-- end new line 4 -->

                       <!-- new line 5 -->
                       <div class="form-group row" style="margin-top: 2vh;">
                        <div class="col-sm-12 col-md-12">
                        <h5 class="formfontcolor " style=" ">並本人聲明並沒有以下任何身體或皮膚之問題:<br>
請選擇(以號表示) / Please Exclusion Criteria'(s)</h5>


                        </div>
                       </div>

                       <!-- end new line 5 -->

                        <!-- option1 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2">
                                      <input  class="radio css-checkbox" type="checkbox" id="question1" name="question" value="1"
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(1, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>
                        <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 
                                       />
                                      <label for="question1" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">未滿十八歲人士 /  Under 18 years of age</h5></label>
                                </div>
            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option1 -->  

                            <!-- option2 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2">
                                      <input  class="radio css-checkbox" type="checkbox" id="question2" name="question" value="2"
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(2, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>
                    <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 

                                       />
                                      <label for="question2" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">孕婦 / Pregnancy</h5></label>
                                </div>
            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option2 --> 


                            <!-- option3 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2">
                                      <input  class="radio css-checkbox" type="checkbox" id="question3" name="question" value="3"
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(3, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>
                    <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 

                                       />
                                      <label for="question3" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">曾一個月內日光曝曬 / Tanned skin</h5></label>
                                </div>
            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option3 -->  


                            <!-- option4 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2">
                                      <input  class="radio css-checkbox" type="checkbox" id="question4" name="question" value="4" 
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(4, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>
                    <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 

                                      />
                                      <label for="question4" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">皮膚發炎 / Inflammatory skin conditions 部位<input type="text" class="form-control" id="question4_text" name="question4_text" placeholder="" value="<?php
                if($pagemethod=="add"){ echo 
                 "";
              } 
                if($pagemethod=="edit"  || $pagemethod=="details"){ 
                  if(!empty($form2adetails->question4_text)){
                    echo 
                 $form2adetails->question4_text;
                 }
              }?>"  <?php if($this->session->userdata('brcustomer_edit')!=1){ echo 
                 "readonly";
              } ?> style=" display: inline-block;max-width: 150px;"></h5></label>
                                </div>
            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option4 -->  

                             <!-- option5 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2">
                                      <input  class="radio css-checkbox" type="checkbox" id="question5" name="question" value="5" 
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(5, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>
                     <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 
                                      />
                                      <label for="question5" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">癲癇症患者 / Epilepsy</h5></label>
                                </div>
            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option5 -->  


                             <!-- option6 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2">
                                      <input  class="radio css-checkbox" type="checkbox" id="question6" name="question" value="6"
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(6, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>

                     <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 
                                       />
                                      <label for="question6" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">六個月內接受口服A酸治療 /</h5></label>
                                </div>
                                <h5 style="margin-top: auto;margin-bottom: auto;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Use of isotrentioin within past 6 months</h5>

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>

                            <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                              
                               
            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option6 -->  

                                <!-- option7 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2">
                                      <input  class="radio css-checkbox" type="checkbox" id="question7" name="question" value="7" 
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(7, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>
                     <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 
                                      />
                                      <label for="question7" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">過去四星期曾接受光敏感藥物理治療者,如:四環素 /</h5></label>
                                </div>
                                <h5 style="margin-top: auto;margin-bottom: auto;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Use of medications causing photosensitivity with the last 4 weeks   eg: cyclomycin</h5>

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option7 --> 

                           


                            <!-- option8 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2 ">
                                      <input  class="radio css-checkbox" type="checkbox" id="question8" name="question" value="8"
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(8, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>

                     <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 
                                       />
                                      <label for="question8" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">過去三個月內接受類固醇治療者(如:氣喘患者)/</h5></label>

                                       

                                </div>
                                 <h5 style="margin-top: auto;margin-bottom: auto;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Use of steroid medication(e.g. asthma) for the last 3 months</h5>

            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option8 --> 


                           


                            <!-- option9 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2 ">
                               
                                      <input  class="radio css-checkbox" type="checkbox" id="question9" name="question" value="9"
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(9, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>
                     <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 
                                       />
                                      <label for="question9" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;word-wrap: break-word;overflow-wrap: break-word;">曾接受化療或细胞病毒性藥物者 /</h5></label>

                                       

                           
            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                             <h5 style="margin-top: auto;margin-bottom: auto;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Use of chemotherapy or cytotoxic drugs</h5>
                              </div>
                                <!-- end 1 -->
                          </div>
                        </div>
                            <!-- option9 --> 


                              <!-- option10 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2">
                                      <input  class="radio css-checkbox" type="checkbox" id="question10" name="question" value="10"
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(10, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>

                     <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 
                                       />
                                      <label for="question10" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">高血壓 / Hypertension</h5></label>

                                       

                                </div>
            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option10 --> 

                             <!-- option11 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2">
                                      <input  class="radio css-checkbox" type="checkbox" id="question11" name="question" value="11"
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(11, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>
                     <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 
                                       />
                                      <label for="question11" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">心臟病 / Heart disease</h5></label>

                                       

                                </div>
            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option11 --> 

                   <!-- option12 -->
                        <div class="form-group row" >


                              <!-- 1 -->
                              <div class="col-sm-12 col-md-12  ">
                            
                              <div>
                                
                               <div style="white-space:nowrap; display: inline-block;"  class="mr-2">
                                      <input  class="radio css-checkbox" type="checkbox" id="question12" name="question" value="12"
                                      <?php 
                    if($pagemethod=="edit" || $pagemethod=="details"){ 
                      if(in_array(12, $pieces)){
                        echo "checked";
                      }
                    }
                    ?>
                     <?php  if($this->session->userdata('brcustomer_edit')!=1){ 
                                                  echo 'disabled="disabled"';}?> 
                                       />
                                      <label for="question12" style="vertical-align: middle;height: 100%"><h5 style="margin-top: auto;margin-bottom: auto;display: inline-block;">糖尿病 / Diabetes</h5></label>

                                       

                                </div>
            

                                <div class="valid-feedback">正確</div>
                              <div class="invalid-feedback">没有资料</div>
                            </div>
                              </div>
                                <!-- end 1 -->
                          </div>
                            <!-- option12 --> 




                       

                       <!-- radio button -->
                       



                            


                          

                           

                            
                         




                       <!-- bottom line -->
                       <div class="form-group row" style="margin-top: 2vh;">
                        <div class="col-sm-12 col-md-12">
                        <h5 class="formfontcolor " style=" text-align: justify;">本人<u>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $customerdetails->display_name;?>&nbsp;&nbsp;&nbsp;&nbsp;</u>清楚了解療程後可能出現的後果,並且同意接受激光療程及遵守療程及遵守療程後的護理建議。</h5>


                        </div>
                       </div>
                       <!-- end bottom line -->



                       <!-- signature place -->
                       <style>
                        .signwrapper{
                          position: relative;
                          /*width:100%;*/
                            /*min-height:200px;*/
                          width: 600px;
                          height: 200px;
                          -moz-user-select: none;
                          -webkit-user-select: none;
                          -ms-user-select: none;
                          user-select: none;
                        }
                        
                          .signature-pad {
                            position: absolute;
                            left: 0;
                            top: 0;
                            width:600px;
                            height: 200px;
                            /*width:100%;*/
                            /*height:100%;*/
                          }
                                                 
                          .is-invalidborder{
                            border-style: solid;
                            border-color: red;
                          }
                          .is-validborder{
                            border-style: solid;
                            border-color: green;
                          }
                      </style>

                       <script src="https://cdn.jsdelivr.net/npm/signature_pad@3.0.0-beta.3/dist/signature_pad.umd.min.js"></script>

                       <script type="text/javascript">
                        $( document ).ready(function() {
                          var signaturePad = new SignaturePad(document.getElementById('signature-pad'), {
                              backgroundColor: 'rgba(255, 255, 255, 0)',
                              penColor: 'rgb(0, 0, 0)'
                            });
                            
                            var cancelButton = document.getElementById('clearbutton');
                            var saveButton = document.getElementById('btnSubmit');

                            var updateButton2  = document.getElementById('btnUpdate2');


                            var deleteButton = document.getElementById('btnDelete');


                            // saveButton.addEventListener('click', function (event) {
                            //   var data = signaturePad.toDataURL('image/png');

                            // // Send data to server instead...
                            //   window.open(data);
                            // });
                            // $('button.save').click(function(){               
                            //     window.open(signaturePad.toDataURL("image/png"));
                            // });

                            if(cancelButton){
                            cancelButton.addEventListener('click', function (event) {
                              signaturePad.clear();



                            });

                          }


                          if(saveButton){
                            saveButton.addEventListener('click', function (event) {
                               // window.open(signaturePad.toDataURL("image/png"));
                              //   var w = window.open("");
                              // // w.document.write(signaturePad.toDataURL("image/png"));


                              // var image = new Image();
                              // //Just getting the source from the span. It was messy in JS.
                              // // image.src = document.getElementById('source').innerHTML;
                              // image.src = signaturePad.toDataURL("image/png");
                              // w.document.body.appendChild(image);

                              //ajax pass data 
                              var forcusitem="";
          var passCheck=true;

                              if (!signaturePad.isEmpty() && passCheck ==true) {
                                  passCheck=true;
                                  // alert('empty sign');
                                  $("#signwrapper").addClass(" is-validborder");
                                  $("#signwrapper").removeClass(" is-invalidborder ");
                              }else{
                                  passCheck=false;
                                  // alert('empty sign');
                                  $("#signwrapper").addClass(" is-invalidborder ");
                                  $("#signwrapper").removeClass(" is-validborder ");
                                  $( '#warningmsg' ).empty().append('<p class="text-danger"  id="feedback">請簽署同意書。</p>');
                              }

          // var dataUrl= this.signaturePad.toDataURL();
          //  var dataUrl= this.signaturePad.toDataURL('image/png');
          // window.open(dataUrl, "toDataURL() image", "width=600, height=200");
          // if($('#mobile').val().length !== 0){
          //   $("#mobile").addClass(" is-valid ");
          //   $("#mobile").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#mobile";
          //      $( '#mobile' ).empty().append('<p class="text-danger"  id="feedback">新增失敗。電話號碼的長度應為 7。</p>');
          //   }
          //   passCheck=false;
          //   $("#mobile").addClass(" is-invalid ");
          //   $("#mobile").removeClass(" is-valid ");
            
          //   passCheck=false;
          // }

          // if($('#code').val().length <=7 && $('#code').val().length!==0){

          //   // $("#code").addClass(" is-valid ");
          //   // $("#code").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#code";
          //   }
          //   $( '#warningmsg' ).empty().append('<p class="text-danger"  id="feedback">新增失敗。客戶編號的長度應為 7。</p>');
          //   passCheck=false;
          //  //  $("#code").addClass(" is-invalid ");
          //  // $("#code").removeClass(" is-valid ");
          // }


        //   if($('#inputadminname').val().length !== 0){
        //     $("#inputadminname").addClass(" is-valid ");
        //     $("#inputadminname").removeClass(" is-invalid ");
        //   }
        //   else{
        //     if(forcusitem.length===0){
        //        forcusitem="#inputadminname";
        //     }
        //     passCheck=false;
        //     $("#inputadminname").addClass(" is-invalid ");
        //    $("#inputadminname").removeClass(" is-valid ");
        //   }

          // if($('#password').val().length !== 0){
          //   $("#password").addClass(" is-valid ");
          //   $("#password").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#password";
          //   }
          //   passCheck=false;
          //   $("#password").addClass(" is-invalid ");
          //  $("#password").removeClass(" is-valid ");
          // }

          // if($('#confirm_password').val().length !== 0){
          //   $("#confirm_password").addClass(" is-valid ");
          //   $("#confirm_password").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#confirm_password";
          //   }
          //   passCheck=false;
          //   $("#confirm_password").addClass(" is-invalid ");
          //  $("#confirm_password").removeClass(" is-valid ");
          // }

          // if($('#confirm_password').val().length !== 0 || ($('#confirm_password').val()!==$('#password').val())){
          //   $("#confirm_password").addClass(" is-valid ");
          //   $("#confirm_password").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#confirm_password";
          //   }
          //   passCheck=false;
          //   $("#confirm_password").addClass(" is-invalid ");
          //  $("#confirm_password").removeClass(" is-valid ");
          // }

          

          //  if($('#chi_name').val().length !== 0){
          //   $("#chi_name").addClass(" is-valid ");
          //   $("#chi_name").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#chi_name";
          //   }
          //   passCheck=false;
          //   $("#chi_name").addClass(" is-invalid ");
          //  $("#chi_name").removeClass(" is-valid ");
          // }

          // if($('#eng_firstname').val().length !== 0){
          //   $("#eng_firstname").addClass(" is-valid ");
          //   $("#eng_firstname").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#eng_firstname";
          //   }
          //   passCheck=false;
          //   $("#eng_firstname").addClass(" is-invalid ");
          //  $("#eng_firstname").removeClass(" is-valid ");
          // }

          //  if($('#eng_lastname').val().length !== 0){
          //   $("#eng_lastname").addClass(" is-valid ");
          //   $("#eng_lastname").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#eng_lastname";
          //   }
          //   passCheck=false;
          //   $("#eng_lastname").addClass(" is-invalid ");
          //  $("#eng_lastname").removeClass(" is-valid ");
          // }


          //  if($('#role_name').val().length !== 0){
          //   $("#role_name").addClass(" is-valid ");
          //   $("#role_name").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#role_name";
          //   }
          //   passCheck=false;
          //   $("#role_name").addClass(" is-invalid ");
          //  $("#role_name").removeClass(" is-valid ");
          // }

          //  if($('#tenant_no').val().length !== 0){
          //   $("#tenant_no").addClass(" is-valid ");
          //   $("#tenant_no").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#tenant_no";
          //   }
          //   passCheck=false;
          //   $("#tenant_no").addClass(" is-invalid ");
          //  $("#tenant_no").removeClass(" is-valid ");
          // }

          //  if($('#income_type').val().length !== 0){
          //   $("#income_type").addClass(" is-valid ");
          //   $("#income_type").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#income_type";
          //   }
          //   passCheck=false;
          //   $("#income_type").addClass(" is-invalid ");
          //  $("#income_type").removeClass(" is-valid ");
          // }


          //  if($('#commission').val().length !== 0){
          //   $("#commission").addClass(" is-valid ");
          //   $("#commission").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#commission";
          //   }
          //   passCheck=false;
          //   $("#commission").addClass(" is-invalid ");
          //  $("#commission").removeClass(" is-valid ");
          // }

          // if($('#gender').val().length !== 0){
          //   $("#gender").addClass(" is-valid ");
          //   $("#gender").removeClass(" is-invalid ");
          // }
          // else{
          //   if(forcusitem.length===0){
          //      forcusitem="#gender";
          //   }
          //   passCheck=false;
          //   $("#gender").addClass(" is-invalid ");
          //  $("#gender").removeClass(" is-valid ");
          // }




        //   alert("1");
          if(passCheck===false){
           
             $(forcusitem).focus();
          }


          if(passCheck===true){

          
          var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  // 'destUrl':'<?php echo base_url();?>/api/v1/frontend/add',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

            event.preventDefault();
            var postUrl= '<?php echo base_url();?>' +'api/v1/portableform2aend/add';
            // var postData ={
            //       'csrfToken' :'',
            //       'custname' : $('#name').val(),
            //       'tel' : $('#tel').val(),
            //       'email' : $('#email').val(),
            //       'wechat' : $('#wechat').val(),
            //       'birthday' : $('#birthday').val(),
            //       // 'selectedBox' :$('.css-checkbox:checked').val()
            //       'selectedBox' :selectBox1

            // }
            // $checkedpurchase=0;
            // if($('#need_purchase_service').is(':checked')){
            //     $checkedpurchase=1;
            // }
            // else
            // {
            //   $checkedpurchase=0;
            // }  

//             var diseasearr = $('input[name=disease]:checked').map(function () {
//   return this.value;
// }).get();

            var postData ={
                'currentFormId':$('#currentFormId').val(),
                'question':$('input[name=question]:checked').map(function () { return this.value;  }).get(), 
                'signaturePad':signaturePad.toDataURL("image/png"),
                'question4_text':$('#question4_text').val(),

                // 'code':$('#code').val(),
                // 'display_name':$('#display_name').val(),
                // // 'chi_name':$('#chi_name').val(),
                // // 'eng_firstname':$('#eng_firstname').val(),
                // // // 'inputadminname':$('#inputadminname').val(),
                // // 'eng_lastname':$('#eng_lastname').val(),
                // // 'gender':$('#gender').val(),
                // 'gender':$('input[name=gender]:checked').val(),
                // 'dob':$('#datepicker').val(),
                // 'mobile':$('#mobile').val(),
                // 'district_id':$('#area1').val(),
                // 'area_id':$('#level2').val(),
                // 'zone':$('#level3').val(),
                // 'address':$('#address').val(),
                // 'join_date':$('#datepicker2').val(),
                // 'shop_id':$('#first_registered_tenant_no').val(),
                // 'skin_improve':$('#skin_improve').val(),
                // 'body_improve':$('#body_improve').val(),
                // 'face_improve':$('#face_improve').val(),
                // 'referred_mobile':$('#referred_mobile').val(),
                // 'remark':$('#remark').val(),
                // 'need_purchase_service':$checkedpurchase,
                // 'service_id':$('#service_id').val(),
                // 'purchased_date':$('#purchased_date').val(),
                // 'purchased_qty':$('#purchased_qty').val(),
                // 'available_qty':$('#available_qty').val(),
                // 'remark2':$('#remark2').val(),
                // 'promotion_code':$('#promotion_code').val(),
                // 'first_registered_tenant_no':$('#first_registered_tenant_no').val(),  
                // 'concurrent_registered_tenant_no':$('#concurrent_registered_tenant_no').val(),  
                // 'level':$('#level').val(),  
                // 'isTemp':$('#isTemp').is(':checked') ? 1 : 0,
                // 'channelSelectID':$('#channelSelectID').val(), 
                // 'prefer_pic':$('#prefer_pic').val(), 
                // 'bodyoptionother_text':$('#bodyoptionother_text').val(), 
                // 'faceoptionother_text':$('#faceoptionother_text').val(), 



                // // addedfield
                // 'id_number':$('#id_number').val(),  
                // 'career_name':$('#career_name').val(),   
                // 'age':$('#age').val(),   
                // 'body_height' :$('#body_height').val(), 
                // 'body_weight' :$('#body_weight').val(), 
                // 'married_status':$('#married_status').val(), 
                // 'child_num':$('#child_num').val(), 
                // // 'disease':$('input[name=disease]:checked').val(), 
                 
                // 'diseaseother': $('#diseaseother').val(), 
                // 'sensitivity' : $('#sensitivity').val(), 
                // 'surgery' : $('#surgery').val(), 
                // 'medicine' : $('#medicine').val(), 
                // 'allergy' : $('#allergy').val(), 
                // 'lifestyle':$('input[name=lifestyle]:checked').map(function () { return this.value;  }).get(),
                // 'habbit':$('input[name=habbit]:checked').map(function () { return this.value;  }).get(),
                // 'lighttheraphist':$('input[name=lighttheraphist]:checked').map(function () { return this.value;  }).get(),
                // 'otherlighttherapist': $('#otherlighttherapist').val(), 
                // 'botoxtherapist':$('input[name=botoxtherapist]:checked').map(function () { return this.value;  }).get(),
                // // 'transtherapist':$('input[name=transtherapist]:checked').map(function () { return this.value;  }).get(),
                // 'transtherapist':$('input[name=transtherapist]:checked').map(function () { return this.value;  }).get(),
                // 'feeding':$('input[name=feeding]:checked').map(function () { return this.value;  }).get(),
                // 'beautytreat':$('input[name=beautytreat]:checked').map(function () { return this.value;  }).get(), 
                // 'paymentmethod':$('input[name=paymentmethod]:checked').map(function () { return this.value;  }).get(), 
                //  'otherpayment' : $('#otherpayment').val(),  


                // end addedfield

                
            }
            //   postData.need_purchase_service=0;
            // if($('#need_purchase_service').is(':checked')===true){
            //   postData.need_purchase_service=1;
            //   postData.service_id=$('#service_id').val();
            //   postData.purchased_date=$('#purchased_date').val();
            //   postData.purchased_price=$('#purchased_price').val();
            //   postData.purchased_qty=$('#purchased_qty').val();
            //   postData.available_qty=$('#available_qty').val();
            // }  

            // alert($('#level2').val());
            $("#spinnermodal").modal('show');

            $.ajax({
                  method: "POST",
                  url: postUrl,
                  dataType: "json",
                 data: postData,
                 success : function(data){

                // alert("posted");
                // // alert('formsubmit');
                // alert(data);
                
                // alert(data['recordstatus']);
                // alert(data['msg']);
                $('#spinnermodal').on('shown.bs.modal', function(e) {
                        $("#spinnermodal").modal("hide");
                      });

                if(data['recordstatus']=="SUCCESS"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-primary" id="feedback">'+data['msg']+'</p>');
                    // setTimeout(function() {
                    //     location.reload();
                    // }, 3000);
                    setTimeout(function() {
                        // location.href='/portable/formselection/'
                        location.href='<?php echo $nextUrl;?>'
                    }, 2000);
                    // location.reload();

                }
                  if(data['recordstatus']=="FAILURE"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-danger"  id="feedback">'+data['msg']+'</p>');
                //   $( '#modal-bodymsg' ).empty();
                //   $( '#modal-bodymsg' ).append( '<h5 class="text-center" style="color: #a03d49;">客戶不能增加。</h5> <h5 class="text-center" style="color: #a03d49;">請稍後再嘗試。</h5>' );
                //   $('#finishModal').modal('show');
                // }
                  // if (data.AJAX_SUCCESS==GlobalVariables.AJAX_SUCCESS){
                  //     window.location.href=GlobalVariables.destUrl;
                  // } else {
                  //     $('.alert').text("登入錯誤");
                  //    $('.alert').removeClass('hidden');
                  }
              }
            });  

            }//if(passCheck==true){



                              //end ajax pass data 



                            }); 

                          }//if(saveButton){


                            //update button click
                          if(updateButton2){


                          updateButton2.addEventListener('click', function (event) {

                               // window.open(signaturePad.toDataURL("image/png"));
                              //   var w = window.open("");
                              // // w.document.write(signaturePad.toDataURL("image/png"));


                              // var image = new Image();
                              // //Just getting the source from the span. It was messy in JS.
                              // // image.src = document.getElementById('source').innerHTML;
                              // image.src = signaturePad.toDataURL("image/png");
                              // w.document.body.appendChild(image);

                              //ajax pass data 
                              var forcusitem="";
          var passCheck=true;

                              // if (!signaturePad.isEmpty() && passCheck ==true) {
                              //     passCheck=true;
                              //     // alert('empty sign');
                              //     $("#signwrapper").addClass(" is-validborder");
                              //     $("#signwrapper").removeClass(" is-invalidborder ");
                              // }else{
                              //     passCheck=false;
                              //     // alert('empty sign');
                              //     $("#signwrapper").addClass(" is-invalidborder ");
                              //     $("#signwrapper").removeClass(" is-validborder ");
                              //     $( '#warningmsg' ).empty().append('<p class="text-danger"  id="feedback">請簽署同意書。</p>');
                              // }

        
        //   alert("1");
          if(passCheck===false){
           
             $(forcusitem).focus();
          }


          if(passCheck===true){

          
          var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  // 'destUrl':'<?php echo base_url();?>/api/v1/frontend/add',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

            event.preventDefault();
            var postUrl= '<?php echo base_url();?>' +'api/v1/portableform2aend/updateform';
            // var postData ={
            //       'csrfToken' :'',
            //       'custname' : $('#name').val(),
            //       'tel' : $('#tel').val(),
            //       'email' : $('#email').val(),
            //       'wechat' : $('#wechat').val(),
            //       'birthday' : $('#birthday').val(),
            //       // 'selectedBox' :$('.css-checkbox:checked').val()
            //       'selectedBox' :selectBox1

            // }
            // $checkedpurchase=0;
            // if($('#need_purchase_service').is(':checked')){
            //     $checkedpurchase=1;
            // }
            // else
            // {
            //   $checkedpurchase=0;
            // }  

//             var diseasearr = $('input[name=disease]:checked').map(function () {
//   return this.value;
// }).get();

            var inputSignature="";
            if(!signaturePad.isEmpty()){
              inputSignature=signaturePad.toDataURL("image/png");
            }

            var postData ={
                'currentFormId':$('#currentFormId').val(),
                'currentUserId':$('#currentUserId').val(),
                'question':$('input[name=question]:checked').map(function () { return this.value;  }).get(), 
                'signaturePad':inputSignature,
                'question4_text':$('#question4_text').val(),
  

                
            }
            //   postData.need_purchase_service=0;
            // if($('#need_purchase_service').is(':checked')===true){
            //   postData.need_purchase_service=1;
            //   postData.service_id=$('#service_id').val();
            //   postData.purchased_date=$('#purchased_date').val();
            //   postData.purchased_price=$('#purchased_price').val();
            //   postData.purchased_qty=$('#purchased_qty').val();
            //   postData.available_qty=$('#available_qty').val();
            // }  

            // alert($('#level2').val());
            $("#spinnermodal").modal('show');

            $.ajax({
                  method: "POST",
                  url: postUrl,
                  dataType: "json",
                 data: postData,
                 success : function(data){

                // alert("posted");
                // // alert('formsubmit');
                // alert(data);
                
                // alert(data['recordstatus']);
                // alert(data['msg']);

                 $('#spinnermodal').on('shown.bs.modal', function(e) {
                        $("#spinnermodal").modal("hide");
                      });

                if(data['recordstatus']=="SUCCESS"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-primary" id="feedback">'+data['msg']+'</p>');
                    // setTimeout(function() {
                    //     location.reload();
                    // }, 3000);
                    setTimeout(function() {
                        // location.href='/portable/formselection/'
                        // location.href='<?php echo $nextUrl;?>'
                        location.href='/portable/form2a/edit/<?php 
                        if(!empty($currentUserId)){
                          echo $currentUserId;
                        }
                        ?>';
                    }, 2000);
                    // location.reload();

                }
                  if(data['recordstatus']=="FAILURE"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-danger"  id="feedback">'+data['msg']+'</p>');
                //   $( '#modal-bodymsg' ).empty();
                //   $( '#modal-bodymsg' ).append( '<h5 class="text-center" style="color: #a03d49;">客戶不能增加。</h5> <h5 class="text-center" style="color: #a03d49;">請稍後再嘗試。</h5>' );
                //   $('#finishModal').modal('show');
                // }
                  // if (data.AJAX_SUCCESS==GlobalVariables.AJAX_SUCCESS){
                  //     window.location.href=GlobalVariables.destUrl;
                  // } else {
                  //     $('.alert').text("登入錯誤");
                  //    $('.alert').removeClass('hidden');
                  }
              }
            });  

            }//if(passCheck==true){



                              //end ajax pass data 



                            }); 

                         
                           }//if(updateButton2){
                          //end update button click
      

                          //delete button
                          if(deleteButton){
                             deleteButton.addEventListener('click', function (event) {

                               // window.open(signaturePad.toDataURL("image/png"));
                              //   var w = window.open("");
                              // // w.document.write(signaturePad.toDataURL("image/png"));


                              // var image = new Image();
                              // //Just getting the source from the span. It was messy in JS.
                              // // image.src = document.getElementById('source').innerHTML;
                              // image.src = signaturePad.toDataURL("image/png");
                              // w.document.body.appendChild(image);

                              //ajax pass data 
                              var forcusitem="";
          var passCheck=true;

                              // if (!signaturePad.isEmpty() && passCheck ==true) {
                              //     passCheck=true;
                              //     // alert('empty sign');
                              //     $("#signwrapper").addClass(" is-validborder");
                              //     $("#signwrapper").removeClass(" is-invalidborder ");
                              // }else{
                              //     passCheck=false;
                              //     // alert('empty sign');
                              //     $("#signwrapper").addClass(" is-invalidborder ");
                              //     $("#signwrapper").removeClass(" is-validborder ");
                              //     $( '#warningmsg' ).empty().append('<p class="text-danger"  id="feedback">請簽署同意書。</p>');
                              // }

        
        //   alert("1");
          if(passCheck===false){
           
             $(forcusitem).focus();
          }


          if(passCheck===true){

          
          var GlobalVariables ={
                  'csrfToken': '123',
                  'baseUrl':'<?php echo base_url();?>',
                  // 'destUrl':'<?php echo base_url();?>/api/v1/frontend/add',
                  'AJAX_SUCCESS' :'SUCCESS',
                  'AJAX_FAILURE' :'FAILURE'
            };

            event.preventDefault();
            var postUrl= '<?php echo base_url();?>' +'api/v1/portableform2aend/deleteform';
            // var postData ={
            //       'csrfToken' :'',
            //       'custname' : $('#name').val(),
            //       'tel' : $('#tel').val(),
            //       'email' : $('#email').val(),
            //       'wechat' : $('#wechat').val(),
            //       'birthday' : $('#birthday').val(),
            //       // 'selectedBox' :$('.css-checkbox:checked').val()
            //       'selectedBox' :selectBox1

            // }
            // $checkedpurchase=0;
            // if($('#need_purchase_service').is(':checked')){
            //     $checkedpurchase=1;
            // }
            // else
            // {
            //   $checkedpurchase=0;
            // }  

//             var diseasearr = $('input[name=disease]:checked').map(function () {
//   return this.value;
// }).get();

            var inputSignature="";
            if(!signaturePad.isEmpty()){
              inputSignature=signaturePad.toDataURL("image/png");
            }

            var postData ={
                'currentFormId':$('#currentFormId').val(),
                'currentUserId':$('#currentUserId').val(),
                'question':$('input[name=question]:checked').map(function () { return this.value;  }).get(), 
                'signaturePad':inputSignature,
                'question4_text':$('#question4_text').val(),



                
            }
            //   postData.need_purchase_service=0;
            // if($('#need_purchase_service').is(':checked')===true){
            //   postData.need_purchase_service=1;
            //   postData.service_id=$('#service_id').val();
            //   postData.purchased_date=$('#purchased_date').val();
            //   postData.purchased_price=$('#purchased_price').val();
            //   postData.purchased_qty=$('#purchased_qty').val();
            //   postData.available_qty=$('#available_qty').val();
            // }  

            // alert($('#level2').val());
            $.ajax({
                  method: "POST",
                  url: postUrl,
                  dataType: "json",
                 data: postData,
                 success : function(data){

                // alert("posted");
                // // alert('formsubmit');
                // alert(data);
                
                // alert(data['recordstatus']);
                // alert(data['msg']);
                if(data['recordstatus']=="SUCCESS"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-primary" id="feedback">'+data['msg']+'</p>');
                    // setTimeout(function() {
                    //     location.reload();
                    // }, 3000);
                    setTimeout(function() {
                        // location.href='/portable/formselection/'
                        // location.href='<?php echo $nextUrl;?>'
                        location.href='/portable/brcustomeradmin/allperson';
                    }, 3000);
                    // location.reload();

                }
                  if(data['recordstatus']=="FAILURE"){
                    $('#feedback').remove();
                    $( '#newmsg' ).append('<p class="text-danger"  id="feedback">'+data['msg']+'</p>');
                //   $( '#modal-bodymsg' ).empty();
                //   $( '#modal-bodymsg' ).append( '<h5 class="text-center" style="color: #a03d49;">客戶不能增加。</h5> <h5 class="text-center" style="color: #a03d49;">請稍後再嘗試。</h5>' );
                //   $('#finishModal').modal('show');
                // }
                  // if (data.AJAX_SUCCESS==GlobalVariables.AJAX_SUCCESS){
                  //     window.location.href=GlobalVariables.destUrl;
                  // } else {
                  //     $('.alert').text("登入錯誤");
                  //    $('.alert').removeClass('hidden');
                  }
              }
            });  

            }//if(passCheck==true){



                              //end ajax pass data 



                            }); 

                          }//if(deleteButton){
                          //end delete button  

                          });

                       </script>

                      <?php 
                        if($pagemethod=="edit" || $pagemethod=="details"){ 
                      ?>

                        <div class="form-group row" style="margin-top: 2vh;">
                        <div class="col-sm-12 col-md-12">
                        <h5 class="formfontcolor " style=" ">
                       舊簽署資料： 
                     </h5>
                        </div>
                      </div>
                      <div class="form-group row" style="margin-top: 2vh;">
                        <div class="col-sm-12 col-md-12">
                        <?php if(!empty($form2adetails->signatureImg)){?>
                        <img src="<?echo base_url();?>uploads/photoform2a/<?php echo $form2adetails->signatureImg;?>">
                      <?php }//if(!empty()){?>
                        </div>
                      </div>


                    <?php
                      }//if($pagemethod=="edit" || $pagemethod=="details"){ 
                    ?>


                       <div class="form-group row" style="margin-top: 2vh;">
                        <div class="col-sm-12 col-md-12">
                        <h5 class="formfontcolor " style=" ">
                       請在此簽署： 
                     </h5>
                        </div>
                      </div>

                        <div class="form-group row" style="">
                        <div class="col-sm-12 col-md-12">
                       
                          <div  id="signwrapper" class="signwrapper" style="background-color: grey;display: inline-block;">
  <canvas id="signature-pad" class="signature-pad" width=600 height=200></canvas>
  <!-- <canvas id="signature-pad" class="signature-pad" style=" min-height: 200px; -->
  <!-- width: 100vw; "></canvas> -->

                          </div>
                          <button id="clearbutton" type="button" class="btn  px-5  custombutton mr-5" style="display: inline-block;">清除</button>
                        

                        </div>
                      </div>
                       <!-- end signature place -->
                       
                        <input type="hidden" class="form-control" id="currentFormId" name="currentFormId" placeholder="" value="<?php
                if($pagemethod=="add"){ echo 
                $currentFormId;
              } 
                if($pagemethod=="edit"  || $pagemethod=="details"){ 
                  if(!empty( $form2adetails->id)){
                    echo  $form2adetails->id;
                  }
                 
              }?>"  <?php if($pagemethod=="details"){ echo 
                 "readonly";
              } ?> style=" display: inline-block;width:auto;" size="3">


                        <input type="hidden" class="form-control" id="currentUserId" name="currentUserId" placeholder="" 

                        value="<?php
                if($pagemethod=="add"){ echo 
                $currentFormId;
              } 
                if($pagemethod=="edit"  || $pagemethod=="details"){ echo 
                 $currentUserId;
              }?>">

                         <!-- end common form data -->


                      

                            <!-- end top row -->


                         
                            


                            


                          
                             

                            

                            


                            


                            <!-- msgrow  -->
                        <div class="form-group row mt-2">
                      <div class="col-sm-12 text-center">
                      <span id="newmsg" class="text-center"></span>
                      </div>
                       </div>  

                        <!-- end msg row -->


                             



                            <!-- twenty one row -->
                              <div class="form-group row mt-5">
                        <div class="col-sm-12 text-center">
                          <span id="warningmsg" class="text-center"></span>
                        <?php
                        if($pagemethod=="add"){?>

                          <?php if($this->session->userdata('brcustomer_add')==1){?>
                            <button type="button" class="btn  px-5  custombutton mr-5" id="btnBack" style="width:40%;">返回</button>
                            <button type="button" class="btn  px-5  custombutton" id="btnSubmit" style="width:40%;">確定</button>
                           <?php }//if($this->session->userdata('brcustomer_add')==1){?>
                        <?php
                        }//if($pagemethod=="add"){?>
                        <?php
                        if($pagemethod=="edit"){?>
                          
                           <input type="hidden" class="form-control" id="id" name="id" placeholder="" value="<?php echo 
                 $customerdetails->id;
              ?>">


                        <?php if($this->session->userdata('brcustomer_delete')==1){?>

                          <button type="button" class="btn  px-5  custombutton mr-5" id="btnDelete" >删除</button>
                         <?php }//if($this->session->userdata('brcustomer_delete')==1){?>

                         <?php if($this->session->userdata('brcustomer_edit')==1){?>
                          <button type="button" class="btn  px-5  custombutton mr-5" id="btnResetUpdate" onClick="window.location.reload();">重設</button>
                          <button type="button" class="btn  px-5  custombutton" id="btnUpdate2">更改</button>
                         <?php }//if($this->session->userdata('brcustomer_edit')==1){?>
                        <?php
                        }//if($pagemethod=="edit"){?>

                        <?php
                        if($pagemethod=="details"){?>
                          
                         
                        <?php
                        }//if($pagemethod=="edit"){?>
                        </div>
            </div>

                            <!-- end twenty one row -->



                       




                          <!-- end card body -->    
                        </div>
                       <!--  <a class="card-footer text-white clearfix small z-1" href="upcoming_appointments.php">
                            <span class="float-left">View Details</span>
                            <span class="float-right">
                    <i class="fas fa-angle-right"></i>
                  </span>
                        </a> -->
                       
                    </div>
                 
              </div>
            <!-- end new customer form -->

            </form>
         



        
           
            <!-- end add button -->

            
        </div>
    </div>

      <script type="text/javascript">
            $(document).ready(function() {
                $('#book-table').DataTable( {
                    "order": [[ 0, "desc" ]],
                     dom: 'Bfrtip',
                    buttons: [
                        // 'colvis'
                    ]
                }

                    );

                $('#bookinglist-table').DataTable( {
                    "order": [[ 1, "desc" ]],
                     dom: 'Bfrtip',
                    buttons: [
                        // 'colvis'
                    ]
                }

                    );
            });
      </script>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#sidebarCollapse').on('click', function () {
                $('#sidebar').toggleClass('active');
            });

            // password click
            bootstrapRevealPassword();

// Plugin to integrate in your javascript file
            function bootstrapRevealPassword() {
            $('[data-password]').closest('.form-group').addClass('position-relative').append('<span class="form-password-icon"><i class="material-icons">visibility_off</i></span>');

            $('.form-password-icon').on('click', function() {
                var clicks = $(this).data('clicks');
                if (clicks) {
                // odd clicks
                $(this).html('<span class="input-group-text "><i class="fas fa-eye-slash"></i></span>').prevAll(':input').attr('type', 'password');
                } else {
                // even clicks
                $(this).html('<span class="input-group-text "><i class="fas fa-eye"></i></span>').prevAll(':input').attr('type', 'text');
                }
                $(this).data("clicks", !clicks);
            });
            }

            // end password click

        });
    </script>

</body>

</html>