
// Increase product quantity on cart page
$(".increaseQty").on('click', function(){
    var getval=("#setavlqty").html();
     var maxVal = $(this).attr('avlincqty');
     alert(getval);
    var minVal = 1 ; // Set Max and Min values
        var $parentElm = $(this).parents(".qtySelector");
        $(this).addClass("clicked");
        setTimeout(function(){
            $(".clicked").removeClass("clicked");
        },100);
        var value = $parentElm.find(".cart-quantity-input").val();
        if (value < maxVal) {
            value++;
        }
        $parentElm.find(".cart-quantity-input").val(value);
});
// Decrease product quantity on cart page
$(".decreaseQty").on('click', function(){
        var $parentElm = $(this).parents(".qtySelector");
        $(this).addClass("clicked");
        setTimeout(function(){
            $(".clicked").removeClass("clicked");
        },100);
        var value = $parentElm.find(".cart-quantity-input").val();
        if (value > 1) {
            value--;
        }
        $parentElm.find(".cart-quantity-input").val(value);
    });


        $(".getsize").click(function () {
    // var size = $(this).attr('size');
    var price = $(this).attr('price');
    var mrp = $(this).attr('mrp');
    var cprice = $(this).attr('cprice');
    var cmrp = $(this).attr('cmrp');
    var currency = $(this).attr('currency');
    // var productid = $(this).attr('productid');
    var unitsize = $(this).attr('getunitsize');
    var skucode = $(this).attr('getskucode');
    var productid = $(this).attr('getproductid');
    var varientid = $(this).attr('getvarientid');
    // $('#addtocart').attr('price',price)
    // $('#addtocart').attr('productid',productid)
    // productid
    $("#setsalprice").html("<del style='color: grey;'>"+cmrp+"</del><span>"+cprice+"</span>");
    // $("#setmrp").html(price);

    // $('.getsize').removeClass('selectsize');
    // $(this).addClass('selectsize');
    // alert(unitsize);
    // exit();
    $('#getproductsize').val(unitsize);
    $('#getproductprice').val(price);
    $('#getproductmrp').val(mrp);
    $('#getskucode').val(skucode);
    $('#getproductid').val(productid);
    $('#getcurrency').val(currency);
    $('#getvarientid').val(varientid);
  })

  function myFunction() {
  var x = document.getElementById("snackbar");
  x.className = "show";
  setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}

/// auto login 
    var userid=localStorage.getItem("userloginid");
      // alert(userid)
    if(userid==null){
        console.log(userid)
    }else{
          
         $.ajax({
            type: "POST",
            url: "function/ajax_function.php",
            data: "action=autoLogin&userid="+userid,
            success: function(html) {
                if(html==1){
                    location.reload()
                }
            }
        });   
    }

/// auto login close 

$(".logout").click(function() {
    // alert('call')
    $.ajax({
        type: "POST",
        url: "function/ajax_function.php",
        data: "action=logout",
        success: function(html) {
            localStorage.clear()
            window.location.href = "index.php";
        }
    });
});   


$(".addtocart").click(function () {
     var quantity  =   $("#steve").val();
     var pprice =   $("#getproductprice").val(); 
     var pmrp   =   $("#getproductmrp").val(); 
     var sku   =   $("#getskucode").val(); 
     var productid   =   $("#getproductid").val(); 
     var currency   =   $("#getcurrency").val(); 
     var varientid   =   $("#getvarientid").val(); 
     var totalselect   =   $("#totalselect").val(); 
      var size   =  $("#getproductsize").val(); 
    

    //  alert("quantity="+quantity+"price ="+pprice+" productid = "+productid+" sku = "+sku+" mrp ="+pmrp+" currency ="+currency+" varientid ="+varientid);
    
      if(size ==""){
      $("body").append("<div class='selectsize-notification animated fadeIn'>Please Select Deity Size !</div>");
      $(".selectsize-notification").delay(2000).fadeOut();
   
      return false
      }
     // alert(pprice);
   //alert("quantity="+quantity+"price ="+pprice+" productid = "+productid+" sku = "+sku+" mrp ="+pmrp);
        $("body").append("<div class='add2cart-notification animated fadeIn'>Added to cart successfully!</div>");
        $(".add2cart-notification").delay(2000).fadeOut();
    //exit();
      // $(this).html('<i class="fa fa-circle-o-notch fa-spin" aria-hidden="true"></i>')
      //   $(this).html('Added to Cart')
       // $(this).css("background-color","#979C01")
          $.ajax({
          type: "POST",
          url: 'function/ajax_function.php',
          data: "action=addCart&quantity="+quantity+"&price="+pprice+"&productid="+productid+"&sku="+sku+"&mrp="+pmrp+"&currency="+currency+"&varientid="+varientid+"&size="+size,
          success: function(returndata){
               var obj = jQuery.parseJSON( returndata );
               if(obj.data[0].status==1){
     
                 $('.cartvalue').html(obj.data[0].cart);
                    // location.reload();
                 

               }
            // ==============================  
            }
      }); 
    
});

$(".addtocart2").click(function () {
     var quantity  =   $("#steve").val();
     var pprice =   $("#getproductprice1").val(); 
     var pmrp   =   $("#getproductmrp1").val(); 
     var sku   =   $("#getskucode1").val(); 
     var productid   =   $("#getproductid1").val(); 
     var currency   =   $("#getcurrency1").val(); 
     var varientid   =   $("#getvarientid1").val(); 
      var size   =  $("#getproductsize1").val(); 
      
    //   alert(currency);
    //   exit();
 
        $("body").append("<div class='add2cart-notification animated fadeIn'>Added to cart successfully!</div>");
        $(".add2cart-notification").delay(2000).fadeOut();
   
          $.ajax({
          type: "POST",
          url: 'function/ajax_function.php',
          data: "action=addCart&quantity="+quantity+"&price="+pprice+"&productid="+productid+"&sku="+sku+"&mrp="+pmrp+"&currency="+currency+"&varientid="+varientid+"&size="+size,
          success: function(returndata){
               var obj = jQuery.parseJSON( returndata );
               if(obj.data[0].status==1){
     
                 $('.cartvalue').html(obj.data[0].cart);
                    // location.reload();
                 

               }
            // ==============================  
            }
      }); 
    
});

$("#directaddtocart").click(function () {
     var quantity  =   $("#qty").val();
     var productid =   $(this).attr('productid'); 
     var unitsize   =    $("#getproductsizeunit").val();
     var pprice =   $("#getproductprice").val(); 

      if(unitsize ==""){
      $("#qty").val('1');
      $("body").append("<div class='selectsize-notification animated fadeIn'>Please Select Variant !</div>");
      $(".selectsize-notification").delay(2000).fadeOut();
   
      return false
      }
          $.ajax({
          type: "POST",
          url: 'function/ajax_function.php',
          data: "action=addCart&quantity="+quantity+"&price="+pprice+"&productid="+productid+"&size="+unitsize,
          success: function(returndata){
               var obj = jQuery.parseJSON( returndata );
               if(obj.data[0].status==1){
     
                 $('.cartvalue').html(obj.data[0].cart);
                    window.location.href="cart.php";
                 

               }
            // ==============================  
            }
      }); 
    
});

$("#userreview").click(function () {

     var usercomment   = $("#usercomments").val();
       var rating   = $("#star1").val();
     // var star2         = $("#star2").val();
     // var star3         = $("#star3").val();
     // var star4         = $("#star4").val();
     // var star5         = $("#star5").val();
     alert(rating);
     // alert(star2);
     // alert(star3);
     // alert(star4);
     // alert(star5);
     exit();
     var pprice =   $("#getproductprice").val(); 
      if(unitsize ==""){
      $("body").append("<div class='selectsize-notification animated fadeIn'>Please Select Variant !</div>");
      $(".selectsize-notification").delay(2000).fadeOut();
   
      return false
      }
          $.ajax({
          type: "POST",
          url: 'function/ajax_function.php',
          data: "action=addCart&quantity="+quantity+"&price="+pprice+"&productid="+productid+"&size="+unitsize,
          success: function(returndata){
               var obj = jQuery.parseJSON( returndata );
               if(obj.data[0].status==1){
     
                 $('.cartvalue').html(obj.data[0].cart);
                    window.location.href="cart.php";
                 

               }
            // ==============================  
            }
      }); 
    
});

$( ".qunatitychange" ).change(function() {
    var itemid = $(this).attr('itemid');
    var price = $(this).attr('price');
    var qty = $(this).val();
    $("#price"+itemid).html((qty*price));
    $("#save"+itemid).show();
});

$(".removecart").click(function () {
    var itemid = $(this).attr('itemid');
      $(this).html('<i class="fa fa-circle-o-notch fa-spin" aria-hidden="true"></i>')
      $.ajax({
        type: "POST",
        url: 'function/ajax_function.php',
        data: "action=deleteCart&cartitemid="+itemid,
        success: function(returndata){
            
            if(returndata==1){
               location.reload();
            }
        // ==============================  
      }
  });
});

$("#frmlogin").submit(function(event) {
        event.preventDefault();
        
        var email       = $("#getloginemail").val();
        var password    = $("#getloginpassword").val();
        var flag=1;
        //============================================================
        if(email==""){
            $('#error_loginemail').html('* Email can not be empty');
            flag=0;
        }
        if(password==""){
            $('#error_loginpassword').html('* Password can not be empty');
            flag=0;
        }

        // email address validation
        var x = email;
        
        if (x.length == 0) {
            $('#error_loginemail').html('Enter your Email ID');
           flag=0
        } 
        
        if(flag==0){
            return false;
        }

        //=============================================================
        var myArray = new Array(); 
        // $("#btnsubmit").html('');
        // $("#btnsubmit").html('<i class="fa fa-circle-o-notch fa-spin" aria-hidden="true"></i>');
        var formData = new FormData($(this)[0]);
        $.ajax({
            url: 'function/ajax_function.php',
            type: 'POST',
            data: formData,
            async: true,
            cache: false,
            contentType: false,
            processData: false,
            success: function(returndata) {
               if (returndata == 1) {
                    //alert(myArray[1])
                    $("#btnsubmit").html('<i class="fa fa-spinner fa-spin"  aria-hidden="true"></i>');
                     window.location.href = "index.php";
                    // alert("Success")
                    $('#message').html('')
                } else if(returndata == 2){
                  window.location.href = "checkout.php";
                }else{
                    // $("#btnsubmit").html('<i class="fa fa-lock"></i>&nbsp; <span>Login</span>');
                    //  $("#getloginemail").focus();
               
                    //  $("#getpassword").val('');
                    
                    // swal("Sorry!", "Email ID and password not matched.", "error");

                    $('#error_details').html('Invalid Email ID and Passowrd !');
                    
                }
            },
            error: function() {
                alert("error in ajax form submission");
            }
        });
        return false;
    });








