function floor(number)
{
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}



function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;

	workStr=""+s

	if (workStr.indexOf(".")==-1){workStr+="."}

	dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
	pStr=workStr.substr(workStr.indexOf("."))

	decimal = 2

	while (pStr.length-1< decimal){pStr+="0"}

	if(pStr =='.') pStr ='';

	   //--- Adds a comma in the thousands place.
	   if (dNum>=1000) {
		  dLen=dStr.length
		  dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
	   }

	   //-- Adds a comma in the millions place.
	   if (dNum>=1000000) {
		  dLen=dStr.length
		  dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
	   }
	   retval = dStr + pStr

	return retval;
}

function removeCommas(aNum) {

//remove any commas

aNum=aNum.replace(/,/g,"");

//remove any spaces

aNum=aNum.replace(/\s/g,"");

return aNum;

}//end of removeCommas(aNum)




 function dosum()
 {

var quantity = document.temps.quantity.value;

var subtotal = quantity * 18.30;

shippingoption = document.temps.shippingoption.value;

if(shippingoption == "USPS")
{
	var shippingrate = 4.75;
	var shippingrate2 = 1.65;
}
else if(shippingoption == "UPS")
{
	var shippingrate = 8.25;
	var shippingrate2 = 2.00;
}
else if(shippingoption == "Fedex")
{
	var shippingrate = 9.50;
	var shippingrate2 = 2.50;
}
else if(shippingoption == "USPS Global")
{
	var shippingrate = 16.50;
	var shippingrate2 = 16.50;
}
else {
	var shippingrate = 4.75;
	var shippingrate2 = 1.65;
}; 

var extras = quantity - 1

if(extras > 0)
{
	var shipping = (1 * shippingrate) + (extras * shippingrate2);
}
else
{
	var shipping = 1 * shippingrate;
}


document.temps.shippingrate_value.value = CurrencyFormatted(shippingrate) + " + $" + CurrencyFormatted(shippingrate2) + " each additional";

document.temps.subtotal.value = CurrencyFormatted(subtotal);

document.temps.shipping.value = CurrencyFormatted(shipping);

var totalcost = shipping + subtotal;

document.temps.totalcost.value = CurrencyFormatted(totalcost);


}
