$(document).ready(function() {   
	$(this).keyup(function(e) {	
		if( e.keyCode == 13 ) {		
			$('#c_or_e').click();
		}
	});
	
	$("img.transfer").click(function(e){
		var s_available = $(this).parent("td").prev().children("select");
		var s_selected = $(this).parent("td").next().children("select");
		
		if( $(this).hasClass('to')){
			if( s_available.find(":selected").length > 0) {
				s_available.find(":selected").clone().appendTo(s_selected);
				s_available.find(":selected").remove();
			}
			else{
				alert("An item must be selected from the Available list to transfer");
			}
		}
	
		if( $(this).hasClass('from') ){
			if( s_selected.find(":selected").length > 0 ) {
				s_selected.find(":selected").clone().appendTo(s_available);
				s_selected.find(":selected").remove();
			}
			else{
				alert("An item must be chosen from the Selected list to transfer");
			}
		}
	});

	$("img.move").click(function(){
		var s_selected = $(this).parent("td").prev().children("select");
		if( $(this).hasClass('up')){
			if( s_selected.find(":selected").length > 0) {
				s_selected.find(":selected").each(function(){
					$(this).insertBefore($(this).prev());
				});
			}
			else{
				alert("An item must be chosen in the Selected list to move it up");
			}
		}
	
		if( $(this).hasClass('down') ){
			if( s_selected.find(":selected").length > 0 ) {
				s_selected.find(":selected").each(function(){
					$(this).insertAfter($(this).next());
				});
			}
			else{
				alert("An item must be chosen in the Selected list to move it down");
			}
		}
	});
	
    $('#filter').keyup(function() {  
		var term = $(this).val();
			
		$('.list').each( function() {
			if ( $(this).text().search( new RegExp( term, "gi" ) ) < 0 ){
				$(this).addClass("hidden");
			}
			else{
				$(this).removeClass("hidden");
			}
		});
    });  	
});  

function display_details( item_id ) {
	$("#detail_pane").load("item_detail.php?item_id="+item_id);
}

function update_cart( cmd, item_id ){
	$("#shoppingcart").load("cart.php?cmd="+cmd+"&item_id="+item_id);
	display_details( item_id );
}
