function addToCart(str)
{
	if (str=="")
	{
	  return;
	}
	if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	} else { // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function() {
	 	if (xmlhttp.readyState==4 && xmlhttp.status==200) {
		 	document.getElementById("cartCount").innerHTML=xmlhttp.responseText;
	 	}
	};

	xmlhttp.open("POST",str,true);
	xmlhttp.send();
}

function recalc()
{
    var totalamount = 0;
    var totalgst = 0;
    var qty = 0;
    var totalqty = 0;
    var price = 0;
    var baseprice = 0;
    var stotal = 0;
    var arr = new Array();
    arr = document.getElementsByName("cbox[]");
    for(var i = 0; i < arr.length; i++)
    {
    	prodid = arr[i].value;
    	qtyfld = "qty_" + prodid;
    	qty = document.getElementsByName(qtyfld)[0].value;
	totalqty += parseInt(qty);
    	pricefld = "price_" + prodid;
    	price = document.getElementsByName(pricefld)[0].value;
    	gstfld = "gst_" + prodid;
    	gst = document.getElementsByName(gstfld)[0].value;
    	basepricefld = "pricewogst_" + prodid;
    	baseprice = document.getElementsByName(basepricefld)[0].value;
	amountfld = "amount_" + prodid;
    	amount = qty * price;
	change(amountfld, amount);
	stotal += qty * baseprice;
	totalamount += amount;
    	totalgst += qty * gst;
    }
    change("subtotal",stotal);
    change("gst", totalgst);
    change("total", totalamount);
    cartText = "<strong>Total Items in Cart: " + totalqty + "</strong>";
    document.getElementById("cartCount").innerHTML=cartText;
}

function change(thefield, thevalue) {
	theresult = Math.round(thevalue * 100) / 100;
	document.getElementById(thefield).value = theresult;
}

