var xhttp;

function createXMLHttpRequest() {
	if (window.ActiveXObject) { 
		try { 
			// IE 6 and higher
			xhttp = new ActiveXObject("MSXML2.XMLHTTP");
		} catch (e) {
			try {
				// IE 5
				xhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				xhttp=false;
			}
		}
	}else if (window.XMLHttpRequest) {
		try {
			// Mozilla, Opera, Safari ...
			xhttp = new XMLHttpRequest();
		} catch (e) {
			xhttp=false;
		}
	}
}

function sendRequest(id, artikel, preis) {           
	if (!xhttp) {
		//alert("An Error occured when trying to initialize XMLHttpRequest!");
		alert("Bitte versuche es nochmal. Die Seite war noch nicht ganz geladen.");
		return; // exit
	}

	var anzahl = eval('document.getElementById("shop_anzahl_' + id + '").value;');
	anzahl = isNaN(anzahl * 1) ? 0 : anzahl;

	xhttp.open("GET","http://"+window.location.host+"/radau-shop/warenkorb/?method=ajax&id="+id+"&artikel="+artikel+"&anzahl="+anzahl+"&preis="+preis,true);
	xhttp.onreadystatechange=sendRequest_callback;
	xhttp.send(null);
}

function sendRequest_callback() {
	//alert ( xhttp.readyState);

	if (xhttp.readyState==4 && xhttp.status==200){
		//alert ( xhttp.responseText );
		document.getElementById('cart').innerHTML = xhttp.responseText;
		if(xhttp.responseText == ""){
			document.getElementById('cart').style.display = 'none';
		}else{
			document.getElementById('cart').style.display = 'block';
		}
	}
}

function init() {
	createXMLHttpRequest();
}
window.onload=init;
