var UpdateCart = function(){
		var Product_ID = $(this).attr("name");
		var Quantity_Ordered = $("#registry_item_" + Product_ID).val();
		
		//call Ajax Script
		$.get("ajax/updateRegistryCart.php",{prod_ID : Product_ID, quantity : Quantity_Ordered });	
	}


$(document).ready(function(){
	
	//add an item to the RegistryCart in Session
	$('.submitBTN').click(UpdateCart);
	$('.removeBTN').click(UpdateCart);

	
	//'Builder Bar' functions
	
	$("#builder_bar_list").change(function(){
		//put registry in session
		var RegValue = $(this).val();
		var optGroupLabel = $(this).find("option").filter(":selected").parents("optgroup").attr("label");
		alert(optGroupLabel);
		$.get("ajax/registryToSession.php",{Registry_ID : RegValue,Registry_Type : optGroupLabel},function(data){
			//callback function, just in case
		});
		$_

		//update the 'current Registry' text
		var newReg = $('#builder_bar_list :selected').text();
		alert(newReg);
		if($('#builder_bar_list :selected').val() > 0){
			$("#builder_bar_current").text(newReg);
		}
		else{
			$("#builder_bar_current").text("none selected");
		}
		
	});
	
	//save working Registry
	$("#builder_bar_save").click(function(){
		$.get("ajax/saveRegistry.php",{},function(data){
			$("#query_log").append(data); //updates the query log in devbar with the queries from saveRegistry.php
		});
	});
	
	//add item to registry
	$(".builder_bar_add").click(function(){
		var Product_ID = $(this).attr("name");
		var QuantityID = "#bb_quantity_" + Product_ID;
		var Quantity_Ordered  = $(QuantityID).val();
		$.get("ajax/updateRegistry.php",{Product_ID : Product_ID, Quantity : Quantity_Ordered},function(data){
			
			//tell user of success or failure to update product in registry
			alert(data);
			
			//update see quantity
			var t = '#quantity_requested_'+Product_ID;
			$(t).html("Quantity Requested: "+Quantity_Ordered);
			
			//TB: do something else that I don't understand fully
			$.get("ajax/saveRegistry.php",{Quantity : Quantity_Ordered},function(data){
				$("#query_log").append(data); //updates the query log in devbar with the queries from saveRegistry.php
			});
		}); 	
	});
	
});