function add_cart(prd_id, prd_slug, prd_name, prd_image, prd_price, prd_v_id, prd_sub_v_id, qty) 
{
    var pin_code = $('#pin_code').val();
    if(!pin_code)
    {
        $('#pin_code_model').modal('show');
        return false;
    }
	$.ajax({
    		beforeSend: function() {
            $(".preloader-ajax").show();
            $(".preloader-ajax-bg").show();
        },
        type: "POST",
        url: base_url+"/add_to_cart",
        data: {prd_id : prd_id, prd_slug:prd_slug, prd_name:prd_name, prd_image:prd_image, prd_price:prd_price, 
          	prd_v_id:prd_v_id, prd_sub_v_id:prd_sub_v_id, qty:qty
        },
        success: function(data) 
        {
         	$("#cart_box").load(window.location.href + " #cart_box" );
            $("#footer-cart").load(window.location.href + " #footer-cart" );
            $(".preloader-ajax").hide();
            $(".preloader-ajax-bg").hide();
            swal('Wow', 'Product Successfully Added in your Cart', 'success')

        },
        error: function(xhr, textStatus) {
              alert(textStatus);
              $(".preloader-ajax").hide();
              $(".preloader-ajax-bg").hide();
        }
    });
}

function cart_btn_both(prd_id_1, prd_id_2) {
    var pin_code = $('#pin_code').val();
    if(!pin_code)
    {
        $('#pin_code_model').modal('show');
        return false;
    }
    var prd_ids = [prd_id_1, prd_id_2];
    $.ajax({
            beforeSend: function() {
            $(".preloader-ajax").show();
            $(".preloader-ajax-bg").show();
        },
        type: "POST",
        url: base_url+"/add_to_cart_both",
        data: {
            prd_ids : prd_ids
        },
        success: function(data) 
        {
            $("#cart_box").load(window.location.href + " #cart_box" );
            $("#footer-cart").load(window.location.href + " #footer-cart" );
            $(".preloader-ajax").hide();
            $(".preloader-ajax-bg").hide();
            swal('Wow', 'Both Product Successfully Added in your Cart', 'success')
        },
        error: function(xhr, textStatus) {
            console.log(xhr.responseText);
              alert(textStatus);
              $(".preloader-ajax").hide();
              $(".preloader-ajax-bg").hide();
        }
    });
}

function remove_cart(cart_id) 
{
	swal({
	  title: "Are you sure?",
	  // text: "Once deleted, you will not be able to recover this imaginary file!",
	  icon: "warning",
	  buttons: true,
	  dangerMode: true,
	})
	.then((willDelete) => {
	  if (willDelete) {
	  	$.ajax({
					beforeSend: function() {
		          $(".preloader-ajax").show();
		          $(".preloader-ajax-bg").show();
		      },
		      type: "GET",
		      url: base_url+"/remove_cart/"+cart_id,
		      success: function(data) 
		      {
		         	$("#cart_box").load(window.location.href + " #cart_box" );
                    $("#footer-cart").load(window.location.href + " #footer-cart" );
		          $(".preloader-ajax").hide();
		          $(".preloader-ajax-bg").hide();
		          swal('Wow', 'Product Successfully Delete From your Cart', 'success')

		      },
		      error: function(xhr, textStatus) {
		          alert(textStatus);
		          $(".preloader-ajax").hide();
		          $(".preloader-ajax-bg").hide();
		      }
		  });
	  } else {
	    swal("Your imaginary file is safe!");
	  }
	});
}
	
function add_review() 
{
	event.preventDefault();
	var mydata = $("form").serialize();
    var rate = $('#star_rate').val();
    var product_id = $('#product_id').val();
    var reviewer_id = $('#reviewer_id').val();
    var comments = $('#review').val();
    if(rate == '')
    {
        swal('Opps', 'Please Select Review Star', 'error');
        return false;
    }
    if(comments == '')
    {
        swal('Opps', 'Please Add Review Comment', 'error');
        return false;
    }
    $.ajax({
        beforeSend: function() {
            $(".preloader-ajax").show();
            $(".preloader-ajax-bg").show();
            $('#submit_review').prop('disabled', true);
        },
        type: "POST",
        url: base_url+"/add_review",
        data: mydata,
        success: function(data) 
        {
            if(data == 5)
            {
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
                $('#submit_review').prop('disabled', false);  
                $('#review').val('');
                $('#star_rate').val('');
                $("#star_ratings").load(window.location.href + " #star_ratings" );
                grecaptcha.reset();
                swal('Wow', 'Review Successfully Submitted', 'success');
            }
            else if(data == 6)
            {
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
                $('#submit_review').prop('disabled', false);  
                grecaptcha.reset();
                swal('Opps', 'Review Submitted Failed', 'error');
            }
            else if(data == 8)
            {
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
                $('#submit_review').prop('disabled', false);  
                swal('Opps', 'Please Fill Captcha First', 'error');
            }
            else if(data == 9)
            {
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
                $('#submit_review').prop('disabled', false);  
                grecaptcha.reset();
                swal('Opps', 'Please Fill All Required Filed', 'error');
            }
            else
            {
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
                $('#review').val('');
                $('#submit_review').prop('disabled', false);  
                grecaptcha.reset();
                $("#star_ratings").load(window.location.href + " #star_ratings" );
                swal('Opps', 'Review Already Given', 'error');
            }
        },
        error: function(xhr, textStatus) {
            console.log(xhr.responseText);
            alert(textStatus);
            $(".preloader-ajax").hide();
            $(".preloader-ajax-bg").hide();
            grecaptcha.reset();
            $('#submit_review').prop('disabled', true);
        }
    });
}
$("#form_s_1").submit(function(e) {

    e.preventDefault(); 
    check_city_pin_code();
    
});
function check_city_pin_code() {
   var id = $('#city-pin-code').val();
   if (id != '') {
       $.ajax({
            beforeSend: function() {
               $('#location_search').hide();
               $('#location_search_2').show();
            },
            url: base_url+"/home/get_all_store_by_pin_or_city",
            method: "POST",
            async: true,
            dataType: "json",
            data: {
               id: id
            },
            success: function(data) {
                if (data.type === "error") 
                {
                    $('#result_error').show();
                    $('#result_error').html('<b style="color:red">'+data.result+'</b>');
                    $('#result_success').hide();
                    $('#location_search').show();
                    $('#location_search_2').hide();
                    $("#pin_code_section").load(window.location.href + " #pin_code_section" );
                    $("#pin_code_section_2").load(window.location.href + " #pin_code_section_2" );
                }
                else
                {
                    $('#result_error').hide();
                    $('#result_success').show();
                    $("#pin_code_section").load(window.location.href + " #pin_code_section" );
                    $("#pin_code_section_2").load(window.location.href + " #pin_code_section_2" );
                    $("#result_success").load(window.location.href + " #result_success" );
                    $('#buckcket_list').load(window.location.href + " #buckcket_list" );
                    $('#pin_code_model').modal('hide');
                    $('#location_search').show();
                    $('#location_search_2').hide();

                    if(url == 'product')
                    {
                        check_city_pin_code_with_details(id);

                    }
                    check_city_pin_code_with_details_quick(id);
                }
            },
            error: function(xhr, textStatus) {
                console.log(xhr.responseText);
            }
       });
   } else {
        $('#result_error').show();
        $('#result_error').html('<b style="color:red"><i class="fa fa-times" aria-hidden="true"></i>&nbsp;Please Enter Pin Code.</b>');
        $('#result_success').hide();
   }
}
$("#idForm").submit(function(e) {

    e.preventDefault(); 

    check_city_pin_code_with_details();
});

 function check_city_pin_code_with_details(ids = null) 
 {       
    var pin_code = $('#city-pin-code-with-details').val();
    if(pin_code)
    {
        var pin = $('#city-pin-code-with-details').val();
    }
    else
    {
        var pin = ids;
        $('#city-pin-code-with-details').val(ids);
    }
    var id = pin;
    if (id != '') {
        var prd_id = $('#prd_id').val();;
        var prd_weight = $('#prd_weight').val();;
       $.ajax({
            beforeSend: function() {
               $('#location_search-with-details').hide();
               $('#location_search_2-with-details').show();
            },
            url: base_url+"/home/get_delivery_details_by_pin_code",
            method: "POST",
            dataType: "json",
            data: {
               id: id, prd_id:prd_id, prd_weight:prd_weight
            },
            success: function(data) {
                if (data.type === "error") 
                {
                    $('#result_success').hide();
                    $("#city-pin-code").val('');
                    $('#location_search-with-details').show();
                    $('#location_search_2-with-details').hide();
                    $("#pin_code_section").load(window.location.href + " #pin_code_section" );
                    $("#pin_code_section_2").load(window.location.href + " #pin_code_section_2" );
                    $('#result_prd_page').html(data.result);
                }
                else
                {
                    $("#pin_code_section").load(window.location.href + " #pin_code_section" );
                    $("#pin_code_section_2").load(window.location.href + " #pin_code_section_2" );
                    $("#result_success").load(window.location.href + " #result_success" );
                    $('#location_search-with-details').show();
                    $('#location_search_2-with-details').hide();
                    $('#buckcket_list').load(window.location.href + " #buckcket_list" );
                    $('#result_prd_page').html(data.result);
                }
            },
            error: function(xhr, textStatus) {
                console.log(xhr.responseText);
            }
       });
   } else {
        $('#result_prd_page').show();
        $('#result_prd_page').html('<b style="color:red"><i class="fa fa-times" aria-hidden="true"></i>&nbsp;Please Enter Pin Code.</b>');
   }
}
 function check_city_pin_code_with_details_quick(ids = '') 
 {       
    var pin_code = $('#city-pin-code-with-details_quick').val();
    if(pin_code)
    {
        var pin = $('#city-pin-code-with-details_quick').val();
    }
    else
    {
        var pin = ids;
        $('#city-pin-code-with-details_quick').val(ids);
    }
    var id = pin;
    if (id != '') {
        var prd_id = $('#prd_id_quick').val();;
        var prd_weight = $('#prd_weight_quick').val();;
       $.ajax({
            beforeSend: function() {
               $('#location_search-with-details_quick').hide();
               $('#location_search_2-with-details_quick').show();
            },
            url: base_url+"/home/get_delivery_details_by_pin_code",
            method: "POST",
            dataType: "json",
            data: {
               id: id, prd_id:prd_id, prd_weight:prd_weight
            },
            success: function(data) {
                if (data.type === "error") 
                {
                    $('#result_success').hide();
                    $("#city-pin-code").val('');
                    $('#location_search-with-details_quick').show();
                    $('#location_search_2-with-details_quick').hide();
                    $("#pin_code_section").load(window.location.href + " #pin_code_section" );
                    $("#pin_code_section_2").load(window.location.href + " #pin_code_section_2" );
                    $('#result_prd_page_quick').html(data.result);
                }
                else
                {
                    $("#pin_code_section").load(window.location.href + " #pin_code_section" );
                    $("#pin_code_section_2").load(window.location.href + " #pin_code_section_2" );
                    $("#result_success").load(window.location.href + " #result_success" );
                    $('#location_search-with-details_quick').show();
                    $('#location_search_2-with-details_quick').hide();
                    $('#buckcket_list').load(window.location.href + " #buckcket_list" );
                    $('#result_prd_page_quick').html(data.result);
                }
            },
            error: function(xhr, textStatus) {
                console.log(xhr.responseText);
            }
       });
   } else {
        $('#result_prd_page_quick').show();
        $('#result_prd_page_quick').html('<b style="color:red"><i class="fa fa-times" aria-hidden="true"></i>&nbsp;Please Enter Pin Code.</b>');
   }
}
function check_coupon_code() 
{       
var id = $('#coupon_code').val();
if (id != '') {
   $.ajax({
        beforeSend: function() {
            $(".preloader-ajax").show();
            $(".preloader-ajax-bg").show();
            $('#apply_coupon').prop('disabled', true);
        },
        url: base_url+"/home/check_coupon_code",
        method: "POST",
        dataType: "json",
        data: {
           id: id
        },
        success: function(data) {
            if (data.type === "error") 
            {

                $("#order_details").load(window.location.href + " #order_details" );
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
                $('#apply_coupon').prop('disabled', false);
                swal('Opps!', "Coupon Code Invalid", 'error');
            }
            else
            {
                $("#order_details").load(window.location.href + " #order_details" );
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
                $('#apply_coupon').prop('disabled', false);
                swal('Wow!', "Coupon Code Successfully Applied", 'success');
            }
        },
        error: function(xhr, textStatus) {
            console.log(xhr.responseText);
        }
   });
} else {
    $('#result').show();
    $('#result').html('<b style="color:red"><i class="fa fa-times" aria-hidden="true"></i>&nbsp;Please Enter Coupon Code.</b>');
}
}
function check_mobile(e) 
{
    var mobile = e.value;
    if(mobile.length == 10)
    {
        $.ajax({
            beforeSend: function() {
                $(".preloader-ajax").show();
                $(".preloader-ajax-bg").show();
            },
            type: "GET",
            dataType:"JSON",
            async: true,
            url: base_url+'/home/check_mobile/'+mobile,
            success: function (data) 
            {
                if (data.type === "error") 
                {
                    $("#submit-button").prop('disabled',true);
                    swal('Opps!', 'Mobile No Already Exits', 'error');
                }
                else
                {
                    $("#submit-button").prop('disabled',false);
                }
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();

            },
            error: function (xhr) {
                console.log(xhr.responseText);
                $("#submit-button").prop('disabled',true);
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
            }
        });
    }
    else
    {
        swal('Opps!', 'Please Enter Valid Mobile No', 'error');
        $("#submit-button").prop('disabled',true);
    }
}
function check_email(e) 
{
    ValidateEmail(e);
    var email = e.value;
    if(email != '')
    {
        ValidateEmail(email);
        $.ajax({
            beforeSend: function() {
                $(".preloader-ajax").show();
                $(".preloader-ajax-bg").show();
            },
            type: "GET",
            dataType:"JSON",
            async: true,
            url: base_url+'/home/check_email/'+mobile,
            success: function (data) 
            {
                if (data.type === "error") 
                {
                    $("#submit-button").prop('disabled',true);
                    swal('Opps!', 'Email ID Already Exits', 'error');
                }
                else
                {
                    $("#submit-button").prop('disabled',false);
                }
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();

            },
            error: function (xhr) {
                console.log(xhr.responseText);
                $("#submit-button").prop('disabled',true);
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
            }
        });
    }
    else
    {
        swal('Opps!', 'Please Enter Valid Email ID', 'error');
        $("#submit-button").prop('disabled',true);
    }
}
function ValidateEmail(inputText)
{
    var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    if(inputText.value.match(mailformat))
    {
        $("#submit-button").prop('disabled',false);
        return true;
    }
    else
    {
        swal('Opps!', 'Please Enter Valid Email ID', 'error');
        $("#submit-button").prop('disabled',true);
        return false;

    }
}
function close_banner() {
    $('#hellobar-bar').fadeOut();
    var info = 1;
    $.ajax({
        type: "POST",
        url: base_url+"/close_top_header_banner",
        data:{info: info},
        success: function(data) 
        {
            
        },
        error: function(xhr, textStatus) {
            console.log(xhr.responseText);
            alert(textStatus);
        }
    });
}
if($('.cookie-notice').length) {
    $('.accept-cookies').on('click', function () {
        var info = 1;
        $.ajax({
            type: "POST",
            url: base_url+"/close_cookies_bar",
            data:{info: info},
            success: function(data) 
            {
                
            },
            error: function(xhr, textStatus) {
                console.log(xhr.responseText);
                alert(textStatus);
            }
        });    
        width = $('.cookie-notice').width();
        $('.cookie-notice').animate({
            left: '-=' + width
        }, 250, 'linear', function() {
            
            $(this).remove();
        });     
    });
}

function add_wishlist(prd_id) {
    var product_id = prd_id;
    if (session == false) {
        swal("Oops", "Please Login First", "warning");
        return false;
    }
    $.ajax({
        type: "post",
        async: true,
        url: base_url+'/add_wishlist',
        data: {
            product_id: product_id
        },
        success: function(data) {
           if (data == '1') {
                $("#wishlist").load(window.location.href + " #wishlist" );
                swal("Wow", "Product Added To Wishlist", "success");
           } else if (data == '2') {
                swal("Oops", "Product Already Exists In Wishlist", "warning");
           } else if (data == '3') {
                swal("Oops", "Please Login First", "warning");
           }
        },
       error: function(e) {
            console.log(e)
        }
    });
}

function remove_wishlist(prd_id) {
    var product_id = prd_id;
    $.ajax({
        type: "post",
        async: true,
        url: base_url+'/remove_wishlist',
        data: {
            product_id: product_id
        },
        success: function(data) {
           if (data == '1') {
                $("#wishlist").load(window.location.href + " #wishlist" );
                $("#wishlist_table").load(window.location.href + " #wishlist_table" );
                swal("Wow", "Wishlist Successfully remove", "success");
           } else if (data == '2') {
                swal("Oops", "Wishlist Remove failed", "warning");
           } 
        },
       error: function(e) {
            console.log(e)
        }
    });
}
function check_del_status() 
{
    var id = $('#del_pin_code').val();
    if(id == '')
    {
        $('#pin_code_msg').html('<b style="color:red">Please Enter Pin Code</b>')
        return false;
    }
    else
    {
        $.ajax({
            beforeSend: function() {
                $(".preloader-ajax").show();
                $(".preloader-ajax-bg").show();
                $("#check_pin_submit").prop('disabled',true);
            },
            type: "POST",
            dataType:"JSON",
            async: true,
            url: base_url+'/home/check_delvery_pin_code_status',
            data : {id:id},
            success: function (data) 
            {
                if(data.type === "error") 
                {

                    $("#check_pin_submit").prop('disabled',false);
                    $('#pin_code_msg').html('Opps!!! Delivery Not Available in Your Pin Code')
                }
                else
                {
                    $("#check_pin_submit").prop('disabled',false);
                    if(data.del_system === "local") 
                    {
                        $('#pin_code_msg').html('Wow!!! Our Store Available in Your Pin Code. <div class="agr_btn"><a href="javascript:void(0)" onclick="close_pin_popup()" class="btn btn-success agree-btn" id="con_shopping">Continue Shopping <i class="fa fa-long-arrow-right"></i></a></div>')
                    }
                    else
                    {
                        $('#pin_code_msg').html('Opps!!! Our Store Not Available in Your Pin Code. But if you want to continue shopping you have to pay Extra Charge <div class="agr_btn"><a onclick="close_pin_popup()" class="btn btn-success agree-btn" href="javascript:void(0)" id="con_shopping">Agree & Continue Shopping <i class="fa fa-long-arrow-right"></i></a></div>')
                    }
                }
                $("#pin_code_section").load(window.location.href + " #pin_code_section" );
                $("#pin_code_section_2").load(window.location.href + " #pin_code_section_2" );
                $("#result_success").load(window.location.href + " #result_success" );
                $('#buckcket_list').load(window.location.href + " #buckcket_list" );
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
                console.log(data)

            },
            error: function (xhr) {
                console.log(xhr.responseText);
                $("#check_pin_submit").prop('disabled',false);
                $(".preloader-ajax").hide();
                $(".preloader-ajax-bg").hide();
            }
        });
    }
}
function close_pin_popup() {
    $("#onload-popup").modal('hide');
};
function hide_fbtp_prd() {
   if ($('#prd_second').is(":checked")) {
       $("#one_price").fadeOut();
       $(".one_price").fadeOut("2000", function() {
           $(".both_price").fadeIn();
           $("#both_price").fadeIn();

           $(".second_prd").fadeIn();
       });
   } else {
       $(".both_price").fadeOut();
       $(".second_prd").fadeOut();
       $("#both_price").fadeOut("2000", function() {
           $("#one_price").fadeIn(500);
           $(".one_price").fadeIn(500);
       });
   }
}