var xmlHttp;
function createXMLHttpRequest()
{
	if(window.ActiveXObject)
	{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest)
	{
		xmlHttp=new XMLHttpRequest();
	}
}

function addToCart(id,type)
{
	createXMLHttpRequest();
	if(id==0){
		var product_arr        = new Object();
		var num=0;
		var product=document.getElementsByName("items[]")
		for(var i=0;i<product.length;i++){ 
			if(product[i].checked==true){
				product_arr[i] = product[i].value;
				num++;
			} 
		} 
		if(num==0){
			alert("No item(s) selected.")
			return;
		}
		productid=JSON.stringify(product_arr);
		var url="../add_basket.php?type="+type;
		xmlHttp.open("POST",url,true);
		xmlHttp.onreadystatechange=handleStateChange;
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
		xmlHttp.send("id="+productid);
	}else{
		var url="../add_basket.php?id="+id+"&type="+type;
		xmlHttp.onreadystatechange=handleStateChange;
		xmlHttp.open("GET",url,true);	
		xmlHttp.send(null);
	}
}

function handleStateChange()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status==200){
			document.getElementById("cart").innerHTML=xmlHttp.responseText;
		}
	}
}