// Calculate the total for items in the form which are selected
function calculateQuote() {

	if (document.quickQuote.quoteQuantity.value == "") {
		document.quickQuote.quoteTotal.value = '';
		alert("Please enter a value for the \"Quantity\" field.");
		document.quickQuote.quoteQuantity.value = '';
		document.quickQuote.quoteQuantity.focus();
	} else if ((document.quickQuote.quoteSize[0].checked && document.quickQuote.quoteQuantity.value < 50) || (document.quickQuote.quoteSize[1].checked && document.quickQuote.quoteQuantity.value < 100)) {
		document.quickQuote.quoteTotal.value = '';
		alert("Too few prints for quote, please increase your quantity.");
		document.quickQuote.quoteQuantity.value = '';
		document.quickQuote.quoteQuantity.focus();
	} else {

		// Assign color count and setup cost
		if (document.quickQuote.quoteColors[0].checked) {
			colorCount = 1;
			setupCost = 1;
		} else if (document.quickQuote.quoteColors[1].checked) {
			colorCount = 1.5;
			setupCost = 2;
		} else if (document.quickQuote.quoteColors[2].checked) {
			colorCount = 2;
			setupCost = 3;
		} else if (document.quickQuote.quoteColors[3].checked) {
			colorCount = 2.5;
			setupCost = 4;
		}
	
		// Display total value
		if (document.quickQuote.quoteSize[0].checked) {
			document.quickQuote.quoteTotal.value = formatCurrency(((document.quickQuote.quoteQuantity.value * .75) + (document.quickQuote.quoteQuantity.value * colorCount)) + (setupCost * 35));
		} else if (document.quickQuote.quoteSize[1].checked) {
			document.quickQuote.quoteTotal.value = formatCurrency((((document.quickQuote.quoteQuantity.value * .75) + (document.quickQuote.quoteQuantity.value * colorCount)) / 2) + (setupCost * 35));
		}
	}
}

// Format a value as currency
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if (isNaN(num)) {
		num = "0";
	}
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if (cents < 10) {
		cents = "0" + cents;
	}
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
		num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
	}
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}