// JavaScript Functions used by the following pages
//            lpd/prices.htm 
//            lpd/neworder.aspx 	 	
//            lpd/weborder.aspx    
//
// computePrice - Calculates the price on the price form 
// computeUpgradePrice - computes the price on the upgrade price form 
//
// Amendments
//   2011/09/06 lgj - Price for 1 copy is 2 times the base price.
//   2011/11/10 lgj - Implement smooth price curve   	 
//
function computePrice(form)
{
	// Set feature prices
	basePrice = 25;
	processingFee = 35;
	amount = basePrice;
	
	// Set quantity discount levels
	if (form.Quantity != null)
	    quantity = eval(form.Quantity.value);
	else
	    quantity = 1;    

	// if (form.ProcessingFee != null) form.ProcessingFee.value = "";
	// form.TotalPrice.value = "";

	// Compute total price with quanity discount
	subtotal = computeTotalPrice(quantity, amount)
	unitPrice = (subtotal / quantity);
	subtotal = Math.ceil(subtotal);                 // round up

		
	// Compute maintenance price
	// maintenance = subtotal * .15;
	maintenance = Math.ceil(subtotal * .15);        // round up
	if (maintenance < 100)
		maintenance = 100;
			
	// Compute Total Price
	totalPrice = subtotal + maintenance;

	// Add processing fee
    	if (form.ProcessingFee != null)
	{
		fee = 0;
		if (totalPrice < 300) 
			fee += processingFee;             
		totalPrice += fee;
		if (fee.toFixed) fee = fee.toFixed(2);
	}

	// Round prices
	totalPrice = Math.ceil(totalPrice);
	
	if (totalPrice != parseFloat(totalPrice))
		totalPrice = 0;
	if (totalPrice.toFixed) 		//if browser supports toFixed() method
	{
		unitPrice = unitPrice.toFixed(2);
		subtotal = subtotal.toFixed(2);
		maintenance = maintenance.toFixed(2);
		totalPrice = totalPrice.toFixed(2);
	}
	

    if (form.UnitPrice != null)
        form.UnitPrice.value = '$' + unitPrice; 
    if (form.Subtotal != null)
        form.Subtotal.value = '$' + subtotal; 
    if (form.MaintenancePlan != null)
        form.MaintenancePlan.value = '$' + maintenance; 
    if (form.ProcessingFee != null)
	form.ProcessingFee.value = '$' + fee;	     
    form.TotalPrice.value = '$' + totalPrice; 
}

// ------------------------------------------------------------------------- 
// Helper functions
// ------------------------------------------------------------------------- 
function computeTotalPrice(quantity, amount)
{
	subtotal = 0;
	currentQuantity = quantity;    
	if (currentQuantity > 99) 
	{
		subtotal += (currentQuantity - 99) * (amount * .72);
		currentQuantity = 99;
	}
	if (currentQuantity > 49)
	{
		subtotal += (currentQuantity - 49) * (amount * .9);
		currentQuantity = 49;
	}
	if (currentQuantity > 14) 
	{
		subtotal += (currentQuantity - 14) * (amount * .95);
		currentQuantity = 14;
	}
	if (currentQuantity > 3) 
	{
		subtotal += (currentQuantity - 3) * (amount * 1);
		currentQuantity = 3;
	}
	
	subtotal += (currentQuantity * amount * 2);
	// alert ("amount = "  + amount + " quantity = " + quantity + " subtotal = " + subtotal);	
	return subtotal;
}


