$(window).on("load", function() {
 // executes when complete page is fully loaded, including all frames, objects and images
 $("#setloader").removeClass("pageloader");
});


var numericInput = document.getElementById("only_number");
numericInput.addEventListener("input", function(event) {
	var inputValue = event.target.value;
	var regex = /^\d*\.?\d*$/; // Regular expression to match numbers and decimal values
	if(!regex.test(inputValue)) {
		event.target.value = inputValue.slice(0, -1); // Remove the last entered character
	}
});


var numericInput = document.getElementById("only_number2");
numericInput.addEventListener("input", function(event) {
	var inputValue = event.target.value;
	var regex = /^\d*\.?\d*$/; // Regular expression to match numbers and decimal values
	if(!regex.test(inputValue)) {
		event.target.value = inputValue.slice(0, -1); // Remove the last entered character
	}
});


var numericInput = document.getElementById("only_number3");
numericInput.addEventListener("input", function(event) {
	var inputValue = event.target.value;
	var regex = /^\d*\.?\d*$/; // Regular expression to match numbers and decimal values
	if(!regex.test(inputValue)) {
		event.target.value = inputValue.slice(0, -1); // Remove the last entered character
	}
});

var numericInput = document.getElementById("only_number4");
numericInput.addEventListener("input", function(event) {
	var inputValue = event.target.value;
	var regex = /^\d*\.?\d*$/; // Regular expression to match numbers and decimal values
	if(!regex.test(inputValue)) {
		event.target.value = inputValue.slice(0, -1); // Remove the last entered character
	}
});

$(document).ready(function() {
	$("#update_info_form").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_info_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".user_update_btn").html("PLEASE WAIT");
				$(".user_update_btn").attr("disabled", "disabled");
			},
			success: function(response) {
				
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Your deatils successfully Updated !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: '#151515'
					});
					setTimeout(function() {
						$("#update_info_form").trigger('reset');
						$(".user_update_btn").html("Save Changes");
						$(".user_update_btn").removeAttr("disabled");
						window.location.href = location.href;
					}, 3300);
				} else {
					Snackbar.show({
						text: 'Something went wrong try again latter!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#update_info_form").trigger('reset');
						$(".user_update_btn").html("Save Changes");
						$(".user_update_btn").removeAttr("disabled");
					}, 3300);
				}
			}
		});
	});
});

$(document).ready(function() {
	$("#add_address").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_address_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".address_btn").html("PLEASE WAIT");
				$(".address_btn").attr("disabled", "disabled");
			},
			success: function(response) {
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Your address successfully added !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: '#151515'
					});
					setTimeout(function() {
						$("#add_address").trigger('reset');
						$(".address_btn").html('<i class="fas fa-plus mr-2"></i>' + "Add Address");
						$(".address_btn").removeAttr("disabled");
						window.location = "https://fomojeans.com/addresses";
					}, 3300);
				} else {
					Snackbar.show({
						text: 'Something went wrong try again latter!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#add_address").trigger('reset');
						$(".address_btn").html('<i class="fas fa-plus mr-2"></i>' + "Add Address");
						$(".address_btn").removeAttr("disabled");
					}, 3300);
				}
			}
		});
	});
});
$(document).ready(function() {
	$("#update_address").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_address_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".update_address_btn").html("PLEASE WAIT");
				$(".update_address_btn").attr("disabled", "disabled");
			},
			success: function(response) {
				
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Your address successfully Updated !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: '#151515'
					});
					setTimeout(function() {
						$("#add_address").trigger('reset');
						$(".update_address_btn").html("Update Now");
						$(".update_address_btn").removeAttr("disabled");
						window.location = "https://fomojeans.com/addresses";
					}, 3300);
				} else {
					Snackbar.show({
						text: 'Something went wrong try again latter!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#add_address").trigger('reset');
						$(".update_address_btn").html("Update Now");
						$(".update_address_btn").removeAttr("disabled");
					}, 3300);
				}
			}
		});
	});
});

// rating form
$(document).ready(function() {
	$("#rating_form").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_rating_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".rating_btn").html("PLEASE WAIT");
				$(".rating_btn").attr("disabled", "disabled");
			},
			success: function(response) {
				
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Thank you for rating products !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 2500,
						textColor: '#fff',
						backgroundColor: 'green'
					});
					setTimeout(function() {
						$("#rating_form").trigger('reset');
						$(".rating_btn").html('Submit Review <i class="lni lni-arrow-right"></i>');
						$(".rating_btn").removeAttr("disabled");
						window.location.href = location.href;
					}, 2700);
				}else if(response.trim() == "not_login"){
					Snackbar.show({
						text: 'God Job login first!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 2500,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#add_address").trigger('reset');
						$(".address_btn").html('<i class="fas fa-plus mr-2"></i>' + "Add Address");
						$(".address_btn").removeAttr("disabled");
					}, 2700);
				}else{

					

					Snackbar.show({
						text: 'Something went wrong try again latter !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 2500,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#rating_form").trigger('reset');
						$(".rating_btn").html('Submit Review <i class="lni lni-arrow-right"></i>');
						$(".rating_btn").removeAttr("disabled");
						window.location.href = location.href;
					}, 2700);
				}
			}

				
		});
	});
});
function loadAttr(val, pid) {
    if(val !== ''){
        $("#with_no_choise").addClass("d-none");
	    $("#with_choise").removeClass("d-none");
    }
	$.ajax({
		url: "load_size_variation.php",
		method: "POST",
		data: {
			val: val,
			pid: pid
		},
		success: function(response) {
			$("#size_get").html(response);
		}
	});
}

function loadAttrQty(size_id, color_id, pid) {
    var color_id_count = $("#ifsingle").val();
   
    if(color_id_count==1){
         var color_id = $("#color_id_for_single").val();
    }
   
	if(color_id == '') {
		Snackbar.show({
			text: 'Please Select Color',
			pos: 'top-right',
			showAction: false,
			actionText: "Dismiss",
			duration: 3000,
			textColor: '#fff',
			backgroundColor: 'red'
		});
	} else {
	    $("#with_no_choise").addClass("d-none");
	    $("#with_choise").removeClass("d-none");
		$.ajax({
			url: "load_size_price_variation.php",
			method: "POST",
			data: {
				size_id: size_id,
				color_id: color_id,
				pid: pid
			},
			success: function(response) {
				if(response.trim() != "no_data") {
                    
					var all_data = JSON.parse(response.trim());
					
					const newLink = document.createElement('a');
					newLink.classList.add("sp-current-big");
					newLink.href = "https://fomojeans.com/admin/upload/post-images/"+all_data[0].product_variation_images;

					const newImg = document.createElement('img');
					newImg.src = "https://fomojeans.com/admin/upload/post-images/"+all_data[0].product_variation_images;
					newImg.alt = 'Products Images';
					newLink.append(newImg);
			
					$(".sp-current-big").replaceWith(newLink);



					$("#price_no_filter").html("₹ "+all_data[0].price);
					$("#discounted_price_no_filter").html("₹ "+all_data[0].discounted_price);
					$("#stock_count").html(all_data[0].product_quantity);
					$(".add_to_cart_btn_details").removeAttr("disabled");
					$("#attr_id").val(all_data[0].id);
				}
			}
		});
	}
}
$(document).ready(function() {
	$("#sginup-form").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".reg-btn").html("PLEASE WAIT");
				$(".reg-btn").attr("disabled", "disabled");
			},
			success: function(response) {
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Verification code has been sent on your email !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: '#151515'
					});
					setTimeout(function() {
						$("#sginup-form").trigger('reset');
						$(".reg-btn").html("Send Otp");
						$(".reg-btn").removeAttr("disabled");
						$("#login").modal("hide");
						$("#register").modal("hide");
						$("#reg_otp").modal("show");
					}, 3500);
				} else if(response.trim() == "already") {
					Snackbar.show({
						text: 'You are already register please login!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#sginup-form").trigger('reset');
						$(".reg-btn").html("Send Otp");
						$(".reg-btn").removeAttr("disabled");
						$("#register").modal("hide");
					}, 3500);
				} else {
					Snackbar.show({
						text: 'Registration failed !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#sginup-form").trigger('reset');
						$(".reg-btn").html("Send Otp");
						$(".reg-btn").removeAttr("disabled");
					}, 3500);
				}
			}
		});
	});
});

// verifie reg otp
$(document).ready(function() {
	$("#reg-form-otp").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_otp_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".reg-otp-verify").html("PLEASE WAIT");
				$(".reg-otp-verify").attr("disabled", "disabled");
			},
			success: function(response) {
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Registration successfull please login with us !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: '#151515'
					});
					setTimeout(function() {
						$("#reg-form-otp").trigger('reset');
						$(".reg-otp-verify").html("Send Otp");
						$(".reg-otp-verify").removeAttr("disabled");
						$("#register").modal("hide");
						$("#reg_otp").modal("hide");
						$("#login").modal("show");
					}, 3500);
				} else if(response.trim() == "wrong_otp") {
					Snackbar.show({
						text: 'Wrong Otp Try again !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#reg-form-otp").trigger('reset');
						$(".reg-otp-verify").html("Verify");
						$(".reg-otp-verify").removeAttr("disabled");
					}, 3500);
				}else{
				    Snackbar.show({
						text: 'Something went wrong Try again !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#reg-form-otp").trigger('reset');
						$(".reg-otp-verify").html("Send Otp");
						$(".reg-otp-verify").removeAttr("disabled");
						$("#register").modal("hide");
						$("#reg_otp").modal("hide");
						window.location.href = location.href;
					}, 3500);
				}
			}
		});
	});
});
// login

// wholesale otp
$(document).ready(function() {
	$("#wholesale-reg-form-otp").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_otp_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".wholesale-reg-otp-verify").html("PLEASE WAIT");
				$(".wholesale-reg-otp-verify").attr("disabled", "disabled");
			},
			success: function(response) {
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Registration successfull please login with us !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: '#151515'
					});
					setTimeout(function() {
						$("#wholesale-reg-form-otp").trigger('reset');
						$(".wholesale-reg-otp-verify").html("Send Otp");
						$(".wholesale-reg-otp-verify").removeAttr("disabled");
						$("#register_wholesaler").modal("hide");
						$("#wholesale_reg_otp").modal("hide");
						$("#login").modal("show");
					}, 3500);
				} else if(response.trim() == "wrong_otp") {
					Snackbar.show({
						text: 'Wrong Otp Try again !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#wholesale-reg-form-otp").trigger('reset');
						$(".wholesale-reg-otp-verify").html("Verify");
						$(".wholesale-reg-otp-verify").removeAttr("disabled");
					}, 3500);
				}else{
				    Snackbar.show({
						text: 'Something went wrong Try again !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#wholesale-reg-form-otp").trigger('reset');
						$(".wholesale-reg-otp-verify").html("Send Otp");
						$(".wholesale-reg-otp-verify").removeAttr("disabled");
						$("#register_wholesaler").modal("hide");
						$("#wholesale_reg_otp").modal("hide");
						window.location.href = location.href;
					}, 3500);
				}
			}
		});
	});
});
// end wholesale otp
$(document).ready(function() {
	$("#wholesaller-form").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".wholesale_reg_btn").html("PLEASE WAIT");
				$(".wholesale_reg_btn").attr("disabled", "disabled");
			},
			success: function(response) {
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Verification code has been sent on your email!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: '#151515'
					});
					setTimeout(function() {
						$("#wholesaller-form").trigger('reset');
						$(".wholesale_reg_btn").html("Send Otp");
						$(".wholesale_reg_btn").removeAttr("disabled");
						$("#login").modal("hide");
						$("#register_wholesaler").modal("hide");
						$("#wholesale_reg_otp").modal("show");
				
					}, 3500);
				} else if(response.trim() == "already") {
					Snackbar.show({
						text: 'You are already register please login!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#wholesaller-form").trigger('reset');
						$(".wholesale_reg_btn").html("Send Otp");
						$(".wholesale_reg_btn").removeAttr("disabled");
						$("#register_wholesaler").modal("hide");
						window.location.href = location.href;
					}, 3500);
				} else {
					Snackbar.show({
						text: 'Registration failed !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#wholesaller-form").trigger('reset');
						$(".wholesale_reg_btn").html("Send Otp");
						$(".wholesale_reg_btn").removeAttr("disabled");
						window.location.href = location.href;
					}, 3500);
				}
			}
		});
	});
});




$(document).ready(function() {
	$("#login-form").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_login_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".login-btn").html("PLEASE WAIT");
				$(".login-btn").attr("disabled", "disabled");
			},
			success: function(response) {
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Login successfull !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: '#151515'
					});
					setTimeout(function() {
						$("#login-form").trigger('reset');
						$(".login-btn").html("Login");
						$(".login-btn").removeAttr("disabled");
						$("#login").modal("hide");
						window.location.href = location.href;
					}, 3100);
				} else if(response.trim() == "notuser") {
					Snackbar.show({
						text: 'You are not register please register first !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#login-form").trigger('reset');
						$(".login-btn").html("Login");
						$(".login-btn").removeAttr("disabled");
						$("#login").modal("hide");
						$("#register").modal("show");
					}, 3300);
				} else {
					Snackbar.show({
						text: 'Login failed try again latter!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#login-form").trigger('reset');
						$(".login-btn").html("Login");
						$(".login-btn").removeAttr("disabled");
					}, 3300);
				}
			}
		});
	});
});
// login otp otp veryfication
$(document).ready(function() {
	$("#otp-form-login").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_otp_login_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".login-with-otp-btn").html("PLEASE WAIT");
				$(".login-with-otp-btn").attr("disabled", "disabled");
			},
			success: function(response) {
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Log in successfull!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: '#151515'
					});
					setTimeout(function() {
						$("#otp-form-login").trigger('reset');
						$(".login-with-otp-btn").html("Verify");
						$(".login-with-otp-btn").removeAttr("disabled");
						$("#login").modal("hide");
						$("#login_otp").modal("hide");
					    window.location.href = location.href;
					}, 3500);
				} else if(response.trim() == "wrong_otp") {
					Snackbar.show({
						text: 'Wrong Otp Try again !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#otp-form-login").trigger('reset');
						$(".login-with-otp-btn").html("Verify");
						$(".login-with-otp-btn").removeAttr("disabled");
					}, 3500);
				}else{
				    Snackbar.show({
						text: 'Something went wrong Try again !',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						$("#otp-form-login").trigger('reset');
						$(".login-with-otp-btn").html("Verify");
						$(".login-with-otp-btn").removeAttr("disabled");
						$("#login").modal("hide");
						$("#login_otp").modal("hide");
						window.location.href = location.href;
					}, 3500);
				}
			}
		});
	});
});
// end login otp veryfication
$(document).ready(function() {
	$("#login-form-checkout").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "user_login_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$(".login-btn-checkout").html("PLEASE WAIT");
				$(".login-btn-checkout").attr("disabled", "disabled");
			},
			success: function(response) {
				if(response.trim() == "success") {
					var notice = document.getElementById("snackbar");
					notice.innerHTML = "Login successfull !";
					notice.style.background = "green";
					notice.className = "show";
					setTimeout(function() {
						notice.className = notice.className.replace("show", "");
						$("#login-form-checkout").trigger('reset');
						$(".login-btn-checkout").html("Login");
						$(".login-btn-checkout").removeAttr("disabled");
						window.location = location.href;
					}, 4000);
				} else if(response.trim() == "notuser") {
					var notice = document.getElementById("snackbar");
					notice.innerHTML = "You are not register please register first !";
					notice.style.background = "red";
					notice.className = "show";
					setTimeout(function() {
						notice.className = notice.className.replace("show", "");
						$("#login-form-checkout").trigger('reset');
						$(".login-btn-checkout").html("Login");
						$(".login-btn-checkout").removeAttr("disabled");
					}, 4000);
				} else {
					var notice = document.getElementById("snackbar");
					notice.innerHTML = "Login failed try again latter!";
					notice.style.background = "red";
					notice.className = "show";
					setTimeout(function() {
						notice.className = notice.className.replace("show", "");
						$("#login-form-checkout").trigger('reset');
						$(".login-btn-checkout").html("Login");
						$(".login-btn-checkout").removeAttr("disabled");
					}, 4000);
				}
			}
		});
	});
});
// subscriber form
$(document).ready(function() {
	$("#subscriber-form").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "subscriber_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			success: function(response) {
				if(response.trim() == "success") {
					Snackbar.show({
						text: 'Thank you for subscriber us!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: '#151515'
					});
					setTimeout(function() {
						$("#subscriber-form").trigger('reset');
					}, 3000);
				} else {
					Snackbar.show({
						text: 'Something Went Wrong Try Again Latter!',
						pos: 'top-right',
						showAction: false,
						actionText: "Dismiss",
						duration: 3000,
						textColor: '#fff',
						backgroundColor: 'red'
					});
					setTimeout(function() {
						notice.className = notice.className.replace("show", "");
						$("#subscriber-form").trigger('reset');
					}, 3000);
				}
			}
		});
	});
});
// manage wishlist
function manage_wishlist(pid, type, qty, vid) {
	var pid = pid;
	var type = type;
	var qty = qty;
	var vid = vid;
	$.ajax({
		url: "manage_wishlist.php",
		method: "POST",
		data: {
			type: type,
			pid: pid,
			qty: qty,
			vid: vid
		},
		success: function(response) {
			if(response.trim() == "allready_exit") {
				Snackbar.show({
					text: 'Your Product Already exits in wishlist !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 1500,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			} else if(response.trim() == "not_login") {
				Snackbar.show({
					text: 'Good Job! Please login first !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 1500,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			} else {
				Snackbar.show({
					text: 'Your product was added to wishlist successfully!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 1500,
					textColor: '#fff',
					backgroundColor: '#151515'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
				$('.wishlist-counter').html(response);
			}
		}
	});
}
// add to cart
function manage_wishlist2(pid, type, qty, vid) {
	var pid = pid;
	var type = type;
	var qty = $("#qty_details").val();
	var vid = $("#attr_id").val();
	$.ajax({
		url: "manage_wishlist.php",
		method: "POST",
		data: {
			type: type,
			pid: pid,
			qty: qty,
			vid: vid
		},
		success: function(response) {
			if(response.trim() == "allready_exit") {
				Snackbar.show({
					text: 'Your Product Already exits in wishlist !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 1500,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			} else if(response.trim() == "not_login") {
				Snackbar.show({
					text: 'Good Job! Please login first !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 1500,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			} else {
				Snackbar.show({
					text: 'Your product was added to wishlist successfully!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 1500,
					textColor: '#fff',
					backgroundColor: '#151515'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1000));
				$('.wishlist-counter').html(response);
			}
		}
	});
}

function manageCartDatabase(pid, type, qty, vid) {
	var pid = pid;
	var type = type;
	var qty = qty;
	var vid = vid;
	$.ajax({
		url: "manage_cart_database.php",
		method: "POST",
		data: {
			pid: pid,
			type: type,
			qty: qty,
			vid: vid
		},
		success: function(response) {
			if(response.trim() == "updated_qty") {
				Snackbar.show({
					text: 'Your Product Quantity added in cart !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'green'
				});
			} else if(response.trim() == "not_login") {
				Snackbar.show({
					text: 'Good Job! Please login first !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			} else {
				Snackbar.show({
					text: 'Your product was added to cart successfully!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: '#151515'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1000));
				$('.cart-counter').html(response);
			}
		}
	});
}

function manage_cart2(pid, type, qty, vid) {
	var pid = pid;
	var type = type;
	var qty = $("#qty_details").val();
	var vid = $("#attr_id").val();
	if(vid==""){
		Snackbar.show({
			text: 'Please Select Color And Size',
			pos: 'top-right',
			showAction: false,
			actionText: "Dismiss",
			duration: 2000,
			textColor: '#fff',
			backgroundColor: 'red'
		});
	}else{
	  
		$.ajax({
		url: "manage_cart_database.php",
		method: "POST",
		data: {
			pid: pid,
			type: type,
			qty: qty,
			vid: vid
		},
		success: function(response) {
			if(response.trim() == "allready_exit") {
				Snackbar.show({
					text: 'Your Product Already exits in cart !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			} else if(response.trim() == "not_login") {
				Snackbar.show({
					text: 'Good Job! Please login first !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			} else {
				Snackbar.show({
					text: 'Your product was added to cart successfully!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: '#151515'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1000));
				$('.cart-counter').html(response);
			}
		}
	});
	}
	
}

function deleteCart(pid, action) {
	$.ajax({
		url: "manage_cart_database.php",
		method: "POST",
		data: {
			pid: pid,
			action: action
		},
		success: function(response) {
			if(response.trim() == "success") {
				Snackbar.show({
					text: 'Your product was  successfully remove from cart!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'green'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			} else {
				Snackbar.show({
					text: 'Try Again Latter!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1000));
			}
		}
	});
}

function deleteWishlist(pid, action) {
	$.ajax({
		url: "manage_wishlist.php",
		method: "POST",
		data: {
			pid: pid,
			action: action
		},
		success: function(response) {
			if(response.trim() == "success") {
				Snackbar.show({
					text: 'Your product was  successfully remove from wishlist!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'green'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1000));
			} else {
				Snackbar.show({
					text: 'Try Again Latter!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1000));
			}
		}
	});
}
// contact form submition
$(document).ready(function() {
	$("#contact-form-contact-page").submit(function(e) {
		e.preventDefault();
		$.ajax({
			type: "POST",
			url: "contact_form_action.php",
			data: new FormData(this),
			processData: false,
			contentType: false,
			cache: false,
			beforeSend: function() {
				$("#contact-submit-btn").html("PLEASE WAIT");
				$("#contact-submit-btn").attr("disabled", "disabled");
			},
			success: function(response) {
			    
				if(response.trim()=="success") {
				    Snackbar.show({
					text: 'Thank you for contact us !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'green'
				}, setTimeout(function() {
						$("#contact-form-contact-page").trigger('reset');
						$("#contact-submit-btn").html("Send");
						$("#contact-submit-btn").removeAttr("disabled");
				}, 1500));
				
				
				
				
				} else {
					 Snackbar.show({
					text: 'Try Again latter !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				}, setTimeout(function() {
						$("#contact-form-contact-page").trigger('reset');
						$("#contact-submit-btn").html("Send");
						$("#contact-submit-btn").removeAttr("disabled");
				}, 1500));
				}
			}
		});
	});
});
// setup coupan system
function set_coupon() {
	var discoun_coupon = $("#checkout-discount-input").val();

	if(discoun_coupon==""){
		Snackbar.show({
					text: 'Please Input Coupon Code !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				});
	}else{
		$.ajax({
		type: "POST",
		url: "set_coupon.php",
		data: {
			discoun_coupon: discoun_coupon
		},
		success: function(response) {
			
		
			
			var data = $.parseJSON(response);
			
			if(data.is_error == "not_login"){
			    	Snackbar.show({
					text: 'Good Job! Login first and apply code',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			}
			
            if(data.is_error == 'yes') {
				Snackbar.show({
					text: 'Coupon is not valid',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			}
			if(data.is_error == 'no') {
				Snackbar.show({
					text: 'Your Coupon is successfull applied',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'green'
				});
				$('#total_price_cart').html('₹' + data.result+'.00');
				$('#coupan_value').html('- '+'₹' + data.coupon_value+'.00');
				$("#total_amount").val(data.result);
				
			
			}
		
		}
	});
	}
	
}
/*filteration data*/
$(document).ready(function() {

  // filter_data();

  function filter_data() {
    $(".filter_data").html('<div class="col-xl-12 col-lg-12 col-md-12 col-12"><div id="loader"></div></div>');
    var action = 'fetch_data';
    var price = $("#price").val();
    var category_id = get_filter('category_id');
    var size = get_filter('size');
    var color = get_filter('color');

   
  

    $.ajax({
      url: "fetch_data.php",
      method: "POST",
      data: {
        action: action,
        category_id: category_id,
        price: price,
        size: size,
        color: color
      },
      beforeSend: function() {
        $(".filter_data").html('<div class="col-xl-12 col-lg-12 col-md-12 col-12"><div id="loader"></div></div>');
      },
      success: function(data) {
        $('.filter_data').html(data);
      }
    });
  }

  function get_filter(class_name) {
    var filter = [];
    $('.' + class_name + ':checked').each(function() {
      filter.push($(this).val());
    });
    return filter;
  }


  $(".common_selector").click(function() {
    filter_data();
  });

  $(".js-range-slider").ionRangeSlider({
		type: "double",
		min: 0,
		max: 5000,
		from:100,
		to:3000,
		grid: true,
		onChange: function () {
            // Called every time handle position is changed
    
             filter_data();
        }
	});

  	
});

function moveToCart(val){
	$.ajax({
		url: "move_to_cart_action.php",
		method: "POST",
		data: {
			val: val
			
		},
		success: function(response) {
		    	if(response.trim() == "success") {
				Snackbar.show({
					text: 'Your product was  successfully move from wishlist!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'green'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			} else {
				Snackbar.show({
					text: 'Try Again Latter!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			}
		
		}
	});
}

function cancealOrder(val){
	
	$.ajax({
		url: "cancel_order.php",
		method: "POST",
		data: {
			val: val
			
		},
		success: function(response) {
			
			if(response.trim() == "success") {
				Snackbar.show({
					text: 'Your order successfully canceal !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'green'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			} else {
				Snackbar.show({
					text: 'Try Again Latter!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			}
		}
	});
}


function manageEnquiry(pid, type, qty, vid) {
	var pid = pid;
	var type = type;
	var qty = qty;
	var vid = vid;
	$.ajax({
		url: "manage_enquiry.php",
		method: "POST",
		data: {
			type: type,
			pid: pid,
			qty: qty,
			vid: vid
		},
		success: function(response) {
			if(response.trim() == "allready_exit") {
				Snackbar.show({
					text: 'Good Job! You are already enquiry this product!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			} else if(response.trim() == "not_login") {
				Snackbar.show({
					text: 'Good Job! Please login first !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				});
			} else {
				Snackbar.show({
					text: 'Thank you for enquiry us we will contact soon!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: '#151515'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
				$('.wishlist-counter').html(response);
			}
		}
	});
}



function deleteEnquiry(pid, action) {
	$.ajax({
		url: "manage_enquiry.php",
		method: "POST",
		data: {
			pid: pid,
			action: action
		},
		success: function(response) {
			if(response.trim() == "success") {
				Snackbar.show({
					text: 'Your product was  successfully remove from enquiry!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'green'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			} else {
				Snackbar.show({
					text: 'Try Again Latter!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			}
		}
	});
}


function deleteAddress(aid,action){
    $.ajax({
		url: "user_address_action.php",
		method: "POST",
		data: {
			aid: aid,
			action: action
		},
		success: function(response) {
			if(response.trim() == "success") {
				Snackbar.show({
					text: 'Your address has been successfully remove !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'green'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			} else {
				Snackbar.show({
					text: 'Try Again Latter!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			}
		}
	});
}

function changDeleiveryAddress(uid,aid,action){
    $.ajax({
		url: "user_address_action.php",
		method: "POST",
		data: {
		    uid: uid,
			aid: aid,
			change_delivery_address: action
		},
		success: function(response) {
			if(response.trim() == "success") {
				Snackbar.show({
					text: 'Your delivery  address has been successfully change !',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'green'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			} else {
				Snackbar.show({
					text: 'Try Again Latter!',
					pos: 'top-right',
					showAction: false,
					actionText: "Dismiss",
					duration: 2000,
					textColor: '#fff',
					backgroundColor: 'red'
				}, setTimeout(function() {
					window.location.href = location.href;
				}, 1500));
			}
		}
	});
}





// Function to copy text to the clipboard
function copyTextToClipboard(value,action) {
  // Select the text input field
  

  // Create a text area element to copy the text
  var textArea = document.createElement("textarea");
  textArea.value = value;
  
  // Append the text area to the document
  document.body.appendChild(textArea);

  // Select the text in the text area
  textArea.select();
  
  // Copy the selected text to the clipboard
  document.execCommand("copy");

  // Remove the temporary text area
  document.body.removeChild(textArea);

  // Display a message indicating that the text has been copied
 
  $("#checkout-discount-input").val(value);
  
  
  alert("Coupon Code has been copied to the clipboard");
}



