
$(document).ready(function(){
	
	


});

function addtocart(id, name, description, price, quantity){
	
	var serializedData = $(quantity).serialize();
	serializedData = serializedData.replace(/&/g,'|');
	serializedData = serializedData.replace(/=/g,':');	
	

	
	$.ajax({
		type: "POST",
		url: SITE_URL+"/shoppingcart/add/",
		data: '&id='+id+'&name='+name+'&description='+description+'&price='+price+'&quantity='+serializedData,
		dataType: 'json',
		beforeSend: function(x){$('#ajax-loader').css('visibility','visible');},
		success: function(msg){
			
			$('#ajax-loader').css('visibility','hidden');
			if(parseInt(msg.status)!=1){
				return false;
			}
			else {
				getCartStatus();
				alert(msg.txt);
			}			
		}
	});
}

function removeFromCart(id){
	$.ajax({
		type: "POST",
		url: SITE_URL+"/shoppingcart/remove/",
		data: 'id='+encodeURIComponent(id),
		dataType: 'json',
		beforeSend: function(x){$('#ajax-loader').css('visibility','visible');},
		success: function(msg){
						
			$('#ajax-loader').css('visibility','hidden');
			if(parseInt(msg.status)!=1)
			{
				return false;
			}else {
				$('#shoppingcart_item_'+id).remove();
				getCartStatus();

			}
		}
	});	
}

function change(id, obj){
	$.ajax({
		type: "POST",
		url: SITE_URL+"shopping_cart/change/",
		data: '&id='+id+'&quantity='+obj.value,
		dataType: 'json',
		beforeSend: function(x){$('#ajax-loader').css('visibility','visible');},
		success: function(msg){
			
			
			$('#ajax-loader').css('visibility','hidden');
			if(parseInt(msg.status)!=1)
			{
				return false;
			}
			else
			{
				getCartStatus();

			}
			
			
		
		}
		});	
	



}

function removeAll(){
	$.ajax({
		type: "POST",
		url: SITE_URL+"shopping_cart/removeall/",
		data: '',
		dataType: 'json',
		beforeSend: function(x){$('#ajax-loader').css('visibility','visible');},
		success: function(msg){
			
			
			$('#ajax-loader').css('visibility','hidden');
			if(parseInt(msg.status)!=1)
			{
				return false;
			}
			else
			{
				getCartStatus();

			}
		}
		});	
}

function getCartStatus( ){
	$('#cart_status').load(SITE_URL+'/shoppingcart/status/');
	
}



