// Function takes a number and puts it into currency format (ie, $0.00)
function toCurrency (input)
{
	input += "";
	var original_input = input;
	if (input . charAt (0) == "$")
		input = input . substring (1, input . length);
	else if
	(
		input . substring (0, 2) == "-$"
	||	input . substring (0, 2) == "+$"
	)
		input = input . charAt (0) + input . substring (2, input . length);
	var amount = parseFloat (input);
	if (isNaN (amount))
		return original_input;
	amount = Math . round (100 * amount);
	var prefix = "$";
	if (amount < 0)
	{
		prefix = "-" + prefix;
		amount = - amount;
	}
	var string;
	if (amount < 10)
		string = "00" + amount;
	else if (amount < 100)
		string = "0" + amount;
	else
		string = "" + amount;
	string = prefix + string;
	string =
		string . substring (0, string . length - 2) +
		"." +
		string . substring (string . length - 2, string . length);
	return string;
}

// Function determines number of square feet requested and calculates costs based on square footage
// last modified 2004-01-20 mbg
function calculate(){

// Initialize and assign variables here
var printingcost = 0;
var laminatecost = 0;
var laminatecostvar = 0;
var mountingcost = 0;
var mountingcostvar = 0;
var shippingcost = 0;
var totalcost = 0;
var widthvar = document.quote.width.value;
var heightvar = document.quote.height.value;
var qty = document.quote.qty.value;
var sqftcost = 0;
var printshippingrate = 0;
var printshippingcost = 0;
var lamshippingrate = 0;
var lamshippingcost = 0;
var mtgshippingrate = 0;
var nd_mtgshippingrate = 0;
var mtgshippingcost = 0;
var lamshippingchk = 0;
var mtgshippingchk = 0;
var printshippingbase = 0;
var mtgshippingbase = 0;
var sqft = 0;
var minarea = 0;

// ********************************************************
// Change BASE Materials Prices here!!!!!
//
//  Graphix Universal Photobase Paper
//if (document.quote.material.options[0].selected == true) {
//sqftcost = 4.50;
//minarea = 0;
//};
//  Graphix Universal Gloss Paper
if (document.quote.material.options[0].selected == true) {
sqftcost = 8.99;
minarea = 0;
};
//  Custom Wall Mural
if (document.quote.material.options[1].selected == true) {
sqftcost = 8.99;
minarea = 0;
};
//  Thrifty Banner
if (document.quote.material.options[2].selected == true) {
sqftcost = 11.95;
minarea = 0;
};
//  Magic Polyester Backprint Film
if (document.quote.material.options[3].selected == true) {
sqftcost = 14.95;
minarea = 0;
};
//  Tradeshow Graphics
if (document.quote.material.options[4].selected == true) {
sqftcost = 14.25;
minarea = 0;
};
if (document.quote.material.options[5].selected == true) {
sqftcost = 14.25;
minarea = 0;
};
if (document.quote.material.options[6].selected == true) {
sqftcost = 16.85;
minarea = 0;
};
if (document.quote.material.options[7].selected == true) {
sqftcost = 23.50;
minarea = 0;
};
if (document.quote.material.options[8].selected == true) {
sqftcost = 11.75;
minarea = 0;
};
if (document.quote.material.options[9].selected == true) {
sqftcost = 16.85;
minarea = 0;
};
if (document.quote.material.options[10].selected == true) {
sqftcost = 16.85;
minarea = 0;
};
if (document.quote.material.options[11].selected == true) {
sqftcost = 10.40;
minarea = 0;
};
if (document.quote.material.options[12].selected == true) {
sqftcost = 15.60;
minarea = 0;
};// ********************************************************
// Change BASE Laminating/Mounting Prices here!!!!!
//
//  3-mil Laminate

laminatecostvar = 0.00;
lamshippingchk = 0;

//  3/16" Gator Foam Mounting
mountingcostvar = 0.00;
mtgshippingchk = 0;

// ********************************************************



// Determine square footage
if (widthvar > 0 && heightvar > 0) {
  sqft = ((widthvar*heightvar)/144);
  sqft = sqft*qty;
  // Custom Wall Mural Minimum Order
  if (sqft < minarea) {
  sqft = 48;
  };
  // Square Footage -- round and display to two decimal places
  document.quote.totalsqft.value = (Math.round(sqft*100)/100).toFixed(2);
};


// ********************************************************
// Change DISCOUNT Materials Pricebreaks here!!!!!
//
//  Remember pricebreaks are cumulative!
//
//  Price discount for Graphix Universal Photobase Paper
//if (document.quote.material.options[0].selected == true) {
//	if (sqft >=50) {
//	sqftcost = sqftcost - 0.10;
//	}
//	if (sqft >=200) {
//	sqftcost = sqftcost - 0.15;
//	}
//};
//  Price discount for Graphix Universal Gloss Paper
if (document.quote.material.options[0].selected == true) {
	if (sqft >=50) {
	sqftcost = sqftcost - 0.05;
	}
	if (sqft >=200) {
	sqftcost = sqftcost - 0.15;
	}
};
//  Price discount for Custom Wall Mural
if (document.quote.material.options[1].selected == true) {
	if (sqft >=50) {
	sqftcost = sqftcost - 0.00;
	}
	if (sqft >=200) {
	sqftcost = sqftcost - 0.00;
	}
};
//  Price discount for Thrifty Banner
if (document.quote.material.options[2].selected == true) {
	if (sqft >=50) {
	sqftcost = sqftcost - 0.25;
	}
	if (sqft >=200) {
	sqftcost = sqftcost - 0.25;
	}
};
//  Price discount for Magic Polyester Backprint Film
if (document.quote.material.options[3].selected == true) {
	if (sqft >=50) {
	sqftcost = sqftcost - 0.25;
	}
	if (sqft >=200) {
	sqftcost = sqftcost - 0.25;
	}
};
//  Price discount for Tradeshow Graphics
if (document.quote.material.options[4].selected == true) {
	if (sqft >=50) {
	sqftcost = sqftcost - 0.50;
	}
	if (sqft >=200) {
	sqftcost = sqftcost - 0.50;
	}
};

// ********************************************************
// Change Shipping Costs here!!!!!
//
//  No Shipping
if (document.quote.shippingmethod.options[0].selected == true) {
shippingcost = 0;

};
//  Shipping for Next Day Delivery
if (document.quote.shippingmethod.options[1].selected == true) {
shippingcost = 35.00;

};
//  Shipping for Ground-Based Delivery
if (document.quote.shippingmethod.options[2].selected == true) {
shippingcost = 15.00;
};
if (document.quote.shippingmethod.options[3].selected == true) {
shippingcost = 10.00;
};
// ********************************************************

// Printing Cost / sqft
document.quote.price.value = toCurrency(sqftcost);

// Printing Cost
printingcost = sqft*sqftcost;
// Minimum Order Size
if (printingcost < 15.00) {
printingcost = 15.00;
};
document.quote.printingcost.value = toCurrency(printingcost);

document.quote.shippingcost.value = toCurrency(shippingcost);

// Total cost
totalcost =  printingcost + laminatecost + mountingcost + shippingcost; 
document.quote.totalcost.value = toCurrency(totalcost);

}
