function BasketControl ( basket_place, child_id, url ) {

	this.basket_place = basket_place;
	this.child_id = child_id;
	this.url = url;

	this.refreshBasket = function ( data, textStatus ) {
		
		$('#' + this.basket_place).load( this.url, { 'act': 'js/basket_load' } ); 
	}

	this.addToBasket = function ( obj, product_id ) {
		var param = 'add';
		
		if ( !obj.checked ) {
			
			param = 'del';
		}
		
		var params = { 'act': 'js/basket', 'command': param, 'child_id': this.child_id, 'product_id': product_id };
		var dummy = this;
		
		$.getJSON( 
			this.url,
			params,
			function ( data, textStatus ) { 
			
				dummy.refreshBasket( data, textStatus ); 
			}
		);
	}
	
	this.delFromBasketMoney = function ( ) {
		var dummy = this;
		var jquery_obj = $( '.add_money_object' );
		
		if ( jquery_obj.length > 0 ) {

			jquery_obj.each( function ( i ) {
				if ( this.checked ) {

					this.click( this );
				}
			});
		} else {
		 
			var params = { 'act': 'js/basket', 'command': 'delMoney' };
			
			$.getJSON( 
				this.url,
				params,
				function ( data, textStatus ) { 
				
					dummy.refreshBasket( data, textStatus ); 
				}
			);
		}
	}
	
	this.addToBasketMoney = function ( obj, money ) {
		
		if ( !obj.checked ) {
			
			money = -1 * money;
		}
		
		var params = { 'act': 'js/basket', 'command': 'addMoney', 'money': money };
		var dummy = this;
		
		$.getJSON( 
			this.url,
			params,
			function ( data, textStatus ) { 
			
				dummy.refreshBasket( data, textStatus ); 
			}
		);
	}
	
	/**
	 * Paspaudus krepselyje esanti mygtuka "trinti", reikia atzymeti ir item'a sarase.
	 * @param child_id - int vaiko id
	 * @param product_id - int produkto id  
	 */
	this.updateDeleteView = function ( child_id, product_id ) {
		
		if ( this.child_id != child_id ) {
			// vartotojas ne tame vaike.
			return false;
		}
		
		var obj = document.getElementById( 'donation_form_object_' + product_id );
		obj.click( obj );

	}
	
	this.updateSelectionView = function ( ) {
		
		var params = { 'act': 'js/basket', 'command': 'list', 'child_id': this.child_id };
		var dummy = this;
		
		$.getJSON( 
			this.url,
			params,
			function ( data, textStatus ) { 
				
				for ( var product in data.orders ) {
					var obj = document.getElementById( 'donation_form_object_' + data.orders[ product ]['item_id'] );
					if ( obj ) {
						
						obj.click( obj );
					}
				}
			}
		);
	}
	
	this.deleteFromBasket = function ( child_id, product_id ) {
		
		var params = { 'act': 'js/basket', 'command': 'del', 'child_id': child_id, 'product_id': product_id };
		var dummy = this;
		
		$.getJSON( 
			this.url,
			params,
			function ( data, textStatus ) { 
				
				dummy.updateDeleteView( child_id, product_id );
				dummy.refreshBasket( data, textStatus ); 
			}
		);
	}
}