<?php
    include('common/header.php');
    $customer_gst_no='';
    $date_of_enrollment= '';
    $contact_person_name= '';
    $designation= '';
    $mobile_no= '';
    $email_id= '';
    $address_line1='';
    $address_line2= '';
    $customer_name= '';
    $customer_pan_no='';
    $postal_code='';
    $city_name=''; 
    $state_name=''; 
    $std_code=''; 
    $state_id=''; 
    $country_id=''; 
    $company_branch_id=''; 
    $city_id=''; 
    $std_code=''; 
    $user_id=''; 
?>
<?php 
 if ($this->uri->segment(4)) {
	 
	$cnt_contacts=count($customer);
   foreach ($customer as  $value){
    $customer_id=$value['customer_id'];
    $state_id=$value['state_id'];
    $country_id=$value['country_id'];
    $company_branch_id=$value['company_branch_id'];
    $city_id=$value['city_id'];
    $customer_name=$value['customer_name'];
    $customer_pan_no=$value['customer_pan_no'];
    $customer_gst_no=$value['customer_gst_no'];
    $date_of_enrollment= $value['date_of_enrollment'];
    $contact_person_name= $value['contact_person_name'];
    $designation=  $value['designation'];
    $mobile_no=  $value['mobile_no'];
    $email_id=  $value['email_id'];
    $address_line1= $value['address_line1'];
    $address_line2=  $value['address_line2'];
    $postal_code= $value['postal_code'];
    $city_name= $value['city_name']; 
    $state_name= $value['state_name'];
    $std_code= $value['std_code'];  
    $user_id= $value['user_id'];  

   }
   
    $contact_person_name= $customer[0]['contact_person_name'];
    $contact_person_name1= $customer[1]['contact_person_name'];
	$designation= $customer[0]['designation'];
    $designation1= $customer[1]['designation'];
	$mobile_no= $customer[0]['mobile_no'];
    $mobile_no1= $customer[1]['mobile_no'];
	$email_id= $customer[0]['email_id'];
    $email_id1= $customer[1]['email_id'];
    $customer_contact_id= $customer[0]['customer_contact_id'];
    $customer_contact_id1= $customer[1]['customer_contact_id'];
   
  }
 ?>
 <div id="messages" style="color: red;"><h5><?php echo $this->session->flashdata('message'); ?></h5></div>
  <div class="">
    <div class="col-xm-12">
      <div class="widget-box light-border">
        <div class="widget-body">
          <div class="widget-main">
            <div class="row">
              <div class="col-sm-12">               
                  <form class="form-horizontal" method="post" action="<?php echo base_url()?>index.php/<?php echo CUSTOMER_MASTER;?>add_customer" onsubmit="return validateForm();" name="manage_client" id="manage_client">                 
                  <input type="hidden" value="<?php echo $customer_id ?>" name="hidden" id="hidden">
                  <section class="panel panel-default">
                  <header class="panel-heading bg-info lt font-bold"><?php echo $c_Company_Details; ?></header>
                  <!-- panel body start -->
                  <div class="panel-body bs-example form-horizontal">
                    <div class="">
                     <div class="hr hr12 dotted"></div>
                       <div class="">
                        <!-- main col-sm-12 -->
                      <div class="col-sm-12"> 
                          <div class="col-sm-6">
                           <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_Branch_Company_Name; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <select name="branch_name" id="branch_name" class="form-control">
                                 <option value="0">Select Branch Company Name</option>
                                       <!--    <?php  
                                          foreach ($branch_name as  $branch) {
                                           if ($company_branch_id == $branch['company_branch_id']) {?>
                                            <option value="<?php echo $branch['company_branch_id'] ?>" selected><?php echo $branch['company_branch_name'] ; ?></option>
                                            <?php
                                           }else{?>
                                            <option value="<?php echo $branch['company_branch_id'] ?>"><?php echo $branch['company_branch_name'] ; ?><?php  } }
                                      ?>    -->    
                                      <?php  
                                          foreach ($branch_name as  $branch) {?>
                                           
                                          <option value="<?php echo $branch['company_branch_id'] ?>"<?php if ($company_branch_id == $branch['company_branch_id']){echo "selected=selected";}?>><?php echo $branch['company_branch_name'] ; ?>
                                <?php   }
                                      ?>                                     
                                </select>   
                                <span id="branch_name1" class="text-danger font-weight-bold">           
                              </div>
                            </div>
                          </div>           
                               
                          <div class="col-sm-6">
                            <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_Customer_Name; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                              
                                <input type="text" name="cutomer_name" value="<?php echo $customer_name;?>" id="customer_name" placeholder="Customer Name" class="form-control"  maxlength="75" /> 
                                 
                                 <span id="customer_name1" class="text-danger font-weight-bold"></span>            
                              </div>
                            </div>
                          </div>
                        </div>
                        <div class="col-sm-12">
                          <div class="col-sm-6">                            
                             <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_Customer_PAN_Number; ?>:</label>
                              <div class="col-sm-7">
                              
                                <input type="text" name="cutomer_pan" value="<?php echo $customer_pan_no;?>" id="cutomer_pan" onkeypress="return RestrictSpace()" placeholder="Customer PAN  Number" class="form-control" maxlength="15" />
                              
                                <span id="cutomer_pan1" class="text-danger font-weight-bold"></span>               
                              </div>
                              </div>
                          </div>
                          <div class="col-sm-6"> 
                            <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_Customer_GST_Number; ?>:</label>
                              <div class="col-sm-7">
                                
                                <input type="text" name="cutomer_gst" value="<?php echo $customer_gst_no;?>" id="cutomer_gst" onkeypress="return RestrictSpace()" placeholder="Customer GST  Number" class="form-control" maxlength="20" />

                                 <span id="cutomer_gst1" class="text-danger font-weight-bold"></span>               
                              </div>
                            </div>
                          </div>
                      </div>                   
                        <div class="col-sm-12">
                           <div class="col-sm-6">                             
                            <div class="form-group">
                               <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_Date_Of_Enrollment; ?>:<font style="color:red">*</font></label>
                                <div class="col-sm-7">  
                                  <div class="input-group">
                                   
                                   <input class="form-control date-picker" id="id-date-picker-2" type="text" data-date-format="dd-mm-yyyy" name="date_of_enroll" value="<?php echo $date_of_enrollment;?>" autocomplete="off">
                                    <span class="input-group-addon">
                                     <i class="fa fa-calendar bigger-110"></i>
                                    </span>
                                  </div>
                                   <span id="date1" class="text-danger font-weight-bold"></span>  
                                </div>
                            </div>

                          </div>

                          <div class="col-sm-6">
                           <div class="form-group">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_sale_person_name; ?>:<font style="color:red">*</font></label>
                                <div class="col-sm-7">
                                  <select name="sale_person_name" class="select2 select2-multiple" multiple="multiple" id="sale_person_name" >
                                    <option value="default">Select Sales Person Name</option>
                                  <?php foreach ($sale_person_name as  $spn) {?>
                                   <option value="<?php echo $spn['user_id'] ?>"<?php if ($spn['user_id']== $user_id) {
                                     echo 'selected="selected"';
                                   } ?>><?php echo $spn['first_name']." ".$spn['last_name']; ?></option>
                                 <?php } ?>
                                 </select>
                              <span id="sale_person_name1" class="text-danger font-weight-bold"></span>
                                  
                                 </div>
                              
                            </div>
                          </div>                       
                        </div>                       
                        <!-- </div> -->
                         <!-- main col-sm-12  close-->
                       </div> <!-- blank close -->
        </div><!-- blank close -->
      </div>   <!-- panel body close -->
    </section> <!-- section close -->
    <!-- customer location start -->
    
    <section class="panel panel-default">
      <header class="panel-heading bg-info lt font-bold"><?php echo $c_Location_Details; ?></header>
       <div class="panel-body bs-example form-horizontal">
        <div class="">
          <div class="hr hr12 dotted"></div>
          <div class="">
            <div class="col-sm-12">
              <div class="col-sm-6">    
                <div class="form-group">  
                  <label class="col-sm-5 control-label required" for="form-field-2 "><?php echo $c_Customer_Address_line_1; ?>:<font style="color:red">*</font></label>
                  <div class="col-sm-7">                   
                    <input type="text" name="customer_addressl1" value="<?php echo $address_line1;?>" id="customer_addressl1" placeholder="Customer Address line 1" class="form-control" maxlength="75" />

                    <span id="customer_addressl1_1" class="text-danger font-weight-bold"></span>                   
                  </div>
              </div>             
               </div>
               <div class="col-sm-6">
                    <div class="form-group" id="qc_name">
                  <label for="qc_name" class="col-sm-5 control-label required"><?php echo $c_Customer_Address_line_2; ?>: </label>
                  <div class="col-sm-7">
                                           
                      <input type="text" name="customer_addressl2" value="<?php echo $address_line2;?>" id="customer_addressl2" placeholder="Customer Address line 2" class="form-control" maxlength="75" />                   
                  </div>
                </div>
                  </div>  
            </div>
              <div class="col-sm-12">
                   <div class="col-sm-6">
                  <div class="form-group" id="qc_name">
                  <label for="qc_name" class="col-sm-5 control-label required"><?php echo $c_Country; ?>:<font style="color:red">*</font></label>
                  <div class="col-sm-7">                             
                    <select name="country_id" id="country_id" onchange="get_state(this.value);" class="form-control" >
                     <option value="0">Select Country</option>
               
                              <?php  
                                          foreach ($country as  $co) {
                                           if ($country_id == $co['country_id']) {?>
                                            <option value="<?php echo $co['country_id'];?>" selected><?php echo $co['country_name'] ; ?></option>
                                            <?php
                                           }else{?>
                                            <option value="<?php echo $co['country_id'];?>"><?php echo $co['country_name'] ; ?><?php 
                                          
                                          }
                                        }
                                        ?>
                                      
                    </select>  
                    <span id="country1" class="text-danger font-weight-bold"></span>
                  </div>
                </div>
                </div> 
                <div class="col-sm-6">
                <div class="form-group" id="qc_name">
                  <label for="qc_name" class="col-sm-5 control-label required"><?php echo $c_State; ?>:<font style="color:red">*</font></label>
                  <div class="col-sm-7">                             
                  <select name="state_id" id="state_id" onchange="get_city(this.value);" class="form-control"  >
                  <?php if ($this->uri->segment(4)){?> 
                    <option value="<?php echo $value['state_id'];?>"><?php echo $state_name;?></option>
                    <?php }else{?>
                        <option value="0" >Select State</option> 
                    <?php } ?>                                    
                  </select>
                  <span id="state_id1" class="text-danger font-weight-bold"></span>            </div>                
                </div>
               </div>
              </div> <!-- col-ms-6 close -->
              <div class="col-sm-12">
              <div class="col-sm-6">               
                <div class="form-group">
                  <label for="qc_name" class="col-sm-5 control-label required"><?php echo $c_City; ?>:<font style="color:red">*</font></label>
                  <div class="col-sm-7">                             
                  <select name="city_id" id="city_id" onChange="" class="form-control">
                   
                    <?php if ($this->uri->segment(4)){?> 
                    <option value="<?php echo $value['city_id'];?>"><?php echo $city_name?></option>
                  <?php }else{?>
                    <option value="0" >Select City</option>
                  <?php } ?>
                
                </select> 
                <span id="city_id1" class="text-danger font-weight-bold"></span>               </div>
                </div>
                </div>
               <div class="col-sm-6">
                 <div class="form-group" >
                  <label for="pincode" class="col-sm-5 control-label required"><?php echo $c_Postal_Code; ?>:<font style="color:red">*</font></label>
                  <div class="col-sm-7">
                                            
                  <input type="text" name="postalcode" value="<?php echo $postal_code;?>" id="postalcode" placeholder="Postal Code" onkeypress="return RestrictSpace()" class="form-control" maxlength="6"/>
                  <span id="postalcode1" class="text-danger font-weight-bold"></span>                       
                  </div>
                </div>
              </div>           
          </div>
        </div>
      </div>
    </section>
       <!-- customer contact s
        tart -->
    <section class="panel panel-default">
      <header class="panel-heading bg-info lt font-bold"><?php echo $c_Contact_Details; ?></header>
       <div class="panel-body bs-example form-horizontal">
        <div class="">
          <div class="hr hr12 dotted"></div>
          <div class="">
            <div class="col-sm-12">

              <div class="col-sm-6">  
                <div class="form-group" id="qc_name">
                      <label for="qc_name" class="col-sm-5 control-label required"><?php echo $c_contact_person_name; ?>:<font style="color:red">*</font></label>
                        <div class="col-sm-7">                                                  
                         <input type="text" name="contact_person_name" value="<?php echo $contact_person_name;?>" id="contact_person_name" placeholder="Contact Person Name" class="form-control" maxlength="75"  />
                         <span id="contact_person_name1" class="text-danger font-weight-bold"></span>                       
                        </div>
                    </div>
               </div>
               <div class="col-sm-6">
                    <div class="form-group">
                       <label for="client_code" class="col-sm-5 control-label required"> <?php echo $c_Designation; ?>:<font style="color:red">*</font></label>
                          <div class="col-sm-7">

                             
                            <input type="text" name="cutomer_designation" value="<?php echo $designation;?>" id="cutomer_designation" placeholder="Designation" class="form-control" maxlength="75" />
                              <span id="cutomer_designation1" class="text-danger font-weight-bold"></span>              
                          </div>
                    </div>
                  </div>
              <div class="col-sm-6">    
                <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_Mobile_Number; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-1" >
                                 <input type="text" value="<?php echo $std_code; ?>"  name="std_code" id="std_code" class="form-control"  style=" width: 120%;" readonly> 
                              </div>
                             
                              <div class="col-sm-6">   
                                <input type="text" name="cutomer_mobile" onkeypress="return RestrictSpace()" value="<?php echo $mobile_no;?>" id="cutomer_mobile" placeholder="Mobile Number" class="form-control" maxlength="10">
                                <span id="cutomer_mobile1" class="text-danger font-weight-bold"></span>                                          
                              </div>   
                </div>                         
            </div> <!-- col-ms-6 close -->

              <div class="col-sm-6">    
   
                  <div class="form-group">
                                <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_Email_Id; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                               
                                <input type="text" name="cutomer_email" onkeypress="return RestrictSpace()" value="<?php echo $email_id;?>" id="cutomer_email" placeholder="Email Id" class="form-control" maxlength="75" />
                             
                                <span id="cutomer_email1" class="text-danger font-weight-bold"></span>             
                              </div>
                </div>                            
            </div> <!-- col-ms-6 close -->
           <!--  -------------------------------------------addmore------------------------- -->
            <div class="col-sm-6" id="contactname1">  
                <div class="form-group" id="qc_name">
                      <label for="qc_name" class="col-sm-5 control-label required"> <?php echo $c_contact_person_name; ?></label>
                        <div class="col-sm-7">                             
                         <input type="text" name="contact_person_name1" id="contact_person_name_1" value="<?php echo $contact_person_name1;?>"placeholder="Contact Person Name" class="form-control contact_person_named" maxlength="75" /> 
                     <span id="contact_person_name11" class="text-danger font-weight-bold"></span> 
                        </div>
                    </div>
              </div>

            <div class="col-sm-6" id="design1">    

                <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_Designation; ?></label>
                              <div class="col-sm-7">
                                <input type="text" name="designation1" value="<?php echo $designation1;?>"  placeholder="Designation" class="form-control" maxlength="75"> 
                                <span id="designation11" class="text-danger font-weight-bold"></span> 
                                                                        
                              </div>  

                </div>                         
            </div>
              <div class="col-sm-6" id="mobilenumber1">    

                <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_Mobile_Number; ?></label>
                              <div class="col-sm-1" >
                                 <input type="text" value="<?php echo $std_code; ?>" name="std_code_1" id="std_coded" class="form-control"  style=" width: 120%;" readonly> 
                              </div>
                              <div class="col-sm-6">

                               <input type="text" name="cutomer_mobile1" onkeypress="return RestrictSpace()" value="<?php echo $mobile_no1;?>"  placeholder="Mobile Number" class="form-control" maxlength="10">

                                <span id="cutomer_mobile11" class="text-danger font-weight-bold"></span> 
                                                                       
                              </div>  
                </div>                         
            </div>
            <div class="col-sm-6" id="email1">    

                <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo $c_Email_Id; ?>:</label>
                              <div class="col-sm-7">
                                <input type="text" name="cutomer_email1" onkeypress="return RestrictSpace()" value="<?php echo $email_id1;?>"  placeholder="Email ID" class="form-control" maxlength="75"> 
                                <span id="cutomer_email11" class="text-danger font-weight-bold"></span> 
                                                                       
                              </div>  

                </div>  

            </div>
			<input type="hidden" name="customer_contact_id" value="<?php echo $customer_contact_id; ?>">
			<input type="hidden" name="customer_contact_id1" value="<?php echo $customer_contact_id1; ?>">

            
<!--  -------------------------------------------addmore------------------------- -->         
            </div>
            <button type="button" class="btn btn-primary btn-xs" id="addmore" style="float: right;">Add More</button>
             <button type="button" class="btn btn-primary btn-xs" id="cancel" style="float: right;">Remove</button>
          </div>
        </div>
      </div>
    </section> 
<input type="hidden" id="fetched_state" value="<?php echo $state_id; ?>">
            <input type="hidden" id="fetched_city" value="<?php echo $city_id; ?>">
            <input type="hidden" id="checking" value="<?php echo $check; ?>">	
    <div class="clearfix form-actions">
    <div class="col-md-offset-5 col-md-5">  
      <button class="btn btn-info" type="submit">
         Submit
      </button>
    </div>
  </div>
    </form>             
            </div>
          </div>  
        </div>
      </div>
    </div>
    <!-- /.col -->
  </div>
  
  <div class="space-4"></div>   
    </div>  
  </div>   
  </div>
<?php
  include('common/footer.php');
?>

<script>
   $(document).ready(function(){
   /*  $('#contactname1').hide();
    $('#mobilenumber1').hide();
    $('#design1').hide();
    $('#email1').hide();
    $('#cancel').hide(); */  
    $(".contact_person_named").attr("id='contact_person_named'");

//      id="contact_person_named" 
// id="cutomer_mobiled"
// id="cutomer_email1"
// id="designationed"


        $(".js-example-tags").select2({
        tags: true
      });
      
        $(".select2").select2();  
      $(".select2").prop("multiple", "");       
    });
   $('#id-date-picker-2').datepicker({ dateFormat: 'dd-mm-yy',maxDate: 0 });


</script>
<script>
  $(document).ready(function(){
      $("#addmore").click(function(){      
     $('#contactname1').show();
     $('#mobilenumber1').show();
      $('#design1').show();
     $('#email1').show();
     $('#addmore').hide(); 
     $('#cancel').show(); 
 });
       $("#cancel").click(function(){
		   $('#contact_person_name_1').val('');
		   
     $('#contactname1').hide();
     $('#mobilenumber1').hide();
    $('#design1').hide();
     $('#email1').hide();
     $('#addmore').show(); 
     $('#cancel').hide(); 
 });
    });
</script>
<script>


   var checking = $('#checking').val();
     //var country_id = $('#country_id').val();
    if (checking=='edit') {
      get_state();
      get_city();

    }
  function get_state()
{
  var country_id = $('#country_id').val();
  var fetched_state = $('#fetched_state').val();
  if (fetched_state!='') {
    var state_id=fetched_state;
  }
  $.ajax({
    url:"<?php echo base_url();?>index.php/gc/customer_master/get_state",
    method:"POST",
    data:{
      country_id:country_id,
      state_id:state_id
    },
    success:function(data)
    {
     $('#state_id').html(data);
    }
   });

   $.ajax({
    url:"<?php echo base_url();?>index.php/gc/customer_master/get_std_code",
    method:"POST",
    data:{
      country_id:country_id
    },
    success:function(data)
    {
     $('#std_code').val(data);
     $('#std_coded').val(data);
    }
   });

  
}

function get_city()
{
  var state_id = $('#state_id').val();
  var fetched_city = $('#fetched_city').val();
   if (fetched_city!='') {
    var city_id=fetched_city;
  }
  $.ajax({
    url:"<?php echo base_url();?>index.php/gc/customer_master/get_city",
    method:"POST",
    data:{
      state_id:state_id,
      city_id:city_id
    },
    success:function(data)
    {
     $('#city_id').html(data);
    }
   });
}
</script>
<script type="text/javascript">

function validateForm(){

       // var reg_gst ='/^([0-9]{2}[a-zA-Z]{4}([a-zA-Z]{1}|[0-9]{1})[0-9]{4}[a-zA-Z]{1}([a-zA-Z]|[0-9]){3}){0,15}$/';
  // var reg_gst ='^([0][1-9]|[1-2][0-9]|[3][0-5])([a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9a-zA-Z]{1}[zZ]{1}[0-9a-zA-Z]{1})+$';

  var reg_pan = '^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$';
                                                                     
  var error=false;  

  var branch_name=$("#branch_name").val();  
  if(branch_name=='0')
  {
    $("#branch_name1").html("Please Select Branch Name");
    error=true; 
  }
  else
  {
    $('#branch_name1').html("");
      
  }

  var customer_name=$("#customer_name").val();  
  if(customer_name=='')
  {
    $("#customer_name1").html("Please Enter Customer Name");
    error=true; 
  }else if(!isNaN(customer_name)){
    $("#customer_name1").html("only characters are allowed");
    error=true; 
  }
  else
  {
    $('#customer_name1').html("");
      
  } 
  var cutomer_pan=$("#cutomer_pan").val();
    if (cutomer_pan!='') {
     if(!cutomer_pan.match(reg_pan)){
     $("#cutomer_pan1").html("PAN number is not valid");
     error=true; 
    }
    else
    {
     $('#cutomer_pan1').html("");
      
    }
  } 
  
  
   const gstRegex = /^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/;
  var cutomer_gst=$("#cutomer_gst").val(); 
  var gt=cutomer_gst.slice(2, 12);
  if(cutomer_gst!="")
  {
   if (!gstRegex.test(cutomer_gst)) {
         $("#cutomer_gst1").html("Please enter valid gst number");
    error=true;
    } else {
       $('#cutomer_gst1').html("");
    }
  }
/*    if (cutomer_gst!='' && cutomer_pan!='') {
   if(gt!=cutomer_pan){
    $("#cutomer_gst1").html("Please check the gst number you have entered");
    error=true;
  }
  else
  {
    $('#cutomer_gst1').html("");      
  }
 } */
  var id_date=$("#id-date-picker-2").val();  
  if(id_date=='')
  {
    $("#date1").html("Please Enter Date");
    error=true; 
  }
  else
  {
    $('#date1').html("");
      
  }
  var sale_person_name=$("#sale_person_name").val();  
  if(sale_person_name=='default')
  {
    $("#sale_person_name1").html("Please Select Sale Person Name");
    error=true; 
  }
  else
  {
    $('#sale_person_name1').html("");
      
  }

  var contact_person_name=$("#contact_person_name").val();  
  if(contact_person_name=='')
  {
    $("#contact_person_name1").html("Please Enter Contact Person Name");
    error=true; 
  }else if(!isNaN(contact_person_name)){
    $("#contact_person_name1").html("Only characters are allowed");
    error=true; 
  }
  else
  {
    $('#contact_person_name1').html("");
      
  }
 
  var cutomer_designation=$("#cutomer_designation").val().trim();  
  if(cutomer_designation=='')
  {
    $("#cutomer_designation1").html("Please Enter Customer Designation");
    error=true; 
  }
  else
  {
    $('#cutomer_designation1').html("");
      
  }
 
  var cutomer_mobile=$("#cutomer_mobile").val();  
  if(cutomer_mobile=='')
  {
    $("#cutomer_mobile1").html("Please Enter Customer Mobile Number");
    error=true; 
  }else if(isNaN(cutomer_mobile)){
    $("#cutomer_mobile1").html("mobile number must be numbers");
    error=true;
  }
  else 
	if(cutomer_mobile.length<10)
	{
		$("#cutomer_mobile1").html("Please fill the 10 digit Branch Mobile Number");
    error=true; 
	}
  else
  {
    $('#cutomer_mobile1').html("");
      
  }
 
  var cutomer_email=$("#cutomer_email").val();  
  if(cutomer_email=='')
  {
    /* $("#cutomer_email1").html("Please Enter Customer Email id");
    error=true;  */
  }
  else if(cutomer_email!='')
  {
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if(!emailReg.test(cutomer_email)) {
		$("#cutomer_email1").html('Please Enter a valid Email Id');
		 error=true; 
	}else{
		$("#cutomer_email1").html('');
	}
   }
  
  /* else if(cutomer_email.indexOf('@') <= 0 ){
    $("#cutomer_email1").html("Invalid email id");
    error=true;
  }else if((cutomer_email.charAt(cutomer_email.length-4)!='.') && (cutomer_email.charAt(cutomer_email.length-3)!='.')){
    $("#cutomer_email1").html("Invalid email id");
    error=true;
  }
  else
  {
    $('#cutomer_email1').html("");
      
  } */
  
  var customer_addressl1=$("#customer_addressl1").val().trim();  
  if(customer_addressl1=='')
  {
    $("#customer_addressl1_1").html("Please Enter Address line 1");
    error=true; 
  }
  else
  {
    $('#customer_addressl1_1').html("");
      
  }
  var country_id=$("#country_id").val();  
  if(country_id=='0' || country_id=='')
  {
    $("#country1").html("Please Select Country Name");
    error=true; 
  }
  else
  {
    $('#country1').html("");
      
  }
  var state_id=$("#state_id").val();  
 
  if(state_id=='0' || state_id=='')
  {
    $("#state_id1").html("Please Select State Name");
    error=true; 
  }
  else
  {
    $('#state_id1').html("");
      
  }
  var city_id=$("#city_id").val();  
  if(city_id=='0' || city_id=='')
  {
    $("#city_id1").html("Please Select City Name");
    error=true; 
  }
  else
  {
    $('#city_id1').html("");
      
  }
  var postalcode=$("#postalcode").val();  
  if(postalcode=='')
  {
    $("#postalcode1").html("Please Enter Postal Code");
    error=true; 
  }else if(isNaN(postalcode)){
    $("#postalcode1").html("Postal Code must be in numbers");
    error=true;
  }
  else
  {
    $('#postalcode1').html("");
      
  }
  ///ad more////////
  //    var contact_person_name1=$("#contact_person_name1").val();  
  // if(contact_person_name1=='')
  // {
  //   $("#contact_person_name11").html("Please Enter Contact Person Name");
  //   error=true; 
  // }else if(!isNaN(contact_person_name)){
  //   $("#contact_person_name11").html("Only characters are allowed");
  //   error=true; 
  // }
  // else
  // {
  //   $('#contact_person_name11').html("");
      
  // }
  //  var cutomer_designation1=$("#cutomer_designation1").val();  
  // if(cutomer_designation1=='')
  // {
  //   $("#cutomer_designation11").html("Please Enter Customer Designation");
  //   error=true; 
  // }
  // else
  // {
  //   $('#cutomer_designation11').html("");
      
  // }
  //   var cutomer_mobile1=$("#cutomer_mobile1").val();  
  // if(cutomer_mobile1=='')
  // {
  //   $("#cutomer_mobile11").html("Please Enter Customer Mobile Number");
  //   error=true; 
  // }else if(isNaN(cutomer_mobile)){
  //   $("#cutomer_mobile11").html("mobile number must be numbers");
  //   error=true;
  // }
  // else
  // {
  //   $('#cutomer_mobile11').html("");
      
  // }
  // var cutomer_email1=$("#cutomer_email1").val();  
  // if(cutomer_email1=='')
  // {
  //   $("#cutomer_email11").html("Please Enter Customer Email id");
  //   error=true; 
  // }else if(cutomer_email1.indexOf('@') <= 0 ){
  //   $("#cutomer_email11").html("Invalid email id");
  //   error=true;
  // }else if((cutomer_email1.charAt(cutomer_email1.length-4)!='.') && (cutomer_email1.charAt(cutomer_email1.length-3)!='.')){
  //   $("#cutomer_email11").html("Invalid email id");
  //   error=true;
  // }
  // else
  // {
  //   $('#cutomer_email11').html("");
      
  // }
  ////ad more///////
  var hidden=$("#hidden").val();  
  if(error==true)
  {
    return false;
  }
  else
  {
   if(hidden==''){
      var r = confirm("Are you sure you want to create Customer!");
      if (r==true) {return true;}else{return false;} 
    }else{
      var r = confirm("Are you sure you want to Edit Customer!");
      if (r==true) {return true;}else{return false;} 
    }
  }

 
     
}
 function RestrictSpace() {
    if (event.keyCode == 32) {
        return false;
    }
}

<?php if($cnt_contacts==2){?>
$('#contactname1').show();
     $('#mobilenumber1').show();
      $('#design1').show();
     $('#email1').show();
     $('#addmore').hide(); 
     $('#cancel').show(); 

<?php } else {?>
$('#contactname1').hide();
    $('#mobilenumber1').hide();
    $('#design1').hide();
    $('#email1').hide();
    $('#cancel').hide();
<?php }?>
</script>
