text: var base_url = window.location.hostname+'/';
  
  // change status using id 
  
  function update_status(request){
  
  	if(!confirm('Are you sure update this')){ return false;}
  
  	var where_id = $(request).data("id");
  
  	var where_column = $(request).data("wclm");
  
  	var update_column = $(request).data("column");
  
  	var table = $(request).data("table");
  
  	var update = $(request).data("update");
  
  	var site_url = $('#site_url').val();
  
  	$.ajax({
  
          url: site_url+'account/produc-ajax',
  
          data: "where_id=" + where_id+"&update_column=" + update_column +"&table=" + table+"&update=" + update+"&where_column=" + where_column+"&action=upate_Status",
  
          type: "post",
  
          dataType: "json",
  
          success: function(data) {
  
              if(data=='1'){ location.reload();}else{ alert('Something went wrong');}
  
          }
  
      });
  
  }
  
  function delete_row(request){
  
  	if(!confirm('Are you sure Delete this')){ return false;}
  
  	var where_id = $(request).data("id");
  
  	var where_column = $(request).data("wclm");
  
  	var table = $(request).data("table");
  
  	var site_url = $('#site_url').val();
  
  	$.ajax({
  
          url: site_url+'account/produc-ajax',
  
          data: "where_id=" + where_id+"&table=" + table+"&where_column=" + where_column+"&action=delete_row",
  
          type: "post",
  
          dataType: "json",
  
          success: function(data) {
  
              if(data=='1'){ location.reload();}else{ alert('Something went wrong');}
  
          }
  
      });
  
  }
  
  function update_img_default(id,pid){
  
  	if(!confirm('Are you sure set as default this')){ return false;}
  
  	var site_url = $('#site_url').val();
  
  	$.ajax({
  
          url: site_url+'account/produc-ajax',
  
          data: "id=" + id+"&table=images&pid=" + pid+"&action=update_product_default",
  
          type: "post",
  
          dataType: "json",
  
          success: function(data) {
  
              if(data=='1'){ $('#up_msg_'+id).html('<span class="text-success">Updated</span>');setTimeout(function(){ $('#up_msg_'+id).html('');}, 1000);}else{ alert('Something went wrong');}
  
          }
  
      });
  
  }
  $('#pincode_state').on('change',function(){
      var state_name = this.value;
      var site_url = $('#site_url').val();
      var pcd = $('#pin_city_district').val();
      var pc = $('#pin_code').val();
      $.ajax({
          url: site_url+'account/pincode-ajax',
          data: "state_name=" + state_name+"&action=get_district_list",
          type: "post",
          dataType: "json",
          beforeSend: function(){
          // Show image container
              $("#loader").show();
          },
          complete:function(data){
              // Hide image container
              $("#loader").hide();
          },
          success: function(data) {
              if(data['status'] == 'success'){
                  $("#loader").show();
                  $('.remove').remove();
                  var html ='';
                  html+= '<div class="col-lg-3 remove"><div class="form-group " ><label>City/District</label><select onchange="get_divisions_list();" id="city_district" name="pin_city_district" class="form-control"><option value="">--Select--</option>';
                  $.each( data['data'], function( key, value ) {
                      if(pcd!=''){ if(pcd == value.district_name){var s = 'selected="selected"';}else{var s = '';}}else{ var s = '';}
                      html+='<option value="'+value.district_name+'" '+s+'>'+value.district_name+'</option>';
                  });
                  html+='</select></div></div><div class="col-lg-3"><div class="form-group "><label>Search</label><input type="text" class="form-control" value="'+data['pincode']+'" name="pin_code"></div></div>';
                  //'<div class="form-group remove"><label>Pincode <input type="number" id="f_pincode" class="form-control" value="'+pc+'" name="pin_code" placeholder="Enter Pin" maxlentgh="6"></label></div>';
                  $('.nav-pin').after(html);
                  $('#pin_count').html(data['count']);
                  // $('#pin_codes_body').html(data['p_data']);
                  $("#loader").hide();
              }
          }
      });
  });
  function clear_filters(){
      var site_url = $('#site_url').val();
      $.ajax({
          url: site_url+'account/pincode-ajax',
          data: "clear_filters=true&action=remove_filters",
          type: "post",
          dataType: "json",
          beforeSend: function(){
          // Show image container
              $("#loader").show();
          },
          complete:function(data){
              // Hide image container
              $("#loader").hide();
          },
          success: function(data) {
              if(data['status'] == 'success'){
                  location.href=site_url+'account/pincodes';
              }
          }
      }); 
  }
  function get_divisions_list(){
      var district = $('#city_district').val();
      var state = $('#pincode_state').val();
      var site_url = $('#site_url').val();
      $.ajax({
          url: site_url+'account/pincode-ajax',
          data: "disrict_name=" + district +"&action=get_division_list&state="+state,
          type: "post",
          dataType: "json",
          beforeSend: function(){
          // Show image container
              $("#loader").show();
          },
          complete:function(data){
              // Hide image container
              $("#loader").hide();
          },
          success: function(data) {
              
              if(data['status'] == 'success'){
                  $("#loader").show();
                  $('#pin_count').html(data['count']);
                  $('#pin_codes_body').html(data['data']);
                  $("#loader").hide();
              }
              
          }
      });
  }   
  // function get_divisions_list(val){
  //     var disrict_name = val;
  //     var state = $('#pincode_state').val();
  //     var site_url = $('#site_url').val();
  //     $.ajax({
  //         url: site_url+'account/pincode-ajax',
  //         data: "disrict_name=" + disrict_name +"&action=get_division_list&state="+state,
  //         type: "post",
  //         dataType: "json",
  //         success: function(data) {
  //             if(data['status'] == 'success'){
  //                 $('#other_dropdowns2').html('');
  //                 var html ='';
  //                 html+= '<div class="form-group"><label>Division <select  id="division" class="form-control">';
  //                 $.each( data['data'], function( key, value ) {
  //                     html+='<option value="'+value.division_name+'">'+value.division_name+'</option>';
  //                 });
  //                 html+='</select></label></div><div id=""></div>';
  //                 $('#other_dropdowns2').append(html);
  
  //             }
  //         }
  //     });
  // }
  function get_pincode_info() {
      var site_url = $('#site_url').val();
      var  pin = $('#add_pincode').val();
      if(pin.match(/^\d+$/)&& pin.length ==6) {
          // your code here
          $.ajax({
          url: site_url+'account/pincode-ajax',
          data: "pincode=" + pin+"&action=get_pincode_info",
          type: "post",
          dataType: "json",
          success: function(data) {
              if(data['data'] !=''){
                  $('#error_inof').html();
                  $('#taluk_name').val(data['data'][0].Taluk);
                  $('#region_name').val(data['data'][0].Region);
                  $('#division_name').val(data['data'][0].Division);
                  $('#circle_name').val(data['data'][0].Circle);
              }else{
                  $('#error_inof').html('details not found');
              }
          }
      });
      }else{
          alert('Enter valid Pincode');
      }
  }
  function get_city_distr(state){
      var site_url = $('#site_url').val();
      $.ajax({
          url: site_url+'account/pincode-ajax',
          data: "state_name=" + state+"&action=get_district_list",
          type: "post",
          dataType: "json",
          success: function(data) {
              if(data['status'] == 'success'){
                  var html ='';
                  html+= '<option value="">--Select--</option>';
                  $.each( data['data'], function( key, value ) {
                      html+='<option value="'+value.district_name+'" >'+value.district_name+'</option>';
                  });
                  $('#add_city_district').html(html);
  
              }
          }
      });
  }
  
  $(document).on('change','#region_states',function(){
      var selected_states = $('#region_states').val();
      if(selected_states!=''){
          get_data_based_on_selected_regions(selected_states,'districts');
      }else{
          $('#regions_button').attr('type','button').attr('disabled','disabled');
      }
  });
  $("#add_new_region").click(function(){
      var selected_states = [];
      $('input[name="selected_region_states[]"]').each(function(){
          selected_states.push($(this).val());
      });
      get_data_based_on_selected_regions(selected_states,'states');
      $('#addstate').modal('show');
  });
  function get_district_pincodes(){
      var selected_districts = $('#region_Districts').val();
      if(selected_districts!=''){
          get_data_based_on_selected_district(selected_districts,'pincodes');
      }else{
          $('#regions_button').attr('type','button').attr('disabled','disabled');
      }
  }
  // $(function(){
  //   $("body").on('change', 'select.selected_districts', function(e){
  //     get_data_based_on_selected_regions($(this).val(),'pincodes');
  //   });
  // });
  function get_data_based_on_selected_regions(val,get_for){
      var site_url = $('#site_url').val();
      $.ajax({
          url: site_url +'account/manage_region',
          data: {
           array:val,
           get_for:get_for
       },
  
          type: "post",
          dataType: "html",
          success: function(data) {
             // $('#region_pins_list').html('<div id="loading"  ></div>');
              if(get_for =='states'){
                  $('#region_states').html(data);
              }else if(get_for =='districts'){
                  var htm = data.split('|');
                  $('#region_districts_list').html(htm[0]);
                  $('#script').html(htm[1]);
              }else if(get_for =='pincodes'){
                  $('.region_pins_list').html('');
                  $('.region_pins_list').html(data);
              }
          }
      });
  }
  // function submit_zone(){
  //      var site_url = $('#site_url').val();
  //     var selected_districts = $('#region_Districts').val();
  //     var selected_states = $('#region_states').val();
  
  //    if(selected_districts =='undefined'){
  //         $('#modal_error').html('<span style="color:red">Please Select State / Disticts</span>');
  //         setTimeout(function(){$('#modal_error').html('');},3000);
  //     }else{
  //     $.ajax({
  //         url: site_url +'account/add_single_region',
  //         data: { states:selected_states,districts:selected_districts},
  //         type: "post",
  //         dataType: "html",
  //         success: function(data) {
  //            if(data != ''){
  //             $('#sel_regions').html(data);
  //             $('#addstate').modal('hide');
  //             $('#region_districts_list').html('');
  //            }
  //        else{
  //         $('#modal_error').html('<span style="color:red">Please Select State / Disticts</span>');
  //         setTimeout(function(){$('#modal_error').html('');},3000);
  //     }
  //      }
  //     });
  //     }
  // }
  
  function submit_zone(){
      var site_url = $('#site_url').val();
      var selected_districts = $('#region_Districts').val();
      var selected_states = $('#region_states').val();
      if(selected_districts =='undefined'){
          $('#modal_error').html('<span style="color:red">Please Select State / Disticts</span>');
          setTimeout(function(){$('#modal_error').html('');},3000);
      }else{
         $.ajax({
              url: site_url +'account/add_single_region',
              data: { states:selected_states,districts:selected_districts},
              type: "post",
              dataType: "html",
              success: function(data) {
                 if(data != ''){
                  $('#sel_regions').html(data);
                  $('#addstate').modal('hide');
                  $('#region_districts_list').html('');
                 }else{
                   $('#modal_error').html('<span style="color:red">Please Select State / Disticts</span>');
                  setTimeout(function(){$('#modal_error').html('');},3000);
                 }
              }
          });
      }
  }
  function remove_state_from_list(remove_state,element){
       var site_url = $('#site_url').val();
      $.ajax({
          url: site_url +'account/remove_state_from_select_region',
          data: { remove_state:remove_state},
          type: "post",
          dataType: "json",
          success: function(data) {
              if(data['status'] == 'success'){
                  $(element).parent().alert('close');
              }
          }
      });
      
  }
  function add_rate_ranges(val,rowCount,from){
      if(from == 'new'){$( ".n-rows" ).remove();}
      m = rowCount --;
      if(val== 1){
          $( "#add_new_btn" ).css('display','block');
          $( "#weight-info-msg" ).css('display','block');
          var recRow = '<div class="row n-rows" id="rate_from_'+rowCount+'"> <div class="col-md-2"> <div class="form-group"> <label class="control-label">Weight From<span class="text-danger">*</span></label> <input type="number" placeholder="Rang Form" name="rate_from[]" required="required" data-id='+rowCount+' id="rate_from'+rowCount+'" class="form-control rate_from"> </div></div><div class="col-md-1 p-0"> <div class="form-group"> <label class="control-label">&nbsp;</label> <select name="rate_from_select[]" required="required" id="rate_from_select'+rowCount+'" class="form-control"> <option value="Kg">Kg</option><!--<option value="Liter" >Liter</option> <option value="Grams" >Grams</option>--></select> </div></div><div class="col-md-2"> <div class="form-group"> <label class="control-label">Weight To<span class="text-danger">*</span></label> <input type="number" required="required" placeholder="Rang To" class="form-control rate_to" data-id='+rowCount+' name="rate_to[]" id="rate_to'+rowCount+'"> </div></div><div class="col-md-1 p-0"> <div class="form-group"> <label class="control-label">&nbsp;</label> <select name="rate_to_select[]" required="required" id="rate_from_select'+rowCount+'" class="form-control"> <option value="Kg">Kg</option><!--<option value="Liter">Liter</option> <option value="Grams">Grams</option>--></select> </div></div><div class="col-md-2"> <br><label class="checkbox-inline"> <input type="checkbox" id="charge_free'+rowCount+'" data-id="'+rowCount+'" class="is_check_rate" name="charge_free['+rowCount+']" value="1"> Free </label> ( OR ) </div><div class="col-md-3"> <div class="form-group"> <label class="control-label">Charge amount</label> <input type="number" class="form-control" placeholder="Amount " name="charge_amount[]" id="charge_amount'+rowCount+'" required="required"> </div></div><div class="col-md-1"> <br><a href="javascript:void(0);" onclick="removeRow('+rowCount+');" style="float:left;"> <i class="mdi mdi-delete btn btn-danger"></i></a> </div><span style="margin-top: 0px ; color: red;" class="from_to_weight_error"></span></div>';
          
      }else if(val== 2){
          $( "#weight-info-msg" ).css('display','none');
          $( "#add_new_btn" ).css('display','block');
          var recRow = '<div class="row n-rows" id="rate_from_'+rowCount+'"> <div class="col-md-3"> <div class="form-group"> <label class="control-label">Price range From<span class="text-danger">*</span></label> <input type="number" placeholder="Rang Form" name="rate_from[]" required="required" id="rate_from'+rowCount+'" class="form-control"> </div></div><div class="col-md-3"> <div class="form-group"> <label class="control-label">Price range To<span class="text-danger">*</span></label> <input type="number" required="required" placeholder="Rang To" class="form-control" name="rate_to[]" id="rate_to'+rowCount+'"> </div></div><div class="col-md-2"> <br><label class="checkbox-inline"> <input type="checkbox" id="charge_free'+rowCount+'" data-id="'+rowCount+'" class="is_check_rate" name="charge_free['+rowCount+']" value="1"> Free </label> ( OR ) </div><div class="col-md-3"> <div class="form-group"> <label class="control-label">Charge amount</label> <input type="number" class="form-control" placeholder="Amount " name="charge_amount[]" id="charge_amount'+rowCount+'" required="required"> </div></div><div class="col-md-1"> <br><a href="javascript:void(0);" onclick="removeRow('+rowCount+');" style="float:left;"> <i class="mdi mdi-delete btn btn-danger"></i></a> </div></div> ';
      }else{
          $( "#add_new_btn" ).css('display','none');
          $( "#weight-info-msg" ).css('display','none');
      }
      $('#addedRows').append(recRow);
      // $.ajax({
      //     url: site_url +'Ajax_response/add_',
      //     data: { remove_state:remove_state},
      //     type: "post",
      //     dataType: "html",
      //     success: function(data) {
      //         if(data == 'success'){
      //             $(element).parent().alert('close');
      //         }
      //     }
      // });
  }
  
  // $(".rate_to").on('keyup', function() {
  //     alert('su');
  //   //  ret = DetailsView.GetProject($(this).attr("#data-id"), OnComplete, OnTimeOut, OnError);
  //   alert($(this).attr("#data-id"));
  
  // });
  
  $(document).on('mouseout','.rate_to',function(e) {
  
      var site_url = $('#site_url').val();
  
      var id = $(this).attr('data-id');
  
      var rate_to = $('#rate_to'+id).val();
  
      var rate_from = $('#rate_from'+id).val();
         $.ajax({
              url: site_url +'account/check_product_zone_weight_value',
              data: { rate_to:rate_to,rate_from:rate_from},
              type: "post",
              dataType: "html",
              success: function(data) {           
                  var myObj = JSON.parse(data);
                  if(myObj.status == 'success'){
                          $('.from_to_weight_error').html('From Weight should be lesser than To Weight');
  
                          $('#rate_to'+id).val('');
                          
                  }else{
  
                      $('.from_to_weight_error').html('');                   
                  }
              }
          });
  });
  $(document).on('mouseout','.rate_from',function(e) {
  
        var site_url = $('#site_url').val();
  
        var id = $(this).attr('data-id');
  
        var rate_to = $('#rate_to'+id).val();  
  
        var rate_from = $('#rate_from'+id).val();
          $.ajax({
              url: site_url +'account/check_product_zone_weight_value',
              data: { rate_to:rate_to,rate_from:rate_from},
              type: "post",
              dataType: "html",
              success: function(data) {           
                  var myObj = JSON.parse(data);           
  
                  if(myObj.status == 'success'){
  
                          $('.from_to_weight_error').html('From Weight should be lesser than To Weight');
  
                          $('#rate_from'+id).val(''); 
                          
                  }else if(myObj.status == 'toempty'){
  
  
                  }else{
  
                      $('.from_to_weight_error').html('');
                     
                  }
              }
          });
  });
  function charge_free(val){
      alert(val)
  }
  $(document).on('click','.is_check_rate',function(e) {
    var id = $(this).attr('data-id');
      if($(this).prop("checked") == true){
          $('#charge_amount'+id).attr("readonly", true);
          $('#charge_amount'+id).attr("required", false);
      }else{
          $('#charge_amount'+id).attr("readonly", false);
          $('#charge_amount'+id).attr("required", true);
      }
  });
  $(document).on('click','#regions_button',function(e) {
      var zone_name = $('#zone_name').val();
      var max_product_limit = $('#max_product_limit').val();
      var max_delivery_product_limit = $('#max_product_delivery_days').val();
      var selected_states = [];
      $('input[name="selected_region_states[]"]').each(function(){
          selected_states.push($(this).val());
      });
      if(zone_name ==''){
          $('#z_name_error').html('Please enter zone name');setTimeout(function(){$('#z_name_error').html('');},3000);
      }else if(max_product_limit =='' || max_product_limit =='0'){
          $('#max_product_limit_err').html('Please enter Valid limit');setTimeout(function(){$('#max_product_limit_err').html('');},3000);
      }else if(max_delivery_product_limit =='' || max_delivery_product_limit =='0'){
          $('#max_delivery_product_limit_err').html('Please enter Valid limit');setTimeout(function(){$('#max_delivery_product_limit_err').html('');},3000);
      }else if(selected_states ==''){
          $('#z_states_error').html('Please select zone States');setTimeout(function(){$('#z_states_error').html('');},3000);
      }else{
          $('#regions_button').attr('type','submit');
      }
      
  });
  
  var rowCount = 1;
  function addMoreRows(frm) {
      var numItems = $('.n-rows').length;
      numItems++;
      var rate_type = $('#region_type').val();
      add_rate_ranges(rate_type,numItems,'add');
  }
     
  function removeRow(del) {
      var removeNum = $('.n-rows').length;
      if(removeNum == 1){
          alert("Cannot Delete this Row");
          return false;
      } else {    
      $('#rate_from_'+del).remove(); 
      }
  }
  
  function manage_pincodes(rid,state_name,distict_name){
      manage_pincode_data(rid,'get','');
      $('#reg_st_name').html(state_name);
      $('#reg_dist_name').html(distict_name);
      $('#region_u_id').val(rid);
      $('#manage_pincodes_modal').modal('show');
  }  
  function manage_pincode_data(r,f,d){
       var site_url = $('#site_url').val();
      $.ajax({
          url: site_url +'account/manage_pincodes_data',
          data: { rid:r,do_for:f,data:d},
          type: "post",
          dataType: "html",
          success: function(data) {
              if(data != ''){
                  $('#region_pincodes_list').html(data);
              }
          }
      });
  }
  function update_pincode_list(){
      var site_url = $('#site_url').val();
  
      var active_pins = [];
      var inactive_pins = [];
      var rid = $('#region_u_id').val();
      $('input[name="pins[]"]').each(function(){
          if($(this).prop("checked") == true){
              active_pins.push($(this).val());
          }else{
              inactive_pins.push($(this).val());
          }
      });
      $.ajax({
          url: site_url +'account/update_pincodes_data',
          data: { apins:active_pins,ipins:inactive_pins,rid:rid},
          type: "post",
          dataType: "json",
          success: function(data) {
              if(data['status'] == 'success'){
                  $('#region_pincodes_list_msg').html('<span style="color:green">Your data successfylly updated</span>');
                  setTimeout(function(){location.reload();},2000);
  
              }
          }
      });
  } 
  function select_zone(val){
      if(val == '1'){
        $('#show_zone_dropdown_select').css('display','block');
        $('#zone').prop('required',true);
        $('#product_weight').val('');
        $('#product_weight').focus();
      }else if(val == '0'){
        $('#show_zone_dropdown_select').css('display','none'); 
        $('#zone').prop('required',false);
        $('#product_weight').val('');
        $('#product_weight').focus();
      }else{
           $('#zone_type').val();
           $('#zone').val();
        alert("Something went Wrong...");
      }
  }
  // wiehgt adding 
  $("#product_weight").keyup(function(){
      var site_url = $('#site_url').val();
      zone_type = $("input[name='zone_type']:checked").val();
      zone = $("#zone").val();
      wiehgt = $(this).val();
      //alert(wiehgt)
      
      if(wiehgt=='' || isNaN(wiehgt) ){ 
          $('#wieght_error').html('Please enter valid wiehgt');setTimeout(function(){$('#wieght_error').html('');},3500);
      }else{
      $.ajax({
          url: site_url +'account/check_product_zone_weight',
          data: { zone_type:zone_type,zone:zone,wiehgt:wiehgt},
          type: "post",
          dataType: "html",
          success: function(data) {
              var myObj = JSON.parse(data);
              if(myObj.status == 'success'){
                  if(wiehgt > parseInt(myObj.msg)){
                      $('#wieght_error').html('Please enter less wieght. Your zone max weight is '+myObj.msg+' kg');
                       $('#product_weight').val('');
                      $('#product_weight').focus();
                      setTimeout(function(){$('#wieght_error').html('');},3500);
                  }
              }else if(myObj.status == 'error'){
                  $('#zone_error').html(myObj.msg);
                  setTimeout(function(){$('#zone_error').html('');},3500);
              }
          }
      });
      }   
  });
  
  function disply_variants_block(isVariant){
      if(isVariant=='1'){
          $('.single_product_block').css('display', 'none');
          $('.variant_block').css('display', 'block');
      }else if(isVariant=='0'){
          $('.single_product_block').css('display', 'block'); 
          $('.variant_block').css('display', 'none');
      }else{
          alert("Something went Wrong...")
      }
  }
  
  $(document).on('change','#sub_category_id',function(){
      $('#cat_variants_block').html('');
      $('#new_tags').html('');
      $('#option_tags').css('display','none');
      $('input[name="is_variant"][value="0"]').prop('checked',true);
  });
  function get_subcategories(valll){
      var site_url = $('#site_url').val();
      var category_id = valll;
      $.ajax({
          url: site_url+'account/subcategory_view',
          data: "category_id=" + category_id,
          type: "post",
          dataType: "json",
          success: function(data) {
              $('#sub_category_id').html(data.html);
          }
      });
  }
  
  function disply_variants_block(isVariant){
     var site_url = $('#site_url').val();
      if(isVariant == '1'){  
          var sub_category_id = $('#sub_category_id').val();
          if(sub_category_id == null){
              $('#erro_sub_cat').html('Please Select Sub Category');
              $('#categorys_err').html('Please Select  Category');
              setTimeout(function(){ $('#erro_sub_cat').html('');$('#categorys_err').html('');},'2000');
              $('#sub_category_id').focus();
              $('input[name="is_variant"][value="0"]').prop('checked',true);
          }else{
              $.ajax({
                  url: site_url +'account/product/get_category_variants',
                  data: "sub_category_id=" + sub_category_id,
                  type: "post",
                  dataType: "json",
                  success: function(data) {
  
                      if(data['status'] == 'success'){
  
                          var htm = data['check'].split('|');
  
                          $('#cat_variants_block').html(htm[0]);
  
                          $('#script').html(htm[1]);
  
                      }else{
  
                          $('input[name="is_variant"][value="0"]').prop('checked',true);
  
                          $('#cat_variants_block').html('<span style="color:red">No Variants on this category. if you want request to admin for variant ? click on categories tab</span>');
                      }
                  }
              });
              $('.variant_block').css('display', 'block');
          }
          //$('.single_product_block').css('display', 'none');
  
      }else if(isVariant=='0'){
  
          //$('.single_product_block').css('display', 'block'); 
  
          $('.variant_block').css('display', 'none');
  
      }else{
  
          alert("Something went Wrong...")
  
      }
  
  }
  $('#zipcode').on('mouseout',function(){
          var pincode = this.value;
          get_picode_data(pincode);
      });
        var locality = [];
      function get_picode_data(pincode){
          var site_url = $('#site_url').val();
          encode = JSON.stringify({
              'pincode' : pincode
          });
          $("body").addClass("loading");
          $.ajax({
              url: site_url+'account/pincode_details',
              dataType: 'json',
              data : {"data" :encode},
              type : 'POST',
              success : function(result){
                  $('#autocomplete_span').html('');
                  if(result!=''){
                          $('#city').val(result[0].district_name);
                          $('#state_name').val(result[0].state_name);
                          $('#add_locality').val('');
                      locality = [];
                      var auto = '<div id="add_localityautocomplete-list" class="autocomplete-items" style="display:block;">';
                      $.each(result, function(key, val) {
                          var s = "'"+val.office_name+"'";
                             auto+='<div  onclick="set_my_location('+s+')">'+val.office_name+'</div>';              
                      });
                      auto+='</div>';
                      $('#autocomplete_span').html(auto);
                  }else{
                          $('#zipcode').val('');
                          $('#city').val('');
                          $('#state_name').val('');
                  }
              },
              error: function(jqXHR, ajaxOptions, thrownError) {
                  alert("error: " + jqXHR.status + "--->" + thrownError);
              }
          });
          $("body").removeClass("loading"); 
      }
      $('#add_locality').on('focus', function(){
    $('.autocomplete-items').css('display','block');
  });
  function set_my_location(text){
  $('#add_locality').val(text);
  $('.autocomplete-items').css('display','none');
  }
  $('#add_locality').on('focus', function(){
    $('.autocomplete-items').css('display','block');
  });
  $('#add_locality').on('keyup', function(){
    $('.autocomplete-items').css('display','none');
  });
  ///seller payments 
  function get_seller_payment_details(val){
      var site_url = $('#site_url').val();
      // var payment_type = $('#payment_type').val();
      if(val!=''){
          // if(payment_type==''){
          //     $('#payment_type_error').html('Please select payment type.');
          //     setTimeout(function(){$('#payment_type_error').html('');},3000); return false;
          // }
          $.ajax({
              url: site_url+'account/payment_ajax',
              data: "seller_id=" + val+"&action=get_seller_sales",
              type: "post",
              dataType: "json",
              beforeSend: function(){
              // Show image container
                  $("#loader").show();
              },
              complete:function(data){
                  // Hide image container
                  $("#loader").hide();
              },
              success: function(data) {
                  //location.href=site_url+"account/add_payment?cid="+data['id'];
              }
          });
      }
  }
  function payment_by_paid(val){
      if(val =='cheque'){
          $('#cheque_details').css('display', 'block');
          $('#chequ_number').attr('required', true);
      }else if(val=='cash'){
          $('#cheque_details').css('display', 'none');
          $('#chequ_number').attr('required', false);
      }else if(val=='online'){
          $('#cheque_details').css('display', 'none');
          $('#chequ_number').attr('required', false);
      }
  }
  // $('#additional_discount').on('blur',function(){
  //     var ad_dis = $(this).val();
  //     var com_amt = $('#comission_amount').val();
  //     var pay_amt = $('#payment_amount').val();
  //     if (ad_dis === '' || isNaN(ad_dis) || ad_dis < 0 || ad_dis > 100 ) {
  //         $(this).val('0');
  //         ad_dis = '0';
  //     }
  //     if(ad_dis == '0'){
  //         $('#discount_amt_details').css('display', 'none');
  //         $('#final_payment_amount').val(pay_amt);
  //     }else{
  //         $('#discount_amt_details').css('display', 'block');
  //         var add_com = (com_amt * ad_dis / 100);
  //         var fin_amt =  (+pay_amt) + (+add_com);
  //         $('#additional_discount_amount').val(add_com);
  //         $('#final_payment_amount').val(fin_amt);
  //     }
  // });
  $('#additional_discount').on('blur',function(){
      var ad_dis = $(this).val();
      var com_amt = $('#comission_amount').val();
      var pay_amt = $('#payment_amount').val();
      if (ad_dis === '' || isNaN(ad_dis) || ad_dis < 0 || ad_dis > 100 ) {
          $(this).val('0');
          ad_dis = '0';
      }
      if(ad_dis == '0'){
          $('#discount_amt_details').css('display', 'none');
          $('#final_payment_amount').val(pay_amt);
          $('#gst option[value="0"]').prop('selected', true);
      }else{
          $('#discount_amt_details').css('display', 'block');
          var add_com = Math.round( (com_amt * ad_dis / 100) );
          var fin_amt = Math.round( (+pay_amt) + (+add_com) );
          $('#additional_discount_amount').val(add_com);
          $('#final_payment_amount').val(fin_amt);
          $('#gst option[value="0"]').prop('selected', true);
      }
  });
  function payment_with_gst(Val){
      var gst = Val;
      
      if (gst === '' || isNaN(gst) || gst < 0 ) {
          $(this).val('0');
          gst = '0';
      }
      if(gst == '0'){
          var ad_dis = $('#additional_discount_amount').val();
          var pay_amt = $('#payment_amount').val();
          if(ad_dis == ''){  var dis = 0;}else{ var dis = ad_dis;}
          var fin_amt =  (+pay_amt) + (+dis);
          $('#final_payment_amount').val(fin_amt);
      }else{
          var ad_dis = $('#additional_discount_amount').val();
          var pay_amt = $('#payment_amount').val();
          if(ad_dis == ''){  var dis = 0;}else{ var dis = ad_dis;}
          
          var fin_amt =  (+pay_amt) + (+gst) + (+dis);
          $('#final_payment_amount').val(Math.round(fin_amt));
      }
  }
   
  function blockSpecialChar(e){
          var x=e.which||e.keycode;
          if((x>=48 && x<=57) || x==8 ||
              (x>=35 && x<=40)|| x==46)
              return true;
          else
            return false;
  }
  function updateProductTrack(val,id){
    if(!confirm('Are you sure Updating Product Tracking?')){
      // location.reload();
      if(val == 'twosteps'){
         $("#radio-two-steps").prop('checked', false);
       
       }else{
        $("#radio-four-steps").prop('checked', false);
       }
     return false;
  
   }else{
    if(val == 'twosteps'){
         $("#radio-four-steps").prop('checked', false);
       
       }else{
        $("#radio-two-steps").prop('checked', false);
       }
  
      var base_url = $('#site_url').val();
       encode = JSON.stringify({
              "change_track": val,
              "setting_id": id
              });
        $.ajax({
             url: base_url+'account/seller_track_update',
              data:{"data":encode},
               type: "post",
                  dataType: "json",
              success: function(result) {
                  if (result['status'] == 'success') {
                      $('#tracking_success_msg').html('<span class="modal_success" style="color:green">' + result['msg'] + '</span>');
                       setTimeout(function(){$('#tracking_success_msg').html('');location.reload(true);},2000);
                  } 
              },
              error: function(jqXHR, ajaxOptions, thrownError) {
                  alert("error: " + jqXHR.status + "--->" + thrownError);
              }
          });
   }
   }  
    
  $(document).ready(function () {
     $("#buyer_cancel_time").change(function() {
   if(!confirm('Are you sure Updating Product Tracking?')){ return false;}
    var canceltime = $('#buyer_cancel_time').val();
    var id = $('#setting_table_id').val();
    var base_url = $('#site_url').val();
        encode = JSON.stringify({
              "order_cancel_time": canceltime,
              "setting_id": id
        });
        $.ajax({
             url: base_url+'account/buyer_order_cancel_time',
              data:{"data":encode},
               type: "post",
                  dataType: "json",
              success: function(result) {
                  if (result['status'] == 'success') {
                      $('#buyer_cancel_time_success_msg').html('<span class="modal_success" style="color:green">' + result['msg'] + '</span>');
                       setTimeout(function(){$('#buyer_cancel_time_success_msg').html('');location.reload(true);},2000);
                  } 
              },
              error: function(jqXHR, ajaxOptions, thrownError) {
                  alert("error: " + jqXHR.status + "--->" + thrownError);
              }
        });
  
   });
    $("#seller_greeting_message").validate({
      rules: {
          default_message_title: {
              required: true
          },
          default_message_description: {
              required: true
          },
          welcome_message_title: {
              required: true
          },
          welcome_message_description: {
              required: true
          }
      },
      messages: {
          default_message_title: {
              required: 'Enter default title'
          },
          default_message_description: {
              required: 'Enter default description'
              
          },
          welcome_message_title: {
              required: 'Enter welcome title'
          },
          welcome_message_description: {
              required: 'Enter welcome description'
              
          }
      },    
      submitHandler: function (form) {           
          var base_url = $('#site_url').val();
          var default_msg_title = $('#default_message_title').val();
          var default_msg_description = $('#default_message_description').val();
          var welcome_msg_title = $('#welcome_message_title').val();
          var welcome_msg_description = $('#welcome_message_description').val();
          encode = JSON.stringify({
              "default_msg_title": default_msg_title,
              "default_msg_description": default_msg_description,
              "welcome_msg_title": welcome_msg_title,
              "welcome_msg_description": welcome_msg_description
          });
          $.ajax({
             url: base_url+'account/seller_greeting_messages',
              data:{"data":encode},
               type: "post",
                  dataType: "json",
              success: function(result) {
                  if (result['status'] == 'success') {
                      $('#default_success_msg').html('<span class="modal_success" style="color:green">' + result['msg'] + '</span>');
                      location.reload();
                  } else {
                      $('#default_success_msg').html('<span class="modal_error">' + result['msg'] + '</span>');
                      location.reload();
                  }
              },
              error: function(jqXHR, ajaxOptions, thrownError) {
                  alert("error: " + jqXHR.status + "--->" + thrownError);
              }
          });
      }
    });
    $("#update_seller_greeting_message").validate({
      rules: {
          update_default_message_title: {
              required: true
          },
          update_default_message_description: {
              required: true
          },
          update_welcome_message_title: {
              required: true
          },
          update_welcome_message_description: {
              required: true
          }
      },
      messages: {
          update_default_message_title: {
              required: "Enter default title"
          },
          update_default_message_description: {
              required: "Enter default description"
              
          },
          update_welcome_message_title: {
              required: "Enter welcome title"
          },
          update_welcome_message_description: {
              required: "Enter welcome description"
              
          }
      },
       highlight: function(element, errorClass, validClass) {
                  $(element).closest('.md-form').addClass(errorClass).removeClass(validClass);
              },
              unhighlight: function(element, errorClass, validClass) {
                  $(element).closest('.md-form').removeClass(errorClass).addClass(validClass);
              },
              errorPlacement: function(error, element) {
                  if (element.is(":radio") || element.is(":checkbox")) {
                      element.closest('.option-group').after(error);
                  } else {
                      error.insertAfter(element.parent());
                  }
              },
      submitHandler: function (form) {           
          var base_url = $('#site_url').val();
          var default_msg_title = $('#update_default_message_title').val();
          var default_msg_description = $('#update_default_message_description').val();
          var welcome_msg_title = $('#update_welcome_message_title').val();
          var welcome_msg_description = $('#update_welcome_message_description').val();
          var msg_id = $('#default_message_id').val();
  
          encode = JSON.stringify({
              "default_msg_title": default_msg_title,
              "default_msg_description": default_msg_description,
              "welcome_msg_title": welcome_msg_title,
              "welcome_msg_description": welcome_msg_description,
              "msg_id": msg_id
          });
          $.ajax({
             url: base_url+'account/update_seller_greeting_meesages',
              data:{"data":encode},
               type: "post",
                  dataType: "json",
              success: function(result) {
                  if (result['status'] == 'success') {
                      $('#default_success_msg').html('<span class="modal_success" style="color:green">' + result['msg'] + '</span>');
                      location.reload();
                  } else {
                      $('#default_success_msg').html('<span class="modal_error">' + result['msg'] + '</span>');
                      location.reload();
                  }
              },
              error: function(jqXHR, ajaxOptions, thrownError) {
                  alert("error: " + jqXHR.status + "--->" + thrownError);
              }
          });
      }
    });
    
  });
  $("#bill_settings").validate({
      rules: {
          billing_time: {
              required: true
          }
      },
      messages: {
          billing_time: {
              required: "Select biiling type"
          }
      },
      submitHandler: function (form) {           
          if(!confirm('Are you sure update this')){ return false;}
          form.submit();
      }
    });
  function product_approval_reject(pid,sid) {
      $('#sid').val(sid);
      $('#pid').val(pid);
      $('#show_reject_msg_modal').modal('show');
  }
  function send_pro_reject_notification(){
      var sid = $('#sid').val();
      var pid = $('#pid').val();
      var base_url = $('#base_url').val();
      var reson = $('#pro_reject_reason').val();
      if(reson){
          encode = JSON.stringify({
              "sid": sid,
              "pid": pid,
              "reson": reson
          });
          $.ajax({
             url: base_url+'admin/Product/admin_reject_product',
              data:{"data":encode},
               type: "post",
                  dataType: "json",
              success: function(result) {
                  if (result['status'] == 'success') {
                      $('#rej_msg').html('<span class="text-success"> Reject notification sent successfylly</span>');
                      setTimeout(function(){$('#rej_msg').html('');location.reload(); },3000);
                  } else {
                      $('#rej_msg').html('<span class="error"> Something went worng</span>');
                      setTimeout(function(){$('#rej_msg').html('');location.reload(); },3000);
                  }
              },
              error: function(jqXHR, ajaxOptions, thrownError) {
                  alert("error: " + jqXHR.status + "--->" + thrownError);
              }
          });
      }else{
          $('#rej_msg').html('<span class="error"> Please enter Reason..</span>');
          setTimeout(function(){$('#rej_msg').html(''); },3000);
      }
  }
  
  function reject_seller(id){
      $('#sid').val(id);
      $('#show_reject_msg_modal').modal('show');
  }
  function send_seller_reject_notification(){
      var sid = $('#sid').val();
      var base_url = $('#base_url').val();
      var reson = $('#pro_reject_reason').val();
      if(reson ==''){ $('#rej_msg').html('<span class="error"> Please Enter Your reason</span>'); return false;}
      encode = JSON.stringify({
              "sid": sid,
              "reson": reson
          }); 
      $.ajax({
         url: base_url+'admin/Sellers/admin_reject_seller',
          data:{"data":encode},
           type: "post",
              dataType: "json",
          success: function(result) {
              // alert(result); return false;
              if (result['status'] == 'success') {
                  $('#rej_msg').html('<span class="text-success"> Reject notification sent successfylly</span>');
                  location.href=base_url+'account/seller_approvals/'+sid+'/rejected'; 
                  // console.log(base_url+'account/seller_approvals/'+sid+'/rejected');
              } else {
                  $('#rej_msg').html('<span class="error"> Something went worng</span>');
                  setTimeout(function(){$('#rej_msg').html('');location.reload(); },3000);
              }
          },
          error: function(jqXHR, ajaxOptions, thrownError) {
              alert("error: " + jqXHR.status + "--->" + thrownError);
          }
      });
  }
  //
  