function cart_refresh(input) {

	var cart = document.getElementById('cart');
	cart.innerHTML = input;
	return true;
	}

function cart_window() {

	new Ajax.Request('/ajax/cart_window',
		{ 
		method:'get',
		onSuccess: function(transport) { cart_refresh(transport.responseText); return true; },
		onFailure: function() { alert('Došlo je do pogreške...') }
		});
	return true;
	}

function cart_window_start() {

	new Ajax.Request('/ajax/cart_window_start',
		{
		method:'get',
		onSuccess: function(transport) { cart_refresh(transport.responseText); return true; },
		onFailure: function() { alert('Došlo je do pogreške...') }
		});
	return true;
	}

function cart_add(artnr) {

	new Ajax.Request('/ajax/cart_add/'+artnr,
		{
		method:'get',
		onSuccess: function(transport) { cart_refresh(transport.responseText); return true; },
		onFailure: function() { alert('Došlo je do pogreške...') }
		});
	
	document.getElementById('dodano_'+artnr).innerHTML = 'Dodano';
	new Effect.Highlight("dodano_"+artnr, { startcolor: '#ff9900', endcolor: '#ffffff', duration:1.75 });
	return true;
	}

function cart_remove(artnr) {

	new Ajax.Request('/ajax/cart_remove/'+artnr,
		{
		method:'get',
		onSuccess: function(transport) { cart_refresh(transport.responseText); return true; },
		onFailure: function() { alert('Došlo je do pogreške...') }
	});
	
	document.getElementById('dodano_'+artnr).innerHTML = 'Uklonjeno';
	new Effect.Highlight("dodano_"+artnr, { startcolor: '#ff9900', endcolor: '#ffffff', duration:1.75 });
	return true;
	}

function cart_empty() {

	new Ajax.Request('/ajax/cart_empty',
		{
		method:'get',
		onSuccess: function(transport) { cart_refresh(transport.responseText); return true; },
		onFailure: function() { alert('Došlo je do pogreške...') }
		});
	return true;
	}

function cart_pieces(artnr) {
	
		new Ajax.Request('/ajax/cart_item/'+artnr,
		{
		method:'get',
		onSuccess: function(transport) { count = transport.responseText; return true; },
		onFailure: function() { alert('Došlo je do pogreške...') }
		});
	return count;
	}

function cart_item(artnr, dir) {

	data = document.getElementById('item_pieces_'+artnr).innerHTML;
	data = data.split(' ');
	kom = data[0];

	if (dir) {
		kom++;
	}

	else if(kom > 0) {
		kom--;
	}
	
	else return false;
	
	if (dir) {
		new cart_add(artnr);
	}

	else if(kom >= 0) {
		new cart_remove(artnr);
	}
	//broj = cart_pieces(artnr);
	document.getElementById('item_pieces_'+artnr).innerHTML = kom+' kom';
	
	return true;
	}

function ajax(action, option, value) {

	var request = '/ajax/'+action;
	var povrat;

	if (option && value)
	{
		request += '&'+option+'='+value;	
	}

	new Ajax.Request(request,
		{
		method:'get',
		onSuccess: function(transport) { povrat = transport.responseText; return true; },
		onFailure: function() { alert('Došlo je do pogreške...') }
		});

	return povrat;
	}
