function kwm_create_cookie(name,value,expires,path,domain,secure){var today=new Date();today.setTime(today.getTime());if(expires){expires=expires*1000*60*60*24}var expires_date=new Date(today.getTime()+(expires));document.cookie=name+"="+escape(value)+((expires)?";expires="+expires_date.toGMTString():"")+((path)?";path="+path:"")+((domain)?";domain="+domain:"")+((secure)?";secure":"")}function kwm_read_cookie(check_name){var i,x,y,ARRcookies=document.cookie.split(';');for(i=0;i{window.location='/cart'})}function kwm_remove_extended_warranty_item(variant_id){var kwm_options='{"updates":{"'+old_variant_id+'": 0}}';kwm_fetch('/cart/update.js','POST',kwm_options).then((data)=>{window.location='/cart'})}function kwm_update_extended_warranty_item(old_variant_id,new_variant_id){var kwm_options='{"updates":{"'+old_variant_id+'": 0}}';kwm_fetch('/cart/update.js','POST',kwm_options).then((data)=>{kwm_options='{"items":[{"quantity":1,"id":'+new_variant_id+'}]}';kwm_fetch('/cart/add.js','POST',kwm_options).then((data)=>{window.location='/cart'})})}function kwm_check_cart_drawer(){if(document.querySelector('cart-drawer.cart-drawer')){var kwm_drawer=document.querySelector('cart-drawer.cart-drawer');if(kwm_drawer.style.visibility==''){kwmCheckDrawer=setTimeout(function(){kwm_check_cart_drawer()},100)}else if(kwm_drawer.style.visibility=='visible'){kwm_read_cart_data()}}else{kwmCheckDrawer=setTimeout(function(){kwm_check_cart_drawer()},100)}}function kwm_read_cart_data(){var cart_data;var xhr=new XMLHttpRequest();xhr.onreadystatechange=function(){if(xhr.readyState===4){cart_data=JSON.parse(xhr.response);console.log(cart_data);kwm_cart_subtotal=cart_data.total_price/100;kwm_cart_subtotal=kwm_cart_subtotal.toFixed(2);if(cart_data.total_discount>0){var kwm_cart_discount=cart_data.total_discount/100;kwm_cart_subtotal=parseFloat(kwm_cart_subtotal)+parseFloat(kwm_cart_discount);kwm_cart_subtotal=kwm_cart_subtotal.toFixed(2)}if(kwm_cart_subtotal>0){if(cart_data.items){var kwm_extended_warranty_product_found=false;for(i=0;i0)){kwm_create_extended_warranty_item(kwm_existing_extended_warranty_variant_id)}var all_warranty_costss=document.querySelectorAll('.kwm-ew-cost');for(i=0;i