window.addEvent('domready', function(){

	// You can skip the following line. We need it to make sure demos
	// are runnable on MooTools demos web page.
	var demo_path = window.demo_path || '';
	// --

	//We can use one Request object many times.
	var reqProductCheck = new Request({

		url: '/shop_checkProduct.php',
		
		onSuccess: function(txt){
			$('result').set('text', txt);
			
						
		},

		// Our request will most likely succeed, but just in case, we'll add an
		// onFailure method which will let the user know what happened.
		onFailure: function(){
			//$('result').set('text', 'The request failed.');
			
		}

	});
	
	var reqProductChangedAmount = new Request({

		url: '/shop_changedAmountProduct.php',
		
		onSuccess: function(txt){
			$('result').set('text', txt);
						
		},

		// Our request will most likely succeed, but just in case, we'll add an
		// onFailure method which will let the user know what happened.
		onFailure: function(){
			//$('result').set('text', 'The request failed.');
			
		}

	});

	$$(".productAmount").addEvent('change', function(){
			reqProductChangedAmount.send("amount=" + this.value + "&product=" + this.id);
			if(this.value>0) {
				$(this.id.replace(/amount_/,"check_")).checked = true;
				} else {
				$(this.id.replace(/amount_/,"check_")).checked = false;
				}
	});

	$$(".productCheck").addEvent('change', function(){
		if(this.checked) {
			reqProductCheck.send("product=" + this.value + "&sel=1");
			$('amount_'+this.value).options[1].selected = true;
			} else {
			reqProductCheck.send("product=" + this.value + "&sel=0");
			$('amount_'+this.value).options[0].selected = true;
			//alert('amount_'+this.value);
			}
	});



});

