function checkBrowserEnableCookie(){var cookieEnabled=(navigator.cookieEnabled)?true:false
if(typeof navigator.cookieEnabled=="undefined"&&!cookieEnabled){document.cookie="testcookie"
cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)?true:false}
if(cookieEnabled)return true;else return false;}
function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString();}
else var expires="";document.cookie=name+"="+value+expires+"; path=/; domain=.denthan.com;";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}
return null;}
function eraseCookie(name){createCookie(name,"",-1);}
function countShoppingCart(name){if(readCookie(name)==null){createCookie(name,'-',1);document.getElementById('count_shopping_cart').innerHTML=0;}else{var current_cart=readCookie(name);var ca=current_cart.split(',');number_product=ca.length;document.getElementById('count_shopping_cart').innerHTML=number_product-1;}}
function emptyShoppingCart(name){createCookie(name,'-',1);}
function addToShoppingCartStop(sellid,quantity,combo_id){if(readCookie('shopping_cart')==null){createCookie('shopping_cart',',',1);}
	var current_cart=readCookie('shopping_cart');if(current_cart.search(','+sellid+'-')==-1){	var new_cart=current_cart+','+sellid+'-'+quantity+'-'+combo_id;createCookie('shopping_cart',new_cart,1);	countShoppingCart('shopping_cart');	document.getElementById('item_'+sellid).innerHTML='Đã thêm vào giỏ hàng';}else{	alert('Sản phẩm đã có trong giỏ hàng!');}}
function addToShoppingCart(sellid,quantity,combo_id){if(readCookie('shopping_cart')==null){createCookie('shopping_cart',',',1);}
	var current_cart=readCookie('shopping_cart');if(current_cart.search(','+sellid+'-')==-1){var new_cart=current_cart+','+sellid+'-'+quantity+'-'+combo_id;createCookie('shopping_cart',new_cart,1);	window.location = '/gio-hang.html';	}else{	alert('Sản phẩm đã có trong giỏ hàng!');}}
function addToShoppingCartAndSelectAccessory(sellid,quantity,combo_id){	if(readCookie('shopping_cart')==null){createCookie('shopping_cart',',',1);}var current_cart=readCookie('shopping_cart');	if(current_cart.search(','+sellid+'-')==-1){var new_cart=current_cart+','+sellid+'-'+quantity+'-'+combo_id;createCookie('shopping_cart',new_cart,1);	window.location = "/chon-phu-kien-"+sellid+".html";	}else{alert('Sản phẩm đã có trong giỏ hàng!');}}
function addComboToShoppingCart(deal_id,id_list){	if(readCookie('shopping_cart')==null){createCookie('shopping_cart',',',1);}var current_cart = readCookie('shopping_cart');	var id_list_array = id_list.split('-');	var product_list = new Array();var check_in_cart = false;for(var i = 0;i<id_list_array.length;i++){	pro_id = parseInt(id_list_array[i]); if(pro_id > 0){product_list[i] = pro_id;if(current_cart.search(','+pro_id+'-')!=-1){check_in_cart = true;	break;}	}	}if(!check_in_cart){for(var i = 0;i<product_list.length;i++){	pro_id = product_list[i];	addToShoppingCart(pro_id,1,deal_id);}}else{alert('Một sản phẩm trong bộ sản phẩm đã có ở giỏ hàng. Để mua bộ sản phẩm, vui lòng xóa bỏ sản phẩm đó khỏi giỏ hàng!');	}}
function removeComboFromCart(deal_id,quantity,id_list){if(confirm('Bạn muốn xóa bỏ bộ sản phẩm này khỏi giỏ hàng ? ')){var id_list_array = id_list.split('-');for(var i = 0;i<id_list_array.length;i++){pro_id = parseInt(id_list_array[i]);if(pro_id > 0){removeShoppingCartItem(pro_id,quantity,deal_id);}}window.location='/gio-hang.html';}}function checkItemInCart(sellid){var current_cart=readCookie('shopping_cart');if(current_cart != null && current_cart.search(','+sellid+'-')!=-1){document.write('Trong giỏ hàng');}else{document.write('<a href=\"javascript:addToShoppingCartStop('+sellid+',1,0);\"><img src=/includes/images/cart_blue.gif></a>');}}
function isItemInCart(sellid){var current_cart=readCookie('shopping_cart');	if(current_cart != null && current_cart.search(','+sellid+'-')!=-1){document.write('Đang trong giỏ hàng');}}
function deleteShoppingCartItem(sellid,quantity,combo_id){	if(confirm('Bạn muốn xóa bỏ sản phẩm này khỏi giỏ hàng ? ')){		removeShoppingCartItem(sellid,quantity,combo_id);window.location='/gio-hang.html';	}}
function removeShoppingCartItem(sellid,quantity,combo_id){	var current_cart=readCookie('shopping_cart');current_cart += ",";var re = new RegExp(","+sellid+"-([0-9]+)-([0-9]+),","i");	new_cart = current_cart.replace(re, ",");new_cart = new_cart.substr(0, new_cart.length-1);	createCookie('shopping_cart',new_cart,1);}
function changeBoxSearch(type){	if(type =="sp"){document.getElementById('query_box').className = 'boxSearch2';document.getElementById('search_category').style.display = 'inline-block';	}else{document.getElementById('query_box').className = 'boxSearch2';document.getElementById('search_category').style.display = 'none';	}}

function showStoreAd(location,width,height,store,cat,limit,type){$.get("/cuahang/show_ad.php", {s:store,c:cat,l:location,li:limit,t:type}, function(data){if(data.length > 10){$('#store_ad_'+location).html("<div style=\"max-height:"+height+"; overflow:hidden;\">"+data+"</div>");}});}

//function showStoreAd(po,w,h,store,c){document.getElementById('store_ad_'+po).innerHTML = "<div style=\"max-height:"+h+"; overflow:hidden;\"><iframe src=\"/quangcao.html?s="+store+"&l="+po+"&c="+c+"\" width=\""+w+"\" height=\""+h+"\" frameborder=0 title=Ad scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" topmargin=\"0\" leftmargin=\"0\" allowtransparency=\"true\"></iframe></div>";}

function getViewedProduct(){document.getElementById('listViewProduct').innerHTML = '<img src=/includes/images/awaiting.gif> ...';	$.get("/sanpham/action.php",{action : "get-view-product"},function(data){		document.getElementById('listViewProduct').innerHTML = data;});}
function selectThum(img_src){document.getElementById('product_image_holder_content').innerHTML = "<img src=\""+img_src+"\">";}
function productTap(tap){document.getElementById('product_'+tap).style.display = 'block';	document.getElementById('tap_'+tap).className = 'selected_tap';	var tapList = ["detail","accessory","warrant","payment","shipping"];for(var i=0;i<tapList.length;i++){
this_tap = 	tapList[i];	if(this_tap != tap){document.getElementById('product_'+this_tap).style.display = 'none';document.getElementById('tap_'+this_tap).className = '';}	}	if(tap != "detail") document.getElementById('head_'+tap).style.display = 'none'; }
function productTapDt(tap){	document.getElementById('product_'+tap).style.display = 'block';	document.getElementById('tap_'+tap).className = 'selected_tap';	var tapList = ["seller","detail","photo","review","similar"];	for(var i=0;i<tapList.length;i++){
this_tap = 	tapList[i];if(this_tap != tap){document.getElementById('product_'+this_tap).style.display = 'none';
document.getElementById('tap_'+this_tap).className = '';}}	if(tap != "seller") document.getElementById('head_'+tap).style.display = 'none'; }
function selectPayMethod(method){	document.getElementById('pay_method_select').value = method;	document.getElementById('send_order_button').disabled = false;	document.getElementById('disable_note').style.display = 'none';}
function showPromoFull(){	var show = $("#product_promo_short").css("display");	if(show == "none"){
$("#product_promo_short").css({display:"block"});$("#product_promo_full").css({display:"none"});
}else{$("#product_promo_short").css({display:"none"});		$("#product_promo_full").slideDown().css({display:"block"});}}
function getProStat(type){	$.get("/sanpham/product_stat.php",{type:type}, function(data){$("#stat_"+type).text(data)});	}
function showMoreResult(block_id, text_id){	var check = document.getElementById(block_id).style.display;	if(check =="none"){	$("#"+block_id).slideDown("slow");document.getElementById(text_id).innerHTML = "<a href=\"javascript:showMoreResult('"+block_id+"', '"+text_id+"')\"><< Rút gọn</a>";	}else{$("#"+block_id).slideUp("slow");document.getElementById(text_id).innerHTML = "<a href=\"javascript:showMoreResult('"+block_id+"', '"+text_id+"')\">Xem thêm >></a>";	}}	
function trackChat(seller,pro, lo){	$.get("/chat_stat.html",{seller:seller, pro:pro, lo:lo});}
function open_request_form(subject, type){tb_show(null, "http://www.denthan.com/request_form.php?type="+type+"&subject="+subject+"&KeepThis=true&TB_iframe=true&height=400&width=500", null);}
function showSubmenu(groupId){
	var curren_open = document.getElementById('menu_open').value;
	if(curren_open != groupId){
		var check = document.getElementById(groupId).style.display; 
		if(check =="none"){$("#"+groupId).slideDown("slow");}else{$("#"+groupId).slideUp("slow");}
		document.getElementById('menu_open').value = groupId;
		if(curren_open.length > 2) $("#"+curren_open).slideUp("slow");
	}
}

function open_ajax_login(storeId, storeName){tb_show(null, "/ajax/login.php?width=500&height=400&storeId="+storeId+"&storeName="+storeName+"&KeepThis=true&TB_iframe=true", null);}
function open_ajax_cart(storeId, storeName){tb_show(null, "/ajax/shopping_cart.php?width=600&height=500&storeId="+storeId+"&storeName="+storeName+"&KeepThis=true&TB_iframe=true", null);}
function open_ajax_register(storeId, storeName){tb_show(null, "/ajax/register.php?width=500&height=200&storeId="+storeId+"&storeName="+storeName+"&KeepThis=true&TB_iframe=true", null);}

$(document).ready(function(){countShoppingCart('shopping_cart');if ( $("#listViewProduct").length > 0 ) {getViewedProduct();}});

