$(document).ready(function(){

  $("#company_edit_model").css("width","800px");
  $('.editaddedemail').hide();

  $(document).on('click', 'div.savedblockedit .fa-chevron-down', function () {
  
    var gettingid=$(this).data('id');
    // $(document).find(".addressblock .fa-chevron-down").toggleClass("rtoate180");
    $(document).find(".saveaddressblockdetailsedit-"+gettingid).stop().slideToggle(500);

  });

  $(document).on('click', 'div.addblockedit .fa-chevron-down', function () {
  
    
    // $(document).find(".addressblock .fa-chevron-down").toggleClass("rtoate180");
    $(document).find(".addressblockdetailsedits").stop().slideToggle(500);

  });

  $(document).on('click', 'div.savedblockedit .fa-minus', function () {

    var gettingid=$(this).data('id');
    var confimation=confirm("Are You Sure,Do You want to delete Shipping Address");

    if (confimation == true) 
    {
      destroyrecord(gettingid);

      $(document).find(".savedblockedit-"+gettingid).remove();
    }   
  });

  $(document).on('click', '#editaddalternate_email', function () {

    // $('#editalternate_emailblock').append('<div class="editaddedemail">'+'<div class="col-md-6 pull-right">'+'<div class="form-group">'+'<label class="control-label" for="inputSuccess"> Alternate Email Id</label>'+'<input type="text" class="form-control cemail" name="company_email" id="alternate_cemail" style="width:300px;">'+'<i class="fa fa-minus" id="editremobealternate_email"></i>'+'<span class="help-block hide" id="cemailblock">Help block with success</span>'+'</div>'+'</div>'+'</div>');
    $('.editaddedemail').show();
    $('#editaddalternate_email').hide();

  });
  
  $(document).on('click', '#editremobealternate_email', function () {

    // $('.editaddedemail').remove();

    $('.editaddedemail').hide();

    $('#editalternate_cemail').val(" ");
  
    $('#editaddalternate_email').show(); 
  
  });

  $('#companies').on("click", ".dataid", function(){
    $('#shippingaddresssectionedit').empty();
    
        var companyID= $(this).data("id");
        if(companyID !=''){
          $.ajaxSetup({
  
              headers: {
    
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    
              }
    
            });  
            $.ajax({
  
              url:url_editcompany,
    
              method:"POST",
    
              data:{companyID:companyID},
    
              success:function(result){
                              
                    $('.editID').val(result.details.id); 
                    $('.editcname').val(result.details.name); 
                    $('.editcgstin').val(result.details.gstin);
                    $('.editccode').val(result.details.company_code);
                    $('.editcemail').val(result.details.email);

                    if(result.details.alternate_email=="null")
                    {
                      $('#editalternate_cemail').val(" ");
                    }
                    else
                    {
                      $('.editaddedemail').show();
                      $('#editaddalternate_email').hide();
                      $('#editalternate_cemail').val(result.details.alternate_email);
                    }
                    
                    var testing=[];

                  for(i=0;i<(result.address.length);i++){

                  if(result.address[i]['type']=="bill_to")
                  {
      
                    $('#billing_id').val(result.address[i]['address_id']);
                  
                    $('.editbilladdline1').val(result.address[i]['address_line1']);
                    $('.editbilladdline2').val(result.address[i]['address_line2']);
                    $('.editbilladdline3').val(result.address[i]['address_line3']);

                    $('#EditCity').append('<option value="'+result.address[i]['city']+'" selected="selected">'+result.address[i]['name']+'</option>');

                    $('#Stateedit').attr("data-id",result.address[i]['state']);
                    $('#Stateedit').attr("data-state-id",result.address[i]['state']);
                    $('.editbilldistrict').val(result.address[i]['district']);
                    $('.editbillstate').val(result.address[i]['state_title']);
                    $('.editbillcountry').val(result.address[i]['country']);
                    $('.editbillpincode').val(result.address[i]['pincode']);
                    $('.editbillmobile').val(result.address[i]['mobile']);     
                  }

                  else if(result.address[i]['type']=="ship_to")
                  {
                      savedaddress(result.address[i]);
                      testing.push(result.address[i]);
                      
                  }
                  

                }

                  
                
              }
            
              
            });     
          }   
          $("#edit_company").modal('show');
       
  });

  countadd=1;

  $('#addbuttoninedit').on('click',function(){

      countadd++;
      addingaddress(countadd);

      sessionStorage.setItem("addbutton","true");

      
  
  });

  $(document).on('click', '.editaltermobileno', function () {

    var gettingid=$(this).data('id');
    
    $('.edit_alternatemobile-'+gettingid).show();
    
    $('.editaltermobileno-'+gettingid).hide();

  });

  $(document).on('click', '.editremobealternate_mobile', function () {

    var gettingid=$(this).data('id');
    
    $('.edit_alternatemobile-'+gettingid).hide();
    
    $('.editaltermobileno-'+gettingid).show();

  });
  
  $(document).on('click', '#addalternate_mobileedit', function () {

    $('.addedmobileedit').show();

    $('#addalternate_mobileedit').hide();

  });

  $(document).on('click', '#remobealternate_mobileedit', function () {

    $('.addedmobileedit').hide();

    $('#addalternate_mobileedit').show();

  });
  
  $(document).on('click', '.edit_shipcity', function () {
 
    var gettingid=$(this).data('id');
    
    $('.edit_shipcity-'+gettingid).select2({
      ajax: {
             url: url_getcity,
             type: "get",
             dataType: 'json',
             delay: 100,
             data: function (params) {
                return {
                   searchTerm: params.term // search term
                };
             },
             processResults: function (response) {
                return {
                   results: response
                };		   
            },
             cache: true
           }
      });
      
      $('.edit_shipcity-'+gettingid).on('select2:select', function (e) {
           var city = e.params.data.id;
           $.ajax(url_getstatefromcity,{
              type : 'get',
              data :{'city' : city} ,
              success : function(data){
                 
                 
                 $(document).find('.edit_shipstate-'+gettingid).val(data.state.state_title);
                 $(document).find('.edit_shipstate-'+gettingid).attr("data-state-id",data.state.state_id);

                 $(document).find('.addedsid-'+gettingid).val(data.state.state_id);

                 
                 
                 $(document).find('.edit_shipcountry-'+gettingid).val("India");
                 
              },
              error: function (jqXhr, textStatus, errorMessage) {
         }
           });
     });

  });

  $(document).on('click', '.editadd_shipcity', function () {
 
    var gettingid=$(this).data('id');
  
    $('.editadd_shipcity-'+gettingid).select2({
      ajax: {
             url: url_getcity,
             type: "get",
             dataType: 'json',
             delay: 100,
             data: function (params) {
                return {
                   searchTerm: params.term // search term
                };
             },
             processResults: function (response) {
                return {
                   results: response
                };		   
            },
             cache: true
           }
      });
        
      $('.editadd_shipcity-'+gettingid).on('select2:select', function (e) {
           var city = e.params.data.id;
           $.ajax(url_getstatefromcity,{
              type : 'get',
              data :{'city' : city} ,
              success : function(data){
                 
                 
                 $(document).find('.editadd_shipstate-'+gettingid).val(data.state.state_title);
                 //$(document).find('.editadd_shipstate-'+gettingid).attr("data-state-id",data.district.state_id);
                 $(document).find('.editadd_shipstate-'+gettingid).attr("data-state-id",data.state.state_id);
                 
                 $(document).find('.editadd_shipcountry-'+gettingid).val("India");
                 
              },
              error: function (jqXhr, textStatus, errorMessage) {
         }
           });
     });
  
  });

  $('#edit-submit').click(function(e){

    e.preventDefault(e);
    
      updatedata();

      if(sessionStorage.getItem("addbutton")=="true")
      {
        newdta();
      }
      
  });
  
});



  function savedaddress(test){

    var alternatemobile_no=test.alternate_mobileno;
    
    var section="";

    section=section+
    '<div class="savedblockedit savedblockedit-'+test.address_id+'">'+

      '<input type="hidden" class="shipping_id" value="'+test.address_id+'"/>'+

      '<label class="control-label" for="Street">'+test.alias_name+'</label>'+

      '&nbsp&nbsp<i class="fa fa-chevron-down" data-id="'+test.address_id+'"></i>'+

      '<i class="fa fa-minus pull-right" data-id="'+test.address_id+'"></i>'+

      '<div class="row">'+
                  
        '<div class="col-md-6">'+

          '<div class="form-group">'+
                    
            '<label class="control-label" for="Address alias name" >Set Address Name</label>'+
                  
            '<input type="text" class="form-control edit_address_name" value="'+test.alias_name+'" autocomplete="off" />'+

          '</div>'+

        '</div>'+

      '</div>'+

      '<div class="saveaddressblockdetailsedit saveaddressblockdetailsedit-'+test.address_id+'" >'+

        '<div class="row">'+

          '<div class="col-md-4">'+
                  
            '<div class="form-group">'+

              '<label class="control-label" for="Street">Address Line:1 <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

              '<input type="text" name="street" class="form-control edit_shipaddl1" id="shipaddline1" value="'+test.address_line1+'" >'+

              '<span class="help-block hide" id="bill_streetblock">Help block with success</span>'+

            '</div>'+

          '</div>'+

          '<div class="col-md-4">'+
                  
            '<div class="form-group">'+

              '<label class="control-label" for="Street">Address Line:2 <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

              '<input type="text" name="street" class="form-control edit_shipaddl2" id="shipaddline2" value="'+test.address_line2+'" >'+

              '<span class="help-block hide" id="bill_streetblock">Help block with success</span>'+

            '</div>'+

          '</div>'+

          '<div class="col-md-4">'+
                  
            '<div class="form-group">'+

              '<label class="control-label" for="Street">Address Line:3</label>'+

              '<input type="text" name="street" class="form-control edit_shipaddl3" id="shipaddline3" value="'+test.address_line3+'" >'+

              '<span class="help-block hide" id="bill_streetblock">Help block with success</span>'+

            '</div>'+

          '</div>'+

        '</div>'+

        '<div class="row">'+

          '<div class="col-md-6">'+

            '<div class="form-group">'+

              '<label>City <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

              '<select class="form-control  select2-cityship edit_shipcity edit_shipcity-'+test.address_id+'" id="CreateShiopToCity" name="CreateShiopToCity" style="width: 100%;" data-id="'+test.address_id+'">'+

                '<option value="0">- Search city -</option>'+

                '<option value="'+test.city+'" selected="selected">'+test.name+'</option>'+

              '</select>'+

              '<span class="help-block hide" id="ShipToCityblock">Help block with success</span>'+

            '</div>'+

          '</div>'+

          '<div class="col-md-6">'+

            '<div class="form-group">'+

              '<label class="control-label" for="ShipToState"> State <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

              '<input type="text" class="form-control edit_shipstate edit_shipstate-'+test.address_id+'" id="ShipToState" name="ShipToState" readonly data-state-id="'+test.state+'" value="'+test.state_title+'">'+

              '<span class="help-block hide">Help block with success</span>'+

            '</div>'+

          '</div>'+          

        '</div>'+

        '<div class="row">'+

          '<div class="col-md-6">'+

            '<div class="form-group">'+

              '<label class="control-label" for="ShipToCountry"> Country <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

              '<input type="text" class="form-control edit_shipcountry edit_shipcountry-'+test.address_id+'" id="ShipToCountry" name="ShipToCountry" readonly value="'+test.country+'">'+

              '<span class="help-block hide">Help block with success</span>'+

            '</div>'+

          '</div>'+

          '<div class="col-md-6">'+

            '<div class="form-group">'+

              '<label class="control-label" for="ShipToPincode"> Pincode <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

              '<input type="text" class="form-control only-numeric edit_shippincode" name="ShipToPincode" id="ShipToPincode"  data-id="" maxlength="6" value="'+test.pincode+'">'+

              '<span class="help-block hide num-error" id="ShipToPincodeblock">Help block with success</span>'+

            '</div>'+

          '</div>'+

        '</div>'+

        '<div class="row">'+           

          '<div class="col-md-6">'+
              
            '<div class="form-group">'+

              '<label class="control-label" for="ShipToMobile"> Mobile No <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

              '<div class="input-group">'+

                '<input type="text" class="form-control edit_shipmobile " id="ShipToMobile" name="ShipToMobile" maxlength="10" value="'+test.mobile+'">'+

                '<span class="input-group-addon"><i class="fa fa-plus-circle editaltermobileno editaltermobileno-'+test.address_id+'" data-toggle="tooltip" data-placement="right" title="" data-original-title="ADD ALTERNATE MOBILE NUMBER" data-id="'+test.address_id+'"></i></span>'+

              '</div>'+

              '<span class="help-block hide" id="ShipToMobileblock">Help block with success</span>'+

            '</div>'+
                  
          '</div>'+

          '<div class="col-md-6">'+
              
            '<div class="form-group">'+

              '<label class="control-label" for="ShipToMobile"> Receiver Name <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

              '<input type="text" class="form-control edit_shipreceiver" id="edit_shipreceiver" name="ShipToMobile" maxlength="100" value="'+test.person_name+'">'+

              '<span class="help-block hide" id="ShipToMobileblock">Help block with success</span>'+

            '</div>'+
                  
          '</div>'+

        '</div>'+

        '<div class="row">'+

          '<div class="edit_alternatemobile edit_alternatemobile-'+test.address_id+'">'+
										
					  '<div class="col-md-6">'+
											
	  					'<div class="form-group">'+
																						
                '<label class="control-label" for="ShipToMobile"> Alternate Mobile No</label>'+
												
									'<div class="input-group">'+
												
										'<input type="text" class="form-control shipmobile mobile editsavealternate_mobile" id="alternate_mobile" name="ShipToMobile" value="'+test.alternate_mobileno+'" maxlength="10">'+
												
                    '<span class="input-group-addon"><i class="fa fa-minus-circle editremobealternate_mobile editremobealternate_mobile-'+test.address_id+'" data-id="'+test.address_id+'"></i></span>'+

									'</div>'+
												
									'<span class="help-block hide " id="">Help block with success</span>'+
											
								'</div>'+
										
							'</div>'+
            
            '</div>'+

            '<div class="col-md-6 pull-right">'+

						'<div class="form-group">'+

							'<label class="control-label" for="ShipToPincode"> Ship Company Name</label>'+

							'<input type="text" class="form-control edit_shipTocompanyname edit_shipTocompanyname-'+test.address_id+'" name="ShipTocompanyname" id="edit_ShipTocompanyname" value="'+test.ship_company_name+'" >'+

							'<span class="help-block hide edit_shipTocompanynameblock edit_shipTocompanynameblock-'+test.address_id+'" id="ShipTocompanynameblock">Help block with success</span>'+

						'</div>'+

					'</div>'+
            
          '</div>'+

        '</div>'+

      '</div>'+
      
    '</div>'


    
  $('#shippingaddresssectionedit').append(section);

    if(alternatemobile_no==0)
      {
        // $('.editaltermobileno-'+test.address_id).hide();

        $('.edit_alternatemobile-'+test.address_id).hide();

      }


  }

  function addingaddress(countadd){
    var section="";
    
    section=section+

  '<div class="addblockedit">'+

    '<label class="control-label" for="Street"></label>'+

    '&nbsp&nbsp<i class="fa fa-chevron-down" ></i>'+

    '<i class="fa fa-minus pull-right" ></i>'+

    '<div class="row">'+
                  
      '<div class="col-md-6">'+

        '<div class="form-group">'+
                    
          '<label class="control-label" for="Street" >Set Address Name</label>'+
                  
          '<input type="text" class="form-control editnew_address_name"  autocomplete="off" />'+

        '</div>'+

      '</div>'+

    '</div>'+

    '<div class="addressblockdetailsedits">'+

      '<div class="row">'+

        '<div class="col-md-4">'+
                  
          '<div class="form-group">'+

            '<label class="control-label" for="Street">Address Line:1 <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

            '<input type="text" name="street" class="form-control editadd_shipaddl1" id="shipaddline1" >'+

            '<span class="help-block hide" id="bill_streetblock">Help block with success</span>'+

          '</div>'+

        '</div>'+

        '<div class="col-md-4">'+
                  
          '<div class="form-group">'+

            '<label class="control-label" for="Street">Address Line:2 <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

            '<input type="text" name="street" class="form-control editadd_shipaddl2" id="shipaddline2" >'+

            '<span class="help-block hide" id="bill_streetblock">Help block with success</span>'+

          '</div>'+

        '</div>'+

        '<div class="col-md-4">'+
                  
          '<div class="form-group">'+

            '<label class="control-label" for="Street">Address Line:3</label>'+

            '<input type="text" name="street" class="form-control editadd_shipaddl3" id="shipaddline3" >'+

            '<span class="help-block hide" id="bill_streetblock">Help block with success</span>'+

          '</div>'+

        '</div>'+

      '</div>'+

      '<div class="row">'+

        '<div class="col-md-6">'+

          '<div class="form-group">'+

            '<label>City <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

            '<select class="form-control  select2-cityship editadd_shipcity editadd_shipcity-'+countadd+' " id="CreateShiopToCity" name="CreateShiopToCity" style="width: 100%;" data-id="'+countadd+'">'+

              '<option value="0">- Search city -</option>'+

            '</select>'+

            '<span class="help-block hide" id="ShipToCityblock">Help block with success</span>'+

          '</div>'+

        '</div>'+

        '<div class="col-md-6">'+

        '<div class="form-group">'+

          '<label class="control-label" for="ShipToState"> State <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

          '<input type="text" class="form-control editadd_shipstate editadd_shipstate-'+countadd+'" id="ShipToState" name="ShipToState" readonly >'+

          '<input type="hidden" class="addedsid-'+countadd+'">'+

          '<span class="help-block hide">Help block with success</span>'+

        '</div>'+

      '</div>'+          

      '</div>'+

      '<div class="row">'+

        '<div class="col-md-6">'+

          '<div class="form-group">'+

              '<label class="control-label" for="ShipToCountry"> Country <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

              '<input type="text" class="form-control editadd_shipcountry editadd_shipcountry-'+countadd+'" id="ShipToCountry" name="ShipToCountry" readonly>'+

              '<span class="help-block hide">Help block with success</span>'+

            '</div>'+

          '</div>'+

          '<div class="col-md-6">'+

          '<div class="form-group">'+

            '<label class="control-label" for="ShipToPincode"> Pincode <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

            '<input type="text" class="form-control only-numeric editadd_shippincode" name="ShipToPincode" id="ShipToPincode"  data-id="" maxlength="6">'+

            '<span class="help-block hide num-error" id="ShipToPincodeblock">Help block with success</span>'+

          '</div>'+

        '</div>'+

        '</div>'+

        '<div class="row">'+           

        '<div class="col-md-6">'+
              
          '<div class="form-group">'+

            '<label class="control-label" for="ShipToMobile"> Mobile No <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

            '<div class="input-group">'+

              '<input type="text" class="form-control editadd_shipmobile" id="ShipToMobile" name="ShipToMobile" maxlength="10">'+

              '<span class="input-group-addon"><i class="fa fa-plus-circle" id="addalternate_mobileedit" data-toggle="tooltip" data-placement="right" title="" data-original-title="ADD ALTERNATE MOBILE NUMBER"></i></span>'+

            '</div>'+

            '<span class="help-block hide" id="ShipToMobileblock">Help block with success</span>'+

          '</div>'+
                  
        '</div>'+

        '<div class="col-md-6">'+
              
          '<div class="form-group">'+

            '<label class="control-label" for="Editadd_receivername"> Receiver Name <sup><i class="fa fa-asterisk" style="font-size: 8px;" data-toggle="tooltip" data-placement="right" title="" data-original-title="THIS FIELD IS REQUIRED"></i></sup></label>'+

              '<input type="text" class="form-control editadd_receivername" id="editadd_receivername" name="editadd_receivername" maxlength="100">'+

            '<span class="help-block hide" id="editadd_receivernameblock">Help block with success</span>'+

          '</div>'+
                  
        '</div>'+

      '</div>'+

      '<div class="row" id="alternate_mobileblockedit">'+

				'<div class="addedmobileedit" style="display:none;">'+
										
					'<div class="col-md-6">'+
											
						'<div class="form-group">'+
												
							'<label class="control-label" for="ShipToMobile"> Alternate Mobile No</label>'+
												
							'<div class="input-group">'+
												
								'<input type="text" class="form-control shipmobile mobile addingalternate_mobile" id="addingalternate_mobile" name="ShipToMobile" maxlength="10">'+
												
								'<span class="input-group-addon"><i class="fa fa-minus-circle" id="remobealternate_mobileedit"></i></span>'+

							'</div>'+
												
							'<span class="help-block hide " id="">Help block with success</span>'+
											
						'</div>'+
										
					'</div>'+

				'</div>'+

      '</div>'+

      '</div>'+
      
      '</div>'

      $('#shippingaddresssectionedit').append(section);

 
  }

  function destroyrecord(shippingid)
  {

    $.ajaxSetup({

      headers: {
 
          'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
 
      }
 
      });
 
     
 
      $.ajax({ 
         url:url_removeaddress,
 
         method:"POST",
 
         data:{shippingid:shippingid},
 
         success:function(result)
 
         {
              if(result==1)
              { 
                  alert("Address Remove successfully");
              }
              else
              {
                alert("Address not removed. Please Try agaiin");
              }
         }
 
      });

  }

  function updatedata()
  {

    var companyID= $('.editID').val();
    var company_cemail=$('.editcemail').val();
    var alter_email=$('#editalternate_cemail').val();
    if(alter_email==" "||alter_email=="")
    {
        alter_email="null";
    }
    
    var billID= $('#billing_id').val();
    
    var company_editbilladdline1=$('.editbilladdline1').val();
    var company_editbilladdline2=$('.editbilladdline2').val();
    var company_editbilladdline3=$('.editbilladdline3').val();
    var company_billcity=$('#EditCity').val();    
    var company_billstate=$('#Stateedit').data('state-id');
    var company_billcountry=$('.editbillcountry').val();
    var company_billpincode=$('.editbillpincode').val();
    var company_billmobile=$('.editbillmobile').val();    

    var shipID=[];
    var company_editshipaddname=[];
    var company_editreceivername=[];
    var company_editshipaddline1=[];
    var company_editshipaddline2=[];
    var company_editshipaddline3=[];
    var company_shipcity=[];
    var company_shipstate=[];
    var company_shipcountry=[];
    var company_shippincode=[];
    var company_shipmobile=[];
    var company_shipaltermobile=[];


    $('.shipping_id').each(function(){
      shipID.push($(this).val());
    });

    $('.edit_address_name').each(function(){
      company_editshipaddname.push($(this).val());
    });

    $('.edit_shipreceiver').each(function(){
      company_editreceivername.push($(this).val());
    });

    $('.edit_shipaddl1').each(function(){
      company_editshipaddline1.push($(this).val());
    });

    $('.edit_shipaddl2').each(function(){
      company_editshipaddline2.push($(this).val());
    });

    $('.edit_shipaddl3').each(function(){
      company_editshipaddline3.push($(this).val());
    });

    $('.edit_shipcity').each(function(){
      company_shipcity.push($(this).val());
    });

    $('.edit_shipstate').each(function(){
      company_shipstate.push($(this).data("state-id"));
    });

    $('.edit_shipcountry').each(function(){
      company_shipcountry.push($(this).val());
    });

    $('.edit_shippincode').each(function(){
      company_shippincode.push($(this).val());
    });

    $('.edit_shipmobile').each(function(){
      company_shipmobile.push($(this).val());
    });

    $('.editsavealternate_mobile').each(function(){
      company_shipaltermobile.push($(this).val());
    });
      
    $.ajax({

      url:url_updatecompany,

      method:"POST",
 
      data:{
            'companyID':companyID,
            'company_email':company_cemail,
            'company_alteremail':alter_email,
            
            'company_billid':billID,
            'company_billaddline1':company_editbilladdline1,
            'company_billaddline2':company_editbilladdline2,
            'company_billaddline3':company_editbilladdline3,
            'company_billcity':company_billcity,
            'company_billstate':company_billstate,
            'company_billcountry':company_billcountry,
            'company_billpincode':company_billpincode,
            'company_billmobile':company_billmobile,

            'company_shipid':shipID,
            'company_editshipaddname':company_editshipaddname,
            'company_editshipreceiver':company_editreceivername,
            'company_shipaddline1':company_editshipaddline1,
            'company_shipaddline2':company_editshipaddline2,
            'company_shipaddline3':company_editshipaddline3,
            'company_shipcity':company_shipcity,
            'company_shipstate':company_shipstate,
            'company_shipcountry':company_shipcountry,
            'company_shippincode':company_shippincode,
            'company_shipmobile':company_shipmobile,
            'company_shipaltermobile':company_shipaltermobile,
          },

          success: function(response){
       
          
            $("#edit_company").modal('hide');
            var success="";

              success=success+
            
              '<p style="text-align:center;"><b>Data Updateed successfully!!!</b></p>';
             
              $('#company_success').append(success);
              $('#company_success').removeClass("hide");

              setTimeout(function(){
                location.reload();
              }, 300);
    
        }
          
        
    });
  }

  function newdta()
  { 
    var companyID= $('.editID').val();

    sessionStorage.removeItem("addbutton");

    var newaddress_name=[];
    var newaddress_line1=[];
    var newaddress_line2=[];
    var newaddress_line3=[];
    var newaddress_city=[];
    // var newaddress_cityid=[];
    var newaddress_state=[];
    var newaddress_country=[];
    var newaddress_pincode=[];
    var newaddress_mobile=[];
    var newaddress_alternatemobile=[];
    var newaddress_receivername=[];

    $('.editnew_address_name').each(function(){
      newaddress_name.push($(this).val());
    });

    $('.editadd_shipaddl1').each(function(){
      newaddress_line1.push($(this).val());
    });

    $('.editadd_shipaddl2').each(function(){
      newaddress_line2.push($(this).val());
    });

    $('.editadd_shipaddl3').each(function(){
      newaddress_line3.push($(this).val());
    });

    $('.editadd_shipcity').each(function(){
      newaddress_city.push($(this).val());
    });

     $('.editadd_shipstate').each(function(){
      newaddress_state.push($(this).data('state-id'));
    });

    $('.editadd_shipcountry').each(function(){
      newaddress_country.push($(this).val());
    });
    

    // console.log($('.editadd_shipstate-2').data("state-id"));

    // for(var i=0;i<(newaddress_cityid).length;i++)
    // {
    //   console.log("hello");
    //   console.log(newaddress_cityid[i]);
      
    
    //   $('.addedsid-'+newaddress_cityid[i]).each(function(){
    //     newaddress_state.push($(this).val());
    //   });
  
    //   $('.editadd_shipcountry-'+newaddress_cityid[i]).each(function(){
    //     newaddress_country.push($(this).val());
    //   });
    // }
 
    $('.editadd_shippincode').each(function(){
      newaddress_pincode.push($(this).val());
    });

    $('.editadd_shipmobile').each(function(){
      newaddress_mobile.push($(this).val());
    });

    $('.addingalternate_mobile').each(function(){
      
      if($(this).val()=='')
      {
        newaddress_alternatemobile.push("0");
      }
      else
      {
        newaddress_alternatemobile.push($(this).val());
      }

        
    });

    $('.editadd_receivername').each(function(){
      newaddress_receivername.push($(this).val());
    });
     
    if(newaddress_name==""&&newaddress_line1==""&&newaddress_line2==""&&newaddress_line3==""&&newaddress_city==""&&newaddress_state==""&&newaddress_country==""&&newaddress_pincode==""&&newaddress_mobile==""&&newaddress_receivername=="")
    { 
      $("#edit_company").modal('hide');
    }
    else if(newaddress_name==""||newaddress_line1==""||newaddress_line2==""||newaddress_city==0||newaddress_pincode==""||newaddress_mobile==""||newaddress_receivername=="")
    {
      alert("please enter all data!!!");
    }

    else{

      $.ajax({

        url:url_addnewaddress,
  
        method:"POST",
   
        data:{
              'companyID':companyID,
              'newaddress_name':newaddress_name,
              'newaddress_line1':newaddress_line1,
              'newaddress_line2':newaddress_line2,
              'newaddress_line3':newaddress_line3,
              'newaddress_city':newaddress_city,
              'newaddress_state':newaddress_state,
              'newaddress_country':newaddress_country,
              'newaddress_pincode':newaddress_pincode,
              'newaddress_mobile':newaddress_mobile,
              'newaddress_alternatemobile':newaddress_alternatemobile,
              'newaddress_receivername':newaddress_receivername,
            },
   
            success: function(response){
             
              $("#edit_company").modal('hide');
            
          } 
      });
    }
  }

  