function remove180()
{
	$("#nitrixSelect").children("option[@value='14']").hide();
}
function show180()
{
	$("#nitrixSelect").children("option[@value='14']").show();
}

$(document).ready(function() {

	var currentQuantity;
	var flavorSize;
	
	$(".select_flavorselect").hide();
	
	$("#answer_nitrix").change(function() {
		if($(this).attr('selectedIndex') == 2)
		{
			remove180();
		}
		else
		{
			show180();
		}
	});
		
	$(".pdc_products li").click(function () {								  
		$(".select_support").attr('selectedIndex',0);
		$(".select_flavorselect").attr('selectedIndex',0);
		$(".button_div").hide();
		$(".pdc_answer").hide();
		$("div [id*=product_]").hide();		
      	$("#product_" + $(this).attr("id")).fadeIn();
		
		$("#fadebg").show();
		centerDiv("ajax_div");
		$("#ajax_div").show();		
    });

	$(".select_support").change(function() {
		$(".pdc_answer").hide();
		$(".select_flavorselect").show();
		//$(".button_div").show();
		$(this).children("option[@value='0']").hide(); 
		$("#"+$(this).attr("id")+'_'+$(this).attr('selectedIndex')).fadeIn();
		currentQuantity = $(this).val();
	});
	
	$(".select_flavorselect").change(function() {						   
		$(".button_div").show();
		$(this).children("option[@value='0']").hide(); 
		$("#"+$(this).attr("id")+'_'+$(this).attr('selectedIndex')).fadeIn();
		flavorSize = $(this).val();
	});
	
	$(".dose_submit").click(function() {		
		$("#ajax_div").hide();
		$("#fadebg").hide();
		$(".select_flavorselect").hide();
		
		var parsedQuantity = getQuantity(flavorSize, currentQuantity);
		
		//alert("product: " + flavorSize + " qty: " + currentQuantity + " parsedQty: " + parsedQuantity);
		
		$.ajax({
			   type: "POST",
			   url: "/_doseadd.html",
			   data: {product: flavorSize, qty: parsedQuantity},
			   async: false,
			   cache: false,
			   success: function(msg)
			   { 
			   }
		});
		
		window.location = "signup_1.html";
	});
		
	$("#ajaxDivClose").click(function() {		
		$("#ajax_div").hide();
		$("#fadebg").hide();
		$(".select_flavorselect").hide();
	});

}); /* End Document Ready */

function getQuantity(product, qtyInfo)
{
	var dose = 1;
	
	var productsDoses = qtyInfo.split("|");
	for(var counter=0; counter < productsDoses.length; counter++)
	{
		var productDose = productsDoses[counter].split(":");
		for(var counter2=0; counter2 < productDose.length; counter2++)
		{
			if(productDose[0] == product)
			{
				dose = productDose[1];
				break;
			}
		}
	}
	
	return dose;
}
