/*
Order Form Program for Triangle Associates
by Entrust Technology Group
updated Aug. 2005
Stephen Thompson III
smt3@entrusttechnology.com
http://entrusttechnology.com
*/
function custRound(x,places)
{
// Created 1997 by Brian Risk.  http://members.aol.com/brianrisk
return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}

var sandh = 0, grandtotal = 0, subtotal1 = 0, subtotal2 = 0, taxes = 0, discount = 0;

var TG16oz = 0, TG7oz = 0, SG5oz = 0;

//var TG16ozpr = 19.95, TG7ozpr = 12.95, SG5ozpr = 10.95;

var TG16ozsub = 0, TG7ozsub = 0, SG5ozsub = 0;
var TG16ozdis = 0, TG7ozdis = 0, SG5ozdis = 0;
var handling = 0, TG16H = 0, TG7H = 0, SG5H = 0;
var CAtax = 0;
var cans = 0, max_cans = 10;
var CA = CA;

var weight16oz = 0, weight7oz = 0, weight5oz =0, WeightTotal = 0;

function fmtPrice(value)
   {
   result="$"+Math.floor(value)+".";
   var cents=100*(value-Math.floor(value))+0.5;
   result += Math.floor(cents/10);
   result += Math.floor(cents%10);
   return result;
   }
   
function total(){

if (document.order.TG16oz.value != null)	{		
		//TG16ozsub = document.order.TG16oz.value * 19.95;		
		if (document.order.TG16oz.value >= 10){			TG16ozsub = document.order.TG16oz.value * 16.95;
			TG16ozdis = (document.order.TG16oz.value * 19.95) - (document.order.TG16oz.value * 16.95);			weight16oz = (document.order.TG16oz.value * 2);			TG16H = 4;
		}

		if (document.order.TG16oz.value >= 5 <= 9){			TG16ozsub = document.order.TG16oz.value * 17.33;
			TG16ozdis = (document.order.TG16oz.value * 19.95) - (document.order.TG16oz.value * 17.33);			weight16oz = (document.order.TG16oz.value * 2);
			TG16H = 3;		}
		
		if (document.order.TG16oz.value >= 2 <= 4){			TG16ozsub = document.order.TG16oz.value * 17.63;			TG16ozdis = (document.order.TG16oz.value * 19.95) - (document.order.TG16oz.value * 17.63);			weight16oz = (document.order.TG16oz.value * 2);
			TG16H = 2;		}
			
		if (document.order.TG16oz.value == 1){			TG16ozsub = document.order.TG16oz.value * 19.95;			TG16ozdis = (document.order.TG16oz.value * 19.95) - (document.order.TG16oz.value * 19.95);
			weight16oz = (document.order.TG16oz.value * 2);			TG16H = 1;
		}		
				if (document.order.TG16oz.value <= 0){			TG16ozsub = document.order.TG16oz.value * 0;
			TG16H = 0;		}
		
		if (document.order.TG16oz.value == null){			TG16ozsub = document.order.TG16oz.value * 0;
			TG16H = 0;		}
	}
if (document.order.TG7oz.value != null)	{
		//TG7ozsub = document.order.TG7oz.value * 12.95;				if (document.order.TG7oz.value >= 10){		TG7ozsub = document.order.TG7oz.value * 11.00;
		TG7ozdis = (document.order.TG7oz.value * 12.95) - (document.order.TG7oz.value * 11.00);		weight7oz = (document.order.TG7oz.value * 1.5);
		TG7H = 4;
		}
		if (document.order.TG7oz.value >= 5 <= 9){			TG7ozsub = document.order.TG7oz.value * 11.46;
			TG7ozdis = (document.order.TG7oz.value * 12.95) - (document.order.TG7oz.value * 11.46);			weight7oz = (document.order.TG7oz.value * 1.5);
			TG7H = 3;		}
		
		if (document.order.TG7oz.value >= 2 <= 4){			TG7ozsub = document.order.TG7oz.value * 11.61;			TG7ozdis = (document.order.TG7oz.value * 12.95) - (document.order.TG7oz.value * 11.61);			weight7oz = (document.order.TG7oz.value * 1.5);
			TG7H = 2;		}
			
		if (document.order.TG7oz.value == 1){			TG7ozsub = document.order.TG7oz.value * 12.95;			TG7ozdis = (document.order.TG7oz.value * 12.95) - (document.order.TG7oz.value * 12.95);
			weight7oz = (document.order.TG7oz.value * 1.5);			TG7H = 1;
		}								
		if (document.order.TG7oz.value <= 0){			TG7ozsub = document.order.TG7oz.value * 0;
			TG7H = 0;		}
		
		if (document.order.TG7oz.value == null){			TG7ozsub = document.order.TG7oz.value * 0;
			TG7H = 0;		}
	}

if (document.order.SG5oz.value != null)	{
		//SG5ozsub = document.order.SG5oz.value * 10.95;				if (document.order.SG5oz.value >= 10){			SG5ozsub = document.order.SG5oz.value * 9.30;
			SG5ozdis = (document.order.SG5oz.value * 10.95) - (document.order.SG5oz.value * 9.30);
			weight5oz = (document.order.SG5oz.value * 1.3);
			SG5H = 4;		}
		if (document.order.SG5oz.value >= 5 <= 9){			SG5ozsub = document.order.SG5oz.value * 9.81;
			SG5ozdis = (document.order.SG5oz.value * 10.95) - (document.order.SG5oz.value * 9.81);			weight5oz = (document.order.SG5oz.value * 1.3);
			SG5H = 3;		}
		
		if (document.order.SG5oz.value >= 2 <= 4){			SG5ozsub = document.order.SG5oz.value * 9.98;			SG5ozdis = (document.order.SG5oz.value * 10.95) - (document.order.SG5oz.value * 9.98);			weight5oz = (document.order.SG5oz.value * 1.3);
			SG5H = 2;		}
			
		if (document.order.SG5oz.value == 1){			SG5ozsub = document.order.SG5oz.value * 10.95;			SG5ozdis = (document.order.SG5oz.value * 10.95) - (document.order.SG5oz.value * 10.95);
			weight5oz = (document.order.SG5oz.value * 1.3);			SG5H = 1;
		}						
				
		if (document.order.SG5oz.value <= 0){			SG5ozsub = document.order.SG5oz.value * 0;
			SG5H = 0;		}
		
		if (document.order.SG5oz.value == null){			SG5ozsub = document.order.SG5oz.value * 0;
			SG5H = 0;		}
	}

if (document.order.coupon.value =="TG33478" && document.order.TG16oz.value == 1){
	TG16ozsub = document.order.TG16oz.value * 17.95;	TG16ozdis = (document.order.TG16oz.value * 19.95) - (document.order.TG16oz.value * 17.95);
	weight16oz = (document.order.TG16oz.value * 2);	TG16H = 1;	
	document.order.SG5oz.value = 1;	SG5ozsub = document.order.SG5oz.value * 0.00;	SG5ozdis = (document.order.SG5oz.value * 10.95) - (document.order.SG5oz.value * 0.00);
	weight5oz = (document.order.SG5oz.value * 1.3);	SG5H = 1;
   }
subtotal1 = TG16ozsub + TG7ozsub + SG5ozsub;
subtotal2 = TG16ozsub + TG7ozsub + SG5ozsub;
WeightTotal = weight16oz + weight7oz + weight5oz;
handling = TG16H + TG7H + SG5H;	
	if ((document.order.BLstate.value == 'CA' ) || (document.order.BLstate.value == 'ca')){
		
		document.order.tax.value = fmtPrice(subtotal2 * 0.0825);
		document.order.taxh.value = custRound((subtotal2 * 0.0825),2);				}else{
		if ((document.order.BLstate.value != 'CA' ) || (document.order.BLstate.value != 'ca'))				document.order.tax.value = fmtPrice(0.00);		document.order.taxh.value = 0;
	}
discount = TG16ozdis + TG7ozdis + SG5ozdis;

document.order.discount.value = fmtPrice(discount);
document.order.subtotal1.value = fmtPrice(subtotal1);document.order.subtotal2.value = fmtPrice(subtotal2);document.order.Weight.value = WeightTotal;
document.order.handling.value = handling;document.order.subtotalh.value = subtotal2;
return
}