$(document)
		.ready
		(
				function()
				{
						quantity();
						orderForm();
				}
		)



function quantity(){
	 $('.less')
		  .click
		  (
			   function()
			   {
					if ($('#textQuantity').length)
					{
						var quantityInput =  $('#textQuantity');
					}
					else
					{
						 var quantityInput =  $(this).next('.textQuantity');
					}
					var qtty = parseInt(quantityInput.val());
					if (qtty>1)
					{
						 qtty--;
						 quantityInput.val(qtty);
					}
			   }
			   
		  )
		  
	 $('.more')
		  .click
		  (
			   function()
			   {
					if ($('#textQuantity').length)
					{
						var quantityInput =  $('#textQuantity');
					}
					else
					{
						 var quantityInput =  $(this).prev('.textQuantity');
					}
					
					var qtty = parseInt(quantityInput.val());
					qtty++;
					quantityInput.val(qtty);
			   }
			   
		  );
		  
	 $('#textQuantity').numeric();
	 $('.textQuantity').numeric();
	 
	 $('#textQuantity')
		  .change
		  (
			   function()
			   {
					var qtty = parseInt($('#textQuantity').val());
					if (qtty<1)
					{
						 qtty = 1;
						 $('#textQuantity').val(qtty);
					}
					
					
			   }
			   
		  );
		  
	  $('.textQuantity')
		  .change
		  (
			   function()
			   {
					var qtty = parseInt($('.textQuantity').val());
					if (qtty<1)
					{
						 qtty = 0;
						 $('.textQuantity').val(qtty);
					}
				
			   }
			   
		  );
		  
		  
		  
		  $('#buy').hover
		  (
			   function()
			   {
					$(this).animate({backgroundColor:'#72E4F1'},150);
			   }
			   ,function()
			   {
					$(this).animate({backgroundColor:'#62D4E1'},150);
			   }
		  );
}


function orderForm()
{
	 if ($('.validFormElement').length)
	 {
		  if ($('#adresses').is(':checked'))
		  {
			   $('#rightColForm input,#rightColForm textarea,#rightColForm select').attr('disabled',true).css({'background':'#EFEFEF'});
			   $('#rightColForm').hide();
		  }
		  
		  if ($('#assujeti').length && !$('#assujeti').is(':checked'))
		  {
				$('#tva_num').attr('disabled',true).css({'background':'#EFEFEF'});
				$('#tva_num').parent('div').hide(150);
				$('input[name="company[liv]"]').parent('div').hide(150);
				$('input[name="company[fact]"]').parent('div').hide(150);
		  }
		  
		  
		  
		  $('#adresses')
			   .change
			   (
					function()
					{
						 if ($(this).is(':checked'))
						 {
							 $('#rightColForm input,#rightColForm textarea,#rightColForm select').attr('disabled',true).css({'background':'#EFEFEF'});
							 $('#rightColForm').hide();
						 }
						 else
						 {
							  $('#rightColForm input,#rightColForm textarea,#rightColForm select').attr('disabled',false).css({'background':'#FFF'});
							  $('#rightColForm').show();
                              if ($('#assujeti').length && !$('#assujeti').is(':checked')){
                                $('#tva_num').attr('disabled',true).css({'background':'#EFEFEF'});
                                $('#tva_num').parent('div').hide(150);
                                $('input[name="company[liv]"]').parent('div').hide(150);
                                $('input[name="company[fact]"]').parent('div').hide(150);
                              }
						 }
					}
			   )
		  $('#assujeti')
			   .change
			   (
					function()
					{
						//alert('change');
						if ($(this).is(':checked'))
						{
								$('#tva_num').attr('disabled',false).css({'background':'#FFF'});
								$('#tva_num').parent('div').show(150);
								$('input[name="company[liv]"]').parent('div').show(150);
								$('input[name="company[fact]"]').parent('div').show(150);
						}
						else
						{
								$('#tva_num').attr('disabled',true).css({'background':'#EFEFEF'});
								$('#tva_num').parent('div').hide(150);
								$('input[name="company[liv]"]').parent('div').hide(150);
								$('input[name="company[fact]"]').parent('div').hide(150);
							 
						}
					}
			   )
	 }
}
