// JavaScript Document
<!-- hide from old browsers
// JavaScript Document
/* The following values dictate the price calculations 
	< 20ft sq =3.75, 21 - 100=3.50, 101-225=3.09, 226-400=2.99 Add a flat 3.50 for edges*/

var quantity = 0;
var material;
var product_height;
var product_length;
var edges;
var turnaround;
var PricePerUnit;
var total;
var sqfeet;
var priceperfoot;
var priceofedges = 3.50;
var totalfootage;
var subtotal1;
var percent;

function calculate(){
	quantity = document.BannerOptions.quantity.value;
	//material = document.BannerOptions.material.value;
	product_height = document.BannerOptions.product_height.value;
	product_length = document.BannerOptions.product_length.value;
	edges = document.BannerOptions.edges.value;
	turnaround = document.BannerOptions.turnaround.value;
	
	// ################### Step 1: Quantity
	if(quantity!=0){
		sqfeet = product_length * product_height;
		totalfootage = sqfeet * quantity;
	
		if(totalfootage <= 20){
			priceperfoot = 3.80;
		}else if(totalfootage >20 && totalfootage <= 100){
			priceperfoot = 3.50;
		}else if(totalfootage >100 && totalfootage <= 225){
			priceperfoot = 3.10;
		}else if(totalfootage >225 && totalfootage <= 400){
			priceperfoot = 3.00;
		}else if (totalfootage >400){
			priceperfoot = 2.80;
			
			//################ HANDLE EXCEEDINGLY LARGE ORDERS!##########
			//alert('Please call for a quote');
					
		}
		
		//Piece price
		PricePerUnit = sqfeet * priceperfoot;
		
		// ################### Step 2: Edges
		if(edges == 1){
			
			if (totalfootage >400){
			
			subtotal1 = quantity * priceofedges;
		    total = (PricePerUnit * quantity) * .05;
		    total = (PricePerUnit * quantity) - total;
            alert('Your order qualifies you for a 5% discount!');
			total += subtotal1;
			
			//Price per unit displays on form + price of edges
			PricePerUnit += priceofedges;	
			} else {
			subtotal1 = quantity * priceofedges;
			total = PricePerUnit * quantity;
			total += subtotal1;
			
			//Price per unit displays on form + price of edges
			PricePerUnit += priceofedges;
			}
			
		} else if (totalfootage >400){
			
                total = (PricePerUnit * quantity) * .05;
		total = (PricePerUnit * quantity) - total;
                alert('Your order qualifies you for a 5% discount!');
		 
		} else {
			total = PricePerUnit * quantity;
			//document.BannerOptions.PricePerUnit.value = PricePerUnit;
			//document.BannerOptions.total.value = total;
		}
		switch(turnaround){
			case "1": percent = .50;
					  total = turnaround_price(total,percent);
					  PricePerUnit = turnaround_price(PricePerUnit,percent);
					  break
			case "2": percent = .25;
					  total = turnaround_price(total,percent);
					  PricePerUnit = turnaround_price(PricePerUnit,percent);
					  break
			case "3":percent = .00;
					 total = turnaround_price(total,percent);
					 break
			}
			document.BannerOptions.sqfeet.value = totalfootage;
			totalfootage = 0;
			quantity = 0;
			percent = 0;
			priceperfoot = 0;
			document.BannerOptions.PricePerUnit.value = PricePerUnit.toFixed(2);
			document.BannerOptions.total.value = total.toFixed(2);
			
			PricePerUnit = 0;
			total = 0;
	
	}else{
		PricePerUnit = 0;
		total = 0;
		totalfootage = 0;
		quantity = 0;
		percent = 0;
		priceperfoot = 0;
		sqfeet = 0;
		document.BannerOptions.PricePerUnit.value = PricePerUnit.toFixed(2);
		document.BannerOptions.total.value = total.toFixed(2);
		
	}
}

function turnaround_price(total,percent){
	percentage = 0;
	price = total;
	percent1 = percent;
	percentage = price * percent1;
	new_price = total+percentage;
	return new_price;
}
//-->
