function adduseraddress() {
    //Countrywise ordering management
    var countryid = $("#txt_country").val();

    loader_show();  
    $("#fcbox_view_heading_tag_edit").html('<i class = "icon-tag"></i> '+add_address+'');
    $.ajax( {
    url : site_url+'controllers/ajax_controller/my-address-ajax-controller.php', 
    type : 'post',
    data: 'editaddress=1&txt_country='+countryid,        
    success : function( resp ) {
      $("#fcbox_view_content_tag_edit").html(resp);
      $(".fcbox_view_tag_edit").trigger('click');
   
      loader_hide();
    }
  });
}

function changeSiteLang(id) {

    $.ajax({
        url: site_url + 'controllers/ajax_controller/common-ajax-controller.php',
        type: 'post',
        data: 'changeSiteLang=1&langID=' + id,
        success: function(result) {
            window.location.reload();
        }
    });
}

//Footer subscribe  

function subscribe(e){

    e.preventDefault();
    flag = 0;
    var email=$("#subscribe_email").val();

    if(requiredValidate('subscribe_email',req_email)){
        flag++;
        $("#subscribe_email").focus();
    }

    if($('#subscribe_email').val()!='' && regexValidate('subscribe_email','',valid_email,'email','yes')){
        flag++;
        $("#subscribe_email").focus();
    }

    if(flag>0){
        return false;
    }

    loader_show();
    $.ajax({
        url: site_url + 'controllers/ajax_controller/common-ajax-controller.php',
        type: 'post',
        data: 'subscribe=1&subscribe_email='+email,
        success: function(result) {
            loader_hide();
            if (result == 1) {
            $("#error_subscribe_email").removeClass('error_msg');
            $("#error_subscribe_email").addClass('success_msg');
            $("#error_subscribe_email").text(succ_subscribe).show().fadeOut(fadeOutSec);
            $("#subscribe_email").val('');
          }else if(result == 2){
            $("#error_subscribe_email").removeClass('success_msg');
            $("#error_subscribe_email").addClass('error_msg');
            $("#error_subscribe_email").text(already_email_exists).show().fadeOut(fadeOutSec);
            $("#subscribe_email").val('');
          }else{
            $("#error_subscribe_email").removeClass('success_msg');
            $("#error_subscribe_email").addClass('error_msg');
            $("#error_subscribe_email").text(went_wrong).show().fadeOut(fadeOutSec);
            $("#subscribe_email").val('');
          }
    }

});


}

 function isAmountKey(evt){
  
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if ((charCode < 48 || charCode > 57 || charCode == 45) && charCode != 46)
            return false;
        return true;
}

function AddToWishlist(id,langId,checkid) {
  var loginvalue = $("#loginvalue").val();
  var checkBox = document.getElementById("fav"+id);
  
  //Countrywise ordering management
  var countryid = $("#txt_country").val();
  
  if(loginvalue!=''){
    if (checkBox.checked == true){
        $.ajax({
          url: site_url + 'controllers/ajax_controller/home-ajax-controller.php',
          type: 'post',
          data: 'wishlistvalue=1&id='+id+'&langId='+langId+'&txt_country='+countryid,
          success: function(result) {
            $("#favirotelist").html(result);
            // loader_hide();
          }
      });
   
    // loader_show();
    }
    else{
       $.ajax({
          url: site_url + 'controllers/ajax_controller/home-ajax-controller.php',
          type: 'post',
          data: 'editwishlistvalue=1&id='+id+'&langId='+langId+'&txt_country='+countryid,
          success: function(result) {
            $("#favirotelist").html(result);
            // loader_hide();
          }
      });
    
    }  
  }else{
    //Based on country wise & language
    var txt_lang_type = $("#txt_lang_type").val();
    window.location.href=site_url+txt_lang_type+"/login";
  }
}


function AddToShopWishlist(productid,userid) {

    if(userid!='' && userid!=undefined){
      var chkWish = document.getElementById("wish"+productid);
       if (chkWish.checked) {
             var iswish=1;
          } else {
             var iswish=0;
          }

       $.ajax({
          url: site_url + 'controllers/ajax_controller/shop-ajax-controller.php',
          type: 'post',
          data: 'AddToShopWishlist=1&productid='+productid+'&userid='+userid+'&iswish='+iswish,
          success: function(result) {
            if(result==2){
              $("#wish"+productid).prop("checked", false);
              $("#login-form").modal('show');
            }
            if(result==1){
              shopwishlistmanageanalytics(productid,userid);
            }
          }
      }); 
  }else{
    $("#wish"+productid).prop("checked", false);
    $("#login-form").modal('show');

  }
}
function shopwishlistmanageanalytics(productid,userid) {
  if(userid!='' && userid!=undefined){
      var chkWish = document.getElementById("wish"+productid);
       if (chkWish.checked) {
             var iswish=1;
          } else {
             var iswish=0; return false;
          }

       $.ajax({
          url: site_url + 'controllers/ajax_controller/shop-ajax-controller.php',
          type: 'post',
          dataType: "json",
          data: 'AddToShopWishlistAnalytics=1&productid='+productid+'&userid='+userid+'&iswish='+iswish,
          success: function(resp) {
            // alert(resp.status);
            if(resp.status==1){
              wishlistanalytics(resp.product_id,resp.product_name);
            }
          }
      }); 
  }
}

function DeleteToShopWishlist(id) {
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  swal({
    title: "",
    text: are_you_sure_you_want_to_remove_this_product_from_wishlist,
    type: "warning",
    showCancelButton: true,
    confirmButtonClass: 'btn-danger',
    confirmButtonText: 'Yes',
    cancelButtonText: "No",
    closeOnConfirm: false,
    closeOnCancel: true
  },
    function(isConfirm){
      if(isConfirm){

   $.ajax({
        url: site_url + 'controllers/ajax_controller/shop-ajax-controller.php',
        type: 'post',
        data: 'deletewishlistvalue=1&id='+id+'&txt_country='+countryid,
        success: function(result) {
        swal.close();    
         getwishlistcat(1);
        }
    });

   } else {
      swal("", "", "error");
    }
    return false;
  });
}

function DeleteAddress(addressid) {
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  swal({
    title: "",
    text: delete_address,
    type: "warning",
    showCancelButton: true,
    confirmButtonClass: 'btn-danger',
    confirmButtonText: 'Yes',
    cancelButtonText: "No",
    closeOnConfirm: false,
    closeOnCancel: true
  },
    function(isConfirm){
      if(isConfirm){
         $.ajax({
              url: site_url + 'controllers/ajax_controller/shop-ajax-controller.php',
              type: 'post',
              data: 'deleteaddress=1&addressid='+addressid+'&txt_country='+countryid,
              success: function(result) {
                $("#addresslist").html(result);
                getshippingchargegov();
                swal.close();    
              }
          });


      } else {
      swal("", "", "error");
    }
    return false;
  });   
}

function getpaginationcat(page){
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  //loader_show();
  $.ajax({
    url : site_url+'controllers/ajax_controller/common-ajax-controller.php',
    type : "post",
    data: 'lenscarelist=1&page='+page+'&txt_country='+countryid,
    beforeSend:  function(){
      //$('#loader_search').show();
    },
    complete: function(){
      //$('#loader_search').hide();
    },
    success : function(resp) {
     
      $("#lenscarelist").html(resp);
      //loader_hide();
    }
  });
}

 function getwishlistcat(page){
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  loader_show();
  $.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    type : "post",
    data: 'getwishlistcate=1&page='+page+'&txt_country='+countryid,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
     
      $("#myfavourite").html(resp);
      loader_hide();
    }
  });
}




function addtoshopcart(productid,attributeid)
{
  var user_id = $("#txt_user").val();
  var productid  = productid;
  var attributeid  = attributeid;
  
  $.ajax({
    url : site_url+'controllers/ajax_controller/product-detail-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'addshopview=1&user_id='+user_id+'&txt_product='+productid+'&txt_attribute='+attributeid,
    beforeSend:  function(){
      //$('#loader_search').show();
    },
    complete: function(){
      //$('#loader_search').hide();
    },
    success : function(resp) {
        $("#cartcounttop").html(resp[1]);
        $("#proid"+productid).html(resp[2]);
    }
  });
}


function addtoshopcart_fav(productid,attributeid)
{
  // alert(productid); alert(attributeid); return false;
  var user_id = $("#txt_user").val();
  // alert(user_id); return false;
  var productid  = productid;
  var attributeid  = attributeid;
  
  $.ajax({
    url : site_url+'controllers/ajax_controller/product-detail-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'addshopview=1&user_id='+user_id+'&txt_product='+productid+'&txt_attribute='+attributeid,
    beforeSend:  function(){
      //$('#loader_search').show();
    },
    complete: function(){
      //$('#loader_search').hide();
    },
    success : function(resp) {
      // if (resp == 1) {
      //Based on country wise & language
      var txt_lang_type = $("#txt_lang_type").val();
      window.location.href=site_url+txt_lang_type+"/cart";

        //$("#cartcounttop").html(resp[1]);
        //$("#proid"+productid).html(resp[2]);
        
      // }
     /*
      $("#myfavourite").html(resp);
      loader_hide();*/
    }
  });
}

function gotoshopcart(){
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  window.location.href=site_url+txt_lang_type+"/cart";
}


 function getattributevalue(attributeid,productid){
  $("input.quantity-input").val(1); 
  loader_show();
  $.ajax({
    url : site_url+'controllers/ajax_controller/product-detail-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'getattributedetail=1&attributeid='+attributeid+'&productid='+productid,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
     $("#symbol").html(resp[0]);
     $("#newprice").html(resp[1]);
     $("#totalqty").val(resp[2]);
    }
  });
}


function cartremove(id){

    var n = $("input[name='hid_cart_quantity[]']").length;
    var array = $("input[name='hid_cart_quantity[]']");
    var card_value = [];
    var cart = $("input[name='hid_cart[]']").length;
    var arrcartid = $("input[name='hid_cart[]']");
    var cartidval = [];
    for(j=0;j < cart;j++) {

       cartidval.push(arrcartid.eq(j).attr("value"));
       var cartqty =$("#cartqty"+arrcartid.eq(j).attr("value")).val();
       card_value.push(cartqty);
    }

  loader_show();

  if(id==0)
  {

  }
  $.ajax({
    url : site_url+'controllers/ajax_controller/cart-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'removecartdata=1&cartid='+id+'&cartquantity='+card_value+'&cartidval='+cartidval,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      if(resp[7]==0){
        $("#emptycartdiv").html(resp[0]);
      }else{
         $("#cartlist").html(resp[0]);
      }
    
     $("#cartitemcount").html(resp[1]);
     $("#taxable_percentage").html(resp[2]);
     $("#taxable_amount").html(resp[3]);
     $("#subtotalamount").html(resp[4]);
     $("#shipping_charge").html(resp[5]);
     $("#grand_total").html(resp[6]);
     $("#cartcounttop").html(resp[7]);
     $("#cod_service_charge").html(resp[8]);
     $("#hid_subtotal_amount").val(resp[9]);
    }

  });
}



function  quantitycounty() {

  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower   = $("#leftpower").val();
  var rightpower = $("#rightpower").val();
  var leftqty    = $("#leftqty").val();
  var rightqty   = $("#rightqty").val();

  if(txt_brand_type==3){
    var totalqty   = $("#hid_accessories_qty").val();
    var countvalue = $("#leftqty").val();
    if(totalqty<=0){ totalqty=1; }
    if(parseInt(countvalue) > parseInt(totalqty))
    {
      $("#leftqty").val(totalqty);
    }

  }
  var div1 = document.getElementById('left'+leftpower);
  var leftoprice = div1.getAttribute('leftoprice');
  var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = div1.getAttribute('leftpowerqty');

  var div2 = document.getElementById('right'+rightpower);
  var rightoprice = div2.getAttribute('rightoprice');
  var rightdprice = div2.getAttribute('rightdprice');
  var rightpowerqty = div2.getAttribute('rightpowerqty');

  if(leftpower==rightpower){

    var countvalue = $("#leftqty").val();
     if(leftpowerqty<=0){ leftpowerqty=1; }
     if(parseInt(countvalue) > parseInt(leftpowerqty))
      {
        $("#leftqty").val(leftpowerqty);
      }
  }else if((leftpower!='' && leftpower!=undefined) && (rightpower!='' && rightpower!=undefined)){

     var countvalue = $("#leftqty").val();
     if(leftpowerqty<=0){ leftpowerqty=1; }
     if(parseInt(countvalue) > parseInt(leftpowerqty))
      {
        $("#leftqty").val(leftpowerqty);
      }

    var countvalue = $("#rightqty").val();
    if(rightpowerqty<=0){ rightpowerqty=1; }
    if(parseInt(countvalue) > parseInt(rightpowerqty))
    {
      $("#rightqty").val(rightpowerqty);
    }



  }else if(leftpower!='' && leftpower!=undefined){
    var countvalue = $("#leftqty").val();
    if(leftpowerqty<=0){ leftpowerqty=1; }
    if(parseInt(countvalue) > parseInt(leftpowerqty))
    {
      $("#leftqty").val(leftpowerqty);
    }
  }else if(rightpower!='' && rightpower!=undefined){
    var countvalue = $("#rightqty").val();
    if(rightpowerqty<=0){ rightpowerqty=1; }
    if(parseInt(countvalue) > parseInt(rightpowerqty))
    {
      $("#rightqty").val(rightpowerqty);
    }
  }

  Priceupdatebyqty();
}


function  cartquantitycounty(id) {  
  

  var availqty = $("#availqty"+id).val();
  if(availqty==0){ availqty=1; }
  var cartqty   = $("#cartqty"+id).val();

  if(parseInt(cartqty) > parseInt(availqty))
  {
    $("#cartqty"+id).val(availqty);
  }else{

  } 
}


function getaddress(lat,long) {
    loader_show();
    $.ajax({
      url:site_url+'controllers/ajax_controller/checkout-ajax-controller.php',
      type:'post',
      dataType:'json',
      data:'hid_getaddress=1&lat='+lat+'&long='+long,
      success:function(resp){
        $("#txt_address").val(resp);
        $("#latitude").val(lat);
        $("#longitude").val(long);
        loader_hide();  
      }
    });
  }

function addaddress() {
    //Countrywise ordering management
    var countryid = $("#txt_country").val();

    loader_show();  
    $("#fcbox_view_heading_tag_edit").html('<i class = "icon-tag"></i>'+add_new_address);
    $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    data: 'editaddress=1&txt_country='+countryid,        
    success : function( resp ) {
      $("#fcbox_view_content_tag_edit").html(resp);
      $(".fcbox_view_tag_edit").trigger('click');
   
      loader_hide();
    }
  });
}

function editaddress(id) {
    //Countrywise ordering management
    var countryid = $("#txt_country").val();

    loader_show();  
    $("#fcbox_view_heading_tag_edit").html('<i class = "icon-tag"></i>'+edit_address);
    $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    data: 'editaddress=1&addressid='+id+'&txt_country='+countryid,        
    success : function( resp ) {
      $("#fcbox_view_content_tag_edit").html(resp);
      $(".fcbox_view_tag_edit").trigger('click');
   
      loader_hide();
    }
  });
}





function changestatus(addressid) {
 loader_show();
 $(".dfult").html('');
 $.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    data: 'changestatus=1&addressid='+addressid,        
    success : function( resp ) {
      $("#editval").html(resp);
      $("#defailt"+addressid).html(defaultaddress);
      getshippingchargegov();
      loader_hide();
    }
  });

 
}

function changeuserstatus(addressid) {
 loader_show();
 $.ajax({
    url : site_url+'controllers/ajax_controller/my-address-ajax-controller.php', 
    type : 'post',
    data: 'changestatus=1&addressid='+addressid,        
    success : function( resp ) {
      $("#editval").html(resp);
      loader_hide();
    }
  });
}



function searchresult(){
  
  var value=$("#search-terms").val();
  value = value.trim();
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();

  if(value!=''){
      window.location.href=site_url+txt_lang_type+"/product-list/search/"+value;
  }else{
      // window.location.href=site_url+txt_lang_type+"/product-list/search";
  }
  // Search for Google Analytics
  gtag('event', 'view_search_results', {
    'search_term': value
  });
  // Search for Google Analytics
}

function searchresult1(value,type){
  
  value = value.trim();
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  
  if(value!=''){
      if(type==1){
        window.location.href=value;
      }else if(type==2){
        window.location.href=site_url+txt_lang_type+"/product-list/brand/"+value;
      }else if(type==3){
        window.location.href=site_url+txt_lang_type+"/product-list/collections/"+value;
      }else{
        window.location.href=site_url+txt_lang_type+"/product-list/search/"+value;
      }
      
  }else{
      window.location.href=site_url+txt_lang_type+"/product-list/search/"+value;
  }  
}


function PaymentType() {

  var paymenttype = $("input[name='paymentoption']:checked").val();
  var flag = 0;
  var txt_promocode= $("#hid_promocode").val();

  if(paymenttype==1){
    $("#cod_charge_div").hide();
  }else{
    $("#cod_charge_div").show();
  }

 loader_show();
 $.ajax({
    url : site_url+'controllers/ajax_controller/paymentdetail-ajax-controller.php', 
    type : 'post',
    dataType: "json",
    data: 'applypromocode=1&txt_promocode='+txt_promocode+'&paymenttype='+paymenttype,    
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },    
    success : function( resp ) {
     $("#cartitemcount").html(resp[1]);
     $("#taxable_percentage").html(resp[2]);
     $("#taxable_amount").html(resp[3]);
     $("#subtotalamount").html(resp[4]);
     $("#shipping_charge").html(resp[5]);
     $("#grand_total").html(resp[6]);
     $("#cartcounttop").html(resp[7]);
     $("#cod_service_charge").html(resp[8]);
     $("#discountcode").html(resp[9]);
     $("#hid_grand_total").val(resp[12]);

     loader_hide();
    }
  });
}


function placeorder() {
 var flag = 0;
 var txt_promocode = $("#txt_promocode").val();
 var paymenttype = $("input[name='paymentoption']:checked").val();
 
 var addressid        = $("#hid_addressids").val();
 var paymenttime      = $("#hid_paymenttime").val();
 var paymentdate      = $("#hid_paymentdate").val();
 var userid           = $("#hid_user_ids").val();
 var hid_grand_total  = $("#hid_grand_total").val();

//Based on country wise & language
var txt_lang_type = $("#txt_lang_type").val();

 loader_show();
 $.ajax({
    url : site_url+'controllers/ajax_controller/order-ajax-controller.php', 
    type : 'post',
    data: 'orderstatus=1&addressid='+addressid+'&txt_promocode='+txt_promocode+'&paymenttype='+paymenttype+'&hid_paymenttime='+paymenttime+'&hid_paymentdate='+paymentdate+'&hid_user_ids='+userid+'&hid_grand_total='+hid_grand_total,        
    success : function( resp ) {
      if(resp.trim()==1){
        window.location.href=site_url+txt_lang_type+'/success';
      }else if(resp.trim()==5){
        alert(went_wrong);
        window.location.reload();
      }else if(resp.trim()==6){
        alert(OUT_OF_STOCk_PRODUCT);
        window.location.href = site_url+txt_lang_type+'/cart';
      }else if(resp.trim()==7){
        alert(order_access_denied_114);
      }
      else{
        window.location.href = resp.trim();
      }
       loader_hide();
    }
  });
}

function logincartpage() {
   var cart_page = $("#cart_val").val();
   //Based on country wise & language
   var txt_lang_type = $("#txt_lang_type").val();

   $.ajax({
      url : site_url+'controllers/ajax_controller/cart-ajax-controller.php', 
      type : 'post',
      data: 'viewcartlogin=1&cart_val='+cart_page,        
      success : function( resp ) {
        if(resp==1){
          window.location.href=site_url+txt_lang_type+"/login";
        }   
      } 
    });
}

function vieworder(id){
  loader_show();  
  $("#fcbox_view_heading_tag").html('<i class = "icon-tag"></i> '+view_details);
  $.ajax( {
    url : site_url+'controllers/ajax_controller/order-ajax-controller.php',
    type : 'post',
    data: 'view=1&id='+id,
    success : function(result)
    {
      $("#fcbox_view_content_tag").html(result);
      $("#common").html('View Detail');
      $(".fcbox_view_tag").trigger('click');
      loader_hide();
    }
  });
}

function timechange(date) {
  var timeValue = $("input[name='addressvalue']:checked").val();
  var dNow = new Date();
  var localdate= (dNow.getMonth()+1) + '/' + dNow.getDate() + '/' + dNow.getFullYear() + ' ' + dNow.getHours() + ':' + dNow.getMinutes();
  var getdate = dNow.getDate() + '/' + (dNow.getMonth()+1) + '/' + dNow.getFullYear();
  var currenttime = dNow.getHours() + ':' + dNow.getMinutes();
  var aftertime1   = '1';
  var aftertime2  = '2';
  var aftertime3  = '3';
  var aftertime4  = '4';
  var currenttime = '9:5';
  // alert(getdate);
  if(date>getdate)
  {
    $("input[type=radio][data-id=" + aftertime1 + "]").attr("disabled",true);  
    $("input[type=radio][data-id=" + aftertime1 + "]").attr('checked', false);  
    $("input[type=radio][data-id=" + aftertime2 + "]").attr('checked', true);  
  }else{

    $("input[type=radio][data-id=" + aftertime1 + "]").attr('checked', true);  
  }
}

function timechangeval(date) {
  var timeValue = $("input[name='addressvalue']:checked").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/checkout-ajax-controller.php',
    type : 'post',
    data: 'gettime=1&date='+date+'&time='+timeValue,
    success : function(result)
    {
      $("#timechange").html(result);
    }
  });
}

function  getPaginate(page) {

  $.ajax({
    url : site_url+'controllers/ajax_controller/my-pageorder-ajax-controller.php',
    type : "post",
    data: 'hid_paginate=1&page='+page,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      $("#filter_data").html(resp);
    }
  });
}

function autoCompleteSearch(searchText){
  //Countrywise ordering management
  var countryid = $("#txt_country").val();
  var txtval = $('#q').val();
  if(txtval==""){
    $('#skill_ul').hide();
  }else{
    $.ajax({
      type: "POST",
      url: site_url+'controllers/ajax_controller/login-ajax-controller.php',
      data: 'hid_textSearch=1&myName='+searchText+'&txt_country='+countryid,
      cache: false,
      success: function(data){
        // alert(data);
        if(data==0)
        {
          $('#skill_ul').hide();
        }
        else if(data!='' && data!='0'){
          $('#skill_ul').show();
          $('#skill_ul').html($.trim(data));
        }else{
          $('#skill_ul').hide();
        }
      }
    });
  }
}

 function isSearch(evt){

    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode == 13){
       searchresult();
    }
}

function GetLensCareDetails(lenscareid) {
  // loader_show();
  
  $("#lense-care-modal-1").modal('show');

  $.ajax({
    url : site_url+'controllers/ajax_controller/home-ajax-controller.php',
    type : 'post',
    data: 'lenscarevideo=1&lenscareid='+lenscareid,
    success : function(result)
    {
      $("#lenscareitem").html(result);
      // loader_hide();
    }
  });
} 



function enterSiteLang() {

    if($("#ar").hasClass('active')){
       var langID=2;
    }else{
      var langID=1;
    }
      
   var countryid=$("input[name='countryradio']:checked").val();
    $('#skill_ul').val();
    $.ajax({
        url: site_url + 'controllers/ajax_controller/common-ajax-controller.php',
        type: 'post',
        data: 'enterSiteLang=1&langID='+langID+'&countryid='+countryid,
        success: function(result) {
           window.location.reload();
        }
    });
}

function enterSiteLang2(langID,countryid) {
    $.ajax({
        url: site_url + 'controllers/ajax_controller/common-ajax-controller.php',
        type: 'post',
        dataType: "json",
        data: 'enterSiteLang=1&langID='+langID+'&countryid='+countryid,
        success: function(result) {
           // window.location.reload();
          var url = window.location.href; 
          var pathname = new URL(url).pathname;
          //Dynamic CICD Setup
          if(pathname.split( '/' )[1]==site_url_Folder)
          {
            var productlist = pathname.split( '/' )[3];
            var typelist = pathname.split( '/' )[4];
            var brandtypelist = pathname.split( '/' )[5];
            var collectiontype = pathname.split( '/' )[6];
            var productname = pathname.split( '/' )[7];
            // alert(productname);
            // var productnamenew = pathname.split( '/' )[8];
            
            var producttype = pathname.split( '&' )[2];  
          }else{
            var productlist = pathname.split( '/' )[2];
            var typelist = pathname.split( '/' )[3];
            var brandtypelist = pathname.split( '/' )[4];
            var collectiontype = pathname.split( '/' )[5];
            var productname = pathname.split( '/' )[6];
            // var productnamenew = pathname.split( '/' )[7];
            
            var producttype = pathname.split( '&' )[1];
          }
          if(producttype==undefined)
          {
            
            if(productlist=='privacy-policy' || productlist=='terms-conditions' || productlist=='return-policy')
            {
              var lang = result.getpageurl;
              window.location.href = site_url+lang+'/'+productlist;
            }else{
              var lang = result.getpageurl;
              if((typelist!='' && typelist!=undefined) || productlist=='product-details')
              {
                if(productlist=='product-details')
                {
                  if(productname!='' && productname!=undefined)
                  {
                  window.location.href = site_url+lang+'/'+productlist+'/'+typelist+'/'+brandtypelist+'/'+collectiontype+'/'+productname;
                  }else{
                  window.location.href = site_url+lang+'/'+productlist+'/'+typelist;
                  }
                }else{
                  if(collectiontype!='' && collectiontype!=undefined)
                  {
                  window.location.href = site_url+lang+'/'+productlist+'/'+typelist+'/'+brandtypelist+'/'+collectiontype;
                  }else{
                    if(productlist=='product-list' && brandtypelist!=undefined)
                    {
                      window.location.href = site_url+lang+'/'+productlist+'/'+typelist+'/'+brandtypelist;
                    }else{
                      window.location.href = site_url+lang+'/'+productlist+'/'+typelist;
                    }
                  }

                }
              }
              else{
                var lang = result.getpageurl;
                // alert(typelist);
                  if(typelist==undefined)
                  {
                    if(productlist==undefined)
                    {
                      window.location.href = site_url+lang;
                    }else{
                      window.location.href = site_url+lang+'/'+productlist;
                    }
                  }else if(brandtypelist==undefined){
                  window.location.href = site_url+lang+'/'+productlist+'/'+typelist;
                  }else{
                  window.location.href = site_url+lang+'/'+productlist+'/'+typelist+'/'+brandtypelist+'/'+collectiontype;
                  }
                }
            }
          }else if(productlist=='booking_cancelled'){
            var lang = result.getpageurl;
            var canceltypelist = pathname.split( '/' )[3];
            window.location.href = site_url+lang+'/'+productlist+'/'+canceltypelist;
          }else{  
            if(producttype=='types=colored' || producttype=='types=colored-lenses' || producttype=='types=accessories');
            {
              var lang = result.getpageurl;
              window.location.href = site_url+lang+'/'+productlist;
            }
          }
        }
    });
    if(langID==2)
    {
      arabiclanganalytics(); //Arabic Lang Google Analytics
    }else{
      englanganalytics(); //English Lang Google Analytics
    }
}

function subscribe(e){

    e.preventDefault();
    flag = 0;
    var email=$("#subscribe_email").val();

    if(requiredValidate('subscribe_email',enter_email_id)){
        flag++;
        $("#subscribe_email").focus();
    }

    if($('#subscribe_email').val()!='' && regexValidate('subscribe_email','',enter_valid_email_id,'email','yes')){
        flag++;
        $("#subscribe_email").focus();
    }

    if(flag>0){
        return false;
    }

   // loader_show();
    $.ajax({
        url: site_url + 'controllers/ajax_controller/common-ajax-controller.php',
        type: 'post',
        data: 'subscribe=1&subscribe_email='+email,
        success: function(result) {
           // loader_hide();
            if (result == 1) {
            $("#error_subscribe_email").removeClass('error_msg');
            $("#error_subscribe_email").addClass('success_msg');
            $("#error_subscribe_email").text(subscribed_successfully).show().fadeOut(fadeOutSec);
            $("#subscribe_email").val('');
          }else if(result == 2){
            $("#error_subscribe_email").removeClass('success_msg');
            $("#error_subscribe_email").addClass('error_msg');
            $("#error_subscribe_email").text(email_already_exist_in_system).show().fadeOut(fadeOutSec);
            $("#subscribe_email").val('');
          }else{
            $("#error_subscribe_email").removeClass('success_msg');
            $("#error_subscribe_email").addClass('error_msg');
            $("#error_subscribe_email").text(something_went_wrong).show().fadeOut(fadeOutSec);
            $("#subscribe_email").val('');
          }
    }

});
}

function addMsg(e){

  flag = 0;
  e.preventDefault();

  var response = grecaptcha.getResponse().length;

   if(requiredValidate('reason',select_reason)){
        flag++;
        $("#reason").focus();
    }

  if(requiredValidate('txt_userName',enter_name)){
        flag++;
        $("#txt_userName").focus();
    }

  if(requiredValidate('txt_userEmail',enter_email)){
        flag++;
        $("#txt_userEmail").focus();
    }

    if($('#txt_userEmail').val()!='' && regexValidate('txt_userEmail','',enter_valid_email_id,'email','yes')){
        flag++;
        $("#txt_userEmail").focus();
    }

    if(requiredValidate('txt_userPhone',enter_phone_number)){
        flag++;
        $("#txt_userPhone").focus();
    }

    if(requiredValidate('txt_userMsg',enter_message)){
        flag++;
        $("#txt_userMsg").focus();
    }
    
    if(response==0){
       if(requiredValidate('txt_capcha_val',select_captcha)){
        flag++;
        $("#txt_capcha_val").focus();
       }
    }

    if(flag>0){
      //For Autofocus validation highlight
        if($("#reason").val()=='')
        {
        document.getElementById('reason').focus();
        return false;
        }else if($("#txt_userName").val()==''){
        document.getElementById('txt_userName').focus();
        return false;
        }else if($("#txt_userEmail").val()==''){
        document.getElementById('txt_userEmail').focus();
        return false;
        }else if($("#txt_userPhone").val()==''){
        document.getElementById('txt_userPhone').focus();
        return false;
        }else if($("#txt_userMsg").val()==''){
        document.getElementById('txt_userMsg').focus();
        return false;
        }else if($("#txt_capcha_val").val()==''){
        document.getElementById('txt_capcha_val').focus();
        return false;
        }

      return false;
    }
    //Countrywise ordering management
    var countryid = $("#txt_country").val();

    var fd = new FormData(document.getElementById("contactusForm"));

    $.ajax({
        url: site_url + 'controllers/ajax_controller/contact-ajax-controller.php',
        type: 'post',
        data : fd+'&txt_country='+countryid,
        processData: false,  // tell jQuery not to process the data
        contentType: false,
        success: function(result) {
         if(result == 1){
            alert("Message send successfully.");
            location.reload();
          }else{
            $("#error_addUserMsg").removeClass('success_msg');
            $("#error_addUserMsg").addClass('error_msg');
            $("#error_addUserMsg").text(something_went_wrong).show().fadeOut(fadeOutSec);
          }
    }

  });
}


function userLogin(e){
  
    flag = 0;
    e.preventDefault();

    if(requiredValidate('loginUserEmail',enter_email_id)){
        flag++;
        $("#loginUserEmail").focus();
    }

    if($('#loginUserEmail').val()!='' && regexValidate('loginUserEmail','',enter_valid_email_id,'email','yes')){
        flag++;
        $("#loginUserEmail").focus();
    }

    if(requiredValidate('loginUserPassword',enter_password)){
        flag++; 
        $("#loginUserPassword").focus(); 
    }

    if(flag>0){
      //For Autofocus validation highlight
        if($("#loginUserEmail").val()=='')
        {
        document.getElementById('loginUserEmail').focus();
        return false;
        }else if($("#loginUserPassword").val()==''){
        document.getElementById('loginUserPassword').focus();
        return false;
        }
      return false;
    }
   // loader_show();

    $.ajax({
        url: site_url + 'controllers/ajax_controller/login-ajax-controller.php',
        type: 'post',
        data: $('#loginForm').serialize(),
        success: function(result) {
            //loader_hide();
          if(result['userId']) {
            
            window.location.reload();
            // if(pageid=='cart'){
            //   window.location.href = site_url+"cart";
            // }else{
            //   window.location.href = site_url+"my-account";
            // }
            
          }else if(result == 2){
            $("#error_login").removeClass('success_msg');
            $("#error_login").addClass('error_msg');
            $("#error_login").text(invalid_email_password).show().fadeOut(fadeOutSec);
          }else if(result == 0){
            $("#error_login").removeClass('success_msg');
            $("#error_login").addClass('error_msg');
            $("#error_login").text(account_inactive_delete).show().fadeOut(fadeOutSec);
          }else if(result == 3) {
             //Based on country wise & language
             var txt_lang_type = $("#txt_lang_type").val();
             window.location.href = site_url+txt_lang_type+"/cart";
          }else{
            $("#error_login").removeClass('success_msg');
            $("#error_login").addClass('error_msg');
            $("#error_login").text(something_went_wrong).show().fadeOut(fadeOutSec);
          }
    }

});


}


function notifyMe(power){
    flag = 0;

    if(requiredValidate('email',enter_email_id)){
        flag++;
        $("#email").focus();
    }

    if($('#email').val()!='' && regexValidate('email','',enter_valid_email_id,'email','yes')){
        flag++;
        $("#email").focus();
    }
    if(power==1){
    if(requiredValidate('check_power',select_power)){
        flag++;
        $("#check_power").focus();
    }
  }

    if(flag>0){
      return false;
    }
   loader_show();

    $.ajax({
        url: site_url + 'controllers/ajax_controller/notifyme-ajax-controller.php',
        type: 'post',
        data: $('#notifyme_form').serialize(),
        success: function(result) {
           loader_hide();
           $("#notifyMeModal").modal('hide');
            if (result == 1) {
            Swal.fire({
              position: 'top-end',
              icon: 'success',
              title: add_cart_successful,
              showConfirmButton: false,
              timer: 1500
            });
          }else{
            $("#error_cartmsg").removeClass('success_msg');
            $("#error_cartmsg").addClass('error_msg');
            $("#error_cartmsg").text(something_went_wrong).show().fadeOut(fadeOutSec);

          }
    }

});


}


function loginVerifyUserEmail(e){
    e.preventDefault();
    flag = 0;
    if(requiredValidate('useremailaddress',enter_email_id)){
        flag++;
        $("#useremailaddress").focus();
    }

    if($('#useremailaddress').val()!='' && regexValidate('useremailaddress','',enter_valid_email_id,'email','yes')){
        flag++;
        $("#useremailaddress").focus();
    }

    if(flag>0){
      //For Autofocus validation highlight
        if($("#useremailaddress").val()=='')
        {
        document.getElementById('useremailaddress').focus();
        return false;
        }
        return false;
    }

    $.ajax({
        url: site_url + 'controllers/ajax_controller/login-ajax-controller.php',
        type: 'post',
        data: $('#emailForm').serialize(),
        success: function(result) {
          if(result == 2){
            $("#error_useremailaddress1").removeClass('success_msg');
            $("#error_useremailaddress1").addClass('error_msg');
            $("#error_useremailaddress1").text(email_address_does_not_exists_in_our_system).show().fadeOut(fadeOutSec);
          }else if(result == 1){
            $("#error_useremailaddress1").removeClass('success_msg');
            $("#error_useremailaddress1").addClass('error_msg');
            $("#error_useremailaddress1").text("Email Sent successfully. Please check your email.").show().fadeOut(fadeOutSec);
            $("#useremailaddress").val('');
          }else if(result == 3){
            $("#error_useremailaddress1").removeClass('success_msg');
            $("#error_useremailaddress1").addClass('error_msg');
            $("#error_useremailaddress1").text(email_address_does_not_exists_in_our_system).show().fadeOut(fadeOutSec);
            $("#useremailaddress").val('');
          }else{
            $("#error_useremailaddress1").removeClass('success_msg');
            $("#error_useremailaddress1").addClass('error_msg');
            $("#error_useremailaddress1").text("Something Went Wrong").show().fadeOut(fadeOutSec);
          }
    }

});
}


function registerUser(e){

  flag = 0;
  e.preventDefault();

    if(regexValidate('FName',enter_first_name,enter_char_allow,'chkSpace')){
        flag++;
        $("#FName").focus();
    }
    if(regexValidate('LName',enter_last_name,enter_char_allow,'chkSpace')){
        flag++;
        $("#LName").focus();
    }
    if(requiredValidate('userEmail',enter_email_id)){
        flag++;
        $("#userEmail").focus();
    }

    if($('#userEmail').val()!='' && regexValidate('userEmail','',enter_valid_email_id,'email','yes')){
        flag++;
        $("#userEmail").focus();
    }

    if(requiredValidate('registerUserPassword',enter_password)){
        flag++;
        $("#registerUserPassword").focus();
    }

    if($('#registerUserPassword').val()!='' && regexValidate('registerUserPassword','',password_length,'password','yes')){
        flag++;
        $("#registerUserPassword").focus();
    }

    if(requiredValidate('userPhone',enter_phone_number)){
        flag++;
        $("#userPhone").focus();
    }

    if(flag>0){
        //For Autofocus validation highlight
        if($("#FName").val()=='')
        {
        document.getElementById('FName').focus();
        return false;
        }else if($("#LName").val()=='')
        {
        document.getElementById('LName').focus();
        return false;
        }else if($("#userEmail").val()=='')
        {
        document.getElementById('userEmail').focus();
        return false;
        }else if($("#registerUserPassword").val()=='')
        {
        document.getElementById('registerUserPassword').focus();
        return false;
        }else if($("#userPhone").val()=='')
        {
        document.getElementById('userPhone').focus();
        return false;
        }
      return false;
    }
    //Based on country wise & language
    var txt_lang_type = $("#txt_lang_type").val();
    //Countrywise ordering management
    var countryid = $("#txt_country").val();

    loader_show();
    $.ajax({
        url: site_url + 'controllers/ajax_controller/login-ajax-controller.php',
        type: 'post',
        data: $('#registerForm').serialize()+'&txt_country='+countryid,
        success: function(result) {
            loader_hide();
          if (result.trim()=='1') {
            // usersignupanalytics();
            gtag('event', 'USER_SIGN_UP', {
                'event_category': 'User Actions',
                'event_label': 'User Signed Up',
                'value': 1, // You can customize the value if applicable
                'non_interaction': true // Set non_interaction to true to avoid affecting bounce rate
            }); 
            $("#error_addrecored").removeClass('error_msg');
            $("#error_addrecored").addClass('success_msg');
            $("#error_addrecored").text("Your Account Registered Successfully").show().fadeOut(fadeOutSec);
            window.location.href = site_url+txt_lang_type+'/my-account';
          }else if (result.trim()=='3') {
            $("#error_register").removeClass('success_msg');
            $("#error_register").addClass('already');
            $("#error_register").text(invalid_referral_code).show().fadeOut(fadeOutSec);
          }else if (result.trim()=='4') {
            $("#error_register").removeClass('success_msg');
            $("#error_register").addClass('already');
            $("#error_register").text(mobile_number_already_exists).show().fadeOut(fadeOutSec);
          }else if(result == 0){
            $("#error_register").removeClass('success_msg');
            $("#error_register").addClass('error_msg');
            $("#error_register").text(email_already_exist_in_system).show().fadeOut(fadeOutSec);
          }else{
            $("#error_register").removeClass('success_msg');
            $("#error_register").addClass('error_msg');
            $("#error_register").text(something_went_wrong).show().fadeOut(fadeOutSec);
          }
    }

});
}

function showcollectionlist(brandid,brandtype){

   var blist=$(".blist:checkbox:checked").length; 
   var chkWish = document.getElementById("tcolor"+brandid);
   var chklength=$('#tcolor'+brandid).length;
   if(chklength==1){
 
    if(chkWish.checked) {
       var chksletedbrand=$("#tcolor"+brandid).attr("blistname");
       var brandlistbind='<span class="brandtaglist1" id="removeb'+brandid+'" onclick="removebrandtag(&apos;'+brandid+'&apos;,1);"><span class="fil_label_dat">'+chksletedbrand+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
       $("#brandtaglist").append(brandlistbind);

    }else{
      $("#removeb"+brandid).remove();

    }
    // getProductList(1);
 }


 if(chkWish.checked==1){
     $("#collectionsdiv"+brandid).show();
 }else{
    $("#collectionsdiv"+brandid).hide();
    $(".collectionschk"+brandid).prop("checked", false);
    $("#removec"+brandid).remove();
    $(".brandc"+brandid).remove();
 }



  if(blist>=1){
    $("#brandtag").show();
  }else{
    $("#brandtag").hide();
    $(".collectiontaglist").remove();
  }


   // if(blist>1){
   //   $(".clist").prop("checked", false);
   //   $(".collectionsdiv").hide();
   //   $(".collectiontaglist").remove();
   // }else{


   //  if(chklength==1){
   //   if(chkWish.checked) {
   //      $("#collectionsdiv"+brandid).show();
   //    } else {
   //        $(".collectionschk"+brandid).prop("checked", false);
   //        $("#collectionsdiv"+brandid).hide();
   //    }
   //  }


   //    var chksletedbrand=$(".blist:checked").attr('id');
   //    if(chksletedbrand!=undefined){
   //      var res = chksletedbrand.replace('tcolor','');
   //      $("#collectionsdiv"+res).show();
   //    }

   // } 

   

   if(brandtype==1){
    $("#replacementlistdiv").show();
    $("#colorlistdiv").show();

   }else if(brandtype==2){
    $("#replacementlistdiv").show();
    $("#colorlistdiv").hide();
    $(".colorlist").prop("checked", false);


   }else if(brandtype==3){
     $("#replacementlistdiv").hide();
     $("#colorlistdiv").hide();
     $(".colorlist").prop("checked", false);
     $(".replacementlist").prop("checked", false);

   }

  var clist=$(".clist:checkbox:checked").length; 
  if(clist>=1){
    $("#collectiontag").show();
  }else{
    
    $("#collectiontag").hide();
  }

  getProductList(1);
}

function removebrandtag(brandid,brandtype){
   $("#removeb"+brandid).remove();
   $("#tcolor"+brandid).prop("checked", false);
   showcollectionlist(brandid,brandtype);

  var clist=$(".clist:checkbox:checked").length; 

  if(clist>=1){
    $("#collectiontag").show();
  }else{
    $("#collectiontag").hide();
  }

  getProductList(1);
}

function collectionSelect(cid,bid){


  var chksletedcat=$("#ccolor"+cid).attr("clistname");
  var chkWish = document.getElementById("ccolor"+cid);
 
  if(chkWish.checked) {
    var colllistbind='<span class="collectiontaglist brandc'+bid+'" id="removec'+cid+'" onclick="removecollectiontag(&apos;'+cid+'&apos;,1);"><span class="fil_label_dat">'+chksletedcat+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
    $("#collectionlist").append(colllistbind);
  }else{
    $("#removec"+cid).remove();
  }

  var clist=$(".clist:checkbox:checked").length; 

  if(clist>=1){
    $("#collectiontag").show();
  }else{
    $("#collectiontag").hide();
  }

  getProductList(1);
}


function colorSelect(cid){
   var chksletedcat=$("#color"+cid).attr("colorlistname");
   var chkWish = document.getElementById("color"+cid);
 
  if(chkWish.checked) {
    var colllistbind='<span class="colortaglist" id="removecolor'+cid+'" onclick="removecolortag(&apos;'+cid+'&apos;,1);"><span class="fil_label_dat">'+chksletedcat+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
    $("#colorlist").append(colllistbind);
  }else{
    $("#removecolor"+cid).remove();
  }

  var clist=$(".colorlist:checkbox:checked").length; 

  if(clist>=1){
    $("#colortag").show();
  }else{
    $("#colortag").hide();
    $(".colortaglist").remove();
  }

  getProductList(1);
}

function removecolortag(cid){
  $("#removecolor"+cid).remove();
  $("#color"+cid).prop("checked", false);

  var clist=$(".colorlist:checkbox:checked").length; 
  if(clist>=1){
    $("#colortag").show();
  }else{
    $("#colortag").hide();
    $(".colortaglist").remove();
  }

  getProductList(1);
}


function replacementSelect(cid){
   var chksletedcat=$("#replacement"+cid).attr("repllistname");
   var chkWish = document.getElementById("replacement"+cid);
 
  if(chkWish.checked) {
    var colllistbind='<span class="repltaglist" id="removerepl'+cid+'" onclick="removerepltag(&apos;'+cid+'&apos;);"><span class="fil_label_dat">'+chksletedcat+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
    $("#repllist").append(colllistbind);
  }else{
    $("#removerepl"+cid).remove();
  }

  var clist=$(".replacementlist:checkbox:checked").length; 

  if(clist>=1){
    $("#repltag").show();
  }else{
    $("#repltag").hide();
    $(".repltaglist").remove();
  }

  getProductList(1);
}

function removerepltag(cid){
  $("#removerepl"+cid).remove();
  $("#replacement"+cid).prop("checked", false);

  var clist=$(".replacementlist:checkbox:checked").length; 
  if(clist>=1){
    $("#repltag").show();
  }else{
    $("#repltag").hide();
    $(".repltaglist").remove();
  }

  getProductList(1);
}

function removecollectiontag(cid){
   $("#removec"+cid).remove();
   $("#ccolor"+cid).prop("checked", false);
   var clist=$(".clist:checkbox:checked").length; 

    if(clist>=1){
      $("#collectiontag").show();
    }else{
      $("#collectiontag").hide();
      $(".collectiontaglist").remove();
      
    }

    getProductList(1);
}






function powerSelection(spower){

   $('#leftqtydiv').show();
   $('#leftqtydivtoric').show();
   $('#leftqtydivtoricboth').show();
   $('#leftpowerdiv').show();
   $('#rightqtydiv').show();
   $('#rightqtydivtoric').show();
   $('#rightpowerdiv').show();
   $('#leftpowershowdiv').show();
   $('#rightpowershowdiv').show();

  if(spower==1){
    //left power change
    $('#leftqty').val(1);
  }else{
    //right power change
     $('#rightqty').val(1);
  }

  var brandtype=$('#txt_brand_type').val();
  var leftpower=$('#leftpower').val();
  var rightpower=$('#rightpower').val();

  $('#leftpowerselectionshow').html(leftpower);
  $('#rightpowerselectionshow').html(rightpower);

  $('#leftpowerselectionshowbtn').html(leftpower);
  $('#rightpowerselectionshowbtn').html(rightpower);

  
  $("#rightpowershowdiv").css("margin-top", "0px");
  $("#leftpowershowdiv").css("margin-top", "0px");
  if(brandtype==1 || brandtype==2){
    if(leftpower!=rightpower){
      $('#rightqtydiv').show();
      $("#leftqtytext").html("Left Qty");
      $("#rightqtytext").html("Right Qty");
      // $('#leftpowershowdiv').show();
      // $('#rightpowershowdiv').show();
    }else{
      $("#leftqtytext").html("Qty");
      $("#rightqtytext").html("Qty");
      $('#rightqtydiv').hide();
      $("#rightpowershowdiv").css("margin-top", "-30px");
      $("#leftpowershowdiv").css("margin-top", "-10px");
    }
    
  }

  if(leftpower=='' || leftpower==undefined){
    $('#leftqtydiv').hide();
    $('#leftqtydivtoric').hide();
    $('#leftpowerdiv').hide();
    $('#leftpowershowdiv').hide();
    
    
  }

  if(rightpower=='' || rightpower==undefined){
    $('#rightqtydiv').hide();
    $('#rightpowerdiv').hide();
    $('#rightpowershowdiv').hide();
    $('#rightqtydivtoric').hide();
    
    
  }

   $('#leftpowerdiv').hide();
   $('#rightpowerdiv').hide();

  Priceupdatebyqty();
}




function gotocart(){
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  window.location.href=site_url+txt_lang_type+"/cart";
}

function addtocart()
{
  var flag = 0;
  // var countvalue = $("#countvalue").val();
  // var totalqty   = $("#totalqty").val();
  // var cardvalue  = $("#txt_card").val();
  var productid       = $("#txt_product").val();
  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower       = $("#leftpower").val();
  var rightpower      = $("#rightpower").val();
  var leftqty         = $("#leftqty").val();
  var rightqty        = $("#rightqty").val();
  var txt_stock_check = $("#txt_stock_check").val();
  // var to_name      = $("#txt_to_name").val();
  // var from_name    = $("#txt_from_name").val();

  if(txt_brand_type==1 || txt_brand_type==2){
 
  if((leftpower=='' || leftpower==undefined) && (rightpower=='' || rightpower==undefined))
  {
    alert(please_select_power);
    flag++;
    return false;
  }
  }else{

  }

  if(txt_stock_check==1){
    if(requiredValidate('hid_power_val',temporarily_out_of_stock)){
        flag++;
        return false;
      }
  }

  if(flag>0){
    return false;
  }
  //Countrywise ordering management
  var countryid = $("#txt_country").val();


  $.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'addtocart=1&productid='+productid+'&txt_brand_type='+txt_brand_type+'&leftpower='+encodeURIComponent(leftpower)+'&rightpower='+encodeURIComponent(rightpower)+'&productid='+productid+'&leftqty='+leftqty+'&rightqty='+rightqty+'&txt_country='+countryid,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      if (resp[0] == 1) {
            //Based on country wise & language
            // var txt_lang_type = $("#txt_lang_type").val();
            // window.location.href=site_url+txt_lang_type+"/cart";

            $("#btngocart").show();
            $("#btnaddcart").hide();
            $(".item-count").html(resp[1]);

            Swal.fire({
              position: 'top-end',
              icon: 'success',
              title: add_cart_successful,
              showConfirmButton: false,
              timer: 1500
            });
            
            //  $("#error_cartmsg").removeClass('error_msg');
            // $("#error_cartmsg").addClass('success_msg');
            // $("#error_cartmsg").text(add_cart_successful).show().fadeOut(fadeOutSec);
            addtocartanalytics(resp.product_id,resp.product_name,resp.qty);
          }
          else{
            $("#error_cartmsg").removeClass('success_msg');
            $("#error_cartmsg").addClass('error_msg');
            $("#error_cartmsg").text(something_went_wrong).show().fadeOut(fadeOutSec);
          }
          $('#loader_search').hide();
    }
  });
}


function Priceupdatebyqty(){

  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower  = $("#leftpower").val();
  var rightpower = $("#rightpower").val();
  var leftqty    = $("#leftqty").val();
  var rightqty   = $("#rightqty").val();
  var avai_acc_qty   = $("#hid_accessories_qty").val();
  var hid_discount_percentage   = $("#hid_discount_percentage").val();

  if((leftpower=='' || leftpower==undefined)){
    $("#leftsidepowerhide").hide();
  }else if((rightpower=='' || rightpower==undefined)){
    $("#rightsidepowerhide").hide();
  }
  //Same power value
  if(leftpower == rightpower)
  {
    $("#rightsidepowerhide").hide();
  }
  if(txt_brand_type==3){

    var oprice  = $("#hid_original_price").val();
    var dprice  = $("#hid_discount_price").val();

  }else{

    var div1 = document.getElementById('left'+leftpower);
    var leftoprice = div1.getAttribute('leftoprice');
    var leftdprice = div1.getAttribute('leftdprice');
    var leftpowerqty = div1.getAttribute('leftpowerqty');

    var div2 = document.getElementById('right'+rightpower);
    var rightoprice = div2.getAttribute('rightoprice');
    var rightdprice = div2.getAttribute('rightdprice');
    var rightpowerqty = div2.getAttribute('rightpowerqty');

  }
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

   $.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'priceupdate=1&oprice='+oprice+'&dprice='+dprice+'&leftqty='+leftqty+'&rightqty='+rightqty+'&leftpower='+encodeURIComponent(leftpower)+'&rightpower='+encodeURIComponent(rightpower)+'&txt_brand_type='+txt_brand_type+'&leftoprice='+leftoprice+'&leftdprice='+leftdprice+'&rightoprice='+rightoprice+'&rightdprice='+rightdprice+'&rightpowerqty='+rightpowerqty+'&leftpowerqty='+leftpowerqty+'&avai_acc_qty='+avai_acc_qty+'&txt_country='+countryid+'&hid_discount_percentage='+hid_discount_percentage,
    success : function(resp) {
      $("#defaultpricediv").html(resp[2]);
      $("#txt_stock_check").val(resp[3]);
      
      //Same power value
      if(leftpower == rightpower)
      {
        $("#dprice_new_left").html(resp[1]);
        $("#oprice_new_left").html(resp[0]);
      }else{
        $("#oprice_new_left").html(resp[4]);
        $("#dprice_new_left").html(resp[5]);
        $("#oprice_new_right").html(resp[6]);
        $("#dprice_new_right").html(resp[7]);
      }
    }
  });
}
function changeajaxpowerval(leftpower,rightpower){
  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower   = $("#leftpower").val();
  var rightpower = $("#rightpower").val();
  var leftqty    = $("#leftqty").val();
  var rightqty   = $("#rightqty").val();
  var avai_acc_qty   = $("#hid_accessories_qty").val();

  var div1 = document.getElementById('left'+leftpower);
  var leftoprice = div1.getAttribute('leftoprice');
  var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = div1.getAttribute('leftpowerqty');

  var div2 = document.getElementById('right'+rightpower);
  var rightoprice = div2.getAttribute('rightoprice');
  var rightdprice = div2.getAttribute('rightdprice');
  var rightpowerqty = div2.getAttribute('rightpowerqty');

  if(txt_brand_type==3){

    var oprice  = $("#hid_original_price").val();
    var dprice  = $("#hid_discount_price").val();

  }else{

    var div1 = document.getElementById('left'+leftpower);
    var leftoprice = div1.getAttribute('leftoprice');
    var leftdprice = div1.getAttribute('leftdprice');
    var leftpowerqty = div1.getAttribute('leftpowerqty');

    var div2 = document.getElementById('right'+rightpower);
    var rightoprice = div2.getAttribute('rightoprice');
    var rightdprice = div2.getAttribute('rightdprice');
    var rightpowerqty = div2.getAttribute('rightpowerqty');

  }

  //Countrywise ordering management
  var countryid = $("#txt_country").val();
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  var hid_discount_percentage = $("#hid_discount_percentage").val();
// alert(hid_discount_percentage);
  $.ajax({
      url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
      type : "post",
      dataType: "json",
      data: 'changeajaxpowerval=1&oprice='+oprice+'&dprice='+dprice+'&leftqty='+leftqty+'&rightqty='+rightqty+'&leftpower='+encodeURIComponent(leftpower)+'&rightpower='+encodeURIComponent(rightpower)+'&txt_brand_type='+txt_brand_type+'&leftoprice='+leftoprice+'&leftdprice='+leftdprice+'&rightoprice='+rightoprice+'&rightdprice='+rightdprice+'&rightpowerqty='+rightpowerqty+'&leftpowerqty='+leftpowerqty+'&avai_acc_qty='+avai_acc_qty+'&txt_country='+countryid+'&txt_lang_type='+txt_lang_type+'&hid_discount_percentage='+hid_discount_percentage,
      beforeSend:  function(){
      },
      complete: function(){
      },
      success : function(resp) {
        $("#changepowerspan").html(resp);
        powerSelection('1');
        powerSelection('2');
        $(".showpricedefault").hide();
      }
});
}
function changeajaxselectpowerbtn(leftpower,rightpower){
  loader_show();
  //Countrywise ordering management
  var countryid = $("#txt_country").val();
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  
$.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'changeajaxselectpower=1&leftpower='+leftpower+'&rightpower='+rightpower+'&txt_country='+countryid+'&txt_lang_type='+txt_lang_type,
    beforeSend:  function(){
    },
    complete: function(){
    },
    success : function(resp) {
      loader_hide();
      $("#changepowerajax").html(resp);
    }
  });
}
function increment_quantity_left(code) {
  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower   = $("#leftpower").val();
  var rightpower = $("#rightpower").val();
  var leftqty    = $("#leftqty").val();
  
  var div1 = document.getElementById('left'+leftpower);
  var leftoprice = div1.getAttribute('leftoprice');
  var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = div1.getAttribute('leftpowerqty');

  if(txt_brand_type==3){
    var totalqty   = $("#hid_accessories_qty").val();
    var countvalue = $("#leftqty").val();
    if(totalqty<=0){ totalqty=1; }
    if(parseInt(countvalue) > parseInt(totalqty))
    {
      $("#leftqty").val(totalqty);
    }else{
      var inputQuantityElement = $("#leftqty");
      var newQuantityleft = parseInt($(inputQuantityElement).val())+1;
      $("#leftqty").val(newQuantityleft);
    }

  }else if(leftpower==rightpower){

    var countvalue = $("#leftqty").val();
     if(leftpowerqty<=0){ leftpowerqty=1; }
     if(parseInt(countvalue) > parseInt(leftpowerqty))
      {
        $("#leftqty").val(leftpowerqty);
      }else{
        var inputQuantityElement = $("#leftqty");
        var newQuantityleft = parseInt($(inputQuantityElement).val())+1;
        $("#leftqty").val(newQuantityleft);
      }
  }else if((leftpower!='' && leftpower!=undefined) && (rightpower!='' && rightpower!=undefined)){

     var countvalue = $("#leftqty").val();
     if(leftpowerqty<=0){ leftpowerqty=1; }
     if(parseInt(countvalue) > parseInt(leftpowerqty))
      {
        $("#leftqty").val(leftpowerqty);
      }else{
        var inputQuantityElement = $("#leftqty");
        var newQuantityleft = parseInt($(inputQuantityElement).val())+1;
        $("#leftqty").val(newQuantityleft);
      }

  }else if(leftpower!='' && leftpower!=undefined){
    var countvalue = $("#leftqty").val();
    if(leftpowerqty<=0){ leftpowerqty=1; }
    if(parseInt(countvalue) > parseInt(leftpowerqty))
    {
      $("#leftqty").val(leftpowerqty);
    }else{
      var inputQuantityElement = $("#leftqty");
      var newQuantityleft = parseInt($(inputQuantityElement).val())+1;
      $("#leftqty").val(newQuantityleft);
    }
  }
  resetaddtocartbtn();
  // Priceupdatebyqty();
}

function decrement_quantity_left(code) {
  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower   = $("#leftpower").val();
  var rightpower = $("#rightpower").val();
  var leftqty    = $("#leftqty").val();
  
  var div1 = document.getElementById('left'+leftpower);
  var leftoprice = div1.getAttribute('leftoprice');
  var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = div1.getAttribute('leftpowerqty');

  if(txt_brand_type==3){
    var totalqty   = $("#hid_accessories_qty").val();
    var countvalue = $("#leftqty").val();
    if(totalqty<=0){ totalqty=1; }
    if(parseInt(countvalue) > parseInt(totalqty))
    {
      $("#leftqty").val(totalqty);
    }else{
        var inputQuantityElement = $("#leftqty");
        if($(inputQuantityElement).val() > 1)
        {
        var newQuantity = parseInt($(inputQuantityElement).val()) - 1;
        $("#leftqty").val(newQuantity);
        }
      }

  }else if(leftpower==rightpower){

    var countvalue = $("#leftqty").val();
     if(leftpowerqty<=0){ leftpowerqty=1; }
     if(parseInt(countvalue) > parseInt(leftpowerqty))
      {
        $("#leftqty").val(leftpowerqty);
      }else{
        var inputQuantityElement = $("#leftqty");
        if($(inputQuantityElement).val() > 1)
        {
        var newQuantity = parseInt($(inputQuantityElement).val()) - 1;
        $("#leftqty").val(newQuantity);
        }
      }
  }else if((leftpower!='' && leftpower!=undefined) && (rightpower!='' && rightpower!=undefined)){

     var countvalue = $("#leftqty").val();
     if(leftpowerqty<=0){ leftpowerqty=1; }
     if(parseInt(countvalue) > parseInt(leftpowerqty))
      {
        $("#leftqty").val(leftpowerqty);
      }else{
        var inputQuantityElement = $("#leftqty");
        if($(inputQuantityElement).val() > 1)
        {
        var newQuantity = parseInt($(inputQuantityElement).val()) - 1;
        $("#leftqty").val(newQuantity);
        }
      }

  }else if(leftpower!='' && leftpower!=undefined){
    var countvalue = $("#leftqty").val();
    if(leftpowerqty<=0){ leftpowerqty=1; }
    if(parseInt(countvalue) > parseInt(leftpowerqty))
    {
      $("#leftqty").val(leftpowerqty);
    }else{
      var inputQuantityElement = $("#leftqty");
      if($(inputQuantityElement).val() > 1)
      {
      var newQuantity = parseInt($(inputQuantityElement).val()) - 1;
      $("#leftqty").val(newQuantity);
      }
    }
  }
  resetaddtocartbtn();
  // Priceupdatebyqty();
}
function increment_quantity_right(code) {
  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower   = $("#leftpower").val();
  var rightpower = $("#rightpower").val();
  var rightqty   = $("#rightqty").val();

  var div2 = document.getElementById('right'+rightpower);
  var rightoprice = div2.getAttribute('rightoprice');
  var rightdprice = div2.getAttribute('rightdprice');
  var rightpowerqty = div2.getAttribute('rightpowerqty');

  if(txt_brand_type==3){
    var totalqty   = $("#hid_accessories_qty").val();
    var countvalue = $("#rightqty").val();
    if(totalqty<=0){ totalqty=1; }
    if(parseInt(countvalue) > parseInt(totalqty))
    {
      $("#rightqty").val(totalqty);
    }else{
      var inputQuantityElement = $("#rightqty");
      var newQuantityright = parseInt($(inputQuantityElement).val())+1;
      $("#rightqty").val(newQuantityright);
    }

  }else if(leftpower==rightpower){

    var countvalue = $("#rightqty").val();
     if(rightpowerqty<=0){ rightpowerqty=1; }
     if(parseInt(countvalue) > parseInt(rightpowerqty))
      {
        $("#rightqty").val(rightpowerqty);
      }else{
        var inputQuantityElement = $("#rightqty");
        var newQuantityright = parseInt($(inputQuantityElement).val())+1;
        $("#rightqty").val(newQuantityright);
      }
  }else if((leftpower!='' && leftpower!=undefined) && (rightpower!='' && rightpower!=undefined)){

    var countvalue = $("#rightqty").val();
    if(rightpowerqty<=0){ rightpowerqty=1; }
    if(parseInt(countvalue) > parseInt(rightpowerqty))
    {
      $("#rightqty").val(rightpowerqty);
    }else{
      var inputQuantityElement = $("#rightqty");
      var newQuantityright = parseInt($(inputQuantityElement).val())+1;
      $("#rightqty").val(newQuantityright);
    }
  }else if(rightpower!='' && rightpower!=undefined){
    var countvalue = $("#rightqty").val();
    if(rightpowerqty<=0){ rightpowerqty=1; }
    if(parseInt(countvalue) > parseInt(rightpowerqty))
    {
      $("#rightqty").val(rightpowerqty);
    }else{
      var inputQuantityElement = $("#rightqty");
      var newQuantityright = parseInt($(inputQuantityElement).val())+1;
      $("#rightqty").val(newQuantityright);
    }
  }
  resetaddtocartbtn();
  // Priceupdatebyqty();
}

function decrement_quantity_right(code) {
  /*//Cart reset value on change qunatity
  $("#btngocart").hide();
  $("#btnaddcart").show();*/

  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower   = $("#leftpower").val();
  var rightpower = $("#rightpower").val();
  var rightqty   = $("#rightqty").val();

  var div2 = document.getElementById('right'+rightpower);
  var rightoprice = div2.getAttribute('rightoprice');
  var rightdprice = div2.getAttribute('rightdprice');
  var rightpowerqty = div2.getAttribute('rightpowerqty');

  if(txt_brand_type==3){
    var totalqty   = $("#hid_accessories_qty").val();
    var countvalue = $("#rightqty").val();
    if(totalqty<=0){ totalqty=1; }
    if(parseInt(countvalue) > parseInt(totalqty))
    {
      $("#rightqty").val(totalqty);
    }else{
      var inputQuantityElement = $("#rightqty");
      if($(inputQuantityElement).val() > 1)
      {
      var newQuantityright = parseInt($(inputQuantityElement).val()) - 1;
      $("#rightqty").val(newQuantityright);
      }
    }

  }else if(leftpower==rightpower){

    var countvalue = $("#rightqty").val();
     if(rightpowerqty<=0){ rightpowerqty=1; }
     if(parseInt(countvalue) > parseInt(rightpowerqty))
      {
        $("#rightqty").val(rightpowerqty);
      }else{
        var inputQuantityElement = $("#rightqty");
        if($(inputQuantityElement).val() > 1)
        {
        var newQuantityright = parseInt($(inputQuantityElement).val()) - 1;
        $("#rightqty").val(newQuantityright);
        }
      }
  }else if((leftpower!='' && leftpower!=undefined) && (rightpower!='' && rightpower!=undefined)){

    var countvalue = $("#rightqty").val();
    if(rightpowerqty<=0){ rightpowerqty=1; }
    if(parseInt(countvalue) > parseInt(rightpowerqty))
    {
      $("#rightqty").val(rightpowerqty);
    }else{
      var inputQuantityElement = $("#rightqty");
      if($(inputQuantityElement).val() > 1)
      {
      var newQuantityright = parseInt($(inputQuantityElement).val()) - 1;
      $("#rightqty").val(newQuantityright);
      }
    }
  }else if(rightpower!='' && rightpower!=undefined){
    var countvalue = $("#rightqty").val();
    if(rightpowerqty<=0){ rightpowerqty=1; }
    if(parseInt(countvalue) > parseInt(rightpowerqty))
    {
      $("#rightqty").val(rightpowerqty);
    }else{
      var inputQuantityElement = $("#rightqty");
      if($(inputQuantityElement).val() > 1)
      {
      var newQuantityright = parseInt($(inputQuantityElement).val()) - 1;
      $("#rightqty").val(newQuantityright);
      }
    }
  }
  resetaddtocartbtn();
  // Priceupdatebyqty();
}
function resetaddtocartbtn() {
  //Cart reset value on change qunatity
  $("#btngocart").hide();
  $("#btnaddcart").show();
}
function applypromocode1(){

 var flag = 0;
 var txt_promocode = $("#txt_promocode").val();

 if(requiredValidate('txt_promocode',enter_gift_voucher_promo_code)){
    flag++;
    $("#txt_promocode").focus();
 }
  if(flag>0){
    return false;
  }

  cartdetails('','','4','','');
}

function clearpromocode1() {

  $("#hid_promocode").val("");
  $("#txt_promocode").val("");
  var txt_promocode = "";
  $("#txt_promocode").prop("disabled", false); 
  $("#btnRemovePromo").hide();
  $("#btnApplyPromo").show();
  $("#hid_promocode_status").val(0);
  cartdetails('','','5','','');

}

function cartdetails(cartid,powertype,type,plusminus,is_toric_product=''){

  var txt_promocode = $("#txt_promocode").val();

  if(type==3){
      swal({
    title: "",
    text: remove_cart_item,
    type: "warning",
    showCancelButton: true,
    confirmButtonClass: 'btn-danger',
    confirmButtonText: 'Yes',
    cancelButtonText: "No",
    closeOnConfirm: false,
    closeOnCancel: true
  },
    function(isConfirm){
      if(isConfirm){
       var leftqty    = $("#leftqty"+cartid).val();
       var rightqty   = $("#rightqty"+cartid).val();
       var left_available_qty   = $("#txt_left_available_qty"+cartid).val();
       var right_available_qty   = $("#txt_right_available_qty"+cartid).val();
       if(plusminus==1){
          if(type==2){
            if(is_toric_product==1)
            {
              //Do nothing
            }else{
              if(parseInt(leftqty)>parseInt(left_available_qty)){
                leftqty=parseInt(leftqty)-1;
                $("#leftqty"+cartid).val(leftqty);
                return false;
              }
            }
          }
          if(type==1){
            if(is_toric_product==1)
            {
              //Do nothing
            }else{
              if(parseInt(rightqty)>parseInt(right_available_qty)){
                rightqty=parseInt(rightqty)-1;
                $("#rightqty"+cartid).val(rightqty);
                return false;
              }
            }
          }
       }
       //Countrywise ordering management
       var countryid = $("#txt_country").val();

        $.ajax({
        url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
        type : "post",
        dataType: "json",
        data: 'cartdetails=1&leftqty='+leftqty+'&rightqty='+rightqty+'&type='+type+'&cartid='+cartid+'&powertype='+powertype+'&txt_promocode='+txt_promocode+'&txt_country='+countryid,
        beforeSend:  function(){
        },
        complete: function(){
        },
        success : function(resp) {

          if(resp[1]>0){
            $("#cartlist").html(resp[0]);
            $(".item-count").html(resp[1]);
            $("#cartcount2").html(resp[1]);
            $("#subtotal").html(resp[2]);
            $("#coupon_discount").html(resp[3]);
            $("#vat").html(resp[4]);
            $("#delivery_shipping").html(resp[5]);
            $("#total_payble").html(resp[6]);
            $("#notesdiv").html(resp[7]);
            $("#alertsdiv").html(resp[8]);
            $("#is_out_of_stock").val(resp[9]);
            //Developer Changes
            // $("#txt_subtotal_miminum_amount").val(resp[10]);
            $("#txt_subtotal_miminum_amount").val(resp[2]);
            $("#txt_promotion_intimate").val(resp[11]);
            $("#notesdivbind").prepend(resp[12]);

            var discountval=resp[13];
            if(discountval>0){
              $("#btnRemovePromo").show();
              $("#btnApplyPromo").hide();
              $("#txt_promocode").prop("disabled", true); 

              // $("#err_checkmessg").fadeIn();
              // $("#err_checkmessg").html(coupon_code_applied_successfully);
              // $("#err_checkmessg").css('color','green');
              // $("#err_checkmessg").fadeOut(5000);
              $("#hid_promocode_status").val(1);
            }else if(type==5){
              $("#hid_promocode_status").val(0);
              $("#txt_promocode").val("");
            }else{
              // $("#err_checkmessg").fadeIn();
              // $("#err_checkmessg").html(please_enter_valid_coupon_code);
              // $("#err_checkmessg").css('color','red');
              // $("#err_checkmessg").fadeOut(5000);
              $("#hid_promocode_status").val(0);
              $("#txt_promocode").val("");
            }

            
          }else{
            $("#emptykart").html(resp[0]);
            $("#notesdiv").html("");
            $("#alertsdiv").html("");
            $(".item-count").html(0);
            $(".order-process").hide();
          }
          swal.close();   
        }
      });


   } else {
      swal("", "", "error");
    }
    return false;
  });  
  }else if(type==4 || type==5){
       var leftqty    = '';
       var rightqty   = '';
       var left_available_qty   = '';
       var right_available_qty   = '';
       // if(plusminus==1){
       //    if(type==2){
       //      if(parseInt(leftqty)>parseInt(left_available_qty)){
       //        leftqty=parseInt(leftqty)-1;
       //        $("#leftqty"+cartid).val(leftqty);
       //        return false;
       //      }
       //    }
       //    if(type==1){
       //      if(parseInt(rightqty)>parseInt(right_available_qty)){
       //        rightqty=parseInt(rightqty)-1;
       //        $("#rightqty"+cartid).val(rightqty);
       //        return false;
       //      }
       //    }
       // }
       //Countrywise ordering management
       var countryid = $("#txt_country").val();

        $.ajax({
        url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
        type : "post",
        dataType: "json",
        data: 'cartdetails=1&leftqty='+leftqty+'&rightqty='+rightqty+'&type='+type+'&cartid='+cartid+'&powertype='+powertype+'&txt_promocode='+txt_promocode+'&txt_country='+countryid,
        beforeSend:  function(){
        },
        complete: function(){
        },
        success : function(resp) {

          if(resp[1]>0){
            $("#cartlist").html(resp[0]);
            $(".item-count").html(resp[1]);
            $("#cartcount2").html(resp[1]);
            $("#subtotal").html(resp[2]);
            $("#coupon_discount").html(resp[3]);
            $("#vat").html(resp[4]);
            $("#delivery_shipping").html(resp[5]);
            $("#total_payble").html(resp[6]);
            $("#notesdiv").html(resp[7]);
            $("#alertsdiv").html(resp[8]);
            $("#is_out_of_stock").val(resp[9]);
            //Developer Changes
            // $("#txt_subtotal_miminum_amount").val(resp[10]);
            $("#txt_subtotal_miminum_amount").val(resp[2]);
            $("#txt_promotion_intimate").val(resp[11]);
            $("#notesdivbind").prepend(resp[12]);
            var discountval=resp[13];
            if(discountval>0){
              $("#btnRemovePromo").show();
              $("#btnApplyPromo").hide();
              $("#txt_promocode").prop("disabled", true); 

              $("#err_checkmessg").fadeIn();
              $("#err_checkmessg").html(coupon_code_applied_successfully);
              $("#err_checkmessg").css('color','green');
              $("#err_checkmessg").fadeOut(5000);
              $("#hid_promocode_status").val(1);
            }else if(type==5){
              $("#hid_promocode_status").val(0);
              $("#txt_promocode").val("");
            }else if(resp[14] == 0){
              $("#err_checkmessg").fadeIn();
              $("#err_checkmessg").html(please_enter_minimum_gift_voucher+' '+resp[15]);
              $("#err_checkmessg").css('color','red');
              $("#err_checkmessg").fadeOut(5000);
              $("#hid_promocode_status").val(0);
              $("#txt_promocode").val("");
            }else{
              $("#err_checkmessg").fadeIn();
              $("#err_checkmessg").html(please_enter_valid_coupon_code);
              $("#err_checkmessg").css('color','red');
              $("#err_checkmessg").fadeOut(5000);
              $("#hid_promocode_status").val(0);
              $("#txt_promocode").val("");
            }
            
            
          }else{
            $("#emptykart").html(resp[0]);
            $("#notesdiv").html("");
            $("#alertsdiv").html("");
            $(".item-count").html(0);
          }
          swal.close();   
        }
      });
  }else{
       var leftqty    = $("#leftqty"+cartid).val();
       var rightqty   = $("#rightqty"+cartid).val();
       var left_available_qty   = $("#txt_left_available_qty"+cartid).val();
       var right_available_qty   = $("#txt_right_available_qty"+cartid).val();
       if(plusminus==1){
          if(type==2){
            if(is_toric_product==1)
            {
              //Do nothing
            }else{
              if(parseInt(leftqty)>parseInt(left_available_qty)){
                leftqty=parseInt(leftqty)-1;
                $("#leftqty"+cartid).val(leftqty);
                return false;
              }
            }
          }
          if(type==1){
            if(is_toric_product==1)
            {
              //Do nothing
            }else{
              if(parseInt(rightqty)>parseInt(right_available_qty)){
                rightqty=parseInt(rightqty)-1;
                $("#rightqty"+cartid).val(rightqty);
                return false;
              }
            }
          }
       }
       //Countrywise ordering management
       var countryid = $("#txt_country").val();

        $.ajax({
        url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
        type : "post",
        dataType: "json",
        data: 'cartdetails=1&leftqty='+leftqty+'&rightqty='+rightqty+'&type='+type+'&cartid='+cartid+'&powertype='+powertype+'&txt_promocode='+txt_promocode+'&txt_country='+countryid,
        beforeSend:  function(){
        },
        complete: function(){
        },
        success : function(resp) {

          if(resp[1]>0){
            $("#cartlist").html(resp[0]);
            $(".item-count").html(resp[1]);
            $("#cartcount2").html(resp[1]);
            $("#subtotal").html(resp[2]);
            $("#coupon_discount").html(resp[3]);
            $("#vat").html(resp[4]);
            $("#delivery_shipping").html(resp[5]);
            $("#total_payble").html(resp[6]);
            $("#notesdiv").html(resp[7]);
            $("#alertsdiv").html(resp[8]);
            $("#is_out_of_stock").val(resp[9]);
            //Developer Changes
            // $("#txt_subtotal_miminum_amount").val(resp[10]);
            $("#txt_subtotal_miminum_amount").val(resp[2]);
            $("#txt_promotion_intimate").val(resp[11]);
            $("#notesdivbind").prepend(resp[12]);
            var discountval=resp[13];
            if(discountval>0){
              $("#btnRemovePromo").show();
              $("#btnApplyPromo").hide();
              $("#txt_promocode").prop("disabled", true); 

              // $("#err_checkmessg").fadeIn();
              // $("#err_checkmessg").html(coupon_code_applied_successfully);
              // $("#err_checkmessg").css('color','green');
              // $("#err_checkmessg").fadeOut(5000);
              $("#hid_promocode_status").val(1);
            }else if(type==5){
              $("#hid_promocode_status").val(0);
              $("#txt_promocode").val("");
            }else{
              // $("#err_checkmessg").fadeIn();
              // $("#err_checkmessg").html(please_enter_valid_coupon_code);
              // $("#err_checkmessg").css('color','red');
              // $("#err_checkmessg").fadeOut(5000);
              $("#hid_promocode_status").val(0);
              $("#txt_promocode").val("");
            }


            
          }else{
            $("#emptykart").html(resp[0]);
            $("#notesdiv").html("");
            $("#alertsdiv").html("");
            $(".item-count").html(0);
          }
          swal.close();   
        }
      });
  }

}
function view_eye_doc(sub_cart_id,product_id){
    
    var sub_cart_id = sub_cart_id;
    var product_id = product_id;
    loader_show();  
    $("#fcbox_view_heading_tag_eye_doc").html('<i class = "icon-tag"></i>Eye Documents');
    $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    data: 'vieweyedoc=1&sub_cart_id='+sub_cart_id+'&product_id='+product_id,        
    success : function( resp ) {
      // alert(resp);
      $("#fcbox_view_content_tag_eye_doc").html(resp);
      $(".fcbox_view_tag_eye_doc").trigger('click');
   
      loader_hide();
    }
  });
}

function processcheckout(type){

  var is_out_of_stock=$("#is_out_of_stock").val();
  var txt_subtotal_miminum_amount=$("#txt_subtotal_miminum_amount").val();
  var txt_miminum_amount=$("#txt_miminum_amount").val();
  var txt_promotion_intimate=$("#txt_promotion_intimate").val();
  var hid_promocode_status=$("#hid_promocode_status").val();
  var txt_promocode=$("#txt_promocode").val();
  var txt_product_id=$("#txt_product_id").val();
  


  if(is_out_of_stock==0){
      $("#error_cartmsg").removeClass('success_msg');
      $("#error_cartmsg").addClass('error_msg');
      $("#error_cartmsg").text(temporarily_out_of_stock).show().fadeOut(fadeOutSec);
      return false;
  }

  if(txt_miminum_amount>0){
    if(parseFloat(txt_miminum_amount)>parseFloat(txt_subtotal_miminum_amount)){
      $("#error_cartmsg").removeClass('success_msg');
      $("#error_cartmsg").addClass('error_msg');
      $("#error_cartmsg").text(order_access_denied_114).show().fadeOut(fadeOutSec);
      return false;
    }
  }

  if(txt_promotion_intimate==1){
     $("#error_cartmsg").removeClass('success_msg');
      $("#error_cartmsg").addClass('error_msg');
      $("#error_cartmsg").text(free_item_alert).show().fadeOut(fadeOutSec);
      return false;
  }

  $.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'processtocheckout=1&type='+type+'&hid_promocode_status='+hid_promocode_status+'&txt_promocode='+txt_promocode+'&txt_product_id='+txt_product_id,
    beforeSend:  function(){
    },
    complete: function(){
    },
    success : function(resp) {
      if(resp==2){
        $("#login-form").modal('show');
      }else if(resp==5){
        $("#error_cartmsg").removeClass('success_msg');
        $("#error_cartmsg").addClass('error_msg');
        $("#error_cartmsg").text(inactive_product_150).show().fadeOut(fadeOutSec);

        var txt_lang_type = $("#txt_lang_type").val();
        window.location.href = site_url+txt_lang_type+ "/cart";
      }else{
        //Based on country wise & language
        var txt_lang_type = $("#txt_lang_type").val();
        window.location.href = site_url+txt_lang_type+ "/address";
      } 
    }
  });
}


 function isNumberKey(evt){
  
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if ((charCode < 48 || charCode > 57 || charCode == 45) && charCode != 46)
            return false;
        return true;
}

function getGovernateArea(){

  var governateId = $('#txt_bill_governate').val();
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  $('#othercitydiv').hide();
  $.ajax({
    type: "POST",
    url: site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    data: 'getGovernateArea=1&governateId='+governateId+'&txt_country='+countryid,
    cache: false,
    success: function(data)
    {

      $('#txt_bill_area').html(data);
      
    }
  });

}

function getGovernatecity(){

  var txt_bill_area = $('#txt_bill_area').val();
  if(txt_bill_area==0 && txt_bill_area!=undefined && txt_bill_area!=''){
    $('#othercitydiv').show();
  }else{
    $('#othercitydiv').hide();
  }


}


function manageAddress(e){
  
    flag = 0;
    e.preventDefault();
    var gulfcountry=$('#hid_gulf').val();
    var hid_national_id=$('#hid_national_id').val();

    if(gulfcountry==1){
      var txt_bill_area=$('#txt_bill_area').val();

      if(requiredValidate('txt_bill_name',enter_name)){
          flag++;
          $("#txt_bill_name").focus();
      }
      /*if(regexValidate('txt_bill_name',enter_name,enter_char_allow,'chkSpace')){
          flag++;
          $("#txt_bill_name").focus();
      }*/

      if(requiredValidate('txt_altmob_name',enter_phone_number)){
          flag++;
          $("#txt_altmob_name").focus();
      }

      if(requiredValidate('txt_bill_governate',please_select_governate)){
          flag++;
          $("#txt_bill_governate").focus();
      }

      if(requiredValidate('txt_bill_area',please_select_area)){
          flag++;
          $("#txt_bill_area").focus();
      }

      if(txt_bill_area==0){
         if(requiredValidate('txt_bill_other_area',enter_other_area)){
          flag++;
          $("#txt_bill_other_area").focus();
         }
      }

      if(requiredValidate('txt_bill_blockarea',enter_block)){
          flag++;
          $("#txt_bill_blockarea").focus();
      }

      if(requiredValidate('txt_bill_street',enter_street)){
          flag++;
          $("#txt_bill_street").focus();
      }

      if(requiredValidate('txt_bill_builidingno',enter_building_number)){
          flag++;
          $("#txt_bill_builidingno").focus();
      }
     

    }else{
      if(requiredValidate('txt_bill_name',enter_name)){
          flag++;
          $("#txt_bill_name").focus();
      }
      /*if(regexValidate('txt_bill_name',enter_name,enter_char_allow,'chkSpace')){
          flag++;
          $("#txt_bill_name").focus();
      }*/

      if(requiredValidate('txt_altmob_name',enter_phone_number)){
          flag++;
          $("#txt_altmob_name").focus();
      }

      if(requiredValidate('txt_bill_address1',enter_address_line_1)){
          flag++;
          $("#txt_bill_address1").focus();
      }

      if(requiredValidate('txt_bill_city',enter_city)){
          flag++;
          $("#txt_bill_city").focus();
      }

      if(requiredValidate('txt_bill_state',enter_area)){
          flag++;
          $("#txt_bill_state").focus();
      }
    } 

    if(hid_national_id==1){
      if(requiredValidate('national_id',enter_national_id)){
          flag++;
          $("#national_id").focus();
      }
    }

    if(flag>0){
      //For Autofocus validation highlight
        if($("#txt_bill_name").val()=='')
        {
        document.getElementById('txt_bill_name').focus();
        return false;
        }else if($("#txt_altmob_name").val()=='')
        {
        document.getElementById('txt_altmob_name').focus();
        return false;
        }else if($("#txt_bill_governate").val()=='')
        {
        document.getElementById('txt_bill_governate').focus();
        return false;
        }else if($("#txt_bill_area").val()=='')
        {
        document.getElementById('txt_bill_area').focus();
        return false;
        }else if($("#txt_bill_blockarea").val()=='')
        {
        document.getElementById('txt_bill_blockarea').focus();
        return false;
        }else if($("#txt_bill_street").val()=='')
        {
        document.getElementById('txt_bill_street').focus();
        return false;
        }else if($("#txt_bill_builidingno").val()=='')
        {
        document.getElementById('txt_bill_builidingno').focus();
        return false;
        }
      return false;
    }
    //Countrywise ordering management
    var countryid = $("#txt_country").val();

    $('#loader_search').show();
    $.ajax({
        url: site_url + 'controllers/ajax_controller/shop-ajax-controller.php',
        type: 'post',
        data: $('#addressForm').serialize()+'&txt_country='+countryid,
        success: function(result) {
         
         $('#loader_search').hide();
         $("#myModalEdit").modal("hide");
         $('#addresslist').html(result);
         getshippingchargegov();

    }
  });
}

function processcheckoutNext(e){
    flag = 0;
    e.preventDefault();
    var gulfcountry=$('#txt_gulf_next').val();
    var is_guest=$('#txt_guest_next').val();
    var is_gift_eligible=$('#is_gift_eligible').val();
    var hid_national_id=$('#hid_national_id').val();
    //Countrywise ordering management
    var countryid = $("#txt_country").val();
    
    if(is_guest>0){
      
      var adresscheck = $("input[name='adress']:checked").val();
      if(adresscheck){

      }else{
        $("#error_address").removeClass('success_msg');
        $("#error_address").addClass('already');
        $("#error_address").text("please select address").show().fadeOut(fadeOutSec);
        flag++;
      }
      
    }else{

      if(gulfcountry==1){
        var txt_bill_area=$('#txt_bill_area').val();

        if(regexValidate('txt_user_fname',enter_first_name,enter_char_allow,'chkSpace')){
            flag++;
            $("#txt_user_fname").focus();
        } 

        if(regexValidate('txt_user_lname',enter_last_name,enter_char_allow,'chkSpace')){
            flag++;
            $("#txt_user_lname").focus();
        } 

        if(requiredValidate('txt_user_email',enter_email_id)){
        flag++;
        $("#txt_user_email").focus();
        }

        if($('#txt_user_email').val()!='' && regexValidate('txt_user_email','',enter_valid_email_id,'email','yes')){
            flag++;
            $("#txt_user_email").focus();
        }

        if(requiredValidate('txt_user_mobile',enter_phone_number)){
            flag++;
            $("#txt_user_mobile").focus();
        }
        if(requiredValidate('txt_bill_name',enter_name)){
            flag++;
            $("#txt_bill_name").focus();
        } 

        /*if(regexValidate('txt_bill_name',enter_name,enter_char_allow,'chkSpace')){
            flag++;
            $("#txt_bill_name").focus();
        }*/

        if(requiredValidate('txt_altmob_name',enter_phone_number)){
            flag++;
            $("#txt_altmob_name").focus();
        }

        if(requiredValidate('txt_bill_governate',please_select_governate)){
            flag++;
            $("#txt_bill_governate").focus();
        }

        if(requiredValidate('txt_bill_area',please_select_area)){
            flag++;
            $("#txt_bill_area").focus();
        }

        if(txt_bill_area==0){
           if(requiredValidate('txt_bill_other_area',enter_other_area)){
            flag++;
            $("#txt_bill_other_area").focus();
           }
        }

        if(requiredValidate('txt_bill_blockarea',enter_block)){
            flag++;
            $("#txt_bill_blockarea").focus();
        }

        if(requiredValidate('txt_bill_street',enter_street)){
            flag++;
            $("#txt_bill_street").focus();
        }

        if(requiredValidate('txt_bill_builidingno',enter_building_number)){
            flag++;
            $("#txt_bill_builidingno").focus();
        }
       

      }else{

        if(regexValidate('txt_user_fname',enter_first_name,enter_char_allow,'chkSpace')){
            flag++;
            $("#txt_user_fname").focus();
        }
        if(regexValidate('txt_user_lname',enter_last_name,enter_char_allow,'chkSpace')){
            flag++;
            $("#txt_user_lname").focus();
        }

        if(requiredValidate('txt_user_email',enter_email_id)){
        flag++;
        $("#txt_user_email").focus();
        }

        if($('#txt_user_email').val()!='' && regexValidate('txt_user_email','',enter_valid_email_id,'email','yes')){
            flag++;
            $("#txt_user_email").focus();
        }

        if(requiredValidate('txt_user_mobile',enter_phone_number)){
            flag++;
            $("#txt_user_mobile").focus();
        }
        if(requiredValidate('txt_bill_name',enter_name)){
            flag++;
            $("#txt_bill_name").focus();
        }
        /*if(regexValidate('txt_bill_name',enter_name,enter_char_allow,'chkSpace')){
            flag++;
            $("#txt_bill_name").focus();
        }*/

        if(requiredValidate('txt_altmob_name',enter_phone_number)){
            flag++;
            $("#txt_altmob_name").focus();
        }

        if(requiredValidate('txt_bill_address1',enter_address_line_1)){
            flag++;
            $("#txt_bill_address1").focus();
        }

        if(requiredValidate('txt_bill_city',enter_city)){
            flag++;
            $("#txt_bill_city").focus();
        }

        if(requiredValidate('txt_bill_state',enter_area)){
            flag++;
            $("#txt_bill_state").focus();
        }
      } 
    }

    if(hid_national_id==1){
      if(requiredValidate('national_id',enter_national_id)){
          flag++;
          $("#national_id").focus();
      }
    } 

    if(flag>0){
        //For Autofocus validation highlight
        if($("#txt_user_fname").val()=='')
        {
        document.getElementById('txt_user_fname').focus();
        return false;
        }else if($("#txt_user_lname").val()=='')
        {
        document.getElementById('txt_user_lname').focus();
        return false;
        }else if($("#txt_user_email").val()=='')
        {
        document.getElementById('txt_user_email').focus();
        return false;
        }else if($("#txt_user_mobile").val()=='')
        {
        document.getElementById('txt_user_mobile').focus();
        return false;
        }else if($("#txt_bill_name").val()=='')
        {
        document.getElementById('txt_bill_name').focus();
        return false;
        }else if($("#txt_altmob_name").val()=='')
        {
        document.getElementById('txt_altmob_name').focus();
        return false;
        }else if($("#txt_bill_governate").val()=='')
        {
        document.getElementById('txt_bill_governate').focus();
        return false;
        }else if($("#txt_bill_area").val()=='')
        {
        document.getElementById('txt_bill_area').focus();
        return false;
        }else if($("#txt_bill_blockarea").val()=='')
        {
        document.getElementById('txt_bill_blockarea').focus();
        return false;
        }else if($("#txt_bill_street").val()=='')
        {
        document.getElementById('txt_bill_street').focus();
        return false;
        }else if($("#txt_bill_builidingno").val()=='')
        {
        document.getElementById('txt_bill_builidingno').focus();
        return false;
        }

      return false;
    }

  $.ajax({
    url: site_url + 'controllers/ajax_controller/checkout-ajax-controller.php',
    type: 'post',
    data: $('#addressFormdirect').serialize()+'&txt_country='+countryid,
    success: function(result) {
      if(result==2){
        $("#error_address").removeClass('success_msg');
        $("#error_address").addClass('already');
        $("#error_address").text(email_already_exist_in_system).show().fadeOut(fadeOutSec);
      }else if(result==3){
        $("#error_address").removeClass('success_msg');
        $("#error_address").addClass('already');
        $("#error_address").text(governate_area_error_146).show().fadeOut(fadeOutSec);
      }else if(result==4){
        $("#error_address").removeClass('success_msg');
        $("#error_address").addClass('already');
        $("#error_address").text(governate_error_145).show().fadeOut(fadeOutSec);
      }else{
        //Based on country wise & language
        var txt_lang_type = $("#txt_lang_type").val();

        if(is_gift_eligible==1){
          window.location.href=site_url+txt_lang_type+"/giftitem";
        }else{
          window.location.href=site_url+txt_lang_type+"/checkout";
        }
        
      }
    }
  });
}


function applypromocode(){

 var flag = 0;
 var txt_promocode = $("#txt_promocode").val();
 var paymenttype = $("input[name='paymentoption']:checked").val();

 if(requiredValidate('txt_promocode',enter_gift_voucher_promo_code)){
    flag++;
    $("#txt_promocode").focus();
 }
  if(flag>0){
    return false;
  }

  changePaymentmethods(2);
}

function clearpromocode() {

  $("#hid_promocode").val("");
  $("#txt_promocode").val("");
  var paymenttype = $("input[name='paymentoption']:checked").val();
  var txt_promocode = "";
  $("#txt_promocode").prop("disabled", false); 
  $("#btnRemovePromo").hide();
  $("#btnApplyPromo").show();
  $("#hid_promocode_status").val(0);
  changePaymentmethods(3);

}

function walletcreditoptions(type){

  var txt_wallet = $("input[name=wallet]:checked").val();
  if(txt_wallet==1 && type==1){
    $('#credit').prop('checked', false);
    $('#giftamount').prop('checked', false);
  }

  var txt_credit = $("input[name=credit]:checked").val();
  if(txt_credit==1 && type==2){
    $('#wallet').prop('checked', false);
    $('#giftamount').prop('checked', false);
  }

  var txt_giftamount = $("input[name=giftamount]:checked").val();
  if(txt_giftamount==1 && type==3){
    $('#wallet').prop('checked', false);
    $('#credit').prop('checked', false);
  }

  changePaymentmethods(4);

}

function changePaymentmethods(type){

  //1:payment option 2:apply 3:clear promo 4:wallet/credit/gift amount 

  var txt_promocode = $("#txt_promocode").val();
  var paymenttype = $("input[name='paymentoption']:checked").val();

  var txt_wallet = $("input[name=wallet]:checked").val();
  var txt_credit = $("input[name=credit]:checked").val();
  var txt_giftamount = $("input[name=giftamount]:checked").val();

  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  loader_show();
   $.ajax({
    url : site_url+'controllers/ajax_controller/checkout-ajax-controller.php', 
    type : 'post',
    dataType: "json",
    data: 'checkoutpayment=1&paymenttype='+paymenttype+'&promotcode_text='+txt_promocode+'&txt_wallet='+txt_wallet+'&txt_credit='+txt_credit+'&txt_giftamount='+txt_giftamount+'&type='+type+'&txt_country='+countryid,    
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },    
    success : function(resp) {

     $("#ordersummarylist").html(resp[17]); 
     $("#subtotal").html(resp[0]);
     $("#coupon_discount").html(resp[1]);
     $("#vat").html(resp[2]);
     if(resp[3]>0){
       $("#delivery_shipping").html(resp[3]);
      }else{
        $("#delivery_shipping").html('FREE');
      }

     if(resp[4]>0){
      $('#coddiv').show();
     }else{
      $('#coddiv').hide();
     }
     $("#cod_charge").html(resp[4]);

     $("#total_payble").html(resp[5]);
     $("#hid_grand_total").val(resp[5]);


     if(resp[7]>0){
       $("#used_wallet_amount_div").show();
       $("#used_wallet_amount").html(resp[7]);
     
     }else{
       $("#used_wallet_amount_div").hide();
       $("#used_wallet_amount").html(resp[7]);
     }

     if(resp[9]>0){
       $("#used_gift_amount_div").show();
       $("#used_gift_amount").html(resp[9]);
     
     }else{
       $("#used_gift_amount_div").hide();
       $("#used_gift_amount").html(resp[9]);
       $('#giftamount').prop('checked', false);
     }

      if(resp[8]>0){
       $("#used_credit_amount_div").show();
       $("#used_credit_amount").html(resp[8]);
     
     }else{
       $("#used_credit_amount_div").hide();
       $("#used_credit_amount").html(resp[8]);
     }

     if(resp[13]>0){
       $("#total_payable_in_usd_div").show();
       $("#total_payable_in_usd").html(resp[13]);

       $("#paypal_transaction_fees_div").show();
       $("#paypal_transaction_fees").html(resp[11]);
       $("#paypal_transaction_percentage").html(resp[10]);

       $("#paypal_fixed_fees_div").show();
       $("#paypal_fixed_fees").html(resp[12]);
       
     }else{
       $("#total_payable_in_usd_div").hide();
       $("#total_payable_in_usd").html(resp[13]);

       $("#paypal_transaction_fees_div").hide();
       $("#paypal_transaction_fees").html(resp[11]);
       $("#paypal_transaction_percentage").html(resp[10]);

       $("#paypal_fixed_fees_div").hide();
       $("#paypal_fixed_fees").html(resp[12]);

     }
     
     if(resp[6]>0){
        $("#btnRemovePromo").show();
        $("#btnApplyPromo").hide();
        $("#txt_promocode").prop("disabled", true); 
        //$("#hid_promocode").val(txt_promocode);

        if(type==2){
          $("#err_checkmessg").fadeIn();
          $("#err_checkmessg").html(coupon_code_applied_successfully);
          $("#err_checkmessg").css('color','green');
          $("#err_checkmessg").fadeOut(5000);
          $("#hid_promocode_status").val(1);
          
        }
     }else{
        if(type==2){
          $("#err_checkmessg").fadeIn();
          $("#err_checkmessg").html(please_enter_valid_coupon_code);
          $("#err_checkmessg").css('color','red');
          $("#err_checkmessg").fadeOut(5000);
          $("#hid_promocode_status").val(0);
        }
        $("#txt_promocode").val("");
     }

     if(type==2 || type==3){
      $("#txt_hid_gifts").val("");
      $("#giftscountshow").html(0);

       if(resp[15]==0){
        $("#gift_item_div").hide();
       }else{
        $("#gift_item_div").show();
       }
     }

    if(resp[18]==0){
      //$(".cashbackdiv").hide()
    }


     if(resp[19]==0){
      $("#cashback_summarydiv").hide()
     }else{
      $("#cashback_summarydiv").show()
     }
     $("#cashbacksummaryintowallet").val(resp[19]);
    

     $("#sub_total_kwd").val(resp[16]);

     loader_hide();
    }
  });
}


function giftItem(){

    
    var sub_total_kwd=$("#sub_total_kwd").val();
    var selectedgifts=$("#txt_hid_gifts").val();
    loader_show();  
    $("#fcbox_view_heading_tag_edit").html('<i class = "icon-tag"></i> Select Gift');
    $.ajax( {
    url : site_url+'controllers/ajax_controller/checkout-ajax-controller.php', 
    type : 'post',
    data: 'giftItem=1&sub_total_kwd='+sub_total_kwd+'&selectedgifts='+selectedgifts,        
    success : function( resp ) {
      $("#fcbox_view_content_tag_edit").html(resp);
      $(".fcbox_view_tag_edit").trigger('click');
   
      loader_hide();
    }
  });
}

function savesalectedgifts(){

   var cntcheckedcount = $('input[name="txt_permission[]"]:checked').length;
   var checkgiftval = [];
     $('input[type="checkbox"][name="txt_permission[]"]:checkbox:checked').each(function(i){
       checkgiftval[i] = $(this).val();
  });

  if(cntcheckedcount==0){
    alert('please select gift');
    return false;
  }   

   $("#txt_hid_gifts").val(checkgiftval);
   $("#giftscountshow").html(cntcheckedcount);
   $('#myModalEdit').modal('hide');

   getUsergiftlist();

}

function removegiftitemlist(id){

  var giftitemlist = $("#txt_hid_gifts").val();

  $.ajax( {
    url : site_url+'controllers/ajax_controller/checkout-ajax-controller.php', 
    type : 'post',
    data: 'removegiftitemlist=1&giftitemlist='+giftitemlist+'&id='+id,        
    success : function( resp ) {
      $("#txt_hid_gifts").val(resp);
      //loader_hide();
      getUsergiftlist();
    }
  });     
}

function getUsergiftlist(){

  var giftitemlist = $("#txt_hid_gifts").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/checkout-ajax-controller.php', 
    type : 'post',
    data: 'getUsergiftlist=1&giftitemlist='+giftitemlist,        
    success : function( resp ) {
      $("#giftlistitem").html(resp);
      loader_hide();
    }
  });   

}




function sendotp(){
    loader_show();

    flag = 0;
    if(requiredValidate('mobile_number',enter_phone_number)){
            flag++;
            $("#mobile_number").focus();
        } 
    if(flag>0){
      return false;
    }
    var mobile_number=$("#mobile_number").val();

    $.ajax( {
    url : site_url+'controllers/ajax_controller/checkout-ajax-controller.php', 
    type : 'post',
    data: 'sendotp=1&mobile_number='+mobile_number,        
    success : function( resp ) {
      if(resp==1){
         $("#mobileotpdiv").hide();
         $("#enterotpdiv").show();
      }else{
          $("#err_checkmessgotp").fadeIn();
          $("#err_checkmessgotp").html("OTP Not sent");
          $("#err_checkmessgotp").css('color','red');
          $("#err_checkmessgotp").fadeOut(5000);
      }
      loader_hide();
    }
  });
}


function verifyotp(){
  flag = 0;
  if(requiredValidate('otp',enter_otp_sent_to_your_mobile)){
          flag++;
          $("#otp").focus();
  } 
  if(flag>0){
    return false;
  }

  proceedtopay();
  
}

function proceedtopay(){


  loader_show();
  $("#mobileotpdiv").show();
  $("#enterotpdiv").hide();
  var otp=$("#otp").val();
  var hid_promocode_status=$("#hid_promocode_status").val();
  
  if(hid_promocode_status==1){
    var txt_promocode = $("#txt_promocode").val();
  }else{
     var txt_promocode = '';
  }
  
  var paymenttype = $("input[name='paymentoption']:checked").val();
  var txt_wallet = $("input[name=wallet]:checked").val();
  var txt_credit = $("input[name=credit]:checked").val();
  var txt_giftamount = $("input[name=giftamount]:checked").val();
  var txt_hid_gifts = $("#txt_hid_gifts").val();
  var hid_grand_total = $("#hid_grand_total").val();
  var hid_currency_rate = $("#hid_currency_rate").val();

  var is_cashback_promotion = $("#is_cashback_promotion").val();
  var is_cashback_discount = $("#is_cashback_discount").val();
  var is_cashback_coupon = $("#is_cashback_coupon").val();
  var hid_user_gift_amount = $("#hid_user_gift_amount").val();
  var hid_paypal_fees_percentage = $("#hid_paypal_fees_percentage").val();
  var hid_paypal_fees = $("#hid_paypal_fees").val();
  var hid_is_gift_enable = $("#hid_is_gift_enable").val();
  var subtotal= $("#subtotal").html();

  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  $.ajax({
    url : site_url+'controllers/ajax_controller/order-ajax-controller.php', 
    type : 'post',
    data: 'proceedtopay=1&otp='+otp+'&paymenttype='+paymenttype+'&txt_wallet='+txt_wallet+'&txt_credit='+txt_credit+'&txt_giftamount='+txt_giftamount+'&txt_hid_gifts='+txt_hid_gifts+'&txt_promocode='+txt_promocode+'&hid_grand_total='+hid_grand_total+'&hid_currency_rate='+hid_currency_rate+'&is_cashback_promotion='+is_cashback_promotion+'&is_cashback_discount='+is_cashback_discount+'&is_cashback_coupon='+is_cashback_coupon+'&hid_user_gift_amount='+hid_user_gift_amount+'&hid_paypal_fees_percentage='+hid_paypal_fees_percentage+'&hid_paypal_fees='+hid_paypal_fees+'&hid_is_gift_enable='+hid_is_gift_enable+'&txt_country='+countryid+'&subtotal='+subtotal,        
    success : function( resp ) {
      if(resp==1){
        $(".fcbox_view_tag_otp").trigger('click');
        $("#myModalOTP").modal('show');
          $("#otp").val("");
      }else if(resp==2){
          $("#otp").val("");
          $("#err_checkmessgotp").fadeIn();
          $("#err_checkmessgotp").html(wrong_otp);
          $("#err_checkmessgotp").css('color','red');
          $("#err_checkmessgotp").fadeOut(5000);
      }else if(resp==3){
        //redirect to thank you page
        window.location.href=site_url+txt_lang_type+"/success-payment";
      }else if(resp==4){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(something_went_wrong);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==11){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(some_product_out_of_stock_new);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
        window.location.href=site_url+txt_lang_type+"/cart";
      }else if(resp==12){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(order_access_denied_114);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==105){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(country_inactive_105);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
        window.location.reload();
      }else if(resp==106){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(payment_type_not_allowed_106);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==116){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(wallet_disable_116);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==107){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(currency_rate_mismatch_107);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==117){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(promotion_cashback_disable_117);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==118){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(discount_cashback_disable_118);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==119){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(coupon_code_disable_119);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==124){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(gift_amount_mismatch_124);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==109){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(shipping_charge_mismatch_109);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==122){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(gift_settings_miss_match_122);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==145){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(governate_error_145);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }else if(resp==5){
        //redirect to thank you page
        window.location.href=site_url+txt_lang_type+"/cart";
      }else if(resp==6){
        //redirect to thank you page
      // giftItem();
      }else if(resp==131){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(error_131);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
        window.location.href=site_url+txt_lang_type+"/cart";
      }else if(resp==132){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(error_132);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
        window.location.href=site_url+txt_lang_type+"/cart";
      }else if(resp==133){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(error_133);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
        window.location.href=site_url+txt_lang_type+"/cart";
      }else if(resp==135){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(error_135);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
        window.location.href=site_url+txt_lang_type+"/cart";
      }else if(resp==147){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(mobile_number_already_exists);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
        window.location.href=site_url+txt_lang_type+"/cart";
      }else if(resp==148){
        $('#MobileData').modal('toggle');
      }else if(resp==150){
        $("#update_mobile").val('');
        $('#MobileData').modal('toggle');
      }else if(resp==151){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(some_product_out_of_stock_new);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
        window.location.reload();
      }/*else if(resp==149){
        $("#err_checkmessgpayment").fadeIn();
        $("#err_checkmessgpayment").html(country_verification_otp);
        $("#err_checkmessgpayment").css('color','red');
        $("#err_checkmessgpayment").fadeOut(5000);
      }*/else{
        window.location.href=resp.trim();
      }
      loader_hide();
    } 

  });
}
function proceedtopayanalytics(){


  loader_show();
  $("#mobileotpdiv").show();
  $("#enterotpdiv").hide();
  var otp=$("#otp").val();
  var hid_promocode_status=$("#hid_promocode_status").val();
  
  if(hid_promocode_status==1){
    var txt_promocode = $("#txt_promocode").val();
  }else{
     var txt_promocode = '';
  }
  
  var paymenttype = $("input[name='paymentoption']:checked").val();
  var txt_wallet = $("input[name=wallet]:checked").val();
  var txt_credit = $("input[name=credit]:checked").val();
  var txt_giftamount = $("input[name=giftamount]:checked").val();
  var txt_hid_gifts = $("#txt_hid_gifts").val();
  var hid_grand_total = $("#hid_grand_total").val();
  var hid_currency_rate = $("#hid_currency_rate").val();

  var is_cashback_promotion = $("#is_cashback_promotion").val();
  var is_cashback_discount = $("#is_cashback_discount").val();
  var is_cashback_coupon = $("#is_cashback_coupon").val();
  var hid_user_gift_amount = $("#hid_user_gift_amount").val();
  var hid_paypal_fees_percentage = $("#hid_paypal_fees_percentage").val();
  var hid_paypal_fees = $("#hid_paypal_fees").val();
  var hid_is_gift_enable = $("#hid_is_gift_enable").val();
  

  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  $.ajax({
    url : site_url+'controllers/ajax_controller/order-ajax-controller.php', 
    type : 'post',
    dataType : 'json',
    data: 'proceedtopayanalytics=1&otp='+otp+'&paymenttype='+paymenttype+'&txt_wallet='+txt_wallet+'&txt_credit='+txt_credit+'&txt_giftamount='+txt_giftamount+'&txt_hid_gifts='+txt_hid_gifts+'&txt_promocode='+txt_promocode+'&hid_grand_total='+hid_grand_total+'&hid_currency_rate='+hid_currency_rate+'&is_cashback_promotion='+is_cashback_promotion+'&is_cashback_discount='+is_cashback_discount+'&is_cashback_coupon='+is_cashback_coupon+'&hid_user_gift_amount='+hid_user_gift_amount+'&hid_paypal_fees_percentage='+hid_paypal_fees_percentage+'&hid_paypal_fees='+hid_paypal_fees+'&hid_is_gift_enable='+hid_is_gift_enable+'&txt_country='+countryid,        
    success : function( resp ) {
      // alert(resp.currencyCode); return false;
      checkoutanalytics(resp.product_id,resp.product_name,resp.qty,resp.currencyCode);
    } 

  });
}


function updateprofile(e){

  flag = 0;
  e.preventDefault();
  var old_password=$("#old_password").val();
  var new_password=$("#new_password").val();
  var confirm_new_password=$("#confirm_new_password").val();
  var otp_status=$("#is_enable_otp").val();


  if(regexValidate('FName1',enter_first_name,enter_char_allow,'chkSpace')){
        flag++;
        $("#FName1").focus();
  }  
    /*if(requiredValidate('LName1',enter_last_name)){
        flag++;
        $("#LName1").focus();
    }*/
    // if(requiredValidate('txt_c_dob1',select_birthdate)){
    //     flag++;
        // $("#txt_c_dob1").focus();
    // } 
    if(requiredValidate('userEmail1',enter_email_id)){
        flag++;
        $("#userEmail1").focus();
    }

    if($('#userEmail1').val()!='' && regexValidate('userEmail1','',enter_valid_email_id,'email','yes')){
        flag++;
        $("#userEmail1").focus();
    }

    if(requiredValidate('userPhone1',enter_phone_number)){
        flag++;
        $("#userPhone1").focus();
    }


    if(old_password!='' && old_password!=undefined){
      if(requiredValidate('old_password',enter_password)){
        flag++;
        $("#old_password").focus();
      }

      if(requiredValidate('new_password',enter_new_password)){
          flag++;
          $("#new_password").focus();
      }

      if($('#new_password').val()!='' && regexValidate('new_password','',password_length,'password','yes')){
        flag++;
        $("#new_password").focus();
    }

      if(requiredValidate('confirm_new_password',enter_confirm_password)){
          flag++;
          $("#confirm_new_password").focus();
      }

      if(new_password!=confirm_new_password && new_password!='' && confirm_new_password!=''){
        $("#error_uprofile").removeClass('success_msg');
        $("#error_uprofile").addClass('error_msg');
        $("#error_uprofile").text(password_does_not_match).show().fadeOut(fadeOutSec);
        flag++;
      }
    }  

    var mobile =   $('#userPhone1').val();
    var user_id =   $('#hid_userid').val();
    var country_code = $("#txt_country_code").val(); 

    if(flag>0){
      return false;
    }

    loader_show();
    $.ajax({
        url: site_url + 'controllers/ajax_controller/login-ajax-controller.php',
        type: 'post',
        data: $('#updateprofileForm').serialize(),
        success: function(result) {
            loader_hide();
          if (result.trim()=='1') {
            $("#error_uprofile").removeClass('error_msg');
            $("#error_uprofile").addClass('success_msg');
            $("#error_uprofile").text(profile_updated_successfully).show().fadeOut(fadeOutSec);
            $("#old_password").val('');
            $("#new_password").val('');
            $("#confirm_new_password").val('');
            if(otp_status==1)
            {
            $('#verifyMobilenumner').val(mobile);
            let labelElement = document
                .getElementById("phonenewnumber");
            labelElement.innerHTML = "+"+country_code+" "+mobile;
            $('#verifyCountrtCode').val(country_code);
            
            $("#MobileData .close").click()
            $("#movileVefificationModel").modal();
            countdown(2,0,user_id);
            }

           }else if (result.trim()=='4') {
            $("#error_uprofile").removeClass('success_msg');
            $("#error_uprofile").addClass('already');
            $("#error_uprofile").text(mobile_number_already_exists).show().fadeOut(fadeOutSec);
          }else if (result.trim()=='5') {
            $("#error_uprofile").removeClass('success_msg');
            $("#error_uprofile").addClass('already');
            $("#error_uprofile").text(old_password_incorrect).show().fadeOut(fadeOutSec);
          }else if(result == 0){
            $("#error_uprofile").removeClass('success_msg');
            $("#error_uprofile").addClass('error_msg');
            $("#error_uprofile").text(email_already_exist_in_system).show().fadeOut(fadeOutSec);
          }else if(result == 6){
            verifymobileupdate(); //Show and redirect to popup verification while change number
          }else{
            $("#error_uprofile").removeClass('success_msg');
            $("#error_uprofile").addClass('error_msg');
            $("#error_uprofile").text(something_went_wrong).show().fadeOut(fadeOutSec);
          }
    }

  });
}
function verifymobileupdate()
{
  var mobile =   $('#userPhone1').val();
  var user_id =   $('#hid_userid').val();
  var country_code = $("#txt_country_code").val();

    loader_show();
    $.ajax({
      url: site_url + 'controllers/ajax_controller/my-account-ajax-controller.php',
      type: 'post',
      data: 'resend_otp=1&mobile=' + mobile + '&country_code=' + country_code +'&user_id=' + user_id,
      success: function(result) {
        // result.trim();
        loader_hide();
        if(result == 1)
        {
            // alert(otpResendSuccess);
            // $('#resendalert').model();
            $("#resend_otp_success_message").addClass('success_msg');
            $("#resend_otp_success_message").removeClass('error_msg');
            $("#resend_otp_success_message").text(otpResendSuccess).show().fadeOut(fadeOutSec);
            $('#verifyMobilenumner').val(mobile);
            let labelElement = document
                .getElementById("phonenewnumber");
            labelElement.innerHTML = "+"+country_code+" "+mobile;
            $('#verifyCountrtCode').val(country_code);
            
            $("#MobileData .close").click()
            $("#movileVefificationModel").modal();
            countdown(2,0,user_id);
        }
        else{
            $("#mobileerror_register").removeClass('success_msg');
            $("#mobileerror_register").addClass('error_msg');
            $("#mobileerror_register").text("Otp not send").show().fadeOut(fadeOutSec);
        }              
      }
  });
}
function updateProfilePic(){
    var flag = 0;
    var img=$("#profilePic").val();
    // alert(img);
    if(img!='' && regexValidate('profilePic',"",upload_img,'img')){
        flag++;
    }
    if(flag>0)
    {
        return false;
    }
    var file_data = $('#profilePic').prop('files')[0];   
    var form_data = new FormData();                  
    form_data.append('profilePic', file_data);
    loader_show();
    $.ajax({
        url: site_url + 'controllers/ajax_controller/my-account-ajax-controller.php',
        type: 'post',
        data: form_data,
        processData: false,
        contentType: false,
        success: function(result) {
            loader_hide();
            // alert(result);
           if (result == 1) {
                location.reload();
            }else{
                location.reload();
            }
    }

});
}


function  getorderlist(page) {

  $.ajax({
    url : site_url+'controllers/ajax_controller/my-order-ajax-controller.php',
    type : "post",
    data: 'orderlist=1&page='+page,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      // alert(resp);
      $("#orderlist").html(resp);
    }
  });
}


function  getwalletlist(page) {
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  $.ajax({
    url : site_url+'controllers/ajax_controller/my-order-ajax-controller.php',
    type : "post",
    data: 'getwalletlist=1&page='+page+'&txt_country='+countryid,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      // alert(resp);
      $("#orderlist").html(resp);
    }
  });
}



function vieworder(id){
  loader_show();  
  $("#fcbox_view_heading_tag_order").html('<i class = "icon-tag"></i> My Order Details');
  $.ajax( {
    url : site_url+'controllers/ajax_controller/my-order-ajax-controller.php',
    type : 'post',
    data: 'vieworder=1&id='+id,
    success : function(result)
    {
      $("#orderdetailsview").html(result);
      $(".fcbox_view_tag_order").trigger('click');
      loader_hide();
    }
  });
}

function vieworder2(id){
  loader_show();  
  $("#fcbox_view_heading_tag_order").html('<i class = "icon-tag"></i> Track Order');
  $.ajax( {
    url : site_url+'controllers/ajax_controller/my-order-ajax-controller.php',
    type : 'post',
    data: 'vieworder2=1&id='+id,
    success : function(result)
    {
      $("#orderdetailsview").html(result);
      $(".fcbox_view_tag_order").trigger('click');
      loader_hide();
    }
  });
}

function reorder(id){
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  loader_show();  
  $.ajax( {
    url : site_url+'controllers/ajax_controller/my-order-ajax-controller.php',
    type : 'post',
    data: 'reorder=1&id='+id+'&txt_country='+countryid,
    success : function(result)
    {
      //Based on country wise & language
      var txt_lang_type = $("#txt_lang_type").val();
      window.location.href=site_url+txt_lang_type+"/cart";
      loader_hide();
    }
  });
}


function walletdetails(id){
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  loader_show();  
  $("#fcbox_view_heading_tag_order").html('<i class = "icon-tag"></i> Transaction Details');
  $.ajax( {
    url : site_url+'controllers/ajax_controller/my-order-ajax-controller.php',
    type : 'post',
    data: 'walletdetails=1&id='+id+'&txt_country='+countryid,
    success : function(result)
    {
      $("#orderdetailsview").html(result);
      $(".fcbox_view_tag_order").trigger('click');
      loader_hide();
    }
  });
}


function  getcreditlist(page) {
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  $.ajax({
    url : site_url+'controllers/ajax_controller/my-order-ajax-controller.php',
    type : "post",
    data: 'getcreditlist=1&page='+page+'&txt_country='+countryid,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      $("#orderlist").html(resp);
    }
  });
}



function  rateNow(id) {
  $("#"+id).show();
}

function  saveRating(id,productid,idk) {
  var star = $("input[name="+id+"]:checked").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/my-order-ajax-controller.php',
    type : 'post',
    data: 'rateNow=1&star='+star+'&productid='+productid,
    success : function(result)
    {
      $("#starsdivmain"+idk).html(result);
    }
  });
}


function copyText() {
  var copyText = document.getElementById("referal_code_text");
  copyText.select();
  copyText.setSelectionRange(0, 99999); /*For mobile devices*/
  document.execCommand("copy");
}

function brandtypeselection(type){

  var type1 = $("input[name=type1]:checked").val();
  $("#typetag").hide();
  if(type1==1 && type==1){
    $('#type2').prop('checked', false);
    $('#type3').prop('checked', false);

    var typenameatt=$("#type"+type).attr("typenameatt");
    var typetaglist='<span class="typetaglistsep" id="removetype'+type+'" onclick="removebrandtypetag(&apos;'+type+'&apos;);"><span class="fil_label_dat">'+typenameatt+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
     $("#typetaglist").append(typetaglist);

     $("#removetype2").remove();
     $("#removetype3").remove();
     $("#typetag").show();
  }else{
    $("#removetype1").remove();
  }

  var type2 = $("input[name=type2]:checked").val();
  if(type2==2 && type==2){

    $('#type1').prop('checked', false);
    $('#type3').prop('checked', false);

    var typenameatt=$("#type"+type).attr("typenameatt");
    var typetaglist='<span class="typetaglistsep" id="removetype'+type+'" onclick="removebrandtypetag(&apos;'+type+'&apos;);"><span class="fil_label_dat">'+typenameatt+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
     $("#typetaglist").append(typetaglist);

     $("#removetype1").remove();
     $("#removetype3").remove();
     $("#typetag").show();

  }else{
    $("#removetype2").remove();
  }

  var type3 = $("input[name=type3]:checked").val();
  if(type3==3 && type==3){
    $('#type1').prop('checked', false);
    $('#type2').prop('checked', false);

    var typenameatt=$("#type"+type).attr("typenameatt");
    var typetaglist='<span class="typetaglistsep" id="removetype'+type+'" onclick="removebrandtypetag(&apos;'+type+'&apos;);"><span class="fil_label_dat">'+typenameatt+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
     $("#typetaglist").append(typetaglist);

     $("#removetype1").remove();
     $("#removetype2").remove();
     $("#typetag").show();

  }else{
    $("#removetype3").remove();
  }



  if(type==2 || type==3){ 
    $('#colorlistdiv').hide();
    $('.colorlist').prop('checked', false);
    $('.colortaglist').remove();
    $('#colortag').hide();
  }else{
    $('#colorlistdiv').show();
    //$('.colorlist').prop('checked', true);
    
  }

   $('.blist').prop('checked', false);
   $('.clist').prop('checked', false);

    $("#brandtag").hide();
    $("#collectiontag").hide();
    $(".brandtaglist1").remove();
    $(".collectiontaglist").remove();

     $("#searchbrand").val('');
     
     getProductList(1);
     autoCompleteBrandSearch('');
} 


function removebrandtypetag(id){
  $("#removetype"+id).remove();
  $("#typetag").hide();
  $('#type'+id).prop('checked', false);

   getProductList(1);
}


function clearReplacement(){
  $('.replacementlist').prop('checked', false);

  $("#repltag").hide();
  $(".repltaglist").remove();

   getProductList(1);
}

function clearColors(){
  $('.colorlist').prop('checked', false);

   $("#colortag").hide();
   $(".colortaglist").remove();

    getProductList(1);
}


function ClearBrand(){
  $('.blist').prop('checked', false);
  $('.clist').prop('checked', false);
  $('#searchbrand').val('');
  
  $(".brandtaglist1").remove();
  $(".collectionlist").remove();

  $("#brandtag").hide();
  $("#collectiontag").hide();
   getProductList(1); 
}

function ClearBrandType(){

  $('#type1').prop('checked', false);
  $('#type2').prop('checked', false);
  $('#type3').prop('checked', false);

  brandtypeselection('');
   getProductList(1);
}

function clearSearchTag(){
  $("#searchtag").hide();
  $(".searchtaglistsep").remove();
  $("#searchtext").val('');
  getProductList(1);
}

function applyproductfilter(){

  var blist=$(".blist:checkbox:checked").length; 
  // if(blist==0){
  //   alert(select_one_brand);
  //   return false;
  // }

  var brand_list_id = $(".blist:checkbox:checked").map( function() {
    return this.value;
  }).get().join(",");

  var collection_list_id = $(".clist:checkbox:checked").map( function() {
    return this.value;
  }).get().join(",");

  var color_list_id = $(".colorlist:checkbox:checked").map( function() {
    return this.value;
  }).get().join(",");

  var replacement_list_id = $(".replacementlist:checkbox:checked").map( function() {
    return this.value;
  }).get().join(",");

  var star_list_id = $(".star:radio:checked").map( function() {
    return this.value;
  }).get().join(",");


  if(brand_list_id!='' && brand_list_id!=undefined){
    $("#filt_txt_brand").val(brand_list_id);
  }else{
     $("#filt_txt_brand").val('');
  }

  if(collection_list_id!='' && collection_list_id!=undefined){
    $("#filt_txt_collection").val(collection_list_id);
  }else{
     $("#filt_txt_collection").val('');
  }

  if(color_list_id!='' && color_list_id!=undefined){
    $("#filt_txt_color").val(color_list_id);
  }else{
     $("#filt_txt_color").val('');
  }

  if(replacement_list_id!='' && replacement_list_id!=undefined){
    $("#filt_txt_replacement").val(replacement_list_id);
  }else{
     $("#filt_txt_replacement").val('');
  }

  if(star_list_id!='' && star_list_id!=undefined){
    $("#filt_txt_rating").val(star_list_id);
  }else{
     $("#filt_txt_rating").val('');
  }

  
  getProductList(1);
}

function msort(){
    $('#modal_sort').modal('hide');
    $("#mapplyfilter").val(1);
    getProductList(1);
}

 function applyfilter(){  

    $('#modal_filter').modal('hide');

    $("#mapplyfilter").val(1);
    var type1 = $("input[name=type11]:checked").val();
    var type2 = $("input[name=type21]:checked").val();
    var type3 = $("input[name=type31]:checked").val();

  
    var type="";
    if(type1==1){
        type = 1;
    }else if(type2==2){
      type = 2;
    }else if(type3==3){
      type = 3;
    }else{

    } 
    $("#mbrandtype").val(type);

    var filt_txt_brand = $(".brandtaglist1").map( function() {
    var text=this.id;
      text = text.replace("removeb", "");
      return text;
    }).get().join(",");

    $("#mbrandlist").val(filt_txt_brand); 

    var filt_txt_collection = $(".collectiontaglist").map( function() {
      var text1=this.id;
       text1 = text1.replace("removec", "");
       return text1;
    }).get().join(",");

    $("#mcategorylist").val(filt_txt_collection);

    var replacement_list_id = $(".replacementlist:checkbox:checked").map( function() {
      return this.value;
    }).get().join(","); 

    $("#mreplacementlist").val(replacement_list_id);

     var color_list_id = $(".colorlist:checkbox:checked").map( function() {
      return this.value;
    }).get().join(",");
    $("#mcolorlist").val(color_list_id);

    var star_list_id = $(".mstar:radio:checked").map( function() {
      return this.value;
    }).get().join(",");

    $("#mratinglist").val(star_list_id);

    // getProductList1(1);

 }

 var action = 'inactive';
 function getProductList(page){

  var txt_page_total=$("#txt_page_total").val();
  if(page>txt_page_total && page!=1){
    return false;
  }

  loader_show();
  //check filter type
  var mapplyfiltertype= $("#mapplyfilter").val();
  if(mapplyfiltertype==1){
      //mobile filter 
      var sortby = $("input[name=sort]:checked").val();
      var mbrandtype = $("#mbrandtype").val();
      
      var type1="";
      var type2="";
      var type3="";
      if(mbrandtype==1){
        type1 = 1;
      }else if(mbrandtype==2){
        type2 = 2;
      }else if(mbrandtype==3){
        type3 = 3;
      }  
      
    
    var filt_txt_brand = $("#mbrandlist").val();
    var filt_txt_collection = $("#mcategorylist").val();

    if(type1==1){
      var typeselect=1;
    }else if(type2==2){
      var typeselect=2;
    }else if(type3==3){
      var typeselect=3;
    }else{
      var typeselect='';
    }

    var color_list_id = $("#mcolorlist").val();
    if(color_list_id!='' && color_list_id!=undefined){
      var filt_txt_color=color_list_id;
    }else{
       var filt_txt_color='';
    }

    var replacement_list_id = $("#mreplacementlist").val();

    if(replacement_list_id!='' && replacement_list_id!=undefined){
      var filt_txt_replacement=replacement_list_id;
    }else{
       var filt_txt_replacement='';
    }

    var star_list_id = $("#mratinglist").val();

    if(star_list_id!='' && star_list_id!=undefined){
      var filt_txt_rating=star_list_id;
    }else{
       var filt_txt_rating='';
    }

  }else{
     //desktop filter 
     var sortby=$("#sortby").val();
     var type1 = $("input[name=type1]:checked").val();
     var type2 = $("input[name=type2]:checked").val();
     var type3 = $("input[name=type3]:checked").val();

     var filt_txt_brand = $(".brandtaglist1").map( function() {
     var text=this.id;
       text = text.replace("removeb", "");
       return text;
     }).get().join(",");

    var checked = $('input[type="checkbox"].blist:checked'); // get checked values
    var checkedValues = [];
    var checked5 = [];
    checked.each(function (i) {
        checkedValues.push($(this).attr("data-id"));
        checked5.push($(this).val());
    });
    var filt_txt_brand = checkedValues.join(',');
    var filt_txt_brand_paginate = checked5.join(',');

    var brandcount = filt_txt_brand.split(",").length;
    if(brandcount == 1)
    {
    /*var checkedcollect = $('input[type="checkbox"].clist:checked'); // get checked values
    var checkedValuesCollect = [];
    var checkedValuesCollectid = [];
    var checked55 = [];
    checkedcollect.each(function (i) {
        checkedValuesCollectid.push($(this).attr("data-id"));
        checkedValuesCollect.push($(this).attr("clistname"));
        checked55.push($(this).val());
    });
    
    var filt_txt_category = checkedValuesCollect.join(',');
    var filt_txt_category_paginate = checked55.join(',');
    var filt_txt_category_id = checkedValuesCollectid.join(',');*/
    var checkedValuesCollect = {};
    var checkedValuesCollectid = {};
    var checked55 = {};
    $('input[type="checkbox"].clist:checked').each(function (i) {
        var dataId = $(this).attr("data-id");
        var clistname = $(this).attr("clistname");
        var value = $(this).val();

        // Use an object or Set to keep track of unique values
        checkedValuesCollectid[dataId] = true;
        checkedValuesCollect[clistname] = true;
        checked55[value] = true;
    });
    var filt_txt_category = Object.keys(checkedValuesCollect).join(',');
    var filt_txt_category_paginate = Object.keys(checked55).join(',');
    var filt_txt_category_id = Object.keys(checkedValuesCollectid).join(',');
    // alert(filt_txt_category);

    }else{
     /*var filt_txt_collection = $(".collectiontaglist").map( function() {
      var text1=this.id;
       text1 = text1.replace("removec", "");
       return text1;
    }).get().join(",");*/


    var checkedcollect = $('.collectiontaglist'); // get checked values
    var checkedValuesCollect = [];
    var collection_list_id_values = [];
    var checked11 = [];
    checkedcollect.each(function (i) {
        collection_list_id_values.push($(this).attr("data-id"));
        checkedValuesCollect.push($(this).attr("clistname"));
        checked11.push($(this).val());
    });
    var filt_txt_category = checkedValuesCollect.join(',');
    var filt_txt_category_paginate = checked11.join(',');
    var filt_txt_category_id = collection_list_id_values.join(',');
    /*alert(filt_txt_category);
    alert(filt_txt_category_id);*/

    }


    var filt_txt_collection = $(".collectiontaglist").map( function() {
      var text1=this.id;
       text1 = text1.replace("removec", "");
       return text1;
    }).get().join(",");
    if(type1==1){
      var typeselect=1;
      var typeselectchar="colored";
    }else if(type2==2){
      var typeselect=2;
      var typeselectchar="prescription";
    }else if(type3==3){
      var typeselect=3;
      var typeselectchar="accessories";
    }else{
      var typeselect='';
      var typeselectchar="";
    }

    var color_list_id = $(".colorlist:checkbox:checked").map( function() {
      return this.value;
    }).get().join(",");

     if(color_list_id!='' && color_list_id!=undefined){
      var filt_txt_color=color_list_id;
    }else{
       var filt_txt_color='';
    }

    var checkedcolor = $('input[type="checkbox"].colorlist:checked'); // get checked values
    var color_list_id_values = [];
    var checked10 = [];
    checkedcolor.each(function (i) {
        color_list_id_values.push($(this).attr("data-id"));
        checked10.push($(this).val());
    });
    var filt_txt_collection = color_list_id_values.join(',');
    var filt_collection_paginate = checked10.join(',');
      

    var replacement_list_id = $(".replacementlist:checkbox:checked").map( function() {
     var text=this.id;
       text = text.replace("removerepl", "");
       return text;
     }).get().join(",");

    var checkedreplace = $('input[type="checkbox"].replacementlist:checked'); // get checked values
    var replacement_list_id_values = [];
    var checked15 = [];
    checkedreplace.each(function (i) {
        replacement_list_id_values.push($(this).attr("data-id"));
        checked15.push($(this).val());
    });
    var replacement_list_id = replacement_list_id_values.join(',');
    var filt_replacement_paginate = checked15.join(',');

    if(replacement_list_id!='' && replacement_list_id!=undefined){
      var filt_txt_replacement=replacement_list_id;
    }else{
       var filt_txt_replacement='';
    }
      
    var star_list_id = $(".star:radio:checked").map( function() {
      return this.value;
    }).get().join(",");

    if(star_list_id!='' && star_list_id!=undefined){
      var filt_txt_rating=star_list_id;
    }else{
       var filt_txt_rating='';
    }
  }

  var txt_last_collection_id=$("#txt_last_collection_id").val();

  if(sortby=='')
  {
    sortby = '4';
  }  
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  
  var queryParam = site_url+txt_lang_type+'/product-list'+'&types='+typeselectchar+'&brand='+filt_txt_brand+'&color='+filt_txt_collection+'&collections='+filt_txt_category+'&replacement_list_id='+replacement_list_id+'&star_list_id='+star_list_id+'&sortby='+sortby; // create query param  
  // alert(queryParam);
  // alert(filt_txt_category_id);
  // alert(filt_txt_category);
  window.location.href = queryParam;
  
  
  if(page==1){
    $("#is_collection_banner").val('0');
  }


  var searchtext=$("#searchtext").val();
  var is_collection_banner=$("#is_collection_banner").val();


  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  $.ajax({
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php',
     type : "post",
    dataType: "json",
    data: 'Productlist=1&page='+page+'&sortby='+sortby+'&filt_txt_brand='+filt_txt_brand_paginate+'&filt_txt_collection='+filt_txt_category_id+'&filt_txt_color='+filt_txt_color+'&filt_txt_replacement='+filt_replacement_paginate+'&filt_txt_rating='+filt_txt_rating+'&searchtext='+searchtext+'&typeselect='+typeselect+'&txt_last_collection_id='+txt_last_collection_id+'&is_collection_banner='+is_collection_banner+'&txt_country='+countryid,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      if(page==1){
        $("#Productlist").html(resp[0]);
      }else{
         if(is_collection_banner==1){
           $(".productlistul").append(resp[0]);
         }else{
           $("#Productlist").append(resp[0]);   
         }
      }
      
      $("#totalproductcount").html(resp[1]);
      $("#txt_page_total").val(resp[2]);
      $("#txt_last_collection_id").val(resp[3]);
      var pagecnt=parseInt(page)+1;
      $("#txt_page_no").val(pagecnt);
       loader_hide();
       action = "inactive";
    }
  });
}
var action = 'inactive';
 function getProductListPagination(page){

  var txt_page_total=$("#txt_page_total").val();
  if(page>txt_page_total && page!=1){
    return false;
  }

  loader_show();
  //check filter type
  var mapplyfiltertype= $("#mapplyfilter").val();
  if(mapplyfiltertype==1){
      //mobile filter 
      var sortby = $("input[name=sort]:checked").val();
      var mbrandtype = $("#mbrandtype").val();
      
      var type1="";
      var type2="";
      var type3="";
      if(mbrandtype==1){
        type1 = 1;
      }else if(mbrandtype==2){
        type2 = 2;
      }else if(mbrandtype==3){
        type3 = 3;
      }  
      
    
    var filt_txt_brand = $("#mbrandlist").val();
    var filt_txt_collection = $("#mcategorylist").val();

    if(type1==1){
      var typeselect=1;
    }else if(type2==2){
      var typeselect=2;
    }else if(type3==3){
      var typeselect=3;
    }else{
      var typeselect='';
    }

    var color_list_id = $("#mcolorlist").val();
    if(color_list_id!='' && color_list_id!=undefined){
      var filt_txt_color=color_list_id;
    }else{
       var filt_txt_color='';
    }

    var replacement_list_id = $("#mreplacementlist").val();

    if(replacement_list_id!='' && replacement_list_id!=undefined){
      var filt_txt_replacement=replacement_list_id;
    }else{
       var filt_txt_replacement='';
    }

    var star_list_id = $("#mratinglist").val();

    if(star_list_id!='' && star_list_id!=undefined){
      var filt_txt_rating=star_list_id;
    }else{
       var filt_txt_rating='';
    }

  }else{
     //desktop filter 
     var sortby=$("#sortby").val();
     var type1 = $("input[name=type1]:checked").val();
     var type2 = $("input[name=type2]:checked").val();
     var type3 = $("input[name=type3]:checked").val();

     var brand_list_id = $(".brandtaglist1").map( function() {
     var text=this.id;
       text = text.replace("removeb", "");
       return text;
     }).get().join(",");

    var checked = $('input[type="checkbox"].blist:checked'); // get checked values
    var checkedValues = [];
    var checked5 = [];
    checked.each(function (i) {
        checkedValues.push($(this).attr("data-id"));
        checked5.push($(this).val());
    });
    if(brand_list_id!='' && brand_list_id!=undefined){
      var filt_txt_brand=brand_list_id;
    }else{
       var filt_txt_brand='';
    }
    // alert(filt_txt_brand);
    var checkedcollect = $('input[type="checkbox"].clist:checked'); // get checked values
    var checkedValuesCollect = [];
    var checked55 = [];
    checkedcollect.each(function (i) {
        // checkedValuesCollect.push($(this).attr("data-id"));
        checkedValuesCollect.push($(this).attr("clistname"));
        checked55.push($(this).val());
    });
    var filt_txt_category = checkedValuesCollect.join(',');
    var filt_txt_category_paginate = checked55.join(',');

    // alert(filt_txt_category);
    // var filt_txt_brand = checkedValues.join(',');
    // var filt_txt_brand_paginate = checked5.join(',');
    // alert(filt_txt_brand_paginate);

    if(type1==1){
      var typeselect=1;
      var typeselectchar="colored";
    }else if(type2==2){
      var typeselect=2;
      var typeselectchar="prescription";
    }else if(type3==3){
      var typeselect=3;
      var typeselectchar="accessories";
    }else{
      var typeselect='';
      var typeselectchar="";
    }

    var filt_txt_collection_new = $(".collectiontaglist").map( function() {
      var text1=this.id;
       text1 = text1.replace("removec", "");
       return text1;
    }).get().join(",");

    var checkedcollect = $('input[type="checkbox"].collectiontaglist:checked'); // get checked values
    var collection_list_id_values = [];
    var checked11 = [];
    checkedcollect.each(function (i) {
        collection_list_id_values.push($(this).attr("data-id"));
        checked11.push($(this).val());
    });

    var checkedcollect = $('.collectiontaglist'); // get checked values
    var checkedValuesCollect = [];
    var collection_list_id_values = [];
    var checked11 = [];
    checkedcollect.each(function (i) {
        collection_list_id_values.push($(this).attr("data-id"));
        checkedValuesCollect.push($(this).attr("clistname"));
        checked11.push($(this).val());
    });
    var filt_txt_category = checkedValuesCollect.join(',');
    var filt_txt_category_paginate = checked11.join(',');
    var filt_txt_category_id = collection_list_id_values.join(',');
    // alert(filt_txt_category);


    if(filt_txt_collection_new!='' && filt_txt_collection_new!=undefined){
      var filt_txt_collection=filt_txt_collection_new;
    }else{
       var filt_txt_collection='';
    }
    // alert(filt_txt_collection);
    /*
    if(filt_txt_collection_new!='')
    {
      filt_txt_collection_new = filt_txt_collection_new;
    }else{   
    var filt_txt_collection_new = collection_list_id_values.join(',');
    // var filt_collection_paginate_new = checked11.join(',');
    }*/

    var color_list_id = $(".colorlist:checkbox:checked").map( function() {
      return this.value;
    }).get().join(",");

    var checkedcolor = $('input[type="checkbox"].colorlist:checked'); // get checked values
    var color_list_id_values = [];
    var checked10 = [];
    checkedcolor.each(function (i) {
        color_list_id_values.push($(this).attr("data-id"));
        checked10.push($(this).val());
    });
   /* var filt_txt_col_new = color_list_id_values.join(',');
    var filt_txt_color_paginate = checked10.join(',');*/
    // alert(filt_txt_col_new);

    if(color_list_id!='' && color_list_id!=undefined){
      var filt_txt_color=color_list_id;
    }else{
       var filt_txt_color='';
    }
    // alert(filt_txt_color);

    var replacement_list_id = $(".replacementlist:checkbox:checked").map( function() {
     var text=this.id;
       text = text.replace("removerepl", "");
       return text;
     }).get().join(",");

    var checkedreplace = $('input[type="checkbox"].replacementlist:checked'); // get checked values
    var replacement_list_id_values = [];
    var checked15 = [];
    checkedreplace.each(function (i) {
        replacement_list_id_values.push($(this).attr("data-id"));
        checked15.push($(this).val());
    });

/*    var replacement_list_id = replacement_list_id_values.join(',');
    var filt_replacement_paginate = checked15.join(',');*/

    if(replacement_list_id!='' && replacement_list_id!=undefined){
      var filt_txt_replacement=replacement_list_id;
    }else{
       var filt_txt_replacement='';
    }
      
    var star_list_id = $(".star:radio:checked").map( function() {
      return this.value;
    }).get().join(",");

    if(star_list_id!='' && star_list_id!=undefined){
      var filt_txt_rating=star_list_id;
    }else{
       var filt_txt_rating='';
    }
  }

  var txt_last_collection_id=$("#txt_last_collection_id").val();

  
  if(page==1){
    $("#is_collection_banner").val('0');
  }


  var searchtext=$("#searchtext").val();
  var is_collection_banner=$("#is_collection_banner").val();

  //Countrywise ordering management
  var countryid = $("#txt_country").val();

  $.ajax({
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php',
     type : "post",
    dataType: "json",
    data: 'Productlist=1&page='+page+'&sortby='+sortby+'&filt_txt_brand='+filt_txt_brand+'&filt_txt_collection='+filt_txt_category_id+'&filt_txt_color='+filt_txt_color+'&filt_txt_category='+filt_txt_category+'&filt_txt_replacement='+filt_txt_replacement+'&filt_txt_rating='+filt_txt_rating+'&searchtext='+searchtext+'&typeselect='+typeselect+'&txt_last_collection_id='+txt_last_collection_id+'&is_collection_banner='+is_collection_banner+'&txt_country='+countryid,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      if(page==1){
        $("#Productlist").html(resp[0]);
      }else{
         if(is_collection_banner==1){
           $(".productlistul").append(resp[0]);
         }else{
           $("#Productlist").append(resp[0]);   
         }
      }
      
      $("#totalproductcount").html(resp[1]);
      $("#txt_page_total").val(resp[2]);
      $("#txt_last_collection_id").val(resp[3]);
      var pagecnt=parseInt(page)+1;
      $("#txt_page_no").val(pagecnt);
       loader_hide();
       action = "inactive";
    }
  });
}

      $(window).scroll(function() {
       
        if($(window).scrollTop() + $(window).height() >= $("#Productlist").height() && action == 'inactive') {
            action = 'active';
            var page=$("#txt_page_no").val();
       
            setTimeout(function(){
          getProductListPagination(parseInt(page));
         }, 1000);
        }

        if ($(window).scrollTop() + $(window).height() >= $("#blogListing").height()) {
          // alert();
          var page=$("#txt_blog_page_no").val();
          getBlogListPagination(parseInt(page))
        }
    });

      function getBlogListPagination(page) {
        // alert(page)
        // return false;
        var txt_page_total=$("#txt_page_total").val();
        // alert(txt_page_total)
        if(page>txt_page_total && page!=1){
          return false;
        }

        loader_show();

        $.ajax({
    url : site_url+'controllers/ajax_controller/blog-ajax-controller.php',
     type : "post",
    dataType: "json",
    data: 'Bloglistpagination=1&page='+page,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      // console.log("resp:"+resp)
       if(page==1){
        $("#blogListing .row").html(resp[0]);
      }else{
           $("#blogListing .row").append(resp[0]);
      }
      // return false;
       var pagecnt=parseInt(page)+1;
      $("#txt_blog_page_no").val(pagecnt);
       loader_hide();
    }
  });
      }


function autoCompleteBrandSearch(searchText){
    
    var type1 = $("input[name=type1]:checked").val();
    var type2 = $("input[name=type2]:checked").val();
    var type3 = $("input[name=type3]:checked").val();

    //Countrywise ordering management
    var countryid = $("#txt_country").val();

    var brand_list_id = $(".brandtaglist1").map( function() {
      var text=this.id;
       text = text.replace("removeb", "");
       return text;
    }).get().join(",");


    var category_list_id = $(".collectiontaglist").map( function() {
      var text1=this.id;
       text1 = text1.replace("removec", "");
       return text1;
    }).get().join(",");




    if(type1==1){
      var typeselect=1;
    }else if(type2==2){
      var typeselect=2;
    }else if(type3==3){
      var typeselect=3;
    }else{
      var typeselect='';
    }

    var sortby=$("#sortby").val();

    $.ajax({
      type: "POST",
      url: site_url+'controllers/ajax_controller/login-ajax-controller.php',
      data: 'hid_textSearch1=1&myName='+searchText+'&type='+typeselect+'&brand_list_id='+brand_list_id+'&category_list_id='+category_list_id+'&txt_country='+countryid,
      cache: false,
      success: function(data){
       
          $('#brandlistul').html(data);
      
      }
    });
}

function changeEnterText(type){
  if(type==1){
     var text=$('#hidden_lan_en').val();
     var text2=$('#hidden_cpy_en').val();
     $('.enname').show();
     $('.arname').hide();
     
     
  }else{
    var text=$('#hidden_lan_ar').val();
    var text2=$('#hidden_cpy_ar').val();
    $('.enname').hide();
    $('.arname').show();
  }
  $('#enterbtn').val(text);
  $('#cntryselecttop').html(text2);



}


function processcheckoutUserNext(e){
    flag = 0;
    e.preventDefault();
    var gulfcountry=$('#txt_gulf_next').val();
    var is_guest=$('#txt_guest_next').val();
    var hid_national_id=$('#hid_national_id').val();

    //Countrywise ordering management
    var countryid = $("#txt_country").val();

      if(gulfcountry==1){
        var txt_bill_area=$('#txt_bill_area').val();
        if(requiredValidate('txt_bill_name',enter_name)){
            flag++;
            $("#txt_bill_name").focus();
        }
        /*if(regexValidate('txt_bill_name',enter_name,enter_char_allow,'chkSpace')){
            flag++;
            $("#txt_bill_name").focus();
        }*/

        if(requiredValidate('txt_altmob_name',enter_phone_number)){
            flag++;
            $("#txt_altmob_name").focus();
        }

        if(requiredValidate('txt_bill_governate',please_select_governate)){
            flag++;
            $("#txt_bill_governate").focus();
        }

        if(requiredValidate('txt_bill_area',please_select_area)){
            flag++;
            $("#txt_bill_area").focus();
        }

        if(txt_bill_area==0){
           if(requiredValidate('txt_bill_other_area',enter_other_area)){
            flag++;
            $("#txt_bill_other_area").focus();
           }
        }

        if(requiredValidate('txt_bill_blockarea',enter_block)){
            flag++;
            $("#txt_bill_blockarea").focus();
        }

        if(requiredValidate('txt_bill_street',enter_street)){
            flag++;
            $("#txt_bill_street").focus();
        }

        if(requiredValidate('txt_bill_builidingno',enter_building_number)){
            flag++;
            $("#txt_bill_builidingno").focus();
        }
       

      }else{
        if(requiredValidate('txt_bill_name',enter_name)){
            flag++;
            $("#txt_bill_name").focus();
        }
        /*if(regexValidate('txt_bill_name',enter_name,enter_char_allow,'chkSpace')){
            flag++;
            $("#txt_bill_name").focus();
        }*/

        if(requiredValidate('txt_altmob_name',enter_phone_number)){
            flag++;
            $("#txt_altmob_name").focus();
        }

        if(requiredValidate('txt_bill_address1',enter_address_line_1)){
            flag++;
            $("#txt_bill_address1").focus();
        }

        if(requiredValidate('txt_bill_city',enter_city)){
            flag++;
            $("#txt_bill_city").focus();
        }

        if(requiredValidate('txt_bill_state',enter_area)){
            flag++;
            $("#txt_bill_state").focus();
        }
      } 
    

    if(hid_national_id==1){
      if(requiredValidate('national_id',enter_national_id)){
          flag++;
            $("#national_id").focus();
      }
    }

    if(flag>0){
        //For Autofocus validation highlight
        if($("#txt_bill_name").val()=='')
        {
        document.getElementById('txt_bill_name').focus();
        return false;
        }else if($("#txt_altmob_name").val()=='')
        {
        document.getElementById('txt_altmob_name').focus();
        return false;
        }else if($("#txt_bill_governate").val()=='')
        {
        document.getElementById('txt_bill_governate').focus();
        return false;
        }else if($("#txt_bill_area").val()=='')
        {
        document.getElementById('txt_bill_area').focus();
        return false;
        }else if($("#txt_bill_blockarea").val()=='')
        {
        document.getElementById('txt_bill_blockarea').focus();
        return false;
        }else if($("#txt_bill_street").val()=='')
        {
        document.getElementById('txt_bill_street').focus();
        return false;
        }else if($("#txt_bill_builidingno").val()=='')
        {
        document.getElementById('txt_bill_builidingno').focus();
        return false;
        }
      return false;
    }

  $.ajax({
    url: site_url + 'controllers/ajax_controller/addressadd-ajax-controller.php',
    type: 'post',
    data: $('#addressFormdirect').serialize()+'&txt_country='+countryid,
    success: function(result) {
      if(result==2){
        $("#error_address").removeClass('success_msg');
        $("#error_address").addClass('already');
        $("#error_address").text(email_already_exist_in_system).show().fadeOut(fadeOutSec);
      }else{
        window.location.reload();
      }
      
    }
  });
}


function showhideBrand(char){
  if(char=='all'){
    $('.charlist').show(); 
  }else{
    $('.charlist').hide(); 
    $('#charid'+char).show(); 
  }
}
$(document).ready(function(){
  $( "#myModalEdit" ).on('shown.bs.modal', function(){
  var $container = $('#changediv'),
  $scrollTo = $('input[type="checkbox"][data-id="1"]');
  $container.scrollTop($scrollTo.offset().top - $container.offset().top + $container.scrollTop() - 20);
  });
});
function powerlistshow(){
  $(".fcbox_view_tag_edit").trigger('click');
}

function notifyMeModalShow(){
  $('#notifyme_form').trigger("reset");
  $("#notifyMeModal").modal('show');
}

function selectedPower(){

    $("#btngocart").hide();
    $("#btnaddcart").show();

    var chkleftpower='';
    var chkrightpower='';
    $("input:checkbox[class=leftpwr]:checked").each(function () {
           chkleftpower=$(this).val();
    });

     $("input:checkbox[class=rightpwr]:checked").each(function () {
           chkrightpower=$(this).val();
    });

    $('#leftpower').val(chkleftpower); 
    $('#rightpower').val(chkrightpower);  
    
     $('#myModalEdit').modal('toggle');

    //Button Select Power
    changeajaxselectpowerbtn(encodeURIComponent(chkleftpower),encodeURIComponent(chkrightpower));
    //Select Power in Description
    changeajaxpowerval(chkleftpower,chkrightpower);
    /*powerSelection('1');
    powerSelection('2');*/

}


function powerselectionchange(power,type){

  var leftpwrcnt=$(".leftpwr:checkbox:checked").length; 
  var rightpwrcnt=$(".rightpwr:checkbox:checked").length; 

  var leftx = document.getElementById("leftpowerlist"+power).checked;
  if(type==1 && leftx==true){
    $(".leftpwr").prop("checked", false);
    document.getElementById("leftpowerlist"+power).checked=true;
  }

  if(rightpwrcnt==0 && type==1){
    document.getElementById("leftpowerlist"+power).checked=true;
  }

  var rightx = document.getElementById("rightpowerlist"+power).checked;
  if(type==2 && rightx==true){
    $(".rightpwr").prop("checked", false);
    document.getElementById("rightpowerlist"+power).checked=true;;
  }

  if(leftpwrcnt==0 && type==2){
    document.getElementById("rightpowerlist"+power).checked=true;
  }

}

function ClearBrand(){
  $('.blist').prop('checked', false);
  $('.clist').prop('checked', false);
  $('#searchbrand').val('');
  
  $(".brandtaglist1").remove();
  $(".collectionlist").remove();

  $("#brandtag").hide();
  $("#collectiontag").hide();
   getProductList(1); 
}

function ClearBrandType(){

  $('#type1').prop('checked', false);
  $('#type2').prop('checked', false);
  $('#type3').prop('checked', false);

  brandtypeselection('');
   getProductList(1);
}

function clearSearchTag(){
  $("#searchtag").hide();
  $(".searchtaglistsep").remove();
  $("#searchtext").val('');
  getProductList(1);
}

function applyproductfilter(){

  var blist=$(".blist:checkbox:checked").length; 
  // if(blist==0){
  //   alert(select_one_brand);
  //   return false;
  // }

  var brand_list_id = $(".blist:checkbox:checked").map( function() {
    return this.value;
  }).get().join(",");

  var collection_list_id = $(".clist:checkbox:checked").map( function() {
    return this.value;
  }).get().join(",");

  var color_list_id = $(".colorlist:checkbox:checked").map( function() {
    return this.value;
  }).get().join(",");

  var replacement_list_id = $(".replacementlist:checkbox:checked").map( function() {
    return this.value;
  }).get().join(",");

  var star_list_id = $(".star:radio:checked").map( function() {
    return this.value;
  }).get().join(",");


  if(brand_list_id!='' && brand_list_id!=undefined){
    $("#filt_txt_brand").val(brand_list_id);
  }else{
     $("#filt_txt_brand").val('');
  }

  if(collection_list_id!='' && collection_list_id!=undefined){
    $("#filt_txt_collection").val(collection_list_id);
  }else{
     $("#filt_txt_collection").val('');
  }

  if(color_list_id!='' && color_list_id!=undefined){
    $("#filt_txt_color").val(color_list_id);
  }else{
     $("#filt_txt_color").val('');
  }

  if(replacement_list_id!='' && replacement_list_id!=undefined){
    $("#filt_txt_replacement").val(replacement_list_id);
  }else{
     $("#filt_txt_replacement").val('');
  }

  if(star_list_id!='' && star_list_id!=undefined){
    $("#filt_txt_rating").val(star_list_id);
  }else{
     $("#filt_txt_rating").val('');
  }

  
  getProductList(1);
}


function setdefaultchecked(){
   $("#defaultadd").prop("checked", true);
}


function viewproductzoom(id){
  //Countrywise ordering management
  var countryid = $("#txt_country").val();
  $("#productviewzoom").html("");
  $.ajax({
    url: site_url + 'controllers/ajax_controller/product-ajax-controller.php',
    type: 'post',
    data: 'viewproductzoom=1&id='+id+'&txt_country='+countryid,
    success: function(result) {
        $("#product-zoom-modal").modal('show');
        $("#productviewzoom").html(result);
    }
  });
}

function viewproductzoomdetails(id){
  //Countrywise ordering management
  var countryid = $("#txt_country").val();
  $("#product-zoom").modal('show');
  $("#productviewzoomdetails").html("");
  $.ajax({
    url: site_url + 'controllers/ajax_controller/product-ajax-controller.php',
    type: 'post',
    data: 'viewproductzoomdetails=1&id='+id+'&txt_country='+countryid,
    success: function(result) {
        $("#productviewzoomdetails").html(result);
    }
  });
}



function proceedtopaycancel(){
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  window.location.href=site_url+txt_lang_type+"/cart";
}


function brandtypeselection1(type){

  var type1 = $("input[name=type11]:checked").val();
  if(type1==1 && type==1){
    $('#type21').prop('checked', false);
    $('#type31').prop('checked', false);

    var typenameatt=$("#type"+type).attr("typenameatt");
    var typetaglist='<span class="typetaglistsep" id="removetype'+type+'" onclick="removebrandtypetag(&apos;'+type+'&apos;);"><span class="fil_label_dat">'+typenameatt+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
     $("#typetaglist").append(typetaglist);

     $("#removetype2").remove();
     $("#removetype3").remove();
     $("#typetag").show();
  }else{
    $("#removetype1").remove();
  }

  var type2 = $("input[name=type21]:checked").val();
  if(type2==2 && type==2){

    $('#type11').prop('checked', false);
    $('#type31').prop('checked', false);

    var typenameatt=$("#type"+type).attr("typenameatt");
    var typetaglist='<span class="typetaglistsep" id="removetype'+type+'" onclick="removebrandtypetag(&apos;'+type+'&apos;);"><span class="fil_label_dat">'+typenameatt+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
     $("#typetaglist").append(typetaglist);

     $("#removetype1").remove();
     $("#removetype3").remove();
     $("#typetag").show();

  }else{
     $("#removetype2").remove();
  }

  var type3 = $("input[name=type31]:checked").val();
  if(type3==3 && type==3){
    $('#type11').prop('checked', false);
    $('#type21').prop('checked', false);

    var typenameatt=$("#type"+type).attr("typenameatt");
    var typetaglist='<span class="typetaglistsep" id="removetype'+type+'" onclick="removebrandtypetag(&apos;'+type+'&apos;);"><span class="fil_label_dat">'+typenameatt+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
     $("#typetaglist").append(typetaglist);

     $("#removetype1").remove();
     $("#removetype2").remove();
     $("#typetag").show();

  }else{
    $("#removetype3").remove();
  }

   $('.blist').prop('checked', false);
   $('.clist').prop('checked', false);

    $("#brandtag").hide();
    $("#collectiontag").hide();
    $(".brandtaglist1").remove();
    $(".collectiontaglist").remove();

     $("#searchbrand").val('');
     
   //   getProductList(1);

   var type11 = $("input[name=type11]:checked").val();
   var type21 = $("input[name=type21]:checked").val();
   var type31 = $("input[name=type31]:checked").val();


   if(type==1){
      $("#mcolor").show();
      $("#mreplacement").show();
   }else if(type21==2){
      $("#mcolor").hide();
      $("#mreplacement").show();
   }else if(type31==3){
      $("#mcolor").hide();
      $("#mreplacement").hide();
   }else{
      $("#mcolor").show();
      $("#mreplacement").show();
   }


      autoCompleteBrandSearch1('');
}


function autoCompleteBrandSearch1(searchText){
    
    var type1 = $("input[name=type11]:checked").val();
    var type2 = $("input[name=type21]:checked").val();
    var type3 = $("input[name=type31]:checked").val();

    //Countrywise ordering management
    var countryid = $("#txt_country").val();

    var brand_list_id = $(".brandtaglist1").map( function() {
      var text=this.id;
       text = text.replace("removeb", "");
       return text;
    }).get().join(",");


    var category_list_id = $(".collectiontaglist").map( function() {
      var text1=this.id;
       text1 = text1.replace("removec", "");
       return text1;
    }).get().join(",");




    if(type1==1){
      var typeselect=1;
    }else if(type2==2){
      var typeselect=2;
    }else if(type3==3){
      var typeselect=3;
    }else{
      var typeselect='';
    }

    var sortby=$("#sortby").val();

    $.ajax({
      type: "POST",
      url: site_url+'controllers/ajax_controller/login-ajax-controller.php',
      data: 'hid_textSearch11=1&myName='+searchText+'&type='+typeselect+'&brand_list_id='+brand_list_id+'&category_list_id='+category_list_id+'&txt_country='+countryid,
      cache: false,
      success: function(data){
       
          $('#brandlistul1').html(data);
      
      }
    });
}


function showcollectionlist1(brandid,brandtype){
  
   var blist=$(".blist1:checkbox:checked").length; 
   var chkWish = document.getElementById("tcolor1"+brandid);
   var chklength=$('#tcolor1'+brandid).length;
   if(chklength==1){
 
    if(chkWish.checked) {
       var chksletedbrand=$("#tcolor1"+brandid).attr("blistname");
       var brandlistbind='<span class="brandtaglist1" id="removeb'+brandid+'" onclick="removebrandtag(&apos;'+brandid+'&apos;,1);"><span class="fil_label_dat">'+chksletedbrand+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
       $("#brandtaglist").append(brandlistbind);

    }else{
      $("#removeb"+brandid).remove();
    }
 }
  if(chkWish.checked==1){
     $("#collectionsdiv"+brandid).show();
  }else{
    $("#collectionsdiv1"+brandid).hide();
    $(".collectionschk1"+brandid).prop("checked", false);
    $("#removec"+brandid).remove();
    $(".brandc"+brandid).remove();
  }

  if(blist>=1){
    $("#brandtag").show();
  }else{
    $("#brandtag").hide();
    $(".collectiontaglist").remove();
    
    //$("#collectiontag").hide();
  }


   /*if(blist>1){
     $(".clist1").prop("checked", false);
     $(".collectionsdiv1").hide();
     $(".collectiontaglist").remove();
   }else{


    if(chklength==1){
     if(chkWish.checked) {
        $("#collectionsdiv1"+brandid).show();
      } else {
          $(".collectionschk1"+brandid).prop("checked", false);
          $("#collectionsdiv1"+brandid).hide();
      }
    }


      var chksletedbrand=$(".blist1:checked").attr('id');
      if(chksletedbrand!=undefined){
        var res = chksletedbrand.replace('tcolor1','');
        $("#collectionsdiv1"+res).show();
      }

   }*/ 

   if(brandtype==1){
    $("#replacementlistdiv").show();
    $("#colorlistdiv").show();

   }else if(brandtype==2){
    $("#replacementlistdiv").show();
    $("#colorlistdiv").hide();
    $(".colorlist").prop("checked", false);


   }else if(brandtype==3){
     $("#replacementlistdiv").hide();
     $("#colorlistdiv").hide();
     $(".colorlist").prop("checked", false);
     $(".replacementlist").prop("checked", false);

   }

  var clist=$(".clist1:checkbox:checked").length; 
  if(clist>=1){
    $("#collectiontag").show();
  }else{
    
    $("#collectiontag").hide();
  }

  // getProductList1(1);
}

function autoCompleteBrandSearch1(searchText){
    
    var type1 = $("input[name=type11]:checked").val();
    var type2 = $("input[name=type21]:checked").val();
    var type3 = $("input[name=type31]:checked").val();

    //Countrywise ordering management
    var countryid = $("#txt_country").val();

    var brand_list_id = $(".brandtaglist1").map( function() {
      var text=this.id;
       text = text.replace("removeb", "");
       return text;
    }).get().join(",");


    var category_list_id = $(".collectiontaglist").map( function() {
      var text1=this.id;
       text1 = text1.replace("removec", "");
       return text1;
    }).get().join(",");




    if(type1==1){
      var typeselect=1;
    }else if(type2==2){
      var typeselect=2;
    }else if(type3==3){
      var typeselect=3;
    }else{
      var typeselect='';
    }

    var sortby=$("#sortby").val();

    $.ajax({
      type: "POST",
      url: site_url+'controllers/ajax_controller/login-ajax-controller.php',
      data: 'hid_textSearch11=1&myName='+searchText+'&type='+typeselect+'&brand_list_id='+brand_list_id+'&category_list_id='+category_list_id+'&txt_country='+countryid,
      cache: false,
      success: function(data){
          $('#brandlistul1').html(data);
      }
    });
}


function collectionSelect1(cid){


  var chksletedcat=$("#ccolor1"+cid).attr("clistname");
  var chkWish = document.getElementById("ccolor1"+cid);
 
  if(chkWish.checked) {
    var colllistbind='<span class="collectiontaglist" id="removec'+cid+'" onclick="removecollectiontag(&apos;'+cid+'&apos;,1);"><span class="fil_label_dat">'+chksletedcat+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
    $("#collectionlist").append(colllistbind);
  }else{
    $("#removec"+cid).remove();
  }

  var clist=$(".clist1:checkbox:checked").length; 

  if(clist>=1){
    $("#collectiontag").show();
  }else{
    $("#collectiontag").hide();
  }

  //getProductList(1);
}


function colorSelect1(cid){
   var chksletedcat=$("#color1"+cid).attr("colorlistname");
   var chkWish = document.getElementById("color1"+cid);
 
  if(chkWish.checked) {
    var colllistbind='<span class="colortaglist" id="removecolor'+cid+'" onclick="removecolortag(&apos;'+cid+'&apos;,1);"><span class="fil_label_dat">'+chksletedcat+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
    $("#colorlist").append(colllistbind);
  }else{
    $("#removecolor"+cid).remove();
  }

  var clist=$(".colorlist:checkbox:checked").length; 

  if(clist>=1){
    $("#colortag").show();
  }else{
    $("#colortag").hide();
    $(".colortaglist").remove();
  }

  //getProductList(1);
}

function replacementSelect1(cid){

   var chksletedcat=$("#replacement1"+cid).attr("repllistname");
   var chkWish = document.getElementById("replacement1"+cid);
 
  if(chkWish.checked) {
    var colllistbind='<span class="repltaglist" id="removerepl'+cid+'" onclick="removerepltag(&apos;'+cid+'&apos;);"><span class="fil_label_dat">'+chksletedcat+'&nbsp;&nbsp;<span class="close_filter">x</span>&nbsp;&nbsp;</span></span>';
    $("#repllist").append(colllistbind);
  }else{
    $("#removerepl"+cid).remove();
  }

  var clist=$(".replacementlist:checkbox:checked").length; 

  if(clist>=1){
    $("#repltag").show();
  }else{
    $("#repltag").hide();
    $(".repltaglist").remove();
  }

  //getProductList(1);
}


function getshippingchargegov(){

    var addresscheck=$( "#txt_my_address_check").length;
    // Countrywise ordering management
    var countryid = $("#txt_country").val();
    if(addresscheck>0){
      return false;
    }
    loader_show();  
    var getpromotionprice= $("#coupon_discount").html();
    var subtotal= $("#subtotal").html();

    $("#fcbox_view_heading_tag_edit").html('<i class = "icon-tag"></i> Edit Address'+edit_address);
    $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    dataType: "json",
    data: 'getshippingchargegov=1&getpromotionprice='+getpromotionprice+'&subtotal='+subtotal+'&txt_country='+countryid,        
    success : function( resp ) {
       $("#total_payble").html(resp[0]);
       $("#delivery_shipping").html(resp[1]);
      loader_hide();
    }
  });
}

function showhomecollectionlist(brandid,showhideid,hid_change_type=''){

    //loader_show();  
    $(".collectiondivcnt").html('');
    $( ".btn-circle").removeClass("active");

    var txt_home_offers_type=$("#txt_home_offers_type").val();
    //Countrywise ordering management
    var countryid = $("#txt_country").val();
    $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    //dataType: "json",
    data: 'showhomecollectionlist=1&brandid='+brandid+'&showhideid='+showhideid+'&txt_home_offers_type='+txt_home_offers_type+'&hid_change_type='+hid_change_type+'&txt_country='+countryid,        
    success : function( resp ) {
       // $("#total_payble").html(resp[0]);
        $("#step-"+showhideid).show();
        $("#step-"+showhideid).html(resp);
        $('html, body').animate({scrollTop: $('#step-'+showhideid).offset().top }, 'slow');

      //loader_hide();
    }
  });
  //For custom dynamic brand generate for analytics
  brand_detail(brandid);
}
function Viewmorebrand(brandtype){
    //loader_show(); 

    var txt_home_offers_type=$("#txt_home_offers_type").val();
    //Countrywise ordering management
    var countryid = $("#txt_country").val();

    $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    //dataType: "json",
    data: 'Viewmorebrand=1&brandtype='+brandtype+'&txt_home_offers_type='+txt_home_offers_type+'&txt_country='+countryid,        
    success : function( resp ) {
       // $("#total_payble").html(resp[0]);
        // $("#step-"+showhideid).show();
         $("#typebrand"+brandtype).html(resp);
         $("#viewmore"+brandtype).hide();

      //loader_hide();
    }
  });
}

function Viewmorebrandmobile(brandtype){
    //loader_show();  

    var txt_home_offers_type=$("#txt_home_offers_type").val();
    //Countrywise ordering management
    var countryid = $("#txt_country").val();
    $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    //dataType: "json",
    data: 'Viewmorebrandmobile=1&brandtype='+brandtype+'&txt_home_offers_type='+txt_home_offers_type+'&txt_country='+countryid,        
    success : function( resp ) {
         $("#typebrand"+brandtype).html(resp);
         $("#mviewmore"+brandtype).hide();
    }
  });
}

function showhomecollectionmobilelist(brandid,showhideid,hid_change_type=''){

    $(".clearslider").html('');
    $( ".btn-circle").removeClass("active");
    $( "#btnmobile"+brandid).addClass("active");
    //Countrywise ordering management
    var countryid = $("#txt_country").val();
    $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    //dataType: "json",
    data: 'showhomecollectionlist=1&brandid='+brandid+'&showhideid='+showhideid+'&hid_change_type='+hid_change_type+'&txt_country='+countryid,        
    success : function( resp ) {
        $("#mstep"+showhideid).show();
        $("#mstep"+showhideid).html(resp);
        $('html, body').animate({scrollTop: $('#mstep'+showhideid).offset().top }, 'slow');
    }
  });
  //For custom dynamic brand generate for analytics
  brand_detail(brandid);
}

function morefilters(type){

  var type3 = $("input[name=type3]:checked").val();

  if(type==0){
    $(".filterclass").hide();
    $(".moreplus").show();
    $(".morehide").hide();
    
  }else{
      $(".filterclass").show();
      $(".moreplus").hide();
      $(".morehide").show();
  }
  if(type3==3){
    $("#replacementlistdiv").hide();
  }
}


function topbrandlist(id){
   var typedynamic=$("#txt_home_tab_type").val();
  //Countrywise ordering management
  var countryid = $("#txt_country").val();
   var type=id;

   $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    //dataType: "json",
    data: 'topbrandlist=1&type='+type+'&txt_country='+countryid+'&toptypedynamic='+typedynamic,        
    success : function( resp ) {
        $("#homeoffersdiv").html(resp);
        if(type==1){
          $("#txt_home_offers_type").val('0');
          /*Dynamic Type Management*/
          $("#txt_home_tab_type").val('1');
          /*Dynamic Type Management*/
            $("#top_offers_text").removeClass("active");
            $("#top_brand_text").addClass("active");
          /*$("#top_brand_text").show();
          $("#top_offers_text").hide();*/
        }else{
          $("#txt_home_offers_type").val('1');
          /*Dynamic Type Management*/
          $("#txt_home_tab_type").val('2');
          /*Dynamic Type Management*/
            $("#top_offers_text").addClass("active");
            $("#top_brand_text").removeClass("active");
          /*$("#top_offers_text").show();
          $("#top_brand_text").hide();*/
        }
    }
  });
}

function viewgiftdetails(id){
  
  $("#giftdetails").html("");
  $.ajax({
    url: site_url + 'controllers/ajax_controller/checkout-ajax-controller.php',
    type: 'post',
    data: 'viewgiftdetails=1&id='+id,
    success: function(result) {
        $("#giftdetails-modal").modal('show');
        $("#giftdetails").html(result);
    }
  });
}


function viewmoregifts(classclick,id,loaddata,key){
    //Countrywise ordering management
    var countryid = $("#txt_country").val();
    
    $.ajax( {
    url : site_url+'controllers/ajax_controller/checkout-ajax-controller.php', 
    type : 'post',
    //dataType: "json",
    data: 'viewmoregifts=1&id='+id+'&key='+key+'&txt_country='+countryid,        
    success : function( resp ) {
         $("#"+loaddata).html(resp);
         $("#"+classclick).hide();
    }
  });
}

function viewmoregiftsfree(gift_plan_id){

    $.ajax( {
    url : site_url+'controllers/ajax_controller/checkout-ajax-controller.php', 
    type : 'post',
    //dataType: "json",
    data: 'viewmoregiftsfree=1&gift_plan_id='+gift_plan_id,        
    success : function( resp ) {
         $("#loaddatafree").html(resp);
         $("#viewmoregiftsfree").hide();
    }
  });
}

function checkoutgiftnext(){
    flag = 0;
    var promotiongift=$("#promotiongift").val();
    if(promotiongift>0){
      for (var i = 1; i <= promotiongift; i++) {
          var allowgifts1=$('input[name="no_of_gifts_key'+i+'[]"]').val();
          var cntcheckedcount1 = $('input[name="key'+i+'[]"]:checked').length;
          if(cntcheckedcount1!=allowgifts1){
            alert("Please select gift that are eligible for you");
            return false;
          }
      }
    }

    if($('input[name="no_of_freegifts_key[]"]').length)
    {
     var allowgifts=$('input[name="no_of_freegifts_key[]"]').val();
     var cntcheckedcount = $('input[name="freekey[]"]:checked').length;
     if(cntcheckedcount!=allowgifts){
        alert("Please select gift that are eligible for you");
        return false;
      }
    }

     
    if(flag>0){
      return false;
    }

    $.ajax({
      url: site_url + 'controllers/ajax_controller/checkout-ajax-controller.php',
      type: 'post',
      data: $('#giftitemselection').serialize(),
      success: function(result) {
        //Based on country wise & language
        var txt_lang_type = $("#txt_lang_type").val();
     // alert(txt_lang_type);
        window.location.href=site_url+txt_lang_type+"/checkout";
      }
    });
}

function Hideappbanner(){
   $('#app-links').hide();
   $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    data: 'Hideappbanner=1',        
    success : function( resp ) {
         
    }
  });
}

function buycloseclick(id) {
  // loader_show();
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  //Countrywise ordering management
  var countryid = $("#txt_country").val();
  
  $.ajax({
    url : site_url + 'controllers/ajax_controller/login-ajax-controller.php',
    type : 'POST',
    data : $("#Paidpopupform").serialize()+'&click_id='+id+'&txt_country='+countryid,
    success : function(result){
      // console.log(result);return false;
      // alert(result.product); return false;
      if(result.status==1 && result.product!=null){
        window.location.href=site_url+txt_lang_type+"/product-details/"+result.brand_type+"/"+result.brand_name+"/"+result.category_name+"/"+result.product;
      }
      else if(result.status==1 && result.brand_type!='' && result.brand_name!='' && result.category_name!=''){
        window.location.href=site_url+txt_lang_type+"/product-list/"+result.brand_type+'/'+result.brand_name+'/'+result.category_name;
      }else if(result.status==1 && result.brand_type!='' && result.brand_name!=''){
        window.location.href=site_url+txt_lang_type+"/product-list/"+result.brand_type+'/'+result.brand_name;
      }else{
        window.location.reload();  
      }
      // window.location.href=site_url+txt_lang_type+"/checkout";
      // $("#dyDivForgot").html(result);
    }
  });
}
function changenamecolordiv(colorname) {
  $("div#coloredheader1").text(colorname);
}
function changenameprescriptiondiv(prescriptionname) {
  $("div#prescriptionheader1").text(prescriptionname);
}
function changenameaccessoriesdiv(accessoriesname) {
  $("div#accessoriesheader1").text(accessoriesname);
}

function deleteprofile(id){
    $("#fcbox_delete_selected_heading_tag").text("Delete");
    $("#fcbox_delete_selected_content_tag").html(deleteuser);
    $(".fcbox_delete_selected_content_btn").attr("onclick","deleteuser_ok('"+id+"')");
    $(".fcbox_delete_selected_content_btn").html("Submit");
    $(".fcbox_delete_selected_tag").trigger('click');
}

function deleteuser_ok(selected){
  // alert(selected);
  $.ajax({
    type: "POST",
    url: site_url+'controllers/ajax_controller/login-ajax-controller.php',
    data: 'deleteuserconfirm=1&id='+selected,
    cache: false,
    success: function(data)
    {
      //Based on country wise & language
      var txt_lang_type = $("#txt_lang_type").val();
      window.location.href=site_url+txt_lang_type+"/logout";
    }
  });
}
function signoutprofile(id){
    $("#fcbox_delete_selected_heading_tag").text("Sign out");
    $("#fcbox_delete_selected_content_tag").html(signoutuser);
    $(".fcbox_delete_selected_content_btn").attr("onclick","signuser_ok('"+id+"')");
    $(".fcbox_delete_selected_content_btn").html("Yes");
    $(".btn-default-outline").html("No");
    $(".fcbox_delete_selected_tag").trigger('click');
}

function signuser_ok(selected){
  // alert(selected);
  $.ajax({
    type: "POST",
    url: site_url+'controllers/ajax_controller/login-ajax-controller.php',
    data: 'signoutuserconfirm=1&id='+selected,
    cache: false,
    success: function(data)
    {
      //Based on country wise & language
      var txt_lang_type = $("#txt_lang_type").val();
      window.location.href=site_url+txt_lang_type+"/logout";
    }
  });
}
/*ALL Model Hide Value*/
$(document).ready(function(){
$("#popup-login-form,#login-form,#lense-care-modal-1,referal-form,#myModalEdit,#product-zoom-modal,#myModalorderView,#myModalDeleteSelected").modal({
show: false,
keyboard: true,
backdrop: 'static'
});
});

/*$(document).ready(function(){
   $('#login-form').modal({
    show: false,
    keyboard: true,
    backdrop: 'static'})

});*/

function checkemailverify(){

    var email_verify=$("#txt_email_verify").val();
    var txt_user_id=$("#txt_user_id").val();
    // alert(email_verify);
    flag = 0;

    if(requiredValidate('txt_email_verify','Please enter email')){
        flag++;
        $("#txt_email_verify").focus();
    }

    if($('#txt_email_verify').val()!='' && regexValidate('txt_email_verify','','Please enter valid email','email','yes')){
        flag++;
        $("#txt_email_verify").focus();
    }

    if(flag>0){
        return false;
    }
    loader_show();  
    $.ajax( {
    url : site_url+'controllers/ajax_controller/common-ajax-controller.php', 
    type : 'post',
    //dataType: "json",
    data: 'CheckEmailVerify=1&email_verify='+email_verify+'&user_id='+txt_user_id,        
    success : function( resp ) {
      loader_hide();
      if(resp==1)
      {
        $("#email-verify").modal("toggle");
        $("#otp-verify").modal("toggle");
        $("#txt_otp_verify").val('');
      }else if(resp==0)
      {
        $("#error_email_already_checked").text('Email already exists').show().fadeOut(5000);
      }
    }
  });
}
function verifyotpcheck() {
  loader_show();
  var otp_verify=$("#txt_otp_verify").val();
  var email_verify=$("#txt_email_verify").val();
    // alert(email_verify);
    flag = 0;

    if(requiredValidate('txt_otp_verify','Please enter OTP')){
        flag++;
        $("#txt_otp_verify").focus();
    }

    if(flag>0){
        return false;
    }
    //Based on country wise & language
    var txt_lang_type = $("#txt_lang_type").val();

    $.ajax( {
    url : site_url+'controllers/ajax_controller/common-ajax-controller.php', 
    type : 'post',
    //dataType: "json",
    data: 'CheckOTPVerify=1&otp_verify='+otp_verify+'&email_verify='+email_verify,        
    success : function( resp ) {
      // alert(resp);
      if(resp==0)
      {
        //fail otp doesn't match
        $("#error_otp_validate_checked").text('Please enter correct OTP').show().fadeOut(5000);
        // alert('Please enter correct OTP');
      }else{
        loader_hide();
        //success
        if (window.confirm('Your email has been verified successfully!'))
        {
            loader_show();
            // They clicked Yes
            window.location.href=site_url+txt_lang_type;
        }
      }
    }
  }); 
}
function skipreturn() {
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  window.location.href=site_url+txt_lang_type;
}
function email_checked() {
  $("#email-verify").modal("toggle");
  var txt_email_checked = $("#txt_email_checked").val();
  var txt_user_id = $("#txt_user_id").val();
  // alert(txt_email_checked);
  $("#txt_email_verify").val(txt_email_checked);
  $("#txt_user_id").val(txt_user_id);
}

function orderprintdata(id){
  //Based on country wise & language
  var txt_lang_type = $("#txt_lang_type").val();
  window.open(site_url+txt_lang_type+'/success_invoice/'+id, '_blank');
   
}
function view_print_new(id){
  loader_show();  
  $("#fcbox_view_heading_tag_order").html('<i class = "icon-tag"></i> View Detail');
  $.ajax( {
    url : site_url+'controllers/ajax_controller/my-order-invoice-ajax-controller.php',
    type : 'post',
    data: 'view_print_new=1&id='+id,
    success : function(result)
    {
      // alert(result);
      //$("#"+show).html(result);
      //loader_hide();
    // $("#"+pid).html(result);
      // $("#orderdetailsview").html(result);
      // $(".fcbox_view_tag_order").trigger('click');
      setTimeout(function(){
        printDivNew(id);
      }, 1000);
      loader_hide();
      
    }
  });
}
function printDivNew(id) {
  var divName='print_receipt';
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;
   
   
      $.ajax( {
      url : site_url+'controllers/ajax_controller/comman-ajax-controller.php',
      type : 'post',
      data: 'UpdatePrintStatus=1&id='+id,
      success : function(result)
      {
        
        //loader_hide();
      }
      });
    // Add print-specific styles
    var printStyle = `
        <style>
            @media print {
                @page {
                    margin: 0; /* Removes browser's headers and footers */
                }
            }
        </style>
    `;
     document.body.innerHTML = printContents;
     //window.print();
     try {
        document.execCommand('print', false, null);
      }
      catch(e) {
        window.print();
      }
    document.body.innerHTML = originalContents;
}
// For multiple country wise redirection in landing page
function filterbycountry() {
  var countrycode = $("#txt_filter_value").val();
  if(countrycode=='')
  {
  $("#error_country_wise_filter").removeClass('error_msg');
  $("#error_country_wise_filter").text('Please select your country').show().fadeOut(5000);
  $("#txt_filter_value").val('');
  return false;  
  }
  window.location.href=site_url+countrycode+'-en';
}
function hideshowpower() {
    var checkbox = document.getElementById('is_power_different');
    var value = document.getElementById('value_different_power');
    var value_same = document.getElementById('value_same_power');
    if (checkbox.checked) {
        value.style.display = 'block';
        value_same.style.display = 'none';
    } else {
        value.style.display = 'none';
        value_same.style.display = 'block';
    }
}
function toric_cycl_left(id) {
  var product_id_toric = $("#product_val").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    data: 'ViewCyclLeft=1&id='+encodeURIComponent(id)+'&product_id='+product_id_toric,        
    success : function( resp ) {
      $("#left_cycl").html(resp);
      //loader_hide();
    }
  });
}
function toric_axis_left(id) {
  var product_id_toric = $("#product_val").val();
  var left_shpere = $("#left_shpere").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    data: 'ViewAxisLeft=1&id='+encodeURIComponent(id)+'&product_id='+product_id_toric+'&left_shpere='+encodeURIComponent(left_shpere),        
    success : function( resp ) {
      $("#left_axis").html(resp);
      //loader_hide();
    }
  });
}
function toric_cycl_right(id) {
  var product_id_toric = $("#product_val").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    data: 'ViewCyclRight=1&id='+encodeURIComponent(id)+'&product_id='+product_id_toric,        
    success : function( resp ) {
      $("#right_cycl").html(resp);
      //loader_hide();
    }
  });
}
function toric_axis_right(id) {
  var product_id_toric = $("#product_val").val();
  var right_shpere = $("#right_shpere").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    data: 'ViewAxisRight=1&id='+encodeURIComponent(id)+'&product_id='+product_id_toric+'&right_shpere='+encodeURIComponent(right_shpere),        
    success : function( resp ) {
      $("#right_axis").html(resp);
      //loader_hide();
    }
  });
}
function toric_cycl_both(id) {
  var product_id_toric = $("#product_val").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    data: 'ViewCyclBoth=1&id='+encodeURIComponent(id)+'&product_id='+product_id_toric,        
    success : function( resp ) {
      $("#both_cycl").html(resp);
      //loader_hide();
    }
  });
}
function toric_axis_both(id) {
  var product_id_toric = $("#product_val").val();
  var both_shpere = $("#both_shpere").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    data: 'ViewAxisBoth=1&id='+encodeURIComponent(id)+'&product_id='+product_id_toric+'&both_shpere='+encodeURIComponent(both_shpere),        
    success : function( resp ) {
      $("#both_axis").html(resp);
      //loader_hide();
    }
  });
}
function updateEyeDoc(){
    var flag = 0;
    var img=$("#document_upload").val();
    var productdata=$("#product_id_toric").val();
    if(sub_cart_id_eye_doc!='')
    {
    var sub_cart_id_eye_doc=$("#sub_cart_id_eye_doc").val();
    }else{
    var sub_cart_id_eye_doc='';
    }
    // alert(productdata);
    if(img!='' && regexValidate('document_upload',"",upload_img,'imgdoc')){
        flag++;
    }
    if(flag>0)
    {
        return false;
    }
    var file_data = $('#document_upload').prop('files')[0];   
    var form_data = new FormData();                  
    form_data.append('document_upload', file_data);
    form_data.append('product_id', productdata);
    loader_show();
    $.ajax({
        url: site_url + 'controllers/ajax_controller/product-ajax-controller.php',
        type: 'post',
        dataType: 'json',
        data: form_data,
        processData: false,
        contentType: false,
        success: function(result) {
          // alert(result.eye_document);
          $('.uploaded-doc').css('display','none');
          $("#uploaded-show-doc").html(result.html);
          $("#eye_document").val(result.eye_document);
          // $(".uploaded-doc").style("hide");
            loader_hide();
    }

});
}
function updateEyeDockart(){
    var flag = 0;
    var img=$("#document_upload").val();
    var productdata=$("#product_id_toric").val();
    if(sub_cart_id_eye_doc!='')
    {
    var sub_cart_id_eye_doc=$("#sub_cart_id_eye_doc").val();
    }else{
    var sub_cart_id_eye_doc='';
    }
    // alert(productdata);
    if(img!='' && regexValidate('document_upload',"",upload_img,'imgdoc')){
        flag++;
    }
    if(flag>0)
    {
        return false;
    }
    var file_data = $('#document_upload').prop('files')[0];   
    var form_data = new FormData();                  
    form_data.append('document_upload', file_data);
    form_data.append('product_id', productdata);
    form_data.append('sub_cart_id_eye_doc', sub_cart_id_eye_doc);
    loader_show();
    $.ajax({
        url: site_url + 'controllers/ajax_controller/shop-ajax-controller.php',
        type: 'post',
        dataType: 'json',
        data: form_data,
        processData: false,
        contentType: false,
        success: function(result) {
            loader_hide();
            // alert(result.html);
            $('.uploaded-doc').css('display','none');
            $("#uploaded-show-doc").html(result.html);
            /*if (result == 1) {
                alert('Eye Document Uploaded Successfully');
                location.reload();
            }*/
    }

});
}
function DeleteEyeDockart(sub_cart_id,document_name){
  
  $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    data: 'Deleteeyedockart=1&sub_cart_id='+sub_cart_id+'&eye_document='+document_name,        
    success : function( resp ) {
      alert('Eye Document Deleted Successfully');
      location.reload();
    }
  });
}
function DeleteEyeDoc(id){
  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    data: 'Deleteeyedoc=1&id='+id,        
    success : function( resp ) {
      alert('Eye Document Deleted Successfully');
      location.reload();
    }
  });
}
function addtocartToric()
{
  var flag = 0;
  // var countvalue = $("#countvalue").val();
  // var totalqty   = $("#totalqty").val();
  // var cardvalue  = $("#txt_card").val();
  var productid       = $("#txt_product").val();
  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower       = $("#left_shpere").val();
  var left_cycl       = $("#left_cycl").val();
  var left_axis       = $("#left_axis").val();
  var rightpower      = $("#right_shpere").val();
  var right_cycl      = $("#right_cycl").val();
  var right_axis      = $("#right_axis").val();
  var leftqty         = $("#leftqtytoric").val();
  var rightqty        = $("#rightqtytoric").val();
  var txt_stock_check = $("#txt_stock_check").val();
  var sub_cart_id     = $("#sub_cart_id").val();
  var document_upload = $("#eye_document").val();
  if (document_upload == undefined) {
  document_upload = '';
  }else{
  document_upload = document_upload;
  }
  var product_id_toric = $("#product_id_toric").val();
  var checkbox = document.getElementById('is_power_different');
  
  //Both Power
  if(checkbox.checked==false)
  {
  var checkbox = 4;
  var leftpower       = $("#both_shpere").val();
  var left_cycl       = $("#both_cycl").val();
  var left_axis       = $("#both_axis").val();
  var leftqty         = $("#qtytoricboth").val();
  }
  //Both Power
  if(txt_brand_type==2){
    // var leftpoweridcheck = document.getElementById('leftpowerselectionshow').innerHTML;
    // var rightpoweridcheck = document.getElementById('rightpowerselectionshow').innerHTML;
    if((leftpower=='' || leftpower==undefined) && (rightpower=='' || rightpower==undefined))
    {
      alert(please_select_power);
      flag++;
      return false;
    }else if((left_cycl=='' || left_cycl==undefined) && leftpower!=''){
      alert(please_select_power);
      flag++;
      return false;
    }else if((left_axis=='' || left_axis==undefined) && leftpower!=''){
      alert(please_select_power);
      flag++;
      return false;
    }


    if((rightpower=='' || rightpower==undefined) && (leftpower=='' || leftpower==undefined)){
      alert(please_select_power);
      flag++;
      return false;
    }else if((right_cycl=='' || right_cycl==undefined) && rightpower!=''){
      alert(please_select_power);
      flag++;
      return false;
    }else if((right_axis=='' || right_axis==undefined) && rightpower!=''){
      alert(please_select_power);
      flag++;
      return false;
    }
  }

  if(flag>0){
    return false;
  }
  //Countrywise ordering management
  var countryid = $("#txt_country").val();


  $.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'addtocarttoric=1&productid='+productid+'&txt_brand_type='+txt_brand_type+'&leftpower='+encodeURIComponent(leftpower)+'&left_cycl='+encodeURIComponent(left_cycl)+'&left_axis='+encodeURIComponent(left_axis)+'&rightpower='+encodeURIComponent(rightpower)+'&right_cycl='+encodeURIComponent(right_cycl)+'&right_axis='+encodeURIComponent(right_axis)+'&productid='+productid+'&leftqty='+leftqty+'&rightqty='+rightqty+'&txt_country='+countryid+'&sub_cart_id='+sub_cart_id+'&document_upload='+document_upload+'&checkbox='+checkbox,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      if (resp[0] == 1) {
            //Based on country wise & language
            // var txt_lang_type = $("#txt_lang_type").val();
            // window.location.href=site_url+txt_lang_type+"/cart";

            $("#btngocart").show();
            $("#btnaddcart").hide();
            $(".item-count").html(resp[1]);

            Swal.fire({
              position: 'top-end',
              icon: 'success',
              title: add_cart_successful,
              showConfirmButton: false,
              timer: 1500
            });
            
            //  $("#error_cartmsg").removeClass('error_msg');
            // $("#error_cartmsg").addClass('success_msg');
            // $("#error_cartmsg").text(add_cart_successful).show().fadeOut(fadeOutSec);
            addtocartanalytics(resp.product_id,resp.product_name,resp.qty);
          }
          else{
            $("#error_cartmsg").removeClass('success_msg');
            $("#error_cartmsg").addClass('error_msg');
            $("#error_cartmsg").text(something_went_wrong).show().fadeOut(fadeOutSec);
          }
          $('#loader_search').hide();
    }
  });
}
function quantitycountylefttoric(){

  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower  = $("#left_shpere").val();
  // var rightpower = $("#rightpower").val();
  var leftqtytoric    = $("#leftqtytoric").val();
  // var rightqty   = $("#rightqty").val();
  // var avai_acc_qty   = $("#hid_accessories_qty").val();
  var hid_discount_percentage   = $("#hid_discount_percentage").val();

  var div1 = document.getElementById('left'+leftpower);
  var leftoprice = div1.getAttribute('leftoprice');
  var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = 0;//Set Default 0
  
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

   $.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'priceupdate_left_toric=1&leftqtytoric='+leftqtytoric+'&leftpower='+encodeURIComponent(leftpower)+'&txt_brand_type='+txt_brand_type+'&leftoprice='+leftoprice+'&leftdprice='+leftdprice+'&leftpowerqty='+leftpowerqty+'&txt_country='+countryid+'&hid_discount_percentage='+hid_discount_percentage,
    success : function(resp) {
      if(resp[3]!='')
      {
      $("#dprice_new_left").html(resp[3]);
      $("#oprice_new_left").html(resp[2]);
      }else{
      $("#dprice_new_left").html(resp[2]);
      }
    }
  });
}
function quantitycountyrighttoric(){

  var txt_brand_type  = $("#txt_brand_type").val();
  var rightpower  = $("#right_shpere").val();
  var rightqtytoric    = $("#rightqtytoric").val();
  var hid_discount_percentage   = $("#hid_discount_percentage").val();

  var div2 = document.getElementById('right'+rightpower);
  var rightoprice = div2.getAttribute('rightoprice');
  var rightdprice = div2.getAttribute('rightdprice');
  var rightpowerqty = 0;//Set Default 0
  
  //Countrywise ordering management
  var countryid = $("#txt_country").val();

   $.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'priceupdate_right_toric=1&rightqtytoric='+rightqtytoric+'&rightpower='+encodeURIComponent(rightpower)+'&txt_brand_type='+txt_brand_type+'&rightoprice='+rightoprice+'&rightdprice='+rightdprice+'&rightpowerqty='+rightpowerqty+'&txt_country='+countryid+'&hid_discount_percentage='+hid_discount_percentage,
    success : function(resp) {
      if(resp[3]!='')
      {
      $("#dprice_new_right").html(resp[3]);
      $("#oprice_new_right").html(resp[2]);
      }else{
      $("#dprice_new_right").html(resp[2]);
      }
    }
  });
}
function quantitycountybothtoric(){

  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower  = $("#both_shpere").val();
  var qtytoricboth    = $("#qtytoricboth").val();
  var hid_discount_percentage   = $("#hid_discount_percentage").val();
  
  var div1 = document.getElementById('left'+leftpower);
  var leftoprice = div1.getAttribute('leftoprice');
  var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = 0; //Set Default 0

  //Countrywise ordering management
  var countryid = $("#txt_country").val();

   $.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'priceupdate_left_toric=1&leftqtytoric='+qtytoricboth+'&leftpower='+encodeURIComponent(leftpower)+'&txt_brand_type='+txt_brand_type+'&leftoprice='+leftoprice+'&leftdprice='+leftdprice+'&leftpowerqty='+leftpowerqty+'&txt_country='+countryid+'&hid_discount_percentage='+hid_discount_percentage,
    success : function(resp) {
      if(resp[3]!='')
      {
      $("#dprice_new_left_both").html(resp[3]);
      $("#oprice_new_left_both").html(resp[2]);
      }else{
      $("#dprice_new_left_both").html(resp[2]);
      }
    }
  });
}
function toric_update_same_price_both(id,product_id) {
  var countryid = $("#txt_country").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    dataType: "json",
    data: 'PriceUpdateToric=1&id='+encodeURIComponent(id)+'&product_id='+product_id+'&countryid='+countryid,        
    success : function( resp ) {
      if(resp.sale_precentage!='' && resp.sale_precentage!=null)
      {
      $("#dprice_new_left_both").html(resp.new_price);
      $("#oprice_new_left_both").html(resp.price);
      $("#sale_precentage_both").html(resp.sale_precentage);
      }else{
      $("#dprice_new_left_both").html(resp.price);  
      }
      $("#Priceshowboth").show();
      $("#showbothprice").show();
      $(".showpricedefault").hide();
      //loader_hide();
    }
  });
}
function toric_update_price(id,product_id) {
  var countryid = $("#txt_country").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    dataType: "json",
    data: 'PriceUpdateToric=1&id='+encodeURIComponent(id)+'&product_id='+product_id+'&countryid='+countryid,        
    success : function( resp ) {
      if(resp.sale_precentage!='' && resp.sale_precentage!=null)
      {
      $("#dprice_new_left").html(resp.new_price);
      $("#oprice_new_left").html(resp.price);
      $("#sale_precentage_left").html(resp.sale_precentage);
      }else{
      $("#dprice_new_left").html(resp.price);  
      }
      $("#Priceshow").show();
      $("#leftpriceshow").show();
      // $("#rightpriceshow").show();
      //loader_hide();
    }
  });
}
function toric_update_right_price(id,product_id) {
  var countryid = $("#txt_country").val();
  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    dataType: "json",
    data: 'PriceUpdateToric=1&id='+encodeURIComponent(id)+'&product_id='+product_id+'&countryid='+countryid,        
    success : function( resp ) {
      if(resp.sale_precentage!='' && resp.sale_precentage!=null)
      {
      $("#dprice_new_right").html(resp.new_price);
      $("#oprice_new_right").html(resp.price);
      $("#sale_precentage_right").html(resp.sale_precentage);
      }else{
      $("#dprice_new_right").html(resp.price);  
      }
      $("#Priceshow").show();
      // $("#leftpriceshow").show();
      $("#rightpriceshow").show();
      //loader_hide();
    }
  });
}

function increment_quantity_left_toric(code) {
  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower   = $("#left_shpere").val();
  var leftcycl   = $("#left_cycl").val();
  var leftaxis   = $("#left_axis").val();
  var leftqtytoric    = $("#leftqtytoric").val();
  if(leftpower=='' || leftcycl=='' || leftaxis=='')
  {
    alert(please_select_power);return false;
    // $("#error_left_shpere").removeClass('success_msg');
    // $("#error_left_shpere").addClass('error_msg');
    // $("#error_left_shpere").text(please_select_power).show().fadeOut(5000);
  }
  var div1 = document.getElementById('left'+leftpower);
  var leftoprice = div1.getAttribute('leftoprice');
  // var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = div1.getAttribute('leftpowerqty');

  if(leftpower){
        var inputQuantityElement = $("#leftqtytoric");
        var newQuantityleft = parseInt($(inputQuantityElement).val())+2;
        $("#leftqtytoric").val(newQuantityleft);
  }
  resetaddtocartbtn();
  // Priceupdatebyqty();
}

function decrement_quantity_left_toric(code) {
  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower   = $("#left_shpere").val();
  var leftcycl    = $("#left_cycl").val();
  var leftaxis    = $("#left_axis").val();
  if(leftpower=='' || leftcycl=='' || leftaxis=='')
  {
    alert(please_select_power);return false;
  }

  var div1 = document.getElementById('left'+leftpower);
  var leftoprice = div1.getAttribute('leftoprice');
  // var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = div1.getAttribute('leftpowerqty');

  if(leftpower){
    var inputQuantityElement = $("#leftqtytoric");
    if($(inputQuantityElement).val() > 1)
    {
    var newQuantity = parseInt($(inputQuantityElement).val());
    $("#leftqtytoric").val(newQuantity);
    }
  }
  resetaddtocartbtn();
  // Priceupdatebyqty();
}
function increment_quantity_right_toric(code) {
  var txt_brand_type  = $("#txt_brand_type").val();
  var rightpower      = $("#right_shpere").val();
  var rightcycl      = $("#right_cycl").val();
  var rightaxis      = $("#right_axis").val();
  var rightqtytoric   = $("#rightqtytoric").val();
  if(rightpower=='' || rightcycl=='' || rightaxis=='')
  {
    alert(please_select_power);return false;
  }
  var div2 = document.getElementById('right'+rightpower);
  var rightoprice = div2.getAttribute('rightoprice');
  var rightdprice = div2.getAttribute('rightdprice');
  var rightpowerqty = div2.getAttribute('rightpowerqty');

  if(rightpower){
        var inputQuantityElement = $("#rightqtytoric");
        var newQuantityright = parseInt($(inputQuantityElement).val())+2;
        $("#rightqtytoric").val(newQuantityright);
  }
  resetaddtocartbtn();
  // Priceupdatebyqty();
}
function decrement_quantity_right_toric(code) {
  var txt_brand_type  = $("#txt_brand_type").val();
  var rightpower      = $("#right_shpere").val();
  var rightcycl      = $("#right_cycl").val();
  var rightaxis      = $("#right_axis").val();
  if(rightpower=='' || rightcycl=='' || rightaxis=='')
  {
    alert(please_select_power);return false;
  }

  var div2 = document.getElementById('right'+rightpower);
  var rightoprice = div2.getAttribute('rightoprice');
  var rightdprice = div2.getAttribute('rightdprice');
  var rightpowerqty = div2.getAttribute('rightpowerqty');

  if(rightpower){
    var inputQuantityElement = $("#rightqtytoric");
    if($(inputQuantityElement).val() > 1)
    {
    var newQuantity = parseInt($(inputQuantityElement).val());
    $("#rightqtytoric").val(newQuantity);
    }
  }
  resetaddtocartbtn();
  // Priceupdatebyqty();
}
function increment_quantity_both_toric(code) {
  var txt_brand_type  = $("#txt_brand_type").val();
  var bothpower   = $("#both_shpere").val();
  var bothcycl   = $("#both_cycl").val();
  var bothaxis   = $("#both_axis").val();
  var qtytoricboth    = $("#qtytoricboth").val();
  if(bothpower=='' || bothcycl=='' || bothaxis=='')
  {
    alert(please_select_power);return false;
    // $("#error_left_shpere").removeClass('success_msg');
    // $("#error_left_shpere").addClass('error_msg');
    // $("#error_left_shpere").text(please_select_power).show().fadeOut(5000);
  }
  var div1 = document.getElementById('left'+bothpower);
  var leftoprice = div1.getAttribute('leftoprice');
  // var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = div1.getAttribute('leftpowerqty');

  if(bothpower){
        var inputQuantityElement = $("#qtytoricboth");
        var newQuantityleft = parseInt($(inputQuantityElement).val())+2;
        $("#qtytoricboth").val(newQuantityleft);
  }
  resetaddtocartbtn();
  // Priceupdatebyqty();
}

function decrement_quantity_both_toric(code) {
  var txt_brand_type  = $("#txt_brand_type").val();
  var bothpower   = $("#both_shpere").val();
  var bothcycl   = $("#both_cycl").val();
  var bothaxis   = $("#both_axis").val();
  var qtytoricboth    = $("#qtytoricboth").val();
  if(bothpower=='' || bothcycl=='' || bothaxis=='')
  {
    alert(please_select_power);return false;
  }

  var div1 = document.getElementById('left'+bothpower);
  var leftoprice = div1.getAttribute('leftoprice');
  // var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = div1.getAttribute('leftpowerqty');

  if(bothpower){
    var inputQuantityElement = $("#qtytoricboth");
    if($(inputQuantityElement).val() > 1)
    {
    var newQuantity = parseInt($(inputQuantityElement).val());
    $("#qtytoricboth").val(newQuantity);
    }
  }
  resetaddtocartbtn();
  // Priceupdatebyqty();
}
function vieweyetest(id){
  loader_show();  
  $("#fcbox_view_heading_tag_order_eye_doc").html('<i class = "icon-tag"></i> View Eye Document');
  $.ajax( {
    url : site_url+'controllers/ajax_controller/my-order-ajax-controller.php',
    type : 'post',
    data: 'view_eye_document=1&id='+id,
    success : function(result)
    {
      $("#vieweyedoc").html(result);
      $(".fcbox_view_tag_order_eye_doc").trigger('click');
      loader_hide();
    }
  });
}
// Normal
function normal_update_price(id,product_id) {
  var countryid = $("#txt_country").val();

  // alert(encodeURIComponent(id);
  var encodedValue = encodeURIComponent(id).replace(/%2B/g, '+');
  $('#leftpower').val(encodedValue);  

  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    dataType: "json",
    data: 'PriceUpdateNormal=1&id='+encodeURIComponent(id)+'&product_id='+product_id+'&countryid='+countryid,        
    success : function( resp ) {
      if(resp.sale_precentage!='' && resp.sale_precentage!=null)
      {
      $("#dprice_new_left").html(resp.new_price);
      $("#oprice_new_left").html(resp.price);
      $("#sale_precentage_left").html(resp.sale_precentage);
      }else{
      $("#dprice_new_left").html(resp.price);  
      }
      $("#Priceshownormal").show();
      $(".showpricedefault").hide();
      if($('#leftpower').val() == $('#rightpower').val()) {
          $("#rightqtydiv").hide();
          $("#rightpriceshownormal").hide();
          $("#leftpriceshownormal").show();
      } else {
          $("#leftpriceshownormal").show();
      }
      //loader_hide();
      $("#leftqty").val('1');
    }
  });
}
function normal_update_right_price(id,product_id) {
  var countryid = $("#txt_country").val();
  var leftpower = $("#leftpower").val();
  var chkrightpower='';
  // alert(encodeURIComponent(id);
  var encodedValue = encodeURIComponent(id).replace(/%2B/g, '+');
  var rightpower = $('#rightpower').val(encodedValue);  
  // $('#leftpower').val(encodeURIComponent(id)); 
  $('#rightpower').val(encodedValue);  
    // alert(leftpower);
  
  //Select Power in Description
  // changeajaxpowerval(chkrightpower,chkrightpower);


  $.ajax( {
    url : site_url+'controllers/ajax_controller/product-ajax-controller.php', 
    type : 'post',
    dataType: "json",
    data: 'PriceUpdateNormal=1&id='+encodeURIComponent(id)+'&product_id='+product_id+'&countryid='+countryid,        
    success : function( resp ) {
      if(resp.sale_precentage!='' && resp.sale_precentage!=null)
      {
      $("#dprice_new_right").html(resp.new_price);
      $("#oprice_new_right").html(resp.price);
      $("#sale_precentage_right").html(resp.sale_precentage);
      }else{
      $("#dprice_new_right").html(resp.price);  
      }
      $("#Priceshownormal").show();
      $(".showpricedefault").hide();
      if($('#leftpower').val() == $('#rightpower').val()) {
          $("#rightqtydiv").hide();
          $("#rightpriceshownormal").hide();
      } else {
          $("#rightpriceshownormal").show();
          $("#rightqtydiv").show();
      }
      $("#rightqty").val('1');
      //loader_hide();
    }
  });
}
function  quantitycountyleftnormal() {

  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower   = $("#leftpower").val();
  var leftqty    = $("#leftqty").val();
  var div1 = document.getElementById('left'+leftpower);
  var leftoprice = div1.getAttribute('leftoprice');
  var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = div1.getAttribute('leftpowerqty');

  if(leftpower!='' && leftpower!=undefined){
    var countvalue = $("#leftqty").val();
     if(leftpowerqty<=0){ leftpowerqty=1; }
     
     if(parseInt(countvalue) > parseInt(leftpowerqty))
      {
        $("#leftqty").val(leftpowerqty);
      }else{
        var inputQuantityElement = $("#leftqty");
        if($(inputQuantityElement).val() > 0)
        {
        var newQuantity = parseInt($(inputQuantityElement).val());
        $("#leftqty").val(newQuantity);
        }
      }
  }

  Priceupdatebyqtynormal();
}
function  quantitycountyrightnormal() {

  var txt_brand_type  = $("#txt_brand_type").val();
  var rightpower   = $("#rightpower").val();
  var rightqty    = $("#rightqty").val();
  var div2 = document.getElementById('right'+rightpower);
  var rightoprice = div2.getAttribute('rightoprice');
  var rightdprice = div2.getAttribute('rightdprice');
  var rightpowerqty = div2.getAttribute('rightpowerqty');

  if(rightpower!='' && rightpower!=undefined){
    var countvalue = $("#rightqty").val();
     if(rightpowerqty<=0){ rightpowerqty=1; }
     
     if(parseInt(countvalue) > parseInt(rightpowerqty))
      {
        $("#rightqty").val(rightpowerqty);
      }else{
        var inputQuantityElement = $("#rightqty");
        if($(inputQuantityElement).val() > 0)
        {
        var newQuantity = parseInt($(inputQuantityElement).val());
        $("#rightqty").val(newQuantity);
        }
      }
  }

  Priceupdatebyqtynormal();
}
function Priceupdatebyqtynormal(){

  var txt_brand_type  = $("#txt_brand_type").val();
  var leftpower  = $("#leftpower").val();
  var rightpower = $("#rightpower").val();
  var leftqty    = $("#leftqty").val();
  var rightqty   = $("#rightqty").val();

  var div1 = document.getElementById('left'+leftpower);
  var leftoprice = div1.getAttribute('leftoprice');
  var leftdprice = div1.getAttribute('leftdprice');
  var leftpowerqty = div1.getAttribute('leftpowerqty');

  var div2 = document.getElementById('right'+rightpower);
  var rightoprice = div2.getAttribute('rightoprice');
  var rightdprice = div2.getAttribute('rightdprice');
  var rightpowerqty = div2.getAttribute('rightpowerqty');

  /*if((leftpower=='' || leftpower==undefined)){
    $("#leftsidepowerhide").hide();
  }else{
    var div1 = document.getElementById('left'+leftpower);
    var leftoprice = div1.getAttribute('leftoprice');
    var leftdprice = div1.getAttribute('leftdprice');
    var leftpowerqty = div1.getAttribute('leftpowerqty');
  }*/

  if(leftpower==rightpower){

    var countvalue = $("#leftqty").val();
     if(leftpowerqty<=0){ leftpowerqty=1; }
     if(parseInt(countvalue) > parseInt(leftpowerqty))
      {
        $("#leftqty").val(leftpowerqty);
      }
      var countvalue = $("#rightqty").val();
       if(rightpowerqty<=0){ rightpowerqty=1; }
       if(parseInt(countvalue) > parseInt(rightpowerqty))
        {
          $("#rightqty").val(rightpowerqty);
        }
  }else if((leftpower!='' && leftpower!=undefined) && (rightpower!='' && rightpower!=undefined)){

     var countvalue = $("#leftqty").val();
     if(leftpowerqty<=0){ leftpowerqty=1; }
     if(parseInt(countvalue) > parseInt(leftpowerqty))
      {
        $("#leftqty").val(leftpowerqty);
      }

    var countvalue = $("#rightqty").val();
    if(rightpowerqty<=0){ rightpowerqty=1; }
    if(parseInt(countvalue) > parseInt(rightpowerqty))
    {
      $("#rightqty").val(rightpowerqty);
    }



  }else if(leftpower!='' && leftpower!=undefined){
    var countvalue = $("#leftqty").val();
    if(leftpowerqty<=0){ leftpowerqty=1; }
    if(parseInt(countvalue) > parseInt(leftpowerqty))
    {
      $("#leftqty").val(leftpowerqty);
    }
  }else if(rightpower!='' && rightpower!=undefined){
    var countvalue = $("#rightqty").val();
    if(rightpowerqty<=0){ rightpowerqty=1; }
    if(parseInt(countvalue) > parseInt(rightpowerqty))
    {
      $("#rightqty").val(rightpowerqty);
    }
  }




  //Countrywise ordering management
  var countryid = $("#txt_country").val();

   $.ajax({
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php',
    type : "post",
    dataType: "json",
    data: 'priceupdate=1&leftqty='+leftqty+'&rightqty='+rightqty+'&leftpower='+encodeURIComponent(leftpower)+'&rightpower='+encodeURIComponent(rightpower)+'&txt_brand_type='+txt_brand_type+'&leftoprice='+leftoprice+'&leftdprice='+leftdprice+'&rightoprice='+rightoprice+'&rightdprice='+rightdprice+'&rightpowerqty='+rightpowerqty+'&leftpowerqty='+leftpowerqty+'&txt_country='+countryid,
    success : function(resp) {
      //Same power value
      if(leftpower == rightpower)
      {
          if(resp[1]!=''){
          $("#dprice_new_left").html(resp[1]);
          $("#oprice_new_left").html(resp[0]);
          }else{
          $("#dprice_new_left").html(resp[0]);
          }
      }else{
        if(resp[5]!='')
        {
        $("#dprice_new_left").html(resp[5]);
        $("#oprice_new_left").html(resp[4]);
        }else{
        $("#dprice_new_left").html(resp[4]);
        }
        if(resp[7]!='')
        {
        $("#dprice_new_right").html(resp[7]);
        $("#oprice_new_right").html(resp[6]);
        }else{
        $("#dprice_new_right").html(resp[6]);
        }

      }
    }
  });
}
function confirm_booking() {
    var selectedValue = $('input[name="time-slots"]:checked').val();
    var date_slot_value = $('#date_slot_value').val();
    var booking_user_id = $('#booking_user_id').val();
    var country_code_name = $('#country_code_name').val();
    var timezone = $('#timezone').val();
    if(booking_user_id)
    {
    var user_id = booking_user_id;
    }else{
    var user_id = $('#user_id').val();
    }
    var time_slot_interval = $('#time_slot_interval').val();
    // alert(date_slot_value);
    // Check if any radio button is checked
    if ($('input[name="time-slots"]:checked').length === 0) {
        // Show the error message
        $("#error_cancel_booking").removeClass('success_msg');
        $("#error_cancel_booking").addClass('error_msg');
        $("#error_cancel_booking").text(please_select_date_time_slot).show().fadeOut(5000);
        return false;
    } else {
      if(booking_user_id!='')
      {
        loader_show(); 
        // Hide the error message and proceed with form submission or other logic
         $.ajax( {
          url : site_url+'controllers/ajax_controller/home-ajax-controller.php', 
          type : 'post',
          data: 'addconfirmbooking=1&user_id='+user_id+'&time_slot_id='+selectedValue+'&time_slot_interval='+time_slot_interval+'&date_slot_value='+date_slot_value+'&country_code_name='+country_code_name+'&timezone='+timezone,        
          success : function( resp ) {
            if(resp==1)
            {
              //Based on country wise & language
              var txt_lang_type = $("#txt_lang_type").val();
              window.location.href=site_url+txt_lang_type+"/booking_confirmed";
            }else if(resp==3){
              alert(mobile);
              $("#MobileData").modal("show");
            }else{
              alert(already_have_an_appointment_booked);
            }
            loader_hide();
          }
        });
       }else{
        $("#login-form-booking").modal("show");

       }
    }
    
}
function userLoginBooking(e){
  
    flag = 0;
    e.preventDefault();

    if(requiredValidate('loginUserEmail_booking',enter_email_id)){
        flag++;
        $("#loginUserEmail_booking").focus();
    }

    if($('#loginUserEmail_booking').val()!='' && regexValidate('loginUserEmail_booking','',enter_valid_email_id,'email','yes')){
        flag++;
        $("#loginUserEmail_booking").focus();
    }

    if(requiredValidate('loginUserPassword_booking',enter_password)){
        flag++; 
        $("#loginUserPassword_booking").focus(); 
    }

    if(flag>0){
      //For Autofocus validation highlight
        if($("#loginUserEmail_booking").val()=='')
        {
        document.getElementById('loginUserEmail_booking').focus();
        return false;
        }else if($("#loginUserPassword_booking").val()==''){
        document.getElementById('loginUserPassword_booking').focus();
        return false;
        }
      return false;
    }
   loader_show();

    $.ajax({
        url: site_url + 'controllers/ajax_controller/login-ajax-controller.php',
        type: 'post',
        data: $('#loginFormBooking').serialize(),
        success: function(result) {
            loader_hide();
          if(result['userId']) {
            $("#booking_user_id").val(result['userId']);
            $('#login-form-booking').modal('hide'); // Assuming you're using Bootstrap modal
            alert(login_success);
          }else if(result == 2){
            $("#error_login_booking").removeClass('success_msg');
            $("#error_login_booking").addClass('error_msg');
            $("#error_login_booking").text(invalid_email_password).show().fadeOut(fadeOutSec);
          }else if(result == 0){
            $("#error_login_booking").removeClass('success_msg');
            $("#error_login_booking").addClass('error_msg');
            $("#error_login_booking").text(account_inactive_delete).show().fadeOut(fadeOutSec);
          }else if(result == 3) {
             //Based on country wise & language
             var txt_lang_type = $("#txt_lang_type").val();
             window.location.href = site_url+txt_lang_type+"/cart";
          }else{
            $("#error_login_booking").removeClass('success_msg');
            $("#error_login_booking").addClass('error_msg');
            $("#error_login_booking").text(something_went_wrong).show().fadeOut(fadeOutSec);
          }
    }

});


}
function  getbookinglist(page) {

  $.ajax({
    url : site_url+'controllers/ajax_controller/home-ajax-controller.php',
    type : "post",
    data: 'bookinglist=1&page='+page,
    beforeSend:  function(){
      $('#loader_search').show();
    },
    complete: function(){
      $('#loader_search').hide();
    },
    success : function(resp) {
      // alert(resp);
      $("#bookinglist").html(resp);
    }
  });
}
function viewconfirmbooking(id,timezone=''){
  loader_show();  
  $("#fcbox_view_heading_tag_booking").html('<i class = "icon-tag"></i> '+'View Detail');
  $.ajax( {
    url : site_url+'controllers/ajax_controller/home-ajax-controller.php',
    type : 'post',
    data: 'viewbookingconfirm=1&id='+id+'&timezone='+timezone,
    success : function(result)
    {
      $("#bookingdetailsview").html(result);
      $("#common").html('View Detail');
      $(".fcbox_view_tag_booking").trigger('click');
      loader_hide();
    }
  });
}

function cancelbooking(id){
    $("#fcbox_delete_selected_heading_tag").text(cancel);
    $("#fcbox_delete_selected_content_tag").html(want_to_cancel_your_booking);
    $(".fcbox_delete_selected_content_btn").attr("onclick","booking_canelled_ok('"+id+"')");
    $(".fcbox_delete_selected_content_btn").html("Yes");
    $(".btn-default-outline").html("No");
    $(".fcbox_delete_selected_tag").trigger('click');
}

function booking_canelled_ok(selected){
  // alert(selected);
  $.ajax({
    type: "POST",
    url: site_url+'controllers/ajax_controller/home-ajax-controller.php',
    data: 'cancelbookingconfirm=1&id='+selected,
    cache: false,
    success: function(data)
    {
      window.location.reload();
    }
  });
}
// Normal

// Google Analytics Starts
function offerAccessoriesAnalytics() {
   gtag('event', 'Accessories_Topoffers', {
      'event_category': 'Accessories',
      'event_label': 'Accessories Topbrands',
      'value': 1 // Numeric value associated with the event
   });
}
function brandAccessoriesAnalytics() {
   gtag('event', 'Accessories_Topbrands', {
      'event_category': 'Accessories',
      'event_label': 'Accessories Topbrands',
      'value': 1 // Numeric value associated with the event
   });
}
function offerPrescriptionAnalytics() {
   gtag('event', 'Prescription_Topoffers', {
      'event_category': 'Prescription',
      'event_label': 'Prescription Topbrands',
      'value': 1 // Numeric value associated with the event
   });
}
function brandPrescriptionAnalytics() {
   gtag('event', 'Prescription_Topbrands', {
      'event_category': 'Prescription',
      'event_label': 'Prescription Topbrands',
      'value': 1 // Numeric value associated with the event
   });
}
function offerColoredAnalytics() {
   gtag('event', 'Colored_Topoffers', {
      'event_category': 'colored-lenses',
      'event_label': 'colored',
      'value': 1 // Numeric value associated with the event
   });
}
function brandColoredAnalytics() {
   gtag('event', 'Colored_Topbrands', {
      'event_category': 'colored-lenses',
      'event_label': 'colored',
      'value': 1 // Numeric value associated with the event
   });
}

function brand_detail(brandid) {
  var txt_lang_type = $("#txt_lang_type").val();
  // alert(txt_lang_type);
  // window.location.href=site_url+txt_lang_type+"/checkout";
  $.ajax( {
    url : site_url+'controllers/ajax_controller/shop-ajax-controller.php', 
    type : 'post',
    dataType : "json",
    data: 'Viewbranddetail=1&brandid='+brandid+'&txt_lang='+txt_lang_type,        
    success : function( resp ) {
      bbrandAnalytics(resp.name);
      //loader_hide();
    }
  });
}
function bbrandAnalytics(brand_name) {
  // alert(brand_name)
   gtag('event', 'B_Brand', {
      'event_category': brand_name,
      'event_label': brand_name,
      'value': 1 // Numeric value associated with the event
   });
}
function addtocartanalytics(productid,productname,productqty) {
   gtag('event', 'add_to_cart', {
        event_category: 'ecommerce',
        event_label: productname,
        value: productqty,
        items: [
            {
                id: productid,
                name: productname,
                price: '0',
                quantity: productqty
            }
        ],
        content_type: 'custom_cart'
    });
}
function wishlistanalytics(productid,productname) {
  // alert(productname);
    gtag('event', 'add_to_wishlist', {
        event_category: 'ecommerce',
        event_label: productname,
        value: productid,
        content_type: 'custom_wishlist'
    });
}
function checkoutanalytics(productid,productname,productqty,currencyCode) {
  // alert(currencyCode);
   gtag('event', 'begin_checkout', {
        'event_category': 'ecommerce',
        'event_label': productname,
        'value': productid,
        'currency': currencyCode,
        'no_of_items': productqty,
        'content_type': 'custom_checkout'  // Custom content type
    });
}
// Purchase event of analytics in thank-you page
// View Product List event of analytics in product-detail page
// Item List event of analytics in cart page
// Search Event Added in analytics default script [Same page - searchresult()]
function shareanalytics(productid) {
   gtag('event', 'share', {
      'event_category': 'Share',
      'event_label': 'Share',
      'value': productid // Numeric value of product id of the event
   });
}
function  englanganalytics()
{
  gtag('event', 'language_en', {
      'event_category': 'Language',
      'event_label': 'English',
   });
}
function  arabiclanganalytics()
{
  gtag('event', 'language_ar', {
      'event_category': 'Language',
      'event_label': 'Arabic',
   });
}
function  Coloredsectionanalytics()
{
  gtag('event', 'Sec_Colored', {
      'event_category': 'Colored',
      'event_label': 'Colored',
      'value': 1 // Numeric value
   });
}
function  Prescriptionsectionanalytics()
{
  gtag('event', 'Sec_Prescription', {
      'event_category': 'Prescription',
      'event_label': 'Prescription',
      'value': 1 // Numeric value
   });
}
function  Accessoriessectionanalytics()
{
  gtag('event', 'Sec_Accessories', {
      'event_category': 'Accessories',
      'event_label': 'Accessories',
      'value': 1 // Numeric value
   });
}
// Shop Cart List event of analytics in product list

function videoanalytics(productid,productname) {
   gtag('event', 'Videos', {
        'event_category': 'Product Videos',
        'event_label': productname,
        'value': productid, // You can customize the value if applicable
        'non_interaction': true // Set non_interaction to true to avoid affecting bounce rate
   });
}
// wish_list event of analytics in wishlist page
// add_payment_info event of analytics in thank-you page


// User Sign Up added gtag in default script only
// Home event of analytics in home page

// Google Analytics End
const check = () => {
  if (!('serviceWorker' in navigator)) {
    throw new Error('No Service Worker support!')
  }
  if (!('PushManager' in window)) {
    throw new Error('No Push API Support!')
  }
}
const main = () => {
  check()
}
main()