/**
 * @author Justin Paul Silva
 */

function addHandlersAndAttrs() {
	// When a radio button is checked
	$("input[type=radio]").click(function() {
		// Unhighlight labels in same fieldset
		$(this).siblings("label").removeClass("active");
		
		// Highlight label
		$("#for" + this.id).addClass("active");
	});
	
	// When a checkbox is clicked
	$("input[type=checkbox]").click(function() {
		// Highlight label
		$("#for" + this.id).toggleClass("active");
	});
	
	// No Disc
	/*$("#DiscMediumNone").click(function() {
		$('#disc_recording input, #disc_color input').attr("disabled", true);
		$('#disc_recording label, #disc_color label').addClass("disabled");
	});
	
	// CDs, DVDs, and Blu-Rays
	$("#DiscMediumCD, #DiscMediumDVD, #DiscMediumBlu-ray").click(function() {
		$('#disc_recording input, #disc_color input').attr("disabled", false);
		$('#disc_recording label, #disc_color label').removeClass("disabled");
	});*/
	
	// No Packaging and Paper Window Sleeve
	$("#PackagingTypeNone, #PackagingTypePaperWindowSleeve").click(function() {
		$('#jc_sl_inserts input, #tray_cards input, #dvd_wrap input, #dvd_inserts input, #BarcodeOption, #ShrinkwrapOption').attr("disabled", true);
		$('#jc_sl_inserts label, #tray_cards label, #dvd_wrap label, #dvd_inserts label, #forBarcodeOption, #forShrinkwrapOption').addClass("disabled");
	});
	
	// Black Jewel Cases
	$("#PackagingTypeJewelCaseBlackTray").click(function() {
		$('#jc_sl_inserts input, #TrayCardTypeNone, #TrayCardTypeTrayCard1Side, #BarcodeOption, #ShrinkwrapOption').attr("disabled", false);
		$('#jc_sl_inserts label, #forTrayCardTypeNone, #forTrayCardTypeTrayCard1Side, #forBarcodeOption, #forShrinkwrapOption').removeClass("disabled");
		$('#TrayCardTypeTrayCard2Side, #dvd_wrap input, #dvd_inserts input').attr("disabled", true);
		$('#forTrayCardTypeTrayCard2Side, #dvd_wrap label, #dvd_inserts label').addClass("disabled");
		
		if (!$("#forTrayCardTypeNone").hasClass('active')) {
			$("#TrayCardTypeTrayCard1Side").attr("checked", "checked");
			$("#TrayCardTypeTrayCard1Side").click();
		}
	});
	
	// Clear Jewel Cases
	$("#PackagingTypeJewelCaseClearTray").click(function() {
		$('#jc_sl_inserts input, #TrayCardTypeNone, #TrayCardTypeTrayCard2Side, #BarcodeOption, #ShrinkwrapOption').attr("disabled", false);
		$('#jc_sl_inserts label, #forTrayCardTypeNone, #forTrayCardTypeTrayCard2Side, #forBarcodeOption, #forShrinkwrapOption').removeClass("disabled");
		$('#TrayCardTypeTrayCard1Side, #dvd_wrap input, #dvd_inserts input').attr("disabled", true);
		$('#forTrayCardTypeTrayCard1Side, #dvd_wrap label, #dvd_inserts label').addClass("disabled");
		
		if (!$("#forTrayCardTypeNone").hasClass('active')) {
			$("#TrayCardTypeTrayCard2Side").attr("checked", "checked");
			$("#TrayCardTypeTrayCard2Side").click();
		}
	});
	
	// Slim Cases
	$("#PackagingTypeSlimCaseBlackTray, #PackagingTypeSlimCaseClearTray").click(function() {
		$('#jc_sl_inserts input, #BarcodeOption, #ShrinkwrapOption').attr("disabled", false);
		$('#jc_sl_inserts label, #forBarcodeOption, #forShrinkwrapOption').removeClass("disabled");
		$('#tray_cards input, #dvd_wrap input, #dvd_inserts input').attr("disabled", true);
		$('#tray_cards label, #dvd_wrap label, #dvd_inserts label').addClass("disabled");
	});
	
	// DVD-Style Cases
	$("#PackagingTypeDVDStyleCase").click(function() {
		$('#dvd_inserts input, #dvd_wrap input, #BarcodeOption, #ShrinkwrapOption').attr("disabled", false);
		$('#dvd_inserts label, #dvd_wrap label, #forBarcodeOption, #forShrinkwrapOption').removeClass("disabled");
		$('#jc_sl_inserts input, #tray_cards input').attr("disabled", true);
		$('#jc_sl_inserts label, #tray_cards label').addClass("disabled");
		
	});
	
	// Mini Jackets
	$("#PackagingTypeColorMiniJacket").click(function() {
		$('#BarcodeOption, #ShrinkwrapOption').attr("disabled", false);
		$('#forBarcodeOption, #forShrinkwrapOption').removeClass("disabled");
		$('#jc_sl_inserts input, #tray_cards input, #dvd_wrap input, #dvd_inserts input').attr("disabled", true);
		$('#jc_sl_inserts label, #tray_cards label, #dvd_wrap label, #dvd_inserts label').addClass("disabled");
	});
	
	// Wallets, and Digi Packages 4P
	$("#PackagingTypeEcoWallet4Panel, #PackagingTypeDigiPackage4Panel").click(function() {
		$('#jc_sl_inserts input, #BarcodeOption, #ShrinkwrapOption').attr("disabled", false);
		$('#jc_sl_inserts label, #forBarcodeOption, #forShrinkwrapOption').removeClass("disabled");
		$('#tray_cards input, #dvd_wrap input, #dvd_inserts input').attr("disabled", true);
		$('#tray_cards label, #dvd_wrap label, #dvd_inserts label').addClass("disabled");
	});
	
	// Wallets, and Digi Packages 6P
	$("#PackagingTypeEcoWallet6Panel, #PackagingTypeDigiPackage6Panel").click(function() {
		$('#jc_sl_inserts input, #BarcodeOption, #ShrinkwrapOption').attr("disabled", false);
		$('#jc_sl_inserts label, #forBarcodeOption, #forShrinkwrapOption').removeClass("disabled");
		$('#tray_cards input, #dvd_wrap input, #dvd_inserts input').attr("disabled", true);
		$('#tray_cards label, #dvd_wrap label, #dvd_inserts label').addClass("disabled");
	});
	
	// On page load, for each label
	$.each($("label"), function() {
		// Assign id to labels for styling
		$(this).attr("id", "for" + $(this).attr("for"));
		
		// Wrap labels' text in <span> to hide in CSS
		$(this).html("<span>" + $(this).text() + "</span>");
	});
	
	// On page load, for each radio button and checkbox, trigger 
	$.each($("input[type=radio], input[type=checkbox]"), function() {
		if (this.id != 'DiscRecording')
			$("label[for=" + this.id + "]").addClass('button');
		$(this).addClass('hidden');
		
		if (this.checked) {
			$(this).triggerHandler('click');
		}
	});
	
	$('#project_form input[type=radio], #project_form input[type=checkbox]').click(function() {
		set_turn_times();
		submit_ajax();
	});
	
	$('#project_form select').change(function() {
		set_turn_times();
		submit_ajax();
	});
	
	set_turn_times();
	submit_ajax();
	
	// IE 6.0 Hacks
	$('label.button').hover(
		function () {
			$(this).addClass('hover');
		}, function () {
			$(this).removeClass('hover');
		}
	);
	
	// ToolTips
	$.fn.qtip.styles.newgreen = { // Last part is the name of the style
		tip: true,
		width: 180,
		background: '#deedb5',
		border: {
			width: 2,
			radius: 5,
			color: '#bee94c'
		},
		name: 'green' // Inherit the rest of the attributes from the preset dark style
	}
	
	// Packaging ToolTips
	$('#forPackagingTypeJewelCaseBlackTray').qtip({
		content: $('#jc_black_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	
	$('#forPackagingTypeJewelCaseClearTray').qtip({
		content: $('#jc_clear_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	
	$('#forPackagingTypeSlimCaseBlackTray').qtip({
		content: $('#sc_black_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	
	$('#forPackagingTypeSlimCaseClearTray').qtip({
		content: $('#sc_clear_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	
	$('#forPackagingTypeDVDStyleCase').qtip({
		content: $('#dvd_case_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	
	$('#forPackagingTypePaperWindowSleeve').qtip({
		content: $('#pws_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	
	$('#forPackagingTypeColorMiniJacket').qtip({
		content: $('#mj_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	
	$('#forPackagingTypeEcoWallet4Panel').qtip({
		content: $('#4p_ec_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: {
			name: 'newgreen',
			width: 335
		}
	});
	
	$('#forPackagingTypeEcoWallet6Panel').qtip({
		content: $('#6p_ec_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: {
			name: 'newgreen',
			width: 335
		}
	});
	
	$('#forPackagingTypeDigiPackage4Panel').qtip({
		content: $('#4p_dp_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: {
			name: 'newgreen',
			width: 335
		}
	});
	
	$('#forPackagingTypeDigiPackage6Panel').qtip({
		content: $('#6p_dp_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: {
			name: 'newgreen',
			width: 335
		}
	});
	
	// Inserts ToolTips
	$('#forInsertType2PanelInsert').qtip({
		content: $('#2p_jc_insert_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	$('#forInsertType4PanelInsert').qtip({
		content: $('#4p_jc_insert_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	$('#forInsertType6PanelInsert').qtip({
		content: $('#6p_jc_insert_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	$('#forInsertType8PageBook').qtip({
		content: $('#8p_jc_booklet_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	$('#forTrayCardTypeTrayCard1Side').qtip({
		content: $('#jc_1sided_traycard_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	
	$('#forTrayCardTypeTrayCard2Side').qtip({
		content: $('#jc_2sided_traycard_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	
	$('#forDVDWrapTypeDVDOuterWrap').qtip({
		content: $('#dvd_case_wrap_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	$('#forDVDInsertTypeDVDInnerInsert2Panel').qtip({
		content: $('#dvd_case_insert_2p_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	$('#forDVDInsertTypeDVDInnerInsert4Panel').qtip({
		content: $('#dvd_case_insert_4p_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftBottom'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: 'newgreen'
	});
	
	// Disc Printing ToolTips
	$('#forDiscColorFullColor').qtip({
		content: $('#full_color_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: {
			name: 'newgreen',
			width: 340
		}
	});
	
	$('#forDiscColorBlackText').qtip({
		content: $('#black_text_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: {
			name: 'newgreen',
			width: 340
		}
	});
	
	$('#forDiscColorBlackSilkscreen').qtip({
		content: $('#black_silkscreen_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: {
			name: 'newgreen',
			width: 340
		}
	});
	
	$('#forDiscColor2ColorSilkscreen').qtip({
		content: $('#2color_silkscreen_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: {
			name: 'newgreen',
			width: 340
		}
	});
	
	$('#forDiscColor3ColorSilkscreen').qtip({
		content: $('#3color_silkscreen_tooltip').html(),
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		},
		show: {
			effect: 'fade'
		},
		hide: {
			fixed: true
		},
		api: {
			beforeShow: toolTipsOn,
			onShow: addFancyBoxHandlers
		},
		style: {
			name: 'newgreen',
			width: 340
		}
	});
}

function set_turn_times() {
	// Replication
	if ($('#ProjectQuantity').val() < 1000) {
		$('#ReplicationOption').attr("disabled", true);
		$('#forReplicationOption').addClass("disabled");
	} else {
		$('#ReplicationOption').attr("disabled", false);
		$('#forReplicationOption').removeClass("disabled");
	}
	
	// Packaging ////////////////////////////////////////////////////////////////////////////////////////////////////
	if ($("#forPackagingTypeNone.active").length) {
		if (!$('#ProjectQuantity option[value=50]').length) {
			$('#ProjectQuantity').prepend('<option value="50">50</option>');
		}
		$("#no_50_note").hide();
		
		if (!$('#ProjectTurn option[value=5]').length) {
			$('#ProjectTurn').prepend('<option value="5">5 Day</option>');
		}
		if (!$('#ProjectTurn option[value=2]').length) {
			$('#ProjectTurn').prepend('<option value="2">2 Day</option>');
		}
		if (!$('#ProjectTurn option[value=1]').length) {
			$('#ProjectTurn').prepend('<option value="1">1 Day</option>');
		}
		if (!$('#ProjectTurn option[value=8]').length) {
			$('#ProjectTurn').append('<option value="8">8 Day</option>');
		}
		if (!$('#ProjectTurn option[value=10]').length) {
			$('#ProjectTurn').append('<option value="10">10 Day</option>');
		}
		$("#turn_note").text("");
	} else if ($("#forPackagingTypeJewelCaseBlackTray.active, #forPackagingTypeJewelCaseClearTray.active, \
		   #forPackagingTypeSlimCaseBlackTray.active, #forPackagingTypeSlimCaseClearTray.active, \
		   #forPackagingTypeDVDStyleCase.active, #forPackagingTypePaperWindowSleeve.active").length) {
		   	
		// If Jewel Case, Slim Case, DVD Case, or Paper Window Sleeve
		
		if (!$('#ProjectQuantity option[value=50]').length) {
			$('#ProjectQuantity').prepend('<option value="50">50</option>');
		}
		$("#no_50_note").hide();
		
		if ($('#ProjectQuantity').val() < 500) {
			if ($("#ProjectTurn").val() == 8 || $("#ProjectTurn").val() == 10) {
				alert("Only 1-, 2-, and 5-Day turn times are available for the Jewel Case, Slim Case, DVD Style Case, and Paper Window Sleeve at the selected quantity. Your turn time will be set to 5.");
				if ($('#ProjectTurn option[value=5]').length) {
					$("#ProjectTurn").val(5);
				}
			}
			
			$('#ProjectTurn option[value=8]').remove();
			$('#ProjectTurn option[value=10]').remove();
			// Allow only 1-, 2-, and 5-Day turns
			if (!$('#ProjectTurn option[value=5]').length) {
				$('#ProjectTurn').prepend('<option value="5">5 Day</option>');
			}
			if (!$('#ProjectTurn option[value=2]').length) {
				$('#ProjectTurn').prepend('<option value="2">2 Day</option>');
			}
			if (!$('#ProjectTurn option[value=1]').length) {
				$('#ProjectTurn').prepend('<option value="1">1 Day</option>');
			}
			$("#turn_note").text("Only 1-, 2-, and 5-Day turn times are available for the Jewel Case, Slim Case, DVD Style Case, and Paper Window Sleeve at the selected quantity.");
		} else if ($('#ProjectQuantity').val() == 500) {
			// Allow all turns
			if (!$('#ProjectTurn option[value=5]').length) {
				$('#ProjectTurn').prepend('<option value="5">5 Day</option>');
			}
			if (!$('#ProjectTurn option[value=2]').length) {
				$('#ProjectTurn').prepend('<option value="2">2 Day</option>');
			}
			if (!$('#ProjectTurn option[value=1]').length) {
				$('#ProjectTurn').prepend('<option value="1">1 Day</option>');
			}
			if (!$('#ProjectTurn option[value=8]').length) {
				$('#ProjectTurn').append('<option value="8">8 Day</option>');
			}
			if (!$('#ProjectTurn option[value=10]').length) {
				$('#ProjectTurn').append('<option value="10">10 Day</option>');
			}
			
			/*$("#turn_note").text("All turn times are available for the Jewel Case, Slim Case, DVD Style Case, and Paper Window Sleeve at the selected quantity.");*/
		} else if ($('#ProjectQuantity').val() == 1000) {
			if ($("#ProjectTurn").val() == 1 || $("#ProjectTurn").val() == 2 || $("#ProjectTurn").val() == 5) {
				alert("Only 8- and 10-Day turn times are available for Jewel Cases, Slim Cases, DVD Style Cases, and Paper Window Sleeves at the selected quantity. Your turn time will be set to 8.");
			}
			
			// Allow only 8- and 10-Day turns
			$('#ProjectTurn option[value=1]').remove();
			$('#ProjectTurn option[value=2]').remove();
			$('#ProjectTurn option[value=5]').remove();
			if (!$('#ProjectTurn option[value=8]').length) {
				$('#ProjectTurn').prepend('<option value="8">8 Day</option>');
			}
			if (!$('#ProjectTurn option[value=10]').length) {
				$('#ProjectTurn').append('<option value="10">10 Day</option>');
			}
			
			$("#turn_note").text("Only 8- and 10-Day turn times are available for Jewel Cases, Slim Cases, DVD Style Cases, and Paper Window Sleeves at the selected quantity.");
		}
	} else if ($("#forPackagingTypeColorMiniJacket.active").length) {
		if (!$('#ProjectQuantity option[value=50]').length) {
			$('#ProjectQuantity').prepend('<option value="50">50</option>');
		}
		$("#no_50_note").hide();
		
		if ($('#ProjectQuantity').val() < 300) {
			if ($("#ProjectTurn").val() == 1 || $("#ProjectTurn").val() == 8 || $("#ProjectTurn").val() == 10) {
				alert("Only 2- and 5-Day turn times are available for Mini Jackets at the selected quantity. Your turn time will be set to 5.");
				if ($('#ProjectTurn option[value=5]').length) {
					$("#ProjectTurn").val(5);
				}
			}
			
			// Allow only 2- and 5-Day turns
			$('#ProjectTurn option[value=1]').remove();
			$('#ProjectTurn option[value=8]').remove();
			$('#ProjectTurn option[value=10]').remove();
			if (!$('#ProjectTurn option[value=5]').length) {
				$('#ProjectTurn').prepend('<option value="5">5 Day</option>');
			}
			if (!$('#ProjectTurn option[value=2]').length) {
				$('#ProjectTurn').prepend('<option value="2">2 Day</option>');
			}
			
			$("#turn_note").text("Only 2- and 5-Day turn times are available for Mini Jackets at the selected quantity.");
		} else if ($('#ProjectQuantity').val() == 300) {
			if ($("#ProjectTurn").val() == 1 || $("#ProjectTurn").val() == 2) {
				alert("Only 5-, 8-, and 10-Day turn times are available for Mini Jackets at the selected quantity. Your turn time will be set to 5.");
				if ($('#ProjectTurn option[value=5]').length) {
					$("#ProjectTurn").val(5);
				}
			}
			
			// Allow only 5-, 8-, and 10-Day turns
			$('#ProjectTurn option[value=1]').remove();
			$('#ProjectTurn option[value=2]').remove();
			if (!$('#ProjectTurn option[value=5]').length) {
				$('#ProjectTurn').append('<option value="5">5 Day</option>');
			}
			if (!$('#ProjectTurn option[value=8]').length) {
				$('#ProjectTurn').append('<option value="8">8 Day</option>');
			}
			if (!$('#ProjectTurn option[value=10]').length) {
				$('#ProjectTurn').append('<option value="10">10 Day</option>');
			}
			
			$("#turn_note").text("Only 5-, 8-, and 10-Day turn times are available for Mini Jackets at the selected quantity.");
		} else if ($('#ProjectQuantity').val() >= 500) {
			if ($("#ProjectTurn").val() == 1 || $("#ProjectTurn").val() == 2 || $("#ProjectTurn").val() == 5) {
				alert("Only 8- and 10-Day turn times are available for Mini Jackets at the selected quantity. Your turn time will be set to 8.");
			}
			
			// Allow only 5-, 8-, and 10-Day turns
			$('#ProjectTurn option[value=1]').remove();
			$('#ProjectTurn option[value=2]').remove();
			$('#ProjectTurn option[value=5]').remove();
			if (!$('#ProjectTurn option[value=8]').length) {
				$('#ProjectTurn').append('<option value="8">8 Day</option>');
			}
			if (!$('#ProjectTurn option[value=10]').length) {
				$('#ProjectTurn').append('<option value="10">10 Day</option>');
			}
			
			$("#turn_note").text("Only 8- and 10-Day turn times are available for Mini Jackets at the selected quantity.");
		}
	} else if ($("#forPackagingTypeEcoWallet4Panel.active, #forPackagingTypeDigiPackage4Panel.active, \
				  #forPackagingTypeEcoWallet6Panel.active, #forPackagingTypeDigiPackage6Panel.active").length) {
		
		if ($("#ProjectQuantity").val() == 50) {
			alert("50-piece quantity is not available for Eco-Wallets or Digi Packages Your quantity will be set to 100.");
		}
		$('#ProjectQuantity option[value=50]').remove();
		$("#no_50_note").show();
		
		if ($('#ProjectQuantity').val() <= 500) {
			if ($("#ProjectTurn").val() == 1 || $("#ProjectTurn").val() == 2 || $("#ProjectTurn").val() == 5) {
				alert("Only 8- and 10-Day turn times are available for Eco-Wallets and Digi Packages at the selected quantity. Your turn time will be set to 8.");
			}
			
			// Allow only 8- and 10-Day turns
			$('#ProjectTurn option[value=1]').remove();
			$('#ProjectTurn option[value=2]').remove();
			$('#ProjectTurn option[value=5]').remove();
			if (!$('#ProjectTurn option[value=8]').length) {
				$('#ProjectTurn').prepend('<option value="8">8 Day</option>');
			}
			if (!$('#ProjectTurn option[value=10]').length) {
				$('#ProjectTurn').append('<option value="10">10 Day</option>');
			}
			
			$("#turn_note").text("Only 8- and 10-Day turn times are available for Eco-Wallets and Digi Packages at the selected quantity.");
		} else if ($('#ProjectQuantity').val() == 1000) {
			if ($("#ProjectTurn").val() < 10) {
				alert("Only the 10-Day turn time is available for Eco-Wallets and Digi Packages at the selected quantity. Your turn time will be set to 10.");
			}
			
			// Allow only 10-Day turn
			$('#ProjectTurn option[value=1]').remove();
			$('#ProjectTurn option[value=2]').remove();
			$('#ProjectTurn option[value=5]').remove();
			$('#ProjectTurn option[value=8]').remove();
			if (!$('#ProjectTurn option[value=10]').length) {
				$('#ProjectTurn').append('<option value="10">10 Day</option>');
			}
			
			$("#turn_note").text("Only the 10-Day turn time is available for Eco-Wallets and Digi Packages at the selected quantity.");
		}
	}
	
	// Inserts ////////////////////////////////////////////////////////////////////////////////////////////////////
	if (!$("#InsertType8PageBook").attr("disabled") && $("#forInsertType8PageBook.active").length) {
		if ($("#ProjectTurn").val() == 1) {
			alert("1-Day turn time is not available for 8-Page Booklets. Your turn time will be set to 2.");
		}
		$('#ProjectTurn option[value=1]').remove();
		$("#turn_note").html($("#turn_note").html() + 
			"<p>1-Day turn time is not available for 8-Page Booklets.</p>");
	}
	
	// Disc Color ////////////////////////////////////////////////////////////////////////////////////////////////////
	if (!$("#DiscColorFullColor").attr("disabled") && $("#forDiscColorFullColor.active").length && $('#ProjectQuantity').val() == 1000) {
		// Full Color Discs: 10-day only @ 1000 units
		
		if ($("#ProjectTurn").val() < 10) {
			alert("Only the 10-Day turn time is available for 1000 Full Color Discs. Your turn time will be set to 10.");
		}
		
		$('#ProjectTurn option[value=1]').remove();
		$('#ProjectTurn option[value=2]').remove();
		$('#ProjectTurn option[value=5]').remove();
		$('#ProjectTurn option[value=8]').remove();
		
		$("#turn_note").html($("#turn_note").html() + 
			"<p>Only the 10-Day turn time is available for 1000 Full Color Discs.</p>");
	} else if (!$("#DiscColorBlackText").attr("disabled") && $("#forDiscColorBlackText.active").length && $('#ProjectQuantity').val() == 1000) {
		// Black Text Discs: 8- and 10-day only @ 1000 units
		
		if ($("#ProjectTurn").val() <= 5) {
			alert("Only 8- and 10-Day turn times are available for 1000 Black Text Discs. Your turn time will be set to 8.");
		}
		
		$('#ProjectTurn option[value=1]').remove();
		$('#ProjectTurn option[value=2]').remove();
		$('#ProjectTurn option[value=5]').remove();
		
		$("#turn_note").html($("#turn_note").html() + 
			"<p>Only 8- and 10-Day turn times are available for 1000 Black Text Discs.</p>");
	} else if ($("#forDiscColorBlackSilkscreen.active, #forDiscColor2ColorSilkscreen.active, #forDiscColor3ColorSilkscreen.active").length && $('#ProjectQuantity').val() < 500) {
		// Silkscreen Discs: 5-day only under 500 units
		
		if ($("#ProjectTurn").val() < 5) {
			alert("Only 5-Day turn times are available for 1000 Black Text Discs. Your turn time will be set to 5.");
		}
		
		$('#ProjectTurn option[value=1]').remove();
		$('#ProjectTurn option[value=2]').remove();
		
		$("#turn_note").html($("#turn_note").html() + 
			"<p>1- and 2-day turn times are not available for Silkscreening at the selected quantity.</p>");
	} else if ($("#forDiscColorBlackSilkscreen.active, #forDiscColor2ColorSilkscreen.active, #forDiscColor3ColorSilkscreen.active").length && $('#ProjectQuantity').val() >= 500) {
		// Silkscreen Discs: 8- and 10-day only @ 500+ units
		
		if ($("#ProjectTurn").val() <= 5) {
			alert("Only 8- and 10-Day turn times are available for 1000 Black Text Discs. Your turn time will be set to 8.");
		}
		
		$('#ProjectTurn option[value=1]').remove();
		$('#ProjectTurn option[value=2]').remove();
		$('#ProjectTurn option[value=5]').remove();
		
		$("#turn_note").html($("#turn_note").html() + 
			"<p>1-, 2-, and 5-day turn times are not available for Silkscreening at the selected quantity.</p>");
	}
	
	// Sort Turn Times
	$("#ProjectTurn > option").tsort({attr:"value"});
}

function submit_ajax() {
	get_summary();
	update_rates();
}

function get_summary() {
	$('#project_form').ajaxSubmit({
		beforeSend:function(request) {
			request.setRequestHeader('X-Update', 'details');
			$('#details').html("");
			$('#details').addClass("loading"); },
		success:function(data, textStatus) {
			$('#details').removeClass("loading"); }, 
		async:true,
		target:'#details',
		type:'post',
		url:'/quoter/projects/get_details'
	});
}

showToolTips = true;

function setToolTipsOn() {
	showToolTips = true;
	$('#tooltipsoff').show();
	$('#tooltipson').hide();
}

function setToolTipsOff() {
	showToolTips = false;
	$('#tooltipson').show();
	$('#tooltipsoff').hide();
}

function toolTipsOn() {
	return showToolTips;
}

function addFancyBoxHandlers() {
	$(".youtube").click(function () {
		$(".qtip").qtip("hide");
	});
	
	$(".youtube").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn' 	: 'fade',
			'transitionOut' : 'fade',
			'title'			: this.title,
			'width'			: 425,
			'height'		: 344,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf'
		});
	
		return false;
	});
}

$(document).ready(function() {addHandlersAndAttrs(); addCheckoutHandlers(); addFancyBoxHandlers();});