/* AJAX JavaScript stuff for adding things to the cart */

/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}


/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* add a single item */
function add_item(item_id){

	http.open('get', 'cart_functions.php?action=add_item&item_id='+item_id);
	http.onreadystatechange = handleProducts; 
	http.send(null);
	alert("Item has been added to your cart");
}
/* remove a single item */
function remove_item(item_id){

	http.open('get', 'cart_functions.php?action=remove_item&item_id='+item_id);
	http.onreadystatechange = handleProducts; 
	http.send(null);
}
/* remove an item line */
function remove_line(item_id){

	http.open('get', 'cart_functions.php?action=remove_line&item_id='+item_id);
	http.onreadystatechange = handleProducts; 
	http.send(null);
}

/* clear all items */
function clear_cart(){

	http.open('get', 'cart_functions.php?action=clear_cart');
	http.onreadystatechange = handleProducts;
	http.send(null);
}

function handleProducts(){

	if(http.readyState == 4){ //Finished loading the response
		var response = http.responseText;
		document.getElementById('cart_holder').innerHTML = response;
		
	}
}