if(uri == 'login' || uri == '')
{
 $(document).ready(function() {
     $("#sign_otp").on("click",function() {
        $('#mobile_login').hide();
        $('.otp_button').hide();
        $('.password_button').show();
        $('#otp_login').show();
        $('#otp_form').hide();
        $('.back').hide();
        $('#get_otp').prop('disabled', false);
        $("#get_otp").html('Get OTP');
        localStorage.setItem('form_2', 1);
        localStorage.removeItem("form_3");
    });
    $("#back").on("click",function() {
        $('#mobile_login').hide();
        $('.otp_button').hide();
        $('.password_button').show();
        $('#otp_login').show();
        $('#otp_form').hide();
        $('.back').hide();
        $('#get_otp').prop('disabled', false);
        $("#get_otp").html('Get OTP');
        localStorage.setItem('form_2', 1);
        localStorage.removeItem("form_3");
    });
   
    if(localStorage.getItem('form_2'))
     {
        localStorage.removeItem("form_3");
        $('#mobile_login').hide();
        $('.otp_button').hide();
        $('.password_button').show();
        $('#otp_login').show();
        $('#otp_form').hide();
        $('.back').hide();
    }
    $("#sign_password").on("click",function() {
        localStorage.removeItem("form_2");
        localStorage.removeItem("form_3");
        $('#mobile_login').show();
        $('.otp_button').show();
        $('.password_button').hide();
        $('#otp_login').hide();
        $('#otp_form').hide();
        $('.back').hide();
    });

    function opan_otp_form()
    {
      localStorage.removeItem("form_2");
      $('#mobile_login').hide();
      $('.otp_button').hide();
      $('.password_button').hide();
      $('#otp_login').hide();
      $('#otp_form').show();
      $('.back').show();
      localStorage.setItem('form_3', 1);
    }
    if(localStorage.getItem('form_3'))
     {
        $('#mobile_login').hide();
        $('.otp_button').hide();
        $('.password_button').hide();
        $('#otp_login').hide();
        $('#otp_form').show();
        $('.back').show();
     }
    var firebaseConfig = {
        apiKey: apiKey,
        authDomain: authDomain,
        projectId: projectId,
        storageBucket: storageBucket,
        messagingSenderId: messagingSenderId,
        appId: appId
    };
    firebase.initializeApp(firebaseConfig);
    firebase.analytics();
    $("#get_otp").on("click",function() 
    {
        $('#get_otp').prop('disabled', true);
        $("#get_otp").html('Sending...');
        var mobile = $('#mobile-no').val();
        if(mobile == '')
        {
          $('#message').html('Please Enter Mobile No.');
          $('#get_otp').prop('disabled', false);
          $("#get_otp").html('Get OTP');
        }
        else if( mobile.length != 10)
        {
          $('#message').html('Please Enter 10 Digit Mobile No.');
          $('#get_otp').prop('disabled', false);
          $("#get_otp").html('Get OTP');
        }
        else
        {
            $.ajax({
              url: base_url+"/check_user_avaliablity",
              method:"POST",
              data:{mobile:mobile},
              success:function(data)
              {
                if(data == 4)
                {
                  code ='+91';
                  phoneinput = code.concat(mobile);
                  window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container', {
                        'size': 'normal',
                        'callback': function(response) {
                        },
                        'expired-callback': function() {
                        }
                    });
                  var cverify=window.recaptchaVerifier;
                  firebase.auth().signInWithPhoneNumber(phoneinput,cverify).then(function(response){
                      opan_otp_form();
                      window.confirmationResult=response;
                  }).catch(function(error){
                      //console.log(error);
                      $('#message').html(error)
                      $('#get_otp').prop('disabled', false);
                      $("#get_otp").html('Get OTP');
                  })
                }
                else
                {
                  $('#message').html('Mobile No Not Registred.');
                  $('#get_otp').prop('disabled', false);
                  $("#get_otp").html('Get OTP');
                }
                
              }
            });
        }
        
    });
    $("#check_otp").on("click",function() 
    {
      $('#check_otp').prop('disabled', true);
      $("#get_otp").html('OTP Checking...');
      var otp = $('#otp').val();
      confirmationResult.confirm(otp).then(function(response){
         //console.log(response);
          var userobj=response.user;
          var token=userobj.xa;
          var provider="phone";
          var email=phoneinput;
          if(token!=null && token!=undefined && token!="")
          {
            sendDatatoServerPhp(email,provider,token,email);
          }
      })
      .catch(function(error)
      {
        console.log(error)
          back(error['message']);
      })
    });
    
});
function sendDatatoServerPhp(email,provider,token,username){
  var xhr = new XMLHttpRequest();
  xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
      if(this.responseText=="Login Successfull")
      {
          location = base_url+'/admin/dashboard';
      }
      else
      {
          location = base_url+'/login';
      }
    }
  });
  xhr.open("POST", base_url+"/check_login?email="+email+"&provider="+provider+"&username="+username+"&token="+token);
  xhr.send();
}
 function back(e)
    {
      $('#mobile_login').hide();
      $('.otp_button').hide();
      $('.password_button').show();
      $('#otp_login').show();
      $('#otp_form').hide();
      $('.back').hide();
      $('#message').html(e);
      localStorage.setItem('form_2', 1);
      localStorage.removeItem("form_3");
      $('#get_otp').prop('disabled', false);
      $("#get_otp").html('Get OTP');
    }
}
function charge_delivery(id) {
    if (id == 1) {
        $('#flat_delivery_charge').removeClass("d-none");
        $('#weight_base').addClass("d-none");
    } else {
        $('#flat_delivery_charge').addClass("d-none");
        $('#weight_base').removeClass("d-none");
    }
}

function logo_header(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function(e) {
            $('#header_logo').attr('src', e.target.result);
        }
        reader.readAsDataURL(input.files[0]);
    }
}
$("#logo_header").change(function() {
    logo_header(this);
});

function logo_footer(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function(e) {
            $('#footer_logo').attr('src', e.target.result);
        }
        reader.readAsDataURL(input.files[0]);
    }
}
$("#logo_footer").change(function() {
    logo_footer(this);
});

function fevicon_icon(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function(e) {
            $('#fevicon').attr('src', e.target.result);
        }
        reader.readAsDataURL(input.files[0]);
    }
}
$("#fevicon_icon").change(function() {
    fevicon_icon(this);
});

function admin_panel_logo(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function(e) {
            $('#admin_logo').attr('src', e.target.result);
        }
        reader.readAsDataURL(input.files[0]);
    }
}
$("#admin_panel_logo").change(function() {
    admin_panel_logo(this);
});

function active_delivery_system(el) {
    if (el.checked) {
        var status = 1;
    } else {
        var status = 0;
    }

    $.post(base_url + '/admin/setting/active_delivery_system', {
            status: status
        },
        function(data) {
            if (data == 1) {

                location.reload();
            } else {
                alert(data);
            }
        });
}

function active_national_delivery_system(el) {
    if (el.checked) {
        var status = 1;
    } else {
        var status = 0;
    }
    $.post(base_url + '/admin/setting/active_national_delivery_system', {
            status: status
        },
        function(data) {
            if (data == 1) {
                location.reload();
            } else {
                alert(data);
            }
        });
}

function active_state_delivery_system(el) {

    if (el.checked) {
        var status = 1;
    } else {
        var status = 0;
    }
    $.post(base_url + '/admin/setting/active_state_delivery_system', {
            status: status
        },
        function(data) {
            if (data == 1) {
                location.reload();
            } else {
                alert(data);
            }
        });
}

function active_local_delivery_system(el) {

    if (el.checked) {
        var status = 1;
    } else {
        var status = 0;
    }
    $.post(base_url + '/admin/setting/active_local_delivery_system', {
            status: status
        },
        function(data) {
            if (data == 1) {
                location.reload();
            } else {
                alert(data);
            }
        });
}

function active_dist_delivery_system(el) {

    if (el.checked) {
        var status = 1;
    } else {
        var status = 0;
    }
    $.post(base_url + '/admin/setting/active_dist_delivery_system', {
            status: status
        },
        function(data) {
            if (data == 1) {
                location.reload();
            } else {
                alert(data);
            }
        });
}
$(document).ready(function() {
    var i = 1;
    $('#add_varient').click(function() {
        i++;
        $('#sub_varient_field').append('<tr id="sub_varient' + i + '"><td><input type="text" name="sub_varient_name[]" class="form-control name_list" placeholder="Enter Sub Varient Name" required/></td><td><button type="button" name="remove" id="' + i + '" class="btn btn-danger sub_varient_remove">X</button></td></tr>');
    });
    $(document).on('click', '.sub_varient_remove', function() {
        var button_id = $(this).attr("id");
        $('#sub_varient' + button_id + '').remove();
    });
});
$(document).on('click', '.btn_remove_old_content', function() {
    var r = confirm("Are you sure!");
    if (r == true) {
        var button_edit_id = $(this).attr("id");
        var ret = button_edit_id.replace('rem_1out_', '');
        $.post(base_url + '/admin/varient/delete_sub_varient/' + ret, {
                ret: ret
            },
            function(data) {
                if (data == 1) {
                    $('#remove_old_content_' + button_edit_id + '').remove();
                    location.reload();
                } else {
                    alert("Sub Varient Delete Failed");
                }
            });

    }
});
//setup before functions
let typingTimer; //timer identifier
let doneTypingInterval = 5000; //time in ms (5 seconds)
let myInput = document.getElementById('current_password');

//on keyup, start the countdown
$("#current_password").keyup(function() {
    clearTimeout(typingTimer);
    $('#current_password').val();
    if (myInput.value) {
        beforeSubmit: $('#result').html("<span>Processing......</span>");
        typingTimer = setTimeout(doneTyping, doneTypingInterval);
    }
});

//user is "finished typing," do something
function doneTyping() {
    var current_password = $('#current_password').val();
    var user_id = "1";
    if (current_password != '') {
        $.ajax({
            beforeSubmit: $('#result').html("<span>Processing......</span>"),
            url: base_url + "/admin/check_current_password/" + current_password,
            method: "GET",
            success: function(data) {
                // alert(data)
                if (data == 1) {
                    $('#result').html("<span style='color:green'>Password Match</span>");
                    $(".new_password").show();
                    $("#submit_button").show();
                } else {
                    $('#result').html("<span style='color:red'>Password Not Match</span>");
                    $(".new_password").hide();
                }
            }
        });
    }
}

function current_password(button) {
    var password = document.getElementById("current_password");
    if (password.type == "password") {
        password.type = "text";
    } else {
        password.type = "password";
    }
}

function show_new_password(button) {
    var password = document.getElementById("new_current_password");
    if (password.type == "password") {
        password.type = "text";
    } else {
        password.type = "password";
    }
}

function show_new_confirm_password(button) {
    var password = document.getElementById("confirm_new_password");
    if (password.type == "password") {
        password.type = "text";
    } else {
        password.type = "password";
    }
}
$(document).ready(function() {
    $('#showing').on('change', function() {
        if (this.value > 0)
        //.....................^.......
        {
            $(".showing").hide();
        } else {
            $(".showing").show();
        }
    });
});
$(document).ready(function() {
    $('#refund').on('change', function() {
        if (this.value == '1')
        //.....................^.......
        {
            document.getElementById("refund_days").readOnly = false;
            document.getElementById("refund_days").required = true;
        } else {
            document.getElementById("refund_days").readOnly = true;
            document.getElementById("refund_days").required = false;
        }
    });
    $('#return').on('change', function() {
        if (this.value == '1')
        //.....................^.......
        {
            document.getElementById("return_days").readOnly = false;
            document.getElementById("return_days").required = true;
        } else {
            document.getElementById("return_days").readOnly = true;
            document.getElementById("return_days").required = false;
        }
    });
});
$(document).ready(function() {
    $('#offer').on('change', function() {
        if (this.value == '1')
        //.....................^.......
        {
            $("#offer_price").show();

        } else {
            $("#offer_price").hide();
        }
    });
});
$(document).ready(function() {
    $('#category').change(function() {
        var category_id = $('#category').val();
        if (category_id != '') {
            $.ajax({
                beforeSend: function() {
                    $(".loader").show();
                },
                url: base_url + "/admin/category/fetch_all_sub_category",
                method: "POST",
                data: {
                    category_id: category_id
                },
                success: function(data) {
                    $('#sub_category').html(data);
                    $('#child_sub_category').html('<option value="">Select Child Sub Category</option>');
                    $(".loader").hide();
                }
            });
        } else {
            $('#sub_category').html('<option value="">Select</option>');
            $('#child_sub_category').html('<option value="">Select Child Sub Category</option>');
            $(".loader").hide();
        }
    });

    $('#sub_category').change(function() {
        var sub_category = $('#sub_category').val();
        if (sub_category != '') {
            $.ajax({
                beforeSend: function() {
                    $(".loader").show();
                },
                url: base_url + "/admin/category/fetch_all_sub_category",
                method: "POST",
                data: {
                    category_id: sub_category
                },
                success: function(data) {
                    $('#child_sub_category').html(data);
                    $(".loader").hide();
                }
            });
        } else {
            $('#child_sub_category').html('<option value="">Select Child Sub Category</option>');
            $(".loader").hide();
        }
    });

});

function varient() {
    var category_id = $('#category').val();
    if (category_id != '') {
        $.ajax({
            url: base_url + "/admin/category/fetch_all_varient",
            method: "POST",
            data: {
                category_id: category_id
            },
            success: function(data) {
                $('#varient').html(data);
            }
        });
    }
}

$(document).ready(function() {
    var i = 1;
    $('#add').click(function() {
        i++;
        $('#dynamic_field').append('<tr id="row' + i + '"><td><input type="file" name="files[]" class="form-control name_list" /></td><td><button type="button" name="remove" id="' + i + '" class="btn btn-danger btn_remove">X</button></td></tr>');
    });
    $(document).on('click', '.btn_remove', function() {
        var button_id = $(this).attr("id");
        $('#row' + button_id + '').remove();
    });
});
$(document).ready(function() {
    var i = 1;
    $('#add_video').click(function() {
        i++;
        $('#video_field').append('<tr id="row' + i + '"> <td><textarea type="text" name="video[]" class="form-control" placeholder="Enter Video Embedded Code" required/></textarea></td><td><button type="button" name="remove" id="' + i + '" class="btn btn-danger btn_remove">X</button></td></tr>');
    });
    $(document).on('click', '.btn_remove', function() {
        var button_id = $(this).attr("id");
        $('#row' + button_id + '').remove();
    });
});
$('.image').bind('change', function() {
    var maxSizeKB = 10000; //Size in KB
    var maxSize = maxSizeKB * 1024; //File size is returned in Bytes
    if (this.files[0].size > maxSize) {
        $(this).val("");
        alert("Max size exceeded. Image Size should be under 100kb");
        return false;
    }
});

 function noteCheck() {
      var low_stock = $('#low_stock').val();
      if(!low_stock)
      {
         alert("Please Enter Low Stock Warning Number");
            $('#low_stock_alert').html("<b class='text-danger'>Product Low Stock Warning Required</b>");
            $('html, body').animate({
                scrollTop: $("#low_stock").offset().top
            }, 2000);
            return false;
      }
      var name = $('#name').val();
      if(!name)
      {
         alert("Please Enter Product Name");
            $('#name_alert').html("<b class='text-danger'>Name Required</b>");
            $('html, body').animate({
                scrollTop: $("#name").offset().top
            }, 2000);
            return false;
      }
      var hsn = $('#hsn').val();
      if(!hsn)
      {
         alert("Please Enter Product HSN");
            $('#hsn_alert').html("<b class='text-danger'>HSN Required</b>");
            $('html, body').animate({
                scrollTop: $("#hsn").offset().top
            }, 2000);
            return false;
      }
      var tax = $('#tax').val();
      if(!tax)
      {
         alert("Please Enter Product TAX");
            $('#tax_alert').html("<b class='text-danger'>TAX Required</b>");
            $('html, body').animate({
                scrollTop: $("#tax").offset().top
            }, 2000);
            return false;
      }
      var category = $('#category').val();
      if(!category)
      {
         alert("Please Select A Category First");
            $('#cat_alert').html("<b class='text-danger'>Category Required</b>");
            $('html, body').animate({
                scrollTop: $("#category").offset().top
            }, 2000);
            return false;
      }
      var sub_category = $('#sub_category').val();
      if(!sub_category)
      {
         alert("Please Select A Sub Category First");
            $('#sub_cat_alert').html("<b class='text-danger'>Sub Category Required</b>");
            $('html, body').animate({
                scrollTop: $("#sub_category").offset().top
            }, 2000);
            return false;
      }

    
      var prd_brand = $('#prd_brand').val();
      if(!prd_brand)
      {
         alert("Please Select a Brand");
            $('#prd_brand_alert').html("<b class='text-danger'>Brand Required</b>");
            $('html, body').animate({
                scrollTop: $("#prd_brand").offset().top
            }, 2000);
            return false;
      }

      var prd_unit = $('#prd_unit').val();
      if(!prd_unit)
      {
         alert("Please Enter Product Unit");
            $('#unit_alert').html("<b class='text-danger'>Unit Required</b>");
            $('html, body').animate({
                scrollTop: $("#prd_unit").offset().top
            }, 2000);
            return false;
      }
      var product_qnty = $('#product_qnty').val();
      if(!product_qnty)
      {
         alert("Please Enter Product Quentity");
            $('#product_qnty_alert').html("<b class='text-danger'>Quentity Required</b>");
            $('html, body').animate({
                scrollTop: $("#product_qnty").offset().top
            }, 2000);
            return false;
      }
      var buy_price = $('#buy_price').val();
      if(!buy_price)
      {
         alert("Please Enter Product Purchase Price");
            $('#buy_price_alert').html("<b class='text-danger'>Purchase Price Required</b>");
            $('html, body').animate({
                scrollTop: $("#buy_price").offset().top
            }, 2000);
            return false;
      }
      var sell_price = $('#sell_price').val();
      if(!sell_price)
      {
         alert("Please Enter Product Main Price");
            $('#sell_price_alert').html("<b class='text-danger'>Main Price Required</b>");
            $('html, body').animate({
                scrollTop: $("#sell_price").offset().top
            }, 2000);
            return false;
      }

      var prd_length = $('#prd_length').val();
      if(!prd_length)
      {
         alert("Please Enter Product Lenght");
            $('#prd_length_alert').html("<b class='text-danger'>Product Lenght Required</b>");
            $('html, body').animate({
                scrollTop: $("#prd_length").offset().top
            }, 2000);
            return false;
      }

      var prd_breadth = $('#prd_breadth').val();
      if(!prd_breadth)
      {
         alert("Please Enter Product Breadth");
            $('#prd_breadth_alert').html("<b class='text-danger'>Product Breadth Required</b>");
            $('html, body').animate({
                scrollTop: $("#prd_breadth").offset().top
            }, 2000);
            return false;
      }

      var prd_height = $('#prd_height').val();
      if(!prd_height)
      {
         alert("Please Enter Product Height");
            $('#prd_height_alert').html("<b class='text-danger'>Product Height Required</b>");
            $('html, body').animate({
                scrollTop: $("#prd_height").offset().top
            }, 2000);
            return false;
      }

      var prd_weight = $('#prd_weight').val();
      if(!prd_weight)
      {
         alert("Please Enter Product Wight");
            $('#prd_weight_alert').html("<b class='text-danger'>Product Wight Required</b>");
            $('html, body').animate({
                scrollTop: $("#prd_weight").offset().top
            }, 2000);
            return false;
      }
      
      var prd_s_invoice_id = $('#prd_s_invoice_id').val();
      if(!prd_s_invoice_id)
      {
         alert("Please Enter Stock Invoice ID");
            $('#prd_s_invoice_id').html("<b class='text-danger'>Invoice ID Required</b>");
            $('html, body').animate({
                scrollTop: $("#prd_s_invoice_id").offset().top
            }, 2000);
            return false;
      }
      // var add_note = $('.add_note').val();
      // var add_note = document.querySelector('.add_note').value;
      // if(!add_note)
      // {
        
      //    alert("Please Select at least One Sub Varient");
      //       return false;
      // }
        arr = [];
        $(".add_note :selected").map(function(i, el) {
            arr.push($(el).val());
        }).get();
        if(allBlanks(arr) == true)
        {
            alert("Please Select at least One Sub Varient");
            return false;
        }
       $("#choice_form").submit();
   }

    function allBlanks(arr)
    {
        for (var i = 0; i < arr.length; i++)
        {
            if (arr[i] !== "") return false;
        }

        return true;
    }

   function noteCheck_2() {
        $(".add_note").get().every(function(el) {
            return $("option:selected", el).val() == "N/A"
        }) ? alert('Please Select at least One Sub Varient') : document.getElementById("choice_form").submit();
   }

    function update_product_status(el){
       if(el.checked){
           var status = 1;
       }
       else{
           var status = 0;
       }
       $.post(base_url+'/admin/product/change_product_status', 
         {id:el.value,status:status
         }, 
         function(data){
           if(data == 1){
               location.reload();
           }
           else{
               alert(data);
           }
       });
   }

   function update_specials_status(el)
   {
      if(el.checked){
           var status = 1;
       }
       else{
           var status = 0;
       }
       $.post(base_url+'/admin/product/update_specials_status', 
         {id:el.value,status:status
         }, 
         function(data){
           if(data == 1){
               location.reload();
           }
           else{
               alert(data);
           }
       });
   }
   function update_featured_status(el)
   {
      if(el.checked){
           var status = 1;
       }
       else{
           var status = 0;
       }
       $.post(base_url+'/admin/product/update_featured_status', 
         {id:el.value,status:status
         }, 
         function(data){
           if(data == 1){
               location.reload();
           }
           else{
               alert(data);
           }
       });
   }

   function update_today_delas_status(el)
   {
      if(el.checked){
           var status = 1;
       }
       else{
           var status = 0;
       }
       $.post(base_url+'/admin/product/update_today_delas_status', 
         {id:el.value,status:status
         }, 
         function(data){
           if(data == 1){
               location.reload();
           }
           else{
               alert(data);
           }
       });
   }

    $("#ifsc").keyup(function(){  
   var ifsc = $('#ifsc').val();
   if(ifsc.length > 10 && ifsc.length < 12)
   {
      $.ajax({
         beforeSend: function() {
              $(".loader").show();
          },
         url: "https://ifsc.razorpay.com/" + ifsc,
         method: "GET",
         success: function(data) {
           if(data)
           {
               $('#user_bank_name').val(data.BANK);
               $("#user_bank_branch").val(data.BRANCH);
               $(".loader").hide();
               $('#alert_ifsc').html('')
           }
           else
           {
               $('#alert_ifsc').html('Please Enter Valid IFSC')
               $(".loader").hide();
           }
           
         }
      });
   }
   else
   {
        $('#alert_ifsc').html('Please Enter Valid IFSC');
        $('#user_bank_name').val("");
        $("#user_bank_branch").val("");
   }
})
function varient_check(e, b) {
   var varient_id = e.value;
   var prd_id = b;
   if(varient_id != '')
   {
       $.ajax({
          beforeSend: function() {
               $(".loader").show();
           },
          url: base_url+"/admin/stock_management/get_sub_varient_by_varient_id/"+varient_id+'/'+prd_id,
          method: "GET",
          success: function(data) {
            if(data)
            {
               $('.sub-varient').html(data);
               $(".loader").hide();
            }
            else
            {
                alert("data Not Found")
                $(".loader").hide();
            }
            
          }
       });
   }
   
}

function get_dist_for_add_taluka(e)
{
    var state_id = e.value;
    if(state_id != '')
    {
       $.ajax({
          beforeSend: function() {
               $(".loader").show();
           },
          url: base_url+"/admin/setting/get_dist_for_add_taluka/"+state_id,
          method: "GET",
          success: function(data) {
            if(data)
            {
               $('#districtid').html(data);
               $(".loader").hide();
               $('#submit_button').show();
            }
            else
            {
                alert("data Not Found")
                $(".loader").hide();
            }
            
          }
       });
    }
}



function get_dist_for_add_partner(e, a = null)
{
    var user_id = e;
    if(user_id != '')
    {
       $.ajax({
          beforeSend: function() {
               $(".loader").show();
           },
          url: base_url+"/admin/setting/get_dist_for_add_partner/"+user_id+'/'+a,
          method: "GET",
          success: function(data) {
            if(data)
            {
               $('#districtid').html(data);
               $(".loader").hide();
               $('#submit_button').show();
            }
            else
            {
                alert("data Not Found")
                $(".loader").hide();
            }
            
          }
       });
    }
}

function get_dist_for_add_taluka_head(e, a = null)
{
    var state_id = e;
    if(state_id != '')
    {
       $.ajax({
          beforeSend: function() {
               $(".loader").show();
           },
          url: base_url+"/admin/setting/get_dist_with_leader_name_by_state_id/"+state_id+'/'+a,
          method: "GET",
          success: function(data) {
            if(data)
            {
               $('#districtid').html(data);
               $(".loader").hide();
               $('#submit_button').show();
            }
            else
            {
                alert("data Not Found")
                $(".loader").hide();
            }
            
          }
       });
    }
}

function get_taluka_by_dist_id(e, a = null)
{
    var data = e;
    if(data != '')
    {
       $.ajax({
          beforeSend: function() {
               $(".loader").show();
           },
          url: base_url+"/admin/setting/get_taluka_by_dist_id/"+data+'/'+a,
          method: "GET",
          success: function(data) {
            if(data)
            {
               $('#taluka_details').html(data);
               $(".loader").hide();
               $('#submit_button').show();
            }
            else
            {
                alert("data Not Found")
                $(".loader").hide();
            }
            
          }
       });
    }
}

function check_user_avaliablity_by_state(e)
{
    var state_id = e;
    if(state_id != '')
    {
       $.ajax({
          beforeSend: function() {
               $(".loader").show();
           },
          url: base_url+"/admin/partner/check_user_avaliablity_by_state/"+state_id,
          method: "GET",
          success: function(data) {
            if(data == 5)
            {
                $(".loader").hide();
                $('#submit_button').hide();
                $('#alert').html('<b style="color:red">State Head Already exits in This State. Add Button Now Hide </b>');
            }
            else
            {
                $(".loader").hide();
                $('#submit_button').show();
                $('#alert').html('');
            }
            
          }
       });
    }
}

function check_user_avaliablity_by_dist(e)
{
    var dist_id = e;
    if(dist_id != '')
    {
       $.ajax({
          beforeSend: function() {
               $(".loader").show();
           },
          url: base_url+"/admin/partner/check_user_avaliablity_by_dist/"+dist_id,
          method: "GET",
          success: function(data) {
            if(data == 5)
            {
                $(".loader").hide();
                $('#submit_button').hide();
                $('#alert2').html('<b style="color:red">District Head Already exits in This District. Add Button Now Hide </b>');
            }
            else
            {
                $(".loader").hide();
                $('#submit_button').show();
                $('#alert2').html('');
            }
            
          }
       });
    }
}

function check_user_avaliablity_by_taluka(e)
{
    var taluka_id = e;
    if(taluka_id != '')
    {
       $.ajax({
          beforeSend: function() {
               $(".loader").show();
           },
          url: base_url+"/admin/partner/check_user_avaliablity_by_taluka/"+taluka_id,
          method: "GET",
          success: function(data) {
            if(data == 5)
            {
                $('#alert-5').html('');
                $(".loader").hide();
                $('#submit_button').hide();
                $('#submit_button-2').show();
                $('#alert3').html('<b style="color:red">Taluka Head Already exits in This Taluka. Add Button Now Hide </b>');
            }
            else
            {
                $(".loader").hide();
                $('#submit_button').show();
                $('#alert3').html('');
                $('#submit_button-2').hide();
                $('#alert-5').html('<b style="color:red">Taluka Head not available in This Taluka. Add Button Now Hide </b>');
            }
            
          }
       });
    }
}

function get_partner_code_by_role(e, a = null)
{
   var role = e;
   if(role != '')
   {
        $('#submit_button').show();
      if(role == 'State Head')
      {
         $.ajax({
            beforeSend: function() {
               $(".loader").show();
            },
            url: base_url+"/admin/partner/get_state_head_code/"+a,
            method: "GET",
            success: function(data) {
               if(data)
               {
                    var objJSON = JSON.parse(data);
                    $('#point_code').val(objJSON.code);
                    $('#info-data').html(objJSON.state);
                    $(".loader").hide();
                    console.log(data)
               }
               else
               {
                    alert("data Not Found")
                    $(".loader").hide();
                    $('#info-data').html('');
               }
            
            }
         });
      }
      else if(role == 'Dist Head')
      {
         $.ajax({
            beforeSend: function() {
               $(".loader").show();
               $('#info-data').html('');
            },
            url: base_url+"/admin/partner/get_dist_head_last_code/"+a,
            method: "GET",
            success: function(data) {
               if(data)
               {
                    var objJSON = JSON.parse(data);
                    $('#point_code').val(objJSON.code);
                    $('#info-data').html(objJSON.data);
                    $(".loader").hide();
               }
               else
               {
                    alert("data Not Found")
                    $(".loader").hide();
               }
            
            }
         });
      }
      else if(role == 'Taluka Head')
      {
         $.ajax({
            beforeSend: function() {
               $(".loader").show();
               $('#info-data').html('');
            },
            url: base_url+"/admin/partner/get_taluka_head_last_code/"+a,
            method: "GET",
            success: function(data) {
               if(data)
               {
                    var objJSON = JSON.parse(data);
                    $('#point_code').val(objJSON.code);
                    $('#info-data').html(objJSON.data);
                    $(".loader").hide();
               }
               else
               {
                    alert("data Not Found")
                    $(".loader").hide();
               }
            
            }
         });
      }
   }
}

function get_all_address_data_for_vendor_ad(e, a = null)
{
     $.ajax({
        beforeSend: function() {
           $(".loader").show();
           $('#info-data').html('');
        },
        url: base_url+"/admin/partner/get_taluka_head_last_code/"+a,
        method: "GET",
        success: function(data) {
           if(data)
           {
                var objJSON = JSON.parse(data);
                $('#point_code').val(objJSON.code);
                $('#info-data').html(objJSON.data);
                $(".loader").hide();
           }
           else
           {
                alert("data Not Found")
                $(".loader").hide();
           }
        
        }
    });
}

function confirmation(id)
{
swal({
    title: "Are you sure?",
    text: "Once deleted, Any error can come in the system!",
    icon: "warning",
    buttons: true,
    dangerMode: true,
  })
  .then((willDelete) => {
    if (willDelete) 
    {
        swal({
             title: "!!!Final Warning !!!!",
             text: "Once deleted, you will not be able to recover this Data & Any error can come in the system!",
             icon: "warning",
             buttons: true,
             dangerMode: true,
        })
        .then((willDelete) => {
          if (willDelete) {
            location.href= base_url+"/admin/partner/delete_partner/"+id;
          } 
        });
    } 
    else 
    {
      swal("System Safe!");
    }
  });
}
 $(document).ready(function(){
   $('#s').change(function(){
       if($('#s:checked').length){
        swal({
            title: "Are you sure?",
            text: "Once Changes, Any error can come in the system!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
          })
          .then((willDelete) => {
            if (willDelete) 
            {
                swal({
                     title: "!!!Final Warning !!!!",
                     text: "Once Changes, Any error can come in the system!",
                     icon: "warning",
                     buttons: true,
                     dangerMode: true,
                })
                .then((willDelete) => {
                  if (willDelete) {
                       $('#role').attr('readonly',false); 
                       $('#state_1').attr('readonly',false); 
                       $('#state_2').attr('readonly',false); 
                       $('#districtid').attr('readonly',false); 
                       $('#state_4').attr('readonly',false); 
                       $('#taluka_details').attr('readonly',false); 
                       $("#state_1").css("pointer-events","");
                       $("#state_2").css("pointer-events","");
                       $("#districtid").css("pointer-events","");
                       $("#state_4").css("pointer-events","");
                       $("#taluka_details").css("pointer-events","");
                  } 
                });
            } 
            else 
            {
              swal("System Safe!");
              $('#s').prop('checked', false);
            }
          });
       }else{
           $('#role').attr('readonly',true); 
           $('#state_1').attr('readonly',true); 
           $('#state_2').attr('readonly',true); 
           $('#districtid').attr('readonly',true); 
           $('#state_4').attr('readonly',true); 
           $('#taluka_details').attr('readonly',true); 
           $("#state_1").css("pointer-events","none");
           $("#state_2").css("pointer-events","none");
           $("#districtid").css("pointer-events","none");
           $("#state_4").css("pointer-events","none");
           $("#taluka_details").css("pointer-events","none");
       }
   });
});

function partner_delete_alert(message)
{
    swal("Oops!", "You do not have permission to "+message+". Please contact administration", "error");
}

function get_dist_by_role_state_head_code(e, a = null)
{
    var state_id = e;
    if(state_id != '')
    {
       $.ajax({
          beforeSend: function() {
                $('#info-data').html('');
                $(".loader").show();
            },
          url: base_url+"/admin/partner/get_all_dist_widt_dist_head_last_code/"+state_id,
          method: "GET",
          success: function(data) {
            if(data)
            {
                var objJSON = JSON.parse(data);
                $('#point_code').val(objJSON.code);
                $('#info-data').html(objJSON.data);
                $(".loader").hide();
            }
            else
            {
                alert("data Not Found")
                $(".loader").hide();
            }
            
          }
       });
    }
}

function get_taluka_by_role_dist_head_code(e)
{
    var dist_id = e;
    if(dist_id != '')
    {
       $.ajax({
          beforeSend: function() {
                $('#info-data').html('');
                $(".loader").show();
            },
          url: base_url+"/admin/partner/get_all_taluka_with_taluka_head_last_code/"+dist_id,
          method: "GET",
          success: function(data) {
            if(data)
            {
                var objJSON = JSON.parse(data);
                $('#point_code').val(objJSON.code);
                $('#info-data').html(objJSON.data);
                $(".loader").hide();
            }
            else
            {
                alert("data Not Found")
                $(".loader").hide();
            }
            
          }
       });
    }
}

var modes = {
      realistic: function realistic() {
        var count = 200;
        var defaults = {
          origin: { y: 0.7 }
        };
        function fire(particleRatio, opts) {
          confetti(Object.assign({}, defaults, opts, {
            particleCount: Math.floor(count * particleRatio)
          }));
        }
        fire(0.25, {
          spread: 26,
          startVelocity: 55,
        });
        fire(0.2, {
          spread: 60,
        });
        fire(0.35, {
          spread: 100,
          decay: 0.91,
          scalar: 0.8
        });
        fire(0.1, {
          spread: 120,
          startVelocity: 25,
          decay: 0.92,
          scalar: 1.2
        });
        fire(0.1, {
          spread: 120,
          startVelocity: 45,
        });
      },
    };
    function pretty(val) {
      return js_beautify(val, { indent_size: 2, brace_style: 'preserve-inline', });
    }
    function getCode(name) {
      var code = pretty(modes[name].toString());
      code = code.split('\n').slice(1).slice(0, -1).map(function (s) {
        return s.trim();
      }).join('\n');
      return pretty(code);
    }
   
    window.onload = function () {
      [].forEach.call(document.querySelectorAll('.group'), function (group) {
        var name = group.getAttribute('data-name');
        var button = group.querySelector('.run');
        var codeElem = group.querySelector('.hurry');
        var editor = ace.edit(codeElem);
        editor.session.setValue(getCode(name));
        var count = editor.session.getLength();
        button.onclick = function (ev) {
          ev.preventDefault();
          try {
            eval(editor.getValue());
          } catch (e) {
            console.error(e);
          }
        };
        editors.push(editor);
      });
    };
