function checkBrowserEnableCookie(){var a=(navigator.cookieEnabled)?true:false;if(typeof navigator.cookieEnabled=="undefined"&&!a){document.cookie="testcookie";a=(document.cookie.indexOf("testcookie")!=-1)?true:false}if(a){return true}else{return false}}function createCookie(c,d,e){if(e){var b=new Date();b.setTime(b.getTime()+(e*24*60*60*1000));var a="; expires="+b.toGMTString()}else{var a=""}document.cookie=c+"="+d+a+"; path=/;"}function readCookie(b){var e=b+"=";var a=document.cookie.split(";");for(var d=0;d<a.length;d++){var f=a[d];while(f.charAt(0)==" "){f=f.substring(1,f.length)}if(f.indexOf(e)==0){return f.substring(e.length,f.length)}}return null}function eraseCookie(a){createCookie(a,"",-1)}function countShoppingCart(b){if(readCookie(b)==null){createCookie(b,"-",1);document.getElementById("count_shopping_cart_store").innerHTML=0}else{var e=readCookie(b);var a=e.split(",");number_product=a.length;document.getElementById("count_shopping_cart_store").innerHTML=number_product-1;if($("#total_shopping_cart_store").length>0){var d=0;for(var c=0;c<a.length;c++){item_content=a[c];if(item_content.length>1){item_detail=item_content.split("-");pro_id=item_detail[0];pro_quantity=parseInt(item_detail[1]);unit_price=parseInt(item_detail[2]);d+=unit_price*pro_quantity}}document.getElementById("total_shopping_cart_store").innerHTML=writeStringToPrice(d+"")}}}function emptyShoppingCart(a){createCookie(a,"-",1)}function addToShoppingCartStop(a,d,c){if(readCookie("shopping_cart_store")==null){createCookie("shopping_cart_store",",",1)}var e=readCookie("shopping_cart_store");if(e.search(","+a+"-")==-1){var b=e+","+a+"-"+d+"-"+c;createCookie("shopping_cart_store",b,1);countShoppingCart("shopping_cart_store");document.getElementById("item_"+a).innerHTML="Đã thêm vào giỏ hàng"}else{alert("Sản phẩm đã có trong giỏ hàng!")}}function addToShoppingCart(a,d,c){if(readCookie("shopping_cart_store")==null){createCookie("shopping_cart_store",",",1)}var e=readCookie("shopping_cart_store");if(e.search(","+a+"-")==-1){var b=e+","+a+"-"+d+"-"+c;createCookie("shopping_cart_store",b,1);window.location="/gio-hang"}else{alert("Sản phẩm đã có trong giỏ hàng!")}}function isItemInCart(a){var b=readCookie("shopping_cart_store");if(b!=null&&b.search(","+a+"-")!=-1){document.write("Đang trong giỏ hàng")}}function deleteShoppingCartItem(a,c,b){if(confirm("Bạn muốn xóa bỏ sản phẩm này khỏi giỏ hàng ? ")){removeShoppingCartItem(a,c,b);window.location="/gio-hang"}}function removeShoppingCartItem(a,d,b){var e=readCookie("shopping_cart_store");e+=",";var c=new RegExp(","+a+"-([0-9]+)-([0-9]+),","i");new_cart=e.replace(c,",");new_cart=new_cart.substr(0,new_cart.length-1);createCookie("shopping_cart_store",new_cart,1)}function writeStringToPrice(f){var e=f.substr(0,f.length%3);var b=f.replace(e,"");var d=b.length/3;var a="";for(var c=0;c<d;c++){group_of_three=b.substr(c*3,3);a+=group_of_three;if(c!=(d-1)){a+="."}}if(e.length>0){if(a!=""){return e+"."+a}else{return e}}else{if(a!=""){return a}else{return""}}}function getItemUnitPrice(b){var a=document.getElementById("sell_price_"+b).innerHTML;while(a.indexOf(".")>0){a=a.replace(".","")}a=parseInt(a);return a}function getItemQuantity(b){var a=document.getElementById("quantity_"+b).value;a=parseInt(a);return a}function updatePrice(b,a){if(!isNumber(a)){alert("Vui lòng nhập số")}else{unit_price=getItemUnitPrice(b);document.getElementById("price_"+b).innerHTML=writeStringToPrice(unit_price*a+"");reCountTotal()}}function reCountTotal(){var b="";var a=document.getElementById("item_update_quantity").value;all_item_array=a.split(",");var d=0;combo_array=new Array();for(var c=0;c<all_item_array.length;c++){item_id=all_item_array[c];if(item_id.length>0){item_price=getItemUnitPrice(item_id);item_quantity=getItemQuantity(item_id);b+=","+item_id+"-"+item_quantity+"-"+item_price;d+=item_price*item_quantity}}createCookie("shopping_cart_store",b,1);document.getElementById("total_value").innerHTML=writeStringToPrice(d+"");document.getElementById("total_cart_value").value=d}function isNumber(a){return !isNaN(parseFloat(a))&&isFinite(a)}function makeUrlAcceptQuery(a){if(a.search("?")>0){return a}else{return a+"?"}}function checkCartForm(){var f=readCookie("shopping_cart_store");var a=f.split(",");number_product=a.length;if(number_product<=1){if(confirm("Giỏ hàng chưa có sản phẩm. Vui lòng chọn sản phẩm vào giỏ hàng")){window.location="/"}return false}else{var c="";var d=document.getElementById("buyer_name").value;if(d.length<4){c+="- Bạn chưa nhập tên\n"}var b=document.getElementById("buyer_mobile").value;if(b.length<5){c+="- Bạn chưa nhập số di động\n"}var e=document.getElementById("buyer_address").value;if(e.length<10){c+="- Bạn chưa nhập địa chỉ"}if(c!=""){alert(c);return false}return true}}$(document).ready(function(){countShoppingCart("shopping_cart_store")});
