var xmlHttp;

function GetXmlHttpObject() {
	try	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch(e) {
		// Internet Explorer
		try	{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
}

function addProduct(absPath, subProId, quantity, lastPrice, vatPrice, flagBuy) {	
	GetXmlHttpObject();
	url = "productajax.php";
	url = absPath + url + "?doAction=AddProduct&subProId=" + subProId + "&quantity=" + quantity + "&lastPrice=" + lastPrice + "&vatPrice=" + vatPrice  + "&flagBuy=" + flagBuy;

	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() {
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {

		strResponseText = xmlHttp.responseText;
		arrResponse = strResponseText.split("#@#");

		strQtyInfo = arrResponse[0];
		//strProdInfo = arrResponse[1];
		
		arrResponseText = strQtyInfo.split("@");
		//arrProductInfo = strProdInfo.split("@~@");

		flMsg = arrResponseText[0];		
		totalQuantity = arrResponseText[1];
		totalPrice = parseFloat(arrResponseText[2]);
		flagCart = arrResponseText[3];

		document.getElementById("itemQuantity").innerHTML = totalQuantity + " Items";
		document.getElementById("itemAmout").innerHTML = totalPrice.toFixed(2);

		// display message
		alert("The item has been added to your basket");
		window.location.reload();
	}
}