/*
Function: mag_price_quote(qfrm)
Purpose: To produce a quick quote price for a FlexMagnet, excluding artwork, setup and shipping fees.

Author: Robert Traulsen
Email: bob@ConcessionSolutions.com

Date: December 14, 2005

*/

function price_quote(qfrm){
var price_per;
var cost;
var w;
var h;

w = 0;
h = 0;

// Verify user entered data as digits plus a '.' in sizes ('w' and 'h') whole number only for quantity 'q'

if (qfrm.q.value == "0") // If user didn't select a quantity, return user to form
{
	alert("You have not selected a quantity.");
	return false;
}

if (isNaN(qfrm.wi.value)) // If invalid digits, return user to width entry box
{
	alert("You have entered an invalid number.  Please use only the digits 0-9 and a '.' for Width inches.");
	qfrm.wi.select();
	qfrm.wi.focus();
	return false;
}

if (qfrm.wi.value == "0")
{
	alert("You have not entered a valid width in inches.  Please enter a value for Width in inches.");
	qfrm.wi.select();
	qfrm.wi.focus();
	return false;
}

if (isNaN(qfrm.hi.value)) // If invalid digits, return user to Height entry box
{
	alert("You have entered an invalid number.  Please use only the digits 0-9 and a '.' for Height inches.");
	qfrm.hi.select();
	qfrm.hi.focus();
	return false;
}

if (qfrm.hi.value == "0")
{
	alert("You have not entered a valid height in inches.  Please enter a value for Height in inches.");
	qfrm.hi.select();
	qfrm.hi.focus();
	return false;
}

// Width and Height appear to be valid so set w and h

w = parseFloat(qfrm.wi.value);
h = parseFloat(qfrm.hi.value);

// If there is a decimal in quantity, only use the whole number

intQty = parseInt(qfrm.q.value);

// Determine cost per square foot based on quantity ordered

if (intQty < 2500){
		qfrm.c.value = "Call";
		qfrm.tc.value = "Call";
		return false;
}

if ((intQty >= 2500) && (intQty < 5000)){
	price_per = .025;
}

if ((intQty >= 5000) && (intQty < 10000)){
	price_per = .02;
}

if ((intQty >= 10000) && (intQty < 22500)){
	price_per = .018;
}

if ((intQty >= 22500) && (intQty < 50000)){
	price_per = .0155;
}

if ((intQty >= 50000) && (inQty < 70000)){
	price_per = .014;
}

if (intQty >= 70000) {
		qfrm.c.value = "Call";
		qfrm.tc.value = "Call";
		return false;
}

/* calculate the price:
			multiply width x height in inches, 
			multiply by price and 
			multiply by quantity

*/

cost = ((w * h) * price_per);

num = cost;
num2 = cost * intQty;

// below is borrowed and modified from the: The JavaScript Source!! http://javascript.internet.com 

/*num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	num = Math.floor(num * 100 + 0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();
	if(cents < 10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
		num = num.substring(0,num.length - (4 * i + 3)) + ',' + num.substring(num.length-(4 * i + 3));*/
		
	qfrm.c.value =  ('$' + num);
	
	num2 = num2.toString().replace(/\$|\,/g,'');
	if(isNaN(num2))
		num2 = "0";
	num2 = Math.floor(num2 * 100 + 0.50000000001);
	cents = num2 % 100;
	num2 = Math.floor(num2 / 100).toString();
	if(cents < 10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num2.length - (1 + i)) / 3); i++)
		num2 = num2.substring(0,num2.length - (4 * i + 3)) + ',' + num2.substring(num2.length-(4 * i + 3));
	qfrm.tc.value =  ('$' + num2 + '.' + cents);

return false;

} // End of function price_quote(qfrm)