// 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 = 5.50;

minarea = 0;

};

//  Custom Wall Mural

if (document.quote.material.options[1].selected == true) {

sqftcost = 7.00;

minarea = 48;

};

//  Thrifty Banner

if (document.quote.material.options[2].selected == true) {

sqftcost = 7.50;

minarea = 0;

};

//  Magic Polyester Backprint Film

if (document.quote.material.options[3].selected == true) {

sqftcost = 7.50;

minarea = 0;

};

//  Tradeshow Graphics

if (document.quote.material.options[4].selected == true) {

sqftcost = 17.00;

minarea = 0;

};

// ********************************************************

// Change BASE Laminating/Mounting Prices here!!!!!

//

//  3-mil Laminate

if (document.quote.laminate[0].checked == true) {

laminatecostvar = 2.10;

lamshippingchk = 1;

}

else {

laminatecostvar = 0.00;

lamshippingchk = 0;

};

//  3/16" Gator Foam Mounting

if (document.quote.mount[0].checked == true) {

mountingcostvar = 3.50;

mtgshippingchk = 1;

// Whenever mounting is done, add price for laminating

laminatecostvar = 2.10;

lamshippingchk = 1;

document.quote.laminate[0].checked = true;

}

else {

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 DISCOUNT Laminating/Mounting Pricebreaks here!!!!!

//

//  Remember pricebreaks are cumulative!

//

//  Price discount for 3-mil Laminate

if (document.quote.laminate[0].checked == true) {

	if (sqft >=50) {

	laminatecostvar = laminatecostvar - 0.10;

	}

	if (sqft >=200) {

	laminatecostvar = laminatecostvar - 0.20;

	}

};

//  Price discount for 3/16" Gator Foam Mounting

if (document.quote.mount[0].checked == true) {

	if (sqft >=50) {

	mountingcostvar = mountingcostvar - 0.00;

	}

	if (sqft >=200) {

	mountingcostvar = mountingcostvar - 0.00;

	}

};

// ********************************************************



// ********************************************************

// Change Shipping Costs here!!!!!

//

//  No Shipping

if (document.quote.shippingmethod.options[0].selected == true) {

printshippingrate = 0.00;

lamshippingrate = 0.00;

mtgshippingrate = 0.00;

printshippingbase = 0.00;

mtgshippingbase = 0.00;

nd_mtgshippingrate = 0.00

};

//  Shipping for Next Day Delivery

if (document.quote.shippingmethod.options[1].selected == true) {

printshippingrate = 0.10;

lamshippingrate = 0.10;

mtgshippingrate = 0.15;

nd_mtgshippingrate = 0.05;

printshippingbase = 20.00;

mtgshippingbase = 5.00;

};

//  Shipping for Ground-Based Delivery

if (document.quote.shippingmethod.options[2].selected == true) {

printshippingrate =  0.10;

lamshippingrate = 0.10;

mtgshippingrate = 0.10;

nd_mtgshippingrate = 0.00;

printshippingbase = 6.00;

mtgshippingbase = 4.00;

};

// ********************************************************



// Printing Cost / sqft

document.quote.price.value = toCurrency(sqftcost);

// Laminating Cost / sqft

document.quote.lprice.value = toCurrency(laminatecostvar);

// Mounting Cost / sqft

document.quote.mprice.value = toCurrency(mountingcostvar);



// Printing Cost

printingcost = sqft*sqftcost;

// Minimum Order Size

if (printingcost < 15.00) {

printingcost = 15.00;

};

document.quote.printingcost.value = toCurrency(printingcost);



// Laminating Cost

laminatecost = sqft*laminatecostvar;

document.quote.laminatingcost.value = toCurrency(laminatecost);



// Mounting Cost

mountingcost = sqft*mountingcostvar;

document.quote.mountingcost.value = toCurrency(mountingcost);



// Shipping Cost

printshippingcost = (printingcost*printshippingrate) + printshippingbase; 

lamshippingcost = laminatecost*lamshippingrate*lamshippingchk;

mtgshippingcost = (mountingcost*mtgshippingrate*mtgshippingchk) + (nd_mtgshippingrate*mtgshippingchk*(printingcost+laminatecost))+ (mtgshippingchk*mtgshippingbase);

shippingcost =  printshippingcost + lamshippingcost + mtgshippingcost;

// Ground-Based Delivery: Determine if free shipping over $150.00 

if ((document.quote.shippingmethod.options[2].selected == true) && (printingcost+laminatecost >= 150.00) && (document.quote.mount[0].checked == false)) {

shippingcost = 0;

};

document.quote.shippingcost.value = toCurrency(shippingcost);



// Total cost

totalcost =  printingcost + laminatecost + mountingcost + shippingcost; 

document.quote.totalcost.value = toCurrency(totalcost);



}

