function handleAdded(req){
	if (req.responseText == "success") {
     	//alert("Your value has been stored successfully");
		getItems();
    } else {
      	
		alert("Something went wrong when adding");
    }
}

function addItem( id, type, img, price, color, size, legsize ){
  new Ajax.Request("lib/model/ajax.php", { parameters: '&action=add' +'&id=' + id +'&type=' + type + '&image=' +img+'&price=' +price+'&color='+color+'&size='+size +'&legsize='+legsize, onComplete: handleAdded });
}

function getItems(){
	new Ajax.Request("lib/model/ajax.php", { parameters: '&action=get', onComplete: handleItems });
}

function handleItems(req){
	if (req.responseText == "error") {
      //alert("There was an error in getting the content");
    } else {
	//
		var element = $('shoppingcart');
		element.innerHTML = req.responseText;
		
		getItemsCount();
      	//alert("Something went wrong when storing your value");
    }
}

function getItemsCount(){
	new Ajax.Request("lib/model/ajax.php", { parameters: '&action=getcount', onComplete: handleItemsCount });
}

function handleItemsCount(req){
	var element = $('shopping-notify');
	element.innerHTML = req.responseText+" Plagg";
	element.visualEffect('highlight',{duration:1.5})
	//new Effect.Shake("shopping-notify", {distance: 2});
}

function deleteItem( id ){
	new Ajax.Request("lib/model/ajax.php", { parameters: '&action=remove' +'&id='+id, onComplete: handleRemove });
}

function handleRemove(req){
	if (req.responseText == "success") {
 		//alert("Your value has been stored successfully");
		getItems();
	} else {
  	
		alert("Something went wrong when removing " + req.responseText );
	}
}

//window.onload = getItems();