
	function addProduct(id)
	{
		var quantity = $("q"+id).value;
		var my_request = new Request ({url:"main.php?page=request&action=add&id=" + id + "&q="+quantity, onSuccess:updateList});
		my_request.send();
	}
	
	function removeProduct(id)
	{
		var my_request = new Request ({url:"main.php?page=request&action=remove&id=" + id, onSuccess:updateList});
		my_request.send();
	}
	
	function updateList()
	{
		var my_request = new Request.HTML ({url:"main.php?page=request&action=list", evalScripts: true, update:$("listato_riepilogo")});
		my_request.send();
	}
	window.addEvent('domready', function() {
		
		updateList();
		
		$('preventivo').addEvent('submit', function(e) {										
			//Prevents the default submit event from loading a new page.
			e.stop();
			//Empty the log and show the spinning indicator.
			var log = $('resultInvio');
			//Set the options of the form's Request handler. 
			//("this" refers to the $('myForm') element).
			this.set('send', {onComplete: function(response) { 
				log.set('html', response);
			}});
			//Send the form.
			this.send();
		});
		
		new FormCheck('preventivo', {
			display : {
				errorsLocation : 1,
				indicateErrors : 1,
				showErrors : 0,
				addClassErrorToField : 1,
				scrollToFirst : false
			}
		});
	
	});
	
	function aggiungi(id)
	{
		$("q"+id).value++;
	}
	
	function togli(id)
	{
		if($("q"+id).value > 1)
		{
			$("q"+id).value--;
		}
	}
	
	//window.addEvent("domready", updateList );
 
