
function deleteFromBasket(div_id) {

	var hash = getHash(div_id);
	ajaxDeleteFromBasket(hash);

	new Effect.Fade(div_id);

	if(num_lines == 1) {

		new Effect.Fade('ready');
		new Effect.Appear("empty", { queue: 'end' });
	}
	num_lines--;
}


function ajaxDeleteFromBasket(hash) {

	var url = APP_DIR_URL + "orders/ajaxDeleteLine/"+hash;

	new Ajax.Request(url, {

		method:'get',

		onSuccess: function(transport) {

			var response = transport.responseText.evalJSON();
			if(response.new_total_price) {
				$("total_price").update(response.new_total_price);
				$("form_total_price").value = response.new_total_price;
				$("form_total_sid").value = response.new_total_sid;
				$("form_order_enc").value = response.order_enc;
				
				console.log(response);
			}
		},

		onFailure: function() {
		}
	});
}


function ajaxAddQuantity(hash) {

	var url = APP_DIR_URL + "orders/ajaxAddQuantity/"+hash;

	new Ajax.Request(url, {

		method:'get',

		onSuccess: function(transport) {

			var response = transport.responseText.evalJSON();
			if(response.status == "ok") {
				$("quantity_"+response.hash).update(response.new_quantity);
				new Effect.Highlight("quantity_"+response.hash);
				new Effect.Highlight("line_price_"+response.hash);
				$("line_price_"+response.hash).update(response.new_line_price);
				$("total_price").update(response.new_total_price);
				$("form_total_price").value = response.new_total_price;
				$("form_total_sid").value = response.new_total_sid;
				$("form_order_enc").value = response.order_enc;
			}
		},

		onFailure: function() {
		}
	});
}


function ajaxReduceQuantity(hash) {

	var url = APP_DIR_URL + "orders/ajaxReduceQuantity/"+hash;

	new Ajax.Request(url, {

		method:'get',

		onSuccess: function(transport) {

			var response = transport.responseText.evalJSON();
			if(response.status == "ok") {
				$("quantity_"+response.hash).update(response.new_quantity);
				new Effect.Highlight("quantity_"+response.hash);
				new Effect.Highlight("line_price_"+response.hash);
				$("line_price_"+response.hash).update(response.new_line_price);
				$("total_price").update(response.new_total_price);
				$("form_total_price").value = response.new_total_price;
				$("form_total_sid").value = response.new_total_sid;
				$("form_order_enc").value = response.order_enc;
			}
		},

		onFailure: function() {
		}
	});
}


function getHash(div_id) {

	return div_id.substr(11);
}