	function clearSearch() {
		
		var value = $( '#search_query' ).val();
		if ( value == 'pavadinimas, žolelė, poveikis' ) {
			
			$( '#search_query' ).removeClass( 'not_active' );
			$( '#search_query' ).val( '' );
		}
	}

	function fillSearch() {
		
		var value = $( '#search_query' ).val();
		if ( value == '' ) {
			
			$( '#search_query' ).addClass( 'not_active' );
			$( '#search_query' ).val( 'pavadinimas, žolelė, poveikis' );
		}
	}
	
	$(document).ready(function() {
		$('.numericfield').numeric();
		$('.add a').click(function() {
			var product_id = (this.id).replace('id_', '');
			var basket_hash = $('#basket_hash').val();
			$.ajax({
				async: false,
				type: 'POST',  
				url: '/handler.php',  
				data: { 
					act: 'add_to_basket', 
					basket_hash: basket_hash, 
					product_id: product_id, 
					qty: $('#qty_'+product_id).val() 
				}, 
				success: function() {
					$('#add_'+product_id).fadeOut('fast', function(){
						$('#id_'+product_id).hide();
						$('#add_'+product_id).append('<span id="success_'+product_id+'">Įdėta</span>');
					});
					$('#add_'+product_id).fadeIn('fast');
					$('#add_'+product_id).fadeOut('fast', function(){
						$('#id_'+product_id).show();
						$('#success_'+product_id).remove();
					});
					$('#add_'+product_id).fadeIn('fast');
					
					update_basket(basket_hash);
				}
			});
		});
		
		$('.add_one').click(function() { add_one(this.id); });
		$('.remove_one').click(function() { remove_one(this.id); });
		$('.delete_one').click(function() { delete_one(this.id); });
		
		var fb = document.getElementById('facebook');
		var old_fb = fb.innerHTML;
		var new_fb = old_fb.replace('<!-- FB_box ', '');
		var new_fb = new_fb.replace(' FB_box -->', '');
		fb.innerHTML = new_fb;
	
	});

	function add_one(product_id) {
		var basket_hash = $('#basket_hash').val();
		$.ajax({
			type: 'POST',  
			url: '/handler.php',  
			data: { 
				act: 'add_one', 
				basket_hash: basket_hash, 
				product_id: product_id
			},
			success: function() {
				update_basket(basket_hash);
			}
		});
	};
	
	function remove_one(product_id) {
		var basket_hash = $('#basket_hash').val();
		$.ajax({
			type: 'POST',  
			url: '/handler.php',  
			data: { 
				act: 'remove_one', 
				basket_hash: basket_hash, 
				product_id: product_id
			},
			success: function() {
				update_basket(basket_hash);
			}
		});
	};
	
	function delete_one(product_id) {
		var basket_hash = $('#basket_hash').val();
		$.ajax({
			type: 'POST',  
			url: '/handler.php',  
			data: { 
				act: 'delete_one', 
				basket_hash: basket_hash, 
				product_id: product_id
			},
			success: function() {
				update_basket(basket_hash);
			}
		});
	};
	
	function update_basket(basket_hash) {
		var old_height = $('#basket_area').height();
		$.ajax({
			type: 'POST',
			url: '/handler.php',
			data: {
				act: 'update_basket',
				basket_hash: basket_hash
			},
			success: function(data){
   				$('#basket_area').fadeOut(300, function() { 
					$('#basket_area').empty().html(data);
					var new_height = $('#basket_area').height();
					$('#basket_area').css('height', old_height);
					$('#basket_area').animate({ height: new_height}, 300, 'swing', function() {
						$('#basket_area').fadeIn(300);
						$('#basket_area').css('height', ''); 
						$('.add_one').click(function() { add_one(this.id); });
						$('.remove_one').click(function() { remove_one(this.id); });
						$('.delete_one').click(function() { delete_one(this.id); });
					});
				});
				
			}
		});
		
	}
	
	function scroll_to(target) {
		if (target != '')
			document.getElementById(target).scrollIntoView(true);
	}
	
	function urlencode(str) {
		return str.replace(/\+/g,'%2B').replace(/\s/g, '+').replace(/\*/g, '%2A').replace(/\//g, '').replace(/\\/g, '').replace(/@/g, '%40');
	}


