/**
 * Fügt einen Artikel zum Einkaufswagen hinzu/entfernt diesen
 */

function addtocart(articleid, deviceid, quantity) {
	
	function writetocart() {
		
		
		if ( client.status == 200 && client.readyState == 4 ) {
			
			document.getElementById('cartwrapper').innerHTML = client.responseText;
						
		}
				
	}
	
	var param = '';	
	param = 'articleid=' + articleid + '&deviceid=' + deviceid + '&quantity=' + quantity + '&action=add';
	
	client = new XMLHttpRequest();
	client.onreadystatechange = function() { writetocart(); }; 
	
	client.open( "POST", "/shop/wp-content/themes/featurepitch/shop/cart.php", true);
	client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	client.setRequestHeader("Content-Length", param.length );
	client.setRequestHeader("Connection", "close");	
	client.send(param);
	
}

function remove(articleid, action) {
	
	function writetocart() {
				
		if ( client.status == 200 && client.readyState == 4 ) {
			
			document.getElementById('cartwrapper').innerHTML = client.responseText;
															
			if ( client.responseText.search('Ihr Warenkorb ist leer') != -1 ) {
								
				$j('#orderdata').html('<strong>Bisher haben Sie noch keine Artikel in Ihrem Warenkorb.</strong>');
				
			}
		
		}
	
	}
	
	if ( !action ) {
		
		var action = 'remove';
		
	}
	
	var param = '';	
	param = 'articleid=' + articleid + '&action=' + action;
	
	client = new XMLHttpRequest();
	client.onreadystatechange = function() { writetocart(); }; 
	
	client.open( "POST", "/shop/wp-content/themes/featurepitch/shop/cart.php", true);
	client.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	client.setRequestHeader("Content-Length", param.length );
	client.setRequestHeader("Connection", "close");	
	client.send(param);	
	
}
