//*************toastr options settings start**************// 
function toastr_option(){
	toastr.options = {
		"closeButton": false,
		"debug": false,
		"newestOnTop": false,
		"progressBar": false,
		"positionClass": "toast-bottom-right",
		"preventDuplicates": true,
		"onclick": null,
		"showDuration": "300",
		"hideDuration": "1000",
		"timeOut": "5000",
		"extendedTimeOut": "1000",
		"showEasing": "swing",
		"hideEasing": "linear",
		"showMethod": "fadeIn",
		"hideMethod": "fadeOut"
	}
}
 
//*************toastr options settings end*************//
 $(document).ready(function(){ 
	$("#forgot_model_click").click(function(){
		$("#myModal1").modal('hide');
	});
	$("#register_modal_click").click(function(){
		$("#myModal1").modal('hide');
	});
}) 

//************** Set GDPR Cookie start*****************//  
$(document).ready(function(){ 
	$(".close_cookie").click(function(){
		$(".cookie_popup").hide(100);
	});
});

function set_gdprcookie(){
	var baseurl =$("#baseurl").val();
	jQuery.ajax({
		type: "POST",
		url: baseurl + "login/set_gdprcookie",
		success: function(resp){
						if(resp ==1){
							$(".cookie_popup").hide(100);
						} 						
				}
	});
}
//************** Set GDPR Cookie end*****************//  

//**********add datatable start*******************// 
$(document).ready(function() {
    $('.example').DataTable();
});
//**********add datatable end******************//  

//**********add active class on click header menu *********//
$(document).ready(function(){
	$('.fd_menu ul li a').click(function(){
		$(this).parents().find('ul li.active').removeClass("active");
		$(this).closest('li').addClass("active");
	});
});
//**********add active class on click header menu *********//

//***************add new user end********************//  
function addnew_user(){
	 
	var baseurl =$("#baseurl").val();
	var user_name =$.trim($("#user_name").val());
	var user_email =$.trim($("#user_email").val());
	var user_password =$.trim($("#user_password").val());
	var user_conf_password =$.trim($("#user_confpassword").val());
	var pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$";
	var error=0;

	toastr_option();
	 
	if(user_name == ""){
		 toastr.error('Please Enter Name')  
		 error++;
	}else if(user_email == "")                                  
    {	toastr.error('Please Enter Email Address')
		error++;
    }else if(!user_email.match(pattern))                
    {	toastr.error('Please Enter Valid Email Address')
        error++;
    }else if(user_password == "")                       
    {  	toastr.error('Please Enter Password')
        error++;
    }else if(user_password.length<6)
	{  	toastr.error('Password must be at least 6 characters long')
		error++;
	}else if(user_conf_password == "")                       
    {  	toastr.error('Please Enter Confirm Password')
        error++;
    }else if(user_conf_password.length<6)
	{  	toastr.error('Password must be at least 6 characters long')
		error++;
	}else if(user_password !== user_conf_password)
	{  	toastr.error('Please Confirm Your Password')
		error++;
	}
	
     if(error == 0){
		 
		jQuery.ajax({
		type: "POST",
		url: baseurl + "register/register_user",
		data: {u_name: user_name ,u_email: user_email,u_password: user_password},
		success: function(resp){
			 
					if(resp == 0){
						toastr.error('Data Not Valid')
					}else if(resp ==1){
						toastr.success('User Register Successfuly. Please Check your Email To Verify Your Email Id')
						setTimeout(function(){ window.location.href = baseurl; 
						}, 3000);
					}else if(resp ==2){
						toastr.error('This Email Address Already Registered');
					} 						
											
				}
		}); 
	}   
	 
} 
//***************add new user end***********************// 
 
//**********login form validation**********//
 function login_validationfunction(){
	var baseurl =$("#baseurl").val(); 
	var user_email= $.trim($("#uemail").val());
    var user_password= $.trim($("#upassword").val());
	var isChecked = $("#user_remember").is(":checked");
	if (isChecked == true) {
	   
		var user_remember = 1;
	 
	}else{
		var user_remember = 0;
	   
	}
	
    var pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$";
    var error=0;
	
	toastr_option(); 
  
	if(user_email == "")
	{	toastr.error('Please enter email Address')  
		error++;
    }else if (!user_email.match(pattern))                
    { 	toastr.error('Please enter a valid e-mail address')
        error++;
    }else if(user_password == "")                       
    { 	toastr.error('Please enter your password')
        error++;
    }else if(user_password.length<6)
	{   toastr.error('Password must be at least 6 characters long')
		error++;
	} 
	
	if(error == 0){

		jQuery.ajax({
		type: "POST",
		url: baseurl + "login/login_user",
		data: {email: user_email, pwd: user_password, u_remeber: user_remember},
		success: function(resp) {
			 
					if(resp == 0){
						toastr.error('email or password does not matched')
					}else if(resp == 1){
						toastr.success('login successfull') 
						window.location.href = baseurl + "admin/dashboard";
					}else if(resp == 2){
						toastr.success('login successfully') 
						window.location.href = baseurl;
					}else if(resp == 3){
					   toastr.error('Please, Activate Your Account')
					}  
				 }
		}); 
	} 
      
 } 
 
//**********Forgot password validation**********//
 function forgot_password(){
	var baseurl =$("#baseurl").val(); 
	var user_email= $.trim($("#forgot_uemail").val());
    var pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$";
    var error=0;
	
	toastr_option(); 
  
	if(user_email == "")
	{	toastr.error('Please enter email Address')  
		error++;
    }else if(!user_email.match(pattern))                
    { 	toastr.error('Please enter a valid e-mail address')
        error++;
    }  
	
	if(error == 0){

		jQuery.ajax({
		type: "POST",
		url: baseurl + "login/forgot_password",
		data: {useremail: user_email},
		success: function(resp) {
			 
					if(resp == 0){
						toastr.error('this email id not registered')
						 
					}else if(resp == 1){
						toastr.success('Please Check your mail ! Reset Link sent') 
						window.location.href = baseurl;
					}else if(resp == 2){
						toastr.error('please confirm your password ! try again')
					}else if(resp == 3){
						toastr.error('Something went wrong!Try Again"')
						window.location.href = baseurl;
					}							
			 }
		}); 
	} 
  } 
 
//************ user reset password *************// 
function reset_password(){	  
	var baseurl =$("#baseurl").val();
	var resetcode =$.trim($("#reset_code").val());
	var u_newpass =$.trim($("#unew_pass").val());
	var u_confpass=$.trim($("#conf_pass").val());
	var error=0;
	toastr_option();  
	event.preventDefault();
	 
	if (u_newpass == "") 
    {   toastr.error('Please enter your new password')
        error++;
    }else if(u_newpass.length<6)
	{   toastr.error('Password must be at least 6 characters long')
	    error++;
	}else if (u_confpass == "")                       
    { 	toastr.error('New password and Confirm pasword must be same')
        error++;
    }else if(u_confpass.length<6)
	{   toastr.error('Password must be at least 6 characters long')
	    error++;
	}else if(u_newpass !== u_confpass ){
        toastr.error('please confirm your password')
        error++;
	}	
	  
	if(error == 0){ 
		 
		jQuery.ajax({
		type: "POST",
		url: baseurl + "login/reset_password",
		data: {verify_code: resetcode,u_newpass: u_newpass,u_confpass: u_confpass},
		success: function(resp) {
			 
					if(resp == 0){
					  toastr.error('data not valid')
					  
					}else if(resp == 1){
						 
						toastr.success('password change successfully! you can login now.')
						window.location.href =baseurl;
					}     
				}
		});  
	}   
}	 

//*********pass table id to booking form******//
function booktable_id(table_id){
    if(table_id !== ''){
		$("#btable_id").val(table_id);
			$('html, body').animate({
				scrollTop: $("#booking_form").offset().top
			}, 1000) 
	}	
}	
//on click table scroll to booking form
$(document).ready(function(){
	$('.fd_table_box ul li').click(function(){
		$(this).parents().find('ul li.table_active ').removeClass("table_active");
		$(this).closest('li').addClass("table_active");
	});
});

//*********pass table id to booking form******// 
 
  
//****************table booking section start***********//
function table_booking(){
 
	var baseurl =$("#baseurl").val();
	var btable_id = $("#btable_id").val();
	var booking_date =$.trim($("#b_date").val());
	var booking_time =$.trim($("#b_time").val());
	var no_of_person =$.trim($("#no_of_people").val());
	var booking_occasion =$.trim($("#b_occasion").val());
	var boking_preferredfood =$.trim($("#b_preferredfood").val());
	var booking_name =$.trim($("#b_name").val());
	var booking_email =$.trim($("#b_email").val());
	var booking_massage =$.trim($("#b_msg").val());
	var pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$";
	var num_pattern = /[^0-9]/g;
	var error=0;
	toastr_option();
	
	if(btable_id == ""){
          
        toastr.error('please select table first')
	    error++;

	}else if(booking_date == ""){
          
        toastr.error('please select booking date')
	    error++;

	}else if(booking_time == ""){
 
	    toastr.error('please select time')
		error++;

	}else if(no_of_person == 0){
 
	    toastr.error('please select no. of person') 
		error++;

	}else if(num_pattern.test(no_of_person) == true){
 
	    toastr.error('please enter valid value') 
		error++;

	}else if(booking_name == ""){
		 
		toastr.error('please enter name')  
        error++;
		
	}else if (booking_email == ""){
		
		toastr.error('please enter email address') 
		error++;
    }else if (!booking_email.match(pattern))                
    {    
        toastr.error('please enter valid email address') 
        error++;
    } 	
	
	if(error == 0){

		jQuery.ajax({
		type: "POST",
		url: baseurl + "booktable/book_table",
		data: {book_date: booking_date, book_time: booking_time, no_person: no_of_person, booktable_id: btable_id, book_occasion: booking_occasion, book_preferredfood: boking_preferredfood, book_name: booking_name, book_email: booking_email, book_msg: booking_massage},
		success: function(resp) {
			 
					if(resp == 0){
						toastr.error('data not valid') 
					}else if(resp == 1){
						toastr.success('Table Booked Successfully') 
						window.location.href = "";
					}else if(resp == 2){
						toastr.error('Table Not Available on selected time!') 
					}  
				}
		});   
	}  
}
//****************table booking section end******************//
 
//****************contact_us section start*******************//
 
$(document).ready(function(){ 
	$("#contactus_form").submit(function(){
 
	var baseurl =$("#baseurl").val();
	var contact_fname =$.trim($("#fname").val());
	var contact_lname =$.trim($("#lname").val());
	var contact_email =$.trim($("#con_email").val());
	var contact_subject =$.trim($("#con_subject").val());
	var contact_comment =$.trim($("#comment").val());
	var pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$";
	var error=0;
	event.preventDefault();
	toastr_option();
 
	if(contact_fname == ""){
          
        toastr.error('Please Enter First Name')
	    error++;

	}else if(contact_lname == ""){
 
	    toastr.error('Please Enter Last Name')
		error++;

	}else if (contact_email == ""){
		
		toastr.error('Please Enter Email Address') 
		error++;
    }else if (!contact_email.match(pattern))                
    {    
        toastr.error('Please Enter Valid Email Address') 
        error++;
    }else if (contact_subject == ""){
		
		toastr.error('Please Enter Subject') 
		error++;
    }else if (contact_comment == ""){
		
		toastr.error('Please Enter Comment') 
		error++;
    } 	
	
	if(error == 0){
		  
		jQuery.ajax({
		type: "POST",
		url: baseurl + "contact_us/contact",
		data: new FormData(this),
		contentType: false,       
		cache: false,             
		processData:false,
		success: function(resp) {
			 
					if(resp == 0){
					toastr.error('data not valid ') 
					}else if(resp == 1){
						toastr.success('Data Saved Successfully') 
						window.location.href = baseurl;
					}  
			 }
		});    
	} 
	});
});
//****************contact_us section end*****************//
 
//****************comment form section start*************//  
$(document).ready(function(){ 
	$("#comment_form").submit(function(){

	var baseurl =$("#baseurl").val();
	var comment_name =$.trim($("#comment_name").val());
	var comment_email =$.trim($("#comment_email").val());
	var comment_content =$.trim($("#comment").val());
	var pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$";
	var error=0;
	event.preventDefault();
	toastr_option();
 
	if(comment_name == ""){
          
        toastr.error('Please Enter Name')
	    error++;

	}else if (comment_email == ""){
		
		toastr.error('Please Enter Email Address') 
		error++;
    }else if (!comment_email.match(pattern))                
    {    
        toastr.error('Please Enter Valid Email Address') 
        error++;
    }else if (comment_content == ""){
		 
		toastr.error('Please Enter Comment') 
		error++;
    }else if (comment_content.length >300){
		toastr.error('comment should be 300 character long only!') 
		error++;
    }  
	 
	if(error == 0){
	   
		jQuery.ajax({
		type: "POST",
		url: baseurl + "contact_us/user_comment",
		data: new FormData(this),
		contentType: false,       
		cache: false,             
		processData:false,
		success: function(resp) {
			 
					if(resp == 0){
						toastr.error('data not valid') 
					}else if(resp == 1){
						toastr.success('Data Saved Successfully') 
						window.location.href ="";
					}  
				}
		});    
	}   
	});
});  
//****************comment form section end*************//   
 
//****************show product on home page start********************//  
//swiper slider initialize
function swiper(){
	new Swiper('.fd_food_menu .swiper-container', {
	  slidesPerView: 4,
	  slidesPerColumn: 2,
	  spaceBetween: 30,
	  loop: false,
	  autoplay:false,
	  speed: 1500,
	  pagination:false,
	   navigation: {
		  nextEl: '.swiper-button-next',
		  prevEl: '.swiper-button-prev',
		},
	});
}   

function display_products(prod_cate_id){
	 
	var baseurl =$("#baseurl").val();
		   
	jQuery.ajax({
	type: "POST",
	url: baseurl + "home/display_products",
	dataType: 'json',
	data: {cate_id: prod_cate_id},
	success: function(resp) {
				if(resp !== 0){
					setTimeout(function () {
					$("#show_menu").html(resp);
					swiper();  	
					}, 100);
				}else{
					$("#show_menu").html('');
				}					
			}
	});   
} 
//****************show product on home page end********************//  
  
//****************show blog by category start********************//  
function show_blog_bycategory(blog_cate_id){
	 
	var baseurl =$("#baseurl").val();
	       
	jQuery.ajax({
	type: "POST",
	url: baseurl + "blogs/display_blog_bycategory",
	dataType: 'json',
	data: {blogcate_id: blog_cate_id},
	success: function(resp) {
				if(resp !== 0){
					$("#show_blog").html(resp);
				}else{
					$("#show_blog").html('');
				} 						
			}
	});  
}  
//****************show blog by category end********************// 

//****************load more portfolio **********************// 
var counts =9;
function loadmore_portfolio(){
	var baseurl =$("#baseurl").val();
		jQuery.ajax({
		type: "POST",
		url: baseurl + "home/loadmore_portfolio",
		//dataType: 'json',
		data: {portfolio_offset: counts},
		success: function(resp){
				var res = JSON.parse(resp);
				if(res !== ""){
					var $content = $(res.output);
					$grid = $('.grid').isotope();
					$grid.append( $content ).isotope( 'appended', $content );
					$grid.imagesLoaded().progress( function() {
					$grid.isotope('layout');
					});
					counts = counts+3;
				
					if(res.total_port < 3){
						$("#loadmre_btn").hide();
					}
				} 
		}							
	});   
 } 
//****************load more portfolio **********************// 

//****************add to cart section start********************//  
function add_to_cart(prod_id,prod_qty){
	 
	var baseurl =$("#baseurl").val();
	toastr_option();
	var error = 0;
	
	if(prod_id !== ''){ 
		var prod_quantity;
		if(prod_qty == null){
			var prod_quantity = $("#quantity").val();
			if(prod_quantity == 0){
				 toastr.error('Invalid Quantity') 
				 error++; 
			}
		}else{
			prod_quantity = prod_qty;
		} 
			 
		if(error == 0){ 
			
			jQuery.ajax({
			type: "POST",
			url: baseurl + "cart/add_to_cart",
			data: {product_id: prod_id, product_quantity: prod_quantity},
			success: function(resp){
				 
					if(resp !== ''){
						if(resp == 0){
							toastr.error('out of stock') 
						}else{
							toastr.success('Item Added To Cart') 
							$("#show_cart_item").html(resp)
						}
					}else{
						toastr.error('Item Not Added To Cart')
					} 						
				}
			});   
		}  
	} 
}
//*********load cart on loading page star*************//
function loadcartitem(){ 
var baseurl =$("#baseurl").val();
	jQuery.ajax({
            type: "POST",
            url: baseurl + "cart/showcart",
			success: function(resp){
			 
				$("#show_cart_item").html(resp);
				
			}
		});
} 
loadcartitem();
//*********load cart on loading page end*************//
 	
//******* remove product from cart start*************// 
function remove_cartitem(prod_rowid,prod_id){
	var baseurl =$("#baseurl").val();
	toastr_option();	  
	if(prod_rowid !== ''){ 
	     
		jQuery.ajax({
		type: "POST",
		url: baseurl + "cart/remove_cartitem",
		data: {prodrowid: prod_rowid, prodid : prod_id},
		success: function(resp) {
				 var respData = JSON.parse(resp);
					if(respData['staus'] == 1){
						toastr.success('Item Removed From Cart') 
						loadcartitem();
						loadview_cart();
						setTimeout( function() {
							calculate_discount();	 
							}, 1000);
						
						if(respData['discount_session'] == 1){
							$("#discount_amount_div").html('');	
							$("#final_amount_div").html('');
						}
					}else{
						$("#show_cart_item").html('');
						$("#view_cart").html('');
					} 						
				}
		});
	  }
}
//******* remove product from cart end*************// 

//*************cart item quantity plus/minus start*********//
 function quantity_minus(prow_id,pid){
	var qty = 0;
	var baseurl =$("#baseurl").val();
	toastr_option();
	var qty = parseInt($("#quantity_"+prow_id).val());
	if(qty>1){
		$("#quantity_"+prow_id).val(qty - 1);
		var quantity = $.trim($("#quantity_"+prow_id).val());
		 
		jQuery.ajax({
		type: "POST",
		url: baseurl + "cart/quantity_update",
		data: {p_rowid: prow_id, prod_id: pid, prod_qty: quantity},
		success: function(resp){
				if(resp == 1){
					loadcartitem();
					loadview_cart();
					setTimeout( function() {
							calculate_discount();	 
							}, 1000);
				}else if(resp == 2){
					toastr.error("Out of stock")
				}
			}
			 
		});
	}
}

function quantity_plus(prow_id,pid){
	var qty = 0;
	var baseurl =$("#baseurl").val();
	toastr_option();
	var qty = parseInt($("#quantity_"+prow_id).val());
	$("#quantity_"+prow_id).val(qty + 1);
	var quantity = $.trim($("#quantity_"+prow_id).val());
	jQuery.ajax({
		type: "POST",
		url: baseurl + "cart/quantity_update",
		data: {p_rowid: prow_id, prod_id: pid, prod_qty: quantity},
		success: function(resp){
			if(resp == 1){
				loadcartitem();
				loadview_cart();
				setTimeout( function() {
							calculate_discount();	 
							}, 1000);
			}else if(resp == 2){
				toastr.error("Out of stock")
			}
		} 
	});
}

//*************cart item quantity plus/minus end*********//
 
//************load view cart start**************// 
 function loadview_cart(){
	var baseurl =$("#baseurl").val();
	jQuery.ajax({
	type: "POST",
	url: baseurl + "cart/loadview_cart",
	success: function(resp){
				var myObject = JSON.parse(resp);
				$("#view_cart").html(myObject.output);
				$("#grand_total").html(myObject.total);
				if(myObject.cart_res == 1){
					$("#checkout_btn").attr("href", "javascript:;");
					$("#checkout_btn").click(function () {
						toastr_option();
						toastr.error('Your cart is empty! Please add item in cart.')
					});
					$('#verify_coupen').attr("disabled", true);
					$("#discount_amount").html(0);	
					$("#final_amount").html(0);
				}
		}
	});
}
loadview_cart();
//************load view cart end*********// 

//*********clear cart start*************//
function clear_cart(){
	var baseurl =$("#baseurl").val();
	toastr_option();
	jQuery.ajax({
		type: "POST",
		url: baseurl + "cart/clear_cart",
		success: function(resp){
			if(resp == 1){
				toastr.success('Cart Clear Successfully')
				loadcartitem();
				loadview_cart();
			}
		}
	});
}
//*********clear cart start *************//  
//****************add to cart section end**********// 

//*************GET RATING/REVIEW DATA START***********//
$(document).ready(function(){ 
	$("#rating_form").submit(function(){
		
	var baseurl =$("#baseurl").val();
	var ratingstar =$.trim($("#rating_stars").val()); 
	var review =$.trim($("#comment").val()); 
	event.preventDefault();
	var error =0;
	toastr_option();
	if(ratingstar == ""){
		toastr.error('Please Select Some Rating Stars') 
		error++;	
	}else if(review == ""){
		toastr.error('Please Enter Review') 
		error++;	
	}
	if(error == 0){
		jQuery.ajax({
		type: "POST",
		url: baseurl + "contact_us/user_rating",
		data: new FormData(this),
		contentType: false,       
		cache: false,             
		processData:false,
		success: function(resp){
			 
					if(resp == 0){
					toastr.error('data not valid') 
					}else if(resp !== ''){
						toastr.success(resp) 
						window.location.href ="";
					}  
				}
		});     
	}
	});
});	


$(document).ready(function(){ 
	        
	$('li.current i.fa.fa-star.star_rating').mouseover(function(){
		obj = $(this);
		$('li.current i.fa.fa-star.star_rating').removeClass('selected');
		$('li.current i.fa.fa-star.star_rating').each(function(index){
			$(this).addClass('selected');
			if(index == $('li.current i.fa.fa-star.star_rating').index(obj)){
				return false;
			}
		});
	});

    $('li.current i.fa.fa-star.star_rating').mouseleave(function(){
        $('li.current i.fa.fa-star.star_rating').removeClass('selected');
    }); 

	$('li.current i.fa.fa-star.star_rating').click(function(){
        obj = $(this);
        $('li.current i.fa.fa-star.star_rating').each(function(index){
            $(this).addClass('selected');
            $('#rating_stars').val((index+1));
            if(index == $('li.current i.fa.fa-star.star_rating').index(obj)){
                return false;
            }
        });
    });

	$('li.current i.fa.fa-star.star_rating').mouseleave(function(){
        if($('#rating_stars').val()){
            $('li.current i.fa.fa-star.star_rating').each(function(index){
                $(this).addClass('selected');
                if((index+1) == $('#rating_stars').val()){
                    return false;
                }
            });
        }
    });   
});  
	
//****************GET RATING DATA END**************// 

//****************search product start*************//		
 
$(document).ready(function(){ 
	$("#selected_item").keyup(function(){	 
	var baseurl = $.trim($("#baseurl").val()); 
	var search_product = $.trim($(this).val());
	if(search_product.length>2){
    
		jQuery.ajax({
		type: "POST",
		url: baseurl + "home/searching_products",
		data: {search_item: search_product},  
		success: function(resp){
					if(resp !==''){
						$("#show_list").fadeIn();
						$("#show_list").html(resp); 
					}else{
						$("#show_list").fadeOut();
						$("#show_list").html('');
					}						
				}
		});     
	}else{
		$("#show_list").fadeOut(); 
		$("#show_list").html('');
	}
});
  
});	 
 
//************search product start***************//			
 		
//************ update user basic information start*****//
$(document).ready(function(){ 
	$("#update_ubasic_info").submit(function(){
	var baseurl =$("#baseurl").val();
	var user_pic = $("#user_pic").val();
	var error=0;
	event.preventDefault();	 
	toastr_option();			
	if(user_pic !== ""){
		var  extension = user_pic.split('.').pop();
		if (extension  == "gif" || extension == "png" || extension == "bmp" || extension == "jpeg" || extension == "jpg") {
			error = 0;
		}else
		{	toastr.error('Photo only allows file types of GIF, PNG, JPG, JPEG') 
			error++;
		}
    }		
				
	if(error == 0){
		jQuery.ajax({
		type: "POST",
		url: baseurl + "user/update_user_basicinfo",
		data: new FormData(this),
		contentType: false,       
		cache: false,             
		processData:false,  
		success: function(resp){
					if(resp == 0){
						toastr.error('Profile not update successfully! try again')
					}else{ 
					   toastr.success('Profile update successfully')
					}						
				}
		});     
	}	
});
//************ update user basic information end*****//	 


//*********update user billing information start*****//  
$("#update_ubilling_info").submit(function(){
	
	var baseurl =$("#baseurl").val();
	var update_umobile = $.trim($("#update_umobile").val());
	var mobilepattern = /[^0-9]/g;
	var error=0;
	event.preventDefault();	 
	toastr_option();			
	if(update_umobile !== ""){
		if(mobilepattern.test(update_umobile) == true) 
		{   toastr.error('Please Enter Valid Phone No.')
			error++;
		}		
	}
		
	if(error == 0){
        jQuery.ajax({
		type: "POST",
		url: baseurl + "user/update_user_billinginfo",
		data: new FormData(this),
		contentType: false,       
		cache: false,             
		processData:false,  
		success: function(resp){
			 
					if(resp == 0){
						toastr.error('Profile not update successfully! try again')
					}else{ 
					   toastr.success('Profile update successfully')
						
					}						
				}
		});     
    }	
});
//*********update user billing information end*****//  

//*********update user password start*****//  
	$("#reset_userpassword_form").submit(function(){
	var baseurl =$("#baseurl").val();
	var user_newpwd =$.trim($("#update_npwd").val());
	var user_confpwd =$.trim($("#update_confpwd").val());
	var error=0;
	toastr_option();  
	event.preventDefault();
	 
	if(user_newpwd == "") 
    {   toastr.error('Please enter your new password')
        error++;
    }else if(user_newpwd.length<6)
	{   toastr.error('Password must be at least 6 characters long')
	    error++;
	}else if (user_confpwd == "")                       
    { 	toastr.error('Please enter confirm password')
        error++;
    }else if(user_confpwd.length<6)
	{   toastr.error('Password must be at least 6 characters long')
	    error++;
	}else if(user_newpwd !== user_confpwd ){
        toastr.error('New password and Confirm pasword must be same')
        error++;
	}	
	  
	if(error == 0){ 
		 
		jQuery.ajax({
		type: "POST",
		url: baseurl + "user/reset_user_password",
		data: new FormData(this),
		contentType: false,       
		cache: false,             
		processData:false,
		success: function(resp){
			 
					if(resp == 0){
					  toastr.error('password not change successfully! try again')
					}else if(resp == 1){
						toastr.success('password change successfully.')
					}     
				}
		});   
	}  

 });
   //*********update user password end*****// 
});

//************checkout start*************//  
$(document).ready(function(){ 
	$("#verify_coupen").click(function(){
	var baseurl =$("#baseurl").val();
	var coupencode =$.trim($("#coupen_code").val());
	toastr_option();
	if(coupencode !== ''){
		jQuery.ajax({
		type: "POST",
		url: baseurl + "checkout/verify_coupen",
		data: {coupen_code: coupencode} ,
		success: function(resp) {
					 var respData = JSON.parse(resp);
					 if(respData['status'] == 1){ 
							var currency_symbol= respData['currency_symbol']
							var grand_total = $("#grand_total").text();
							var final_amount = grand_total - respData['final_amount'];
							var discount_amount ='<div class="price_summery"><h3>Discount Amount</h3><h5 ><span>'+currency_symbol+'</span> <span id="discount_amount">'+respData['final_amount']+'</span></h5></div>';
							var final_amount =' <div class="price_summery"><h3>Final Amount</h3><h5 ><span>'+currency_symbol+'</span> <span id="final_amount">'+final_amount+'</span></h5></div>';
							$("#discount_amount_div").html(discount_amount);
							$("#final_amount_div").html(final_amount);							
							toastr.success('Promo Code Apply Succesfuly')		
					 }else{
						 toastr.error(respData['error'])
					 }
				}
			});
	}else{
			toastr.error('Please Enter Coupen Code')
	}		
	
	});

	$("#checkout_form").submit(function(){
	var baseurl =$("#baseurl").val();
	var u_fname =$.trim($("#ufname").val());
	var u_lname =$.trim($("#ulname").val());
	var u_email =$.trim($("#ucheck_email").val());
	var u_contact =$.trim($("#ucontact").val());
	var u_address =$.trim($("#uaddress").val());
	var u_city =$.trim($("#ucity").val());
	var u_pincode =$.trim($("#upincode").val());
	var pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$";
	var mobilepattern = /[^0-9]/g;
	var error=0;
	toastr_option();  
	event.preventDefault();
	if(u_fname == "") 
    {   toastr.error('Please Enter First Name')
        error++;
    }else if(u_lname == "")                       
    { 	toastr.error('Please Enter Last Name')
        error++;
    }else if(u_email == "")                       
    { 	toastr.error('Please Enter Email Id')
        error++;
    }else if(!u_email.match(pattern))                
    {	toastr.error('Please Enter Valid Email Address')
        error++;
    }else if(u_contact == "")                       
    { 	toastr.error('Please Enter Contact No.')
        error++;
    }else if(mobilepattern.test(u_contact) == true) 
	{   toastr.error('Please Enter Valid Contact No.')
				error++;
	}else if(u_address == "")                       
    { 	toastr.error('Please Enter Full Address')
        error++;
    }else if(u_city == "")                       
    { 	toastr.error('Please Enter Your City')
        error++;
    }else if(u_pincode == "")                       
    { 	toastr.error('Please Enter Pin Code')
        error++;
    }else{
		var isChecked = $('[name="payment_group"]').is(":checked");
		if (isChecked !== true) {
				toastr.error('Please Select Payment Option')
				error++;  
		}
	}		
	if(error == 0){ 
		 
		jQuery.ajax({
		type: "POST",
		url: baseurl + "checkout/checkout_payment",
		data: new FormData(this),
		contentType: false,       
		cache: false,             
		processData:false,
		success: function(resp) {
					if(resp == 0  || resp == 4 ){
						toastr.error('Something went wrong. please try again!')
					}else if(resp == 5){
						toastr.error('Your Cart is empty ! Please add item in cart')
						
					}else if(resp == 3){
					
						toastr.error('Your Wallet Balance Is Low. Please Recharge Your Wallet And Try Again or Choose Another Payment Option!')
						
					}else{
						$("#show_paymentform").html(resp);
						$("#payaple_form").submit();	
					}
				}
		});    
	} 
	});
});
//************checkout end*************//

function calculate_discount(){
	var dis_amount = $("#discount_amount").text();
	var grand_total =$("#grand_total").text();
	var calc_discount = grand_total - dis_amount;
	$("#final_amount").text(calc_discount);
} 
 
		