

// Precondition:
	// changedValue = Changed Value
	// itemChanged = Item type changed
	// displayObj = Object to display value in.
// Postcondition:
	// Calculated values and displays while saving total in hidden field
	
	
	
	
function setAmts()
	{

	// Get values
	var flagQuant = document.orderForm.quantity_1.value;
	var flagQuant2 = document.orderForm.quantity_2.value;
	var shippingType = document.orderForm.shippingType.value;
	var shippingTypeText = document.orderForm.shippingType.options[document.orderForm.shippingType.selectedIndex].text;
	var taxAmt = document.orderForm.vaRes.value;
	
	
	
	// If values are NULL make into 0
	if(trimData(flagQuant) == "")
	var flagQuant = 0;
	
	if(trimData(flagQuant2) == "")
	var flagQuant2 = 0;
	// Get total flag quantity
	var totalFlagQuant = parseInt(flagQuant) + parseInt(flagQuant2);
	
		
	// Get price totals
	var flagAmt = quantityTotalPrice(flagQuant);
	var flagAmt2 = quantityTotalPrice2(flagQuant2);		
	var shippHndlAmtArray = shippHndlPrice(totalFlagQuant,shippingType);	
		
	// Display new value
	document.getElementById("shpAmountDisplay").innerHTML = shippHndlAmtArray[0].toFixed(2);	
	document.getElementById("flagAmountDisplay").innerHTML = flagAmt.toFixed(2);		
	document.getElementById("flagAmountDisplay2").innerHTML = flagAmt2.toFixed(2);		
	document.getElementById("hdlAmountDisplay").innerHTML = shippHndlAmtArray[1].toFixed(2);				
	
	var taxVal = taxAmt * (flagAmt + flagAmt2 + shippHndlAmtArray[0] + shippHndlAmtArray[1]);
	document.getElementById("taxAmountDisplay").innerHTML = taxVal.toFixed(2);		
		
	// Calculate total value and store in hidden field	
	var totalValue = flagAmt + flagAmt2 + shippHndlAmtArray[0] + shippHndlAmtArray[1] + taxVal;			
	document.orderForm.totalAmt.value = totalValue;
		
	// Display total
	document.getElementById("totalAmountDisplay").innerHTML = totalValue.toFixed(2);	
	
	
	// Set paypal fields
	document.orderForm.amount_1.value = flagQuant;
	document.orderForm.amount_2.value = flagQuant2;
	document.orderForm.shipping_1.value = shippHndlAmtArray[0] + shippHndlAmtArray[1];
	document.orderForm.on1_1.value = shippingTypeText;
	document.orderForm.on1_2.value = shippingTypeText;
	document.orderForm.amount_1.value = quantityEachPrice(flagQuant);
	document.orderForm.amount_2.value = quantityEachPrice2(flagQuant2);
	document.orderForm.tax_1.value = taxVal;
		
	}
	
// ****************************************************************************

// Precondition:
	// flagQuant = Amount of flags requested
// Postcondition:
	// Calculates quantity price
	
function quantityTotalPrice(flagQuant)
	{
	
	var amtEach = 0;
	
		// Determine amount for each flag
		if(flagQuant >= 1 && flagQuant <= 9)
		amtEach = 3.50;
			else if(flagQuant >= 10 && flagQuant <= 49)
			amtEach = 3.25;
				else if(flagQuant >= 50 && flagQuant <= 99)
				amtEach = 3.00;
					else if(flagQuant >= 100 && flagQuant <= 999)
					amtEach = 2.50;
						else if(flagQuant >= 1000)
						amtEach = 2.00;
						
						
	// Calculate total
	var totalAmt = amtEach * flagQuant;
	
	return totalAmt;
	}
	
// ****************************************************************************

// Precondition:
	// flagQuant = Amount of flags requested
// Postcondition:
	// Calculates quantity price
	
function quantityTotalPrice2(flagQuant2)
	{
	
	var amtEach = 0;
	
		// Determine amount for each flag
		if(flagQuant2 >= 1 && flagQuant2 <= 9)
		amtEach = 1.75;
			else if(flagQuant2 >= 10 && flagQuant2 <= 49)
			amtEach = 1.65;
				else if(flagQuant2 >= 50 && flagQuant2 <= 99)
				amtEach = 1.50;
					else if(flagQuant2 >= 100 && flagQuant2 <= 999)
					amtEach = 1.25;
						else if(flagQuant2 >= 1000)
						amtEach = 1.00;
						
						
	// Calculate total
	var totalAmt = amtEach * flagQuant2;
	return totalAmt;
	}
	
// ****************************************************************************

// Precondition:
	// flagQuant = Amount of flags requested
// Postcondition:
	// Calculates quantity price for each
	
function quantityEachPrice(flagQuant)
	{
	
	var amtEach = 0;
	
		// Determine amount for each flag
		if(flagQuant >= 1 && flagQuant <= 9)
		amtEach = 3.50;
			else if(flagQuant >= 10 && flagQuant <= 49)
			amtEach = 3.25;
				else if(flagQuant >= 50 && flagQuant <= 99)
				amtEach = 3.00;
					else if(flagQuant >= 100 && flagQuant <= 999)
					amtEach = 2.50;
						else if(flagQuant >= 1000)
						amtEach = 2.00;
						
						
	return amtEach;
	}
	
	
// ****************************************************************************

// Precondition:
	// flagQuant = Amount of flags requested
// Postcondition:
	// Calculates quantity price for each
	
function quantityEachPrice2(flagQuant2)
	{
	
	
	var amtEach = 0;
	
		// Determine amount for each flag
		if(flagQuant2 >= 1 && flagQuant2 <= 9)
		amtEach = 1.75;
			else if(flagQuant2 >= 10 && flagQuant2 <= 49)
			amtEach = 1.65;
				else if(flagQuant2 >= 50 && flagQuant2 <= 99)
				amtEach = 1.50;
					else if(flagQuant2 >= 100 && flagQuant2 <= 999)
					amtEach = 1.25;
						else if(flagQuant2 >= 1000)
						amtEach = 1.00;
						
						
						
	return amtEach;
	}
	
	
// ****************************************************************************

// Precondition:
	// flagQuant = Amount of flags requested
// Postcondition:
	// Calculates quantity price
	
function shippHndlPrice(flagQuant,shippingType)
	{
	
	var shipAmt = 0;
	var handlAmt = 0;
	
	
	// Set values for shipping type
	if(shippingType == 1)
	{
	var q1 = 3.50;
	var q2 = 6.50;
	var q3 = 18.50;
	var q4 = 32.50;
	}
		else if(shippingType == 2)
		{
		var q1 = 6.50;
		var q2 = 9.50;
		var q3 = 22.50;
		var q4 = 37.50;
		}
			else if(shippingType == 3)
			{
			var q1 = 22.50;
			var q2 = 24.50;
			var q3 = 37.50;
			var q4 = 56.50;
			}
		
	
	
	
		// Determine amount by flag quantity
		if(flagQuant >= 1 && flagQuant <= 4)
		{
		shipAmt = q1;
		handlAmt = .95;
		}
			else if(flagQuant >= 5 && flagQuant <= 10)
			{
			shipAmt = q2;
			handlAmt = .95;
			}
				else if(flagQuant >= 11 && flagQuant <= 50)
				{
				shipAmt = q3;
				handlAmt = 1.95;
				}
					else if(flagQuant >= 51 && flagQuant <= 100)
					{
					shipAmt = q4;
					handlAmt = 1.95;
					}
						else if(flagQuant >= 101)
						{
							
							// Get multiples of 100
							var multipleAmt = Math.round((flagQuant/100)*100)/100
							
						shipAmt = multipleAmt * q4;
						handlAmt = 1.95;
						}
						
	var shippHandleArray = new Array(shipAmt,handlAmt);			
	
	return shippHandleArray;
	}
	
	

// ****************************************************************************

// Precondition:
	// flagQuant = Amount of flags requested
// Postcondition:
	// Calculates quantity price
	
function checkSubmit()
{
	
	var flagAmt1 = document.orderForm.quantity_1.value;
	var flagAmt2 = document.orderForm.quantity_2.value;
	
	var item1 = 0;
	var item2 = 0;
	
	//Check if item 1 is requested
	if(trimData(flagAmt1) != 0 && trimData(flagAmt1) != "")
	{
	item1 = 1;	
	}
	// Check if item 2 is requested
	if(trimData(flagAmt2) != 0 && trimData(flagAmt2) != "")
	{
	item2 = 1;	
	}
	
	
	if(item1 && item2)
	{
	document.orderForm.submit();
	}
		else if(item1 && !item2)
		{
		document.singleItem.quantity_1.value = document.orderForm.quantity_1.value;
		document.singleItem.shipping_1.value = document.orderForm.shipping_1.value;
		document.singleItem.item_name_1.value = document.orderForm.item_name_1.value;
		document.singleItem.on0_1.value = document.orderForm.on0_1.value;
		document.singleItem.on1_1.value = document.orderForm.on1_1.value;
		document.singleItem.item_number_1.value = document.orderForm.item_number_1.value;
		document.singleItem.amount_1.value = document.orderForm.amount_1.value;
		
		document.singleItem.submit();
		}
			else if(item2 && !item1)
			{			
			document.singleItem.quantity_1.value = document.orderForm.quantity_2.value;
			document.singleItem.shipping_1.value = document.orderForm.shipping_1.value;
			document.singleItem.item_name_1.value = document.orderForm.item_name_2.value;
			document.singleItem.on0_1.value = document.orderForm.on0_2.value;
			document.singleItem.on1_1.value = document.orderForm.on1_2.value;
			document.singleItem.item_number_1.value = document.orderForm.item_number_2.value;
			document.singleItem.amount_1.value = document.orderForm.amount_2.value;
			
			document.singleItem.submit();
			}		
				else
				{
				alert("Please enter a flag quantity.");
				document.orderForm.quantity_1.focus();
				}
}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	