var Browser = new Object();

Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;

function addToCart( id, wcase )
{
	var wcase = (wcase == null) ? false : wcase;

	var xmlObj = null;
	if(Browser.isMozilla)
	{
		xmlObj = new XMLHttpRequest();
	} 
	else if(Browser.isIE)
	{
		xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else 
		return;


	xmlObj.onreadystatechange = function()
	{
		if( xmlObj.readyState == 4 )
		{
			 if (xmlObj.status == 200) {
				var info = xmlObj.responseText.split("\n");
				if ( info[0] === "OK" );
				{				
					document.getElementById('icount').innerHTML = info[1];
					document.getElementById('icost').innerHTML = "&pound;"+info[2];
					//document.getElementById('workingc').innerHTML = "<span style=\"color: white;\"><strong><h3>Wine added to cart.</h3><strong></span>"+
					//"<div id=\"wbtnOk\" onClick=\"document.getElementById('workingw').style.visibility='hidden'; document.body.style.overflow = 'scroll'; document.getElementById('workingb').style.visibility='hidden';\">OK</div>";
					document.getElementById('workingw').style.visibility='hidden';
					document.getElementById('workingb').style.visibility='hidden';
				}
			}
			else
			{
				document.getElementById('icount').innerHTML = "~";
				document.getElementById('icost').innerHTML = "~";
				document.getElementById('workingc').innerHTML = "<span style=\"color: white;\"><strong><h3><u>Error</u></h3><strong></span>"+
					"<div id=\"wbtnOk\" onClick=\"document.getElementById('workingw').style.visibility='hidden'; document.body.style.overflow = 'scroll'; document.getElementById('workingb').style.visibility='hidden';\">Close</div>";
			}
		}
	}

	var reqs = 'addtocart.php?vid='+id;
	if ( wcase )
		reqs = reqs + '&wcase=1'
	//document.body.style.overflow = "hidden";
	xmlObj.open ('GET', reqs, true);
	if ( typeof( window.innerWidth ) == 'number' ) {
		document.getElementById('workingw').style.top = window.innerHeight/2+window.pageYOffset-50;
		document.getElementById('workingw').style.left = window.innerWidth/2-100;
		document.getElementById('workingb').style.top = window.pageYOffset;
	} 
	else {
		document.getElementById('workingw').style.top = document.body.clientHeight/2+document.body.scrollTop-50;
		document.getElementById('workingw').style.left = document.body.clientWidth/2-100;
		document.getElementById('workingb').style.top = document.body.scrollTop;
	}
	
	document.getElementById('workingw').style.visibility = "visible";
	document.getElementById('workingb').style.visibility = "visible";
	document.getElementById('workingc').innerHTML = "<span style=\"color: white;\"><strong><h3>Adding...</h3><strong></span>";
	xmlObj.send ('');   
}
