﻿function addToShoppingCart(id, strName) {
	ShoppingCart_ProductId = getCookie('ShoppingCart_ProductId');
	//checkedProductId = GetProductCheckBoxCheckedID();
	if (ShoppingCart_ProductId!=null && ShoppingCart_ProductId!="") {
		arrProductId = ShoppingCart_ProductId.split(",");
		for (i=0;i<arrProductId.length;i++){
			if (arrProductId[i]==id) {
				alert ('San pham:\n' + strName + '\nda co trong Gio hang');
				return;
			}
		}
		alert ('Da them san pham:\n' + strName + '\nvao Gio hang');
		//document.all.ShoppingCart.innerHTML = "(" + (arrProductId.length + 1) + ")";
		document.getElementById("ShoppingCart").innerHTML = "(" + (arrProductId.length + 1) + ")";
		setCookie("ShoppingCart_ProductId", ShoppingCart_ProductId + "," + id, 1); //1 day
	} else {
		alert ('Da them san pham:\n' + strName + '\nvao Gio hang');
		//document.all.ShoppingCart.innerHTML = "(" + 1 + ")";
		document.getElementById("ShoppingCart").innerHTML = "(" + 1 + ")";
		setCookie("ShoppingCart_ProductId", id, 1); //1 day
	}
	return;
}

function setCookie(c_name,value,expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +value+ ";path=/" + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function viewShoppingCart() {
	document.frmShoppingCart.submit();
}
