/* 	RippleFX Copyright 2002-2003 */
/*--------------------------------------------------------------------------
File:		order.js
Author:		Tim Tomanik

Purpose:	This file provides script services for /order.asp
			
Version:	1.01

Dependant:	Requires the rfx_detect library to have been initialized.

Updates
Nov 12, 2003 Justin Frydman		Added steves new CD to the form (inp_cd2Qty)
Jan 12, 2003 Tim Tomnik			Removed output for old multiple price levels
Dec 11, 2002 Tim Tomanik		Completed initial version						
						
-----------------------------------------------------------------------------*/

function CalculateTotal() {
	var total;
	var inp_cdQty;
	var inp_cd2Qty;
	var inp_giftQty;	
	var tempTotal;
	var tempResult;
	var outText;

	// Get our user values
	if(isNS4) {
		inp_cdQty = document.calcform.inp_cdQty.value;
		inp_cd2Qty = document.calcform.inp_cd2Qty.value;
	} else {
		inp_cdQty = ObjectReference("inp_cdQty").value;
		inp_cd2Qty = ObjectReference("inp_cd2Qty").value;
	}
	if(!IsInteger(inp_cdQty)) {
		inp_cdQty = 0;
	}
	
	if(!IsInteger(inp_cd2Qty)) {
		inp_cd2Qty = 0;
	}
		
	if(isNS4) {
		inp_giftQty	= document.calcform.inp_giftQty.value;
	} else {
		inp_giftQty	= ObjectReference("inp_giftQty").value;
	}
	if(!IsInteger(inp_giftQty)) {
		inp_giftQty = 0;
	}
	
	// Figure out the 1-10 grouping
	tempResult = (inp_cdQty >= 10) ? 10 : inp_cdQty;
	tempResult2 = (inp_cd2Qty >= 10) ? 10 : inp_cd2Qty;
	tempTotal = tempResult*15;
	tempTotal2 = tempResult2*15;
	total = tempTotal + tempTotal2;
		
		
	// Figure out the 11-20 grouping	
	tempResult = (inp_cdQty >= 20) ? 10 : inp_cdQty - tempResult;
	tempResult2 = (inp_cd2Qty >= 20) ? 10 : inp_cd2Qty - tempResult2;
	tempTotal = tempResult*13;
	tempTotal2 = tempResult2*13;
	tempTotal += tempTotal2;
	total += tempTotal;
	
	// Figure out the 21+ grouping	
	tempResult = (inp_cdQty > 20) ? inp_cdQty - 20 : 0;
	tempResult2 = (inp_cd2Qty > 20) ? inp_cd2Qty - 20 : 0;
	tempTotal = tempResult*10;
	tempTotal2 = tempResult2*10;
	tempTotal += tempTotal2;
	total += tempTotal;
				
	// Figure out the CD total grouping
	outText = (total > 0) ? "$ " + total + ".00" : "";
	document.calcform.inp_price.value = outText;					
				
	// Figure out the gift wrapping grouping	
	
	
	if ((inp_giftQty*1) < ((inp_cdQty*1) + (inp_cd2Qty*1))) {
		tempResult = inp_giftQty;
	} else {
		tempResult = ((inp_cdQty*1) + (inp_cd2Qty*1));
	}
	
	
	tempTotal = tempResult*1;
	//tempResult = ((inp_giftQty*1) < (inp_cdQty + inp_cd2Qty)) ? inp_giftQty : inp_cdQty + inp_cd2Qty;
	//tempResult2 = ((inp_giftQty*1) < (inp_cd2Qty*1)) ? inp_giftQty : inp_cd2Qty;
	//tempTotal2 = tempResult2*1;
	//if(tempTotal2 != 0 ) {
	//	tempTotal += tempTotal2;
	//}
	total += tempTotal;
	outText = (tempTotal > 0) ? "$ " + tempTotal + ".00" : "";
	document.calcform.inp_priceGiftWrap.value = outText;				

	// Figure out the taxes grouping	
	tempTotal = total * 0.07;
	total += tempTotal;
	if(isNS4 || isMac) {
		outText = (total > 0) ? "$ " + RoundPrice(tempTotal) : "";	
	} else {
		outText = (total > 0) ? "$ " + RoundPrice(tempTotal) : "";
	}
	document.calcform.inp_priceGST.value = outText;	

	// Figure out the total		
	total += 3			
	if(isNS4 || isMac) {
		outText = (total > 3) ? "$ " + RoundPrice(total) : "";	
	} else {	
		outText = (total > 3) ? "$ " + RoundPrice(total) : "";			
	}
	document.calcform.inp_priceTotal.value = outText;
}
