/**
 * Author - Onur Şimşek
 */
// Sepete ürün ekleme
$(document).ready(function(){


	
	updateShoppingCart();
	
	$('button[name=addShoppingCart]').click(function(){
		var form		= $(this).parent('form');
		var productID	= form.find('input[name=frmProductID]').val();
		
		$.ajax({
			type	: 'post',
			url		: '../ajax/addShoppingCart.php',
			data	: form.serialize(),
			success	: function(data){
				form.find('button[name=addShoppingCart]').html('Eklendi');
				form.find('button[name=addShoppingCart]').attr('disabled', 'disabled');
				updateShoppingCart();
			}
		});
		return false;
	});
	
	function updateShoppingCart(){
		$.ajax({
			type	: 'post',
			url		: '../ajax/updateShoppingCart.php',
			success	: function(data){
				$('#shoppingCart a').html(data);
			}
		});
	}
	
	                                                                   
	/* MEHMET SOYLU - DÜZENLEME */
	
	$('button[name=deleteShoppingCartProduct]').click(function(){
		var parentDiv				= $(this).parent('div.deleteProductInShoppingCart');
		var parentTr			= $(this).parent('div.deleteProductInShoppingCart');
		var shoppingCartProductID	= parentDiv.find('input[name=shoppingCartProductID]').val();
      
     $.ajax({
			type	: 'post',
			url		: '../ajax/deleteShoppingCartProduct.php',
			data	: 'shoppingCartProductID='+ shoppingCartProductID,
			success	: function(data){
				       window.location.href ='/shoppingCart';
			}
		});
		
		return false;
	});
	
		
	$('button[name=clearShoppingCart]').click(function(){ 
  	 
     var shoppingCartID	= $(this).val(); 
        
     $.ajax({
      			type	: 'post',
      			url		: '../ajax/clearShoppingCart.php',
      			data	: 'shoppingCartID='+ shoppingCartID,
      			success	: function(data){
      				     window.location.href ='/shoppingCart';
      			}
		  }); 
      
		  return false;
	});
	
	 
	$('button[name=arttir]').click(function(){ 
  	 
     var shoppingCartProductID	= $(this).val(); 
     $.ajax({
      			type	: 'post',
      			url		: '../ajax/changeQuantityShoppingCartProduct.php',
      			data	: 'shoppingCartProductID='+shoppingCartProductID+'&changeQuantityValue=1',
      			success	: function(data){
      			          window.location.href ='/shoppingCart';
      			}
		  }); 
		  return false;
	});
	
	$('button[name=azalt]').click(function(){ 
		var shoppingCartProductID	= $(this).val();
		$.ajax({
      			type	: 'post',
      			url		: '../ajax/changeQuantityShoppingCartProduct.php',
      			data	: 'shoppingCartProductID='+shoppingCartProductID+'&changeQuantityValue=-1',
      			success	: function(data){
      			     window.location.href ='/shoppingCart';
      			}
		  });
		  return false;
	});
		 
	
	/* MEHMET SOYLU - DÜZENLEME BITTI */
	
});



