/* Shipping Rates */

var shipping = new Array(20);
shipping[0] = new Array(1.0,1000.0,8.00,12.00,18.00);
shipping[1] = new Array(1001.0,2000.0,16.00,24.00,36.00);
shipping[2] = new Array(2001.0,3000.0,24.00,36.00,54.00);
shipping[3] = new Array(3001.0,4000.0,32.00,48.00,72.00);
shipping[4] = new Array(4001.0,5000.0,40.00,60.00,90.00);
shipping[5] = new Array(5001.0,6000.0,48.00,72.00,108.00);
shipping[6] = new Array(6001.0,7000.0,56.00,84.00,126.00);
shipping[7] = new Array(7001.0,8000.0,64.00,96.00,144.00);
shipping[8] = new Array(8001.0,9000.0,72.00,108.00,162.00);
shipping[9] = new Array(9001.0,10000.0,80.00,120.00,180.00);
shipping[10] = new Array(10001.0,11000.0,88.00,132.00,198.00);
shipping[11] = new Array(11001.0,12000.0,96.00,144.00,216.00);
shipping[12] = new Array(12001.0,13000.0,104.00,156.00,234.00);
shipping[13] = new Array(13001.0,14000.0,112.00,168.00,252.00);
shipping[14] = new Array(14001.0,15000.0,120.00,180.00,270.00);
shipping[15] = new Array(15001.0,16000.0,128.00,192.00,288.00);
shipping[16] = new Array(16001.0,17000.0,136.00,204.00,306.00);
shipping[17] = new Array(17001.0,18000.0,144.00,216.00,324.00);
shipping[18] = new Array(18001.0,19000.0,152.00,228.00,342.00);
shipping[19] = new Array(19001.0,20000.0,160.00,240.00,360.00);



/* 4inch Pricing */
//From,To,PrintBase,PrintMultiplier,MailingBase,MailingMultiplier,Std,FC
//(mailing base) + (mailing multiplier x qty mailed)

var fourinch = new Array(40);
fourinch[0] = new Array(250.0,500.0,99,0.14,50.00,0.025,0.212,0.230);
fourinch[1] = new Array(501.0,1000.0,134,0.09,50.00,0.025,0.212,0.187);
fourinch[2] = new Array(1001.0,1500.0,179,0.09,50.00,0.025,0.212,0.187);
fourinch[3] = new Array(1501.0,2000.0,224,0.11,50.00,0.025,0.212,0.187);
fourinch[4] = new Array(2001.0,2500.0,280,0.07,50.00,0.025,0.212,0.187);
fourinch[5] = new Array(2501.0,3000.0,314,0.08,50.00,0.025,0.212,0.187);
fourinch[6] = new Array(3001.0,3500.0,352,0.07,50.00,0.025,0.212,0.187);
fourinch[7] = new Array(3501.0,4000.0,389,0.07,50.00,0.025,0.212,0.187);
fourinch[8] = new Array(4001.0,4500.0,426,0.07,50.00,0.025,0.212,0.187);
fourinch[9] = new Array(4501.0,5000.0,463,0.07,50.00,0.025,0.212,0.187);
fourinch[10] = new Array(5001.0,5500.0,500,0.07,50.00,0.025,0.212,0.187);
fourinch[11] = new Array(5501.0,6000.0,537,0.07,50.00,0.025,0.212,0.187);
fourinch[12] = new Array(6001.0,6500.0,574,0.07,50.00,0.025,0.212,0.187);
fourinch[13] = new Array(6501.0,7000.0,611,0.07,50.00,0.025,0.212,0.187);
fourinch[14] = new Array(7001.0,7500.0,649,0.07,50.00,0.025,0.212,0.187);
fourinch[15] = new Array(7501.0,8000.0,686,0.07,50.00,0.025,0.212,0.187);
fourinch[16] = new Array(8001.0,8500.0,723,0.07,50.00,0.025,0.212,0.187);
fourinch[17] = new Array(8501.0,9000.0,760,0.07,50.00,0.025,0.212,0.187);
fourinch[18] = new Array(9001.0,9500.0,797,0.07,50.00,0.025,0.212,0.187);
fourinch[19] = new Array(9501.0,10000.0,834,0.07,50.00,0.025,0.212,0.187);
fourinch[20] = new Array(10001.0,10500.0,871,0.07,50.00,0.025,0.212,0.187);
fourinch[21] = new Array(10501.0,11000.0,902,0.06,50.00,0.025,0.212,0.187);
fourinch[22] = new Array(11001.0,11500.0,936,0.07,50.00,0.025,0.212,0.187);
fourinch[23] = new Array(11501.0,12000.0,971,0.07,50.00,0.025,0.212,0.187);
fourinch[24] = new Array(12001.0,12500.0,1005,0.07,50.00,0.025,0.212,0.187);
fourinch[25] = new Array(12501.0,13000.0,1040,0.07,50.00,0.025,0.212,0.187);
fourinch[26] = new Array(13001.0,13500.0,1074,0.07,50.00,0.025,0.212,0.187);
fourinch[27] = new Array(13501.0,14000.0,1109,0.07,50.00,0.025,0.212,0.187);
fourinch[28] = new Array(14001.0,14500.0,1143,0.07,50.00,0.025,0.212,0.187);
fourinch[29] = new Array(14501.0,15000.0,1178,0.07,50.00,0.025,0.212,0.187);
fourinch[30] = new Array(15001.0,15500.0,1212,0.07,50.00,0.025,0.212,0.187);
fourinch[31] = new Array(15501.0,16000.0,1247,0.07,50.00,0.025,0.212,0.187);
fourinch[32] = new Array(16001.0,16500.0,1281,0.07,50.00,0.025,0.212,0.187);
fourinch[33] = new Array(16501.0,17000.0,1316,0.07,50.00,0.025,0.212,0.187);
fourinch[34] = new Array(17001.0,17500.0,1350,0.07,50.00,0.025,0.212,0.187);
fourinch[35] = new Array(17501.0,18000.0,1385,0.07,50.00,0.025,0.212,0.187);
fourinch[36] = new Array(18001.0,18500.0,1419,0.07,50.00,0.025,0.212,0.187);
fourinch[37] = new Array(18501.0,19000.0,1454,0.07,50.00,0.025,0.212,0.187);
fourinch[38] = new Array(19001.0,19500.0,1488,0.07,50.00,0.025,0.212,0.187);
fourinch[39] = new Array(19501.0,20000.0,1523,0.07,50.00,0.025,0.212,0.187);


/* 5inch Pricing */
//From,To,PrintBase,PrintMultiplier,MailingBase,MailingMultiplier,Std,FC

var fiveinch = new Array(40);
fiveinch[0] = new Array(250.0,500.0,169,0.16,50.00,0.025,0.212,0.370);
fiveinch[1] = new Array(501.0,1000.0,211,0.16,50.00,0.025,0.212,0.301);
fiveinch[2] = new Array(1001.0,1500.0,290,0.06,50.00,0.025,0.212,0.301);
fiveinch[3] = new Array(1501.0,2000.0,323,0.17,50.00,0.025,0.212,0.301);
fiveinch[4] = new Array(2001.0,2500.0,407,0.12,50.00,0.025,0.212,0.301);
fiveinch[5] = new Array(2501.0,3000.0,466,0.13,50.00,0.025,0.212,0.301);
fiveinch[6] = new Array(3001.0,3500.0,528,0.13,50.00,0.025,0.212,0.301);
fiveinch[7] = new Array(3501.0,4000.0,591,0.13,50.00,0.025,0.212,0.301);
fiveinch[8] = new Array(4001.0,4500.0,654,0.13,50.00,0.025,0.212,0.301);
fiveinch[9] = new Array(4501.0,5000.0,717,0.07,50.00,0.025,0.212,0.301);
fiveinch[10] = new Array(5001.0,5500.0,752,0.10,50.00,0.025,0.212,0.301);
fiveinch[11] = new Array(5501.0,6000.0,801,0.10,50.00,0.025,0.212,0.301);
fiveinch[12] = new Array(6001.0,6500.0,850,0.10,50.00,0.025,0.212,0.301);
fiveinch[13] = new Array(6501.0,7000.0,899,0.10,50.00,0.025,0.212,0.301);
fiveinch[14] = new Array(7001.0,7500.0,948,0.10,50.00,0.025,0.212,0.301);
fiveinch[15] = new Array(7501.0,8000.0,997,0.10,50.00,0.025,0.212,0.301);
fiveinch[16] = new Array(8001.0,8500.0,1046,0.10,50.00,0.025,0.212,0.301);
fiveinch[17] = new Array(8501.0,9000.0,1095,0.10,50.00,0.025,0.212,0.301);
fiveinch[18] = new Array(9001.0,9500.0,1144,0.10,50.00,0.025,0.212,0.301);
fiveinch[19] = new Array(9501.0,10000.0,1193,0.10,50.00,0.025,0.212,0.301);
fiveinch[20] = new Array(10001.0,10500.0,1244,0.09,50.00,0.025,0.212,0.301);
fiveinch[21] = new Array(10501.0,11000.0,1287,0.09,50.00,0.025,0.212,0.301);
fiveinch[22] = new Array(11001.0,11500.0,1331,0.09,50.00,0.025,0.212,0.301);
fiveinch[23] = new Array(11501.0,12000.0,1375,0.09,50.00,0.025,0.212,0.301);
fiveinch[24] = new Array(12001.0,12500.0,1419,0.09,50.00,0.025,0.212,0.301);
fiveinch[25] = new Array(12501.0,13000.0,1463,0.09,50.00,0.025,0.212,0.301);
fiveinch[26] = new Array(13001.0,13500.0,1506,0.09,50.00,0.025,0.212,0.301);
fiveinch[27] = new Array(13501.0,14000.0,1550,0.09,50.00,0.025,0.212,0.301);
fiveinch[28] = new Array(14001.0,14500.0,1594,0.09,50.00,0.025,0.212,0.301);
fiveinch[29] = new Array(14501.0,15000.0,1638,0.09,50.00,0.025,0.212,0.301);
fiveinch[30] = new Array(15001.0,15500.0,1682,0.09,50.00,0.025,0.212,0.301);
fiveinch[31] = new Array(15501.0,16000.0,1725,0.09,50.00,0.025,0.212,0.301);
fiveinch[32] = new Array(16001.0,16500.0,1769,0.09,50.00,0.025,0.212,0.301);
fiveinch[33] = new Array(16501.0,17000.0,1813,0.09,50.00,0.025,0.212,0.301);
fiveinch[34] = new Array(17001.0,17500.0,1857,0.09,50.00,0.025,0.212,0.301);
fiveinch[35] = new Array(17501.0,18000.0,1901,0.09,50.00,0.025,0.212,0.301);
fiveinch[36] = new Array(18001.0,18500.0,1944,0.09,50.00,0.025,0.212,0.301);
fiveinch[37] = new Array(18501.0,19000.0,1988,0.09,50.00,0.025,0.212,0.301);
fiveinch[38] = new Array(19001.0,19500.0,2032,0.09,50.00,0.025,0.212,0.301);
fiveinch[39] = new Array(19501.0,20000.0,2076,0.07,50.00,0.025,0.212,0.301);



/* 6inch Pricing */
//From,To,PrintBase,PrintMultiplier,MailingBase,MailingMultiplier,Std,FC
var sixinch = new Array(40);
sixinch[0] = new Array(250.0,500.0,284,0.21,50.0000,0.025,0.212,0.37);
sixinch[1] = new Array(501.0,1000.0,337,0.25,50.0000,0.025,0.212,0.301);
sixinch[2] = new Array(1001.0,1500.0,464,0.10,50.0000,0.025,0.212,0.301);
sixinch[3] = new Array(1501.0,2000.0,516,0.27,50.0000,0.025,0.212,0.301);
sixinch[4] = new Array(2001.0,2500.0,652,0.19,50.0000,0.025,0.212,0.301);
sixinch[5] = new Array(2501.0,3000.0,745,0.20,50.0000,0.025,0.212,0.301);
sixinch[6] = new Array(3001.0,3500.0,846,0.20,50.0000,0.025,0.212,0.301);
sixinch[7] = new Array(3501.0,4000.0,946,0.20,50.0000,0.025,0.212,0.301);
sixinch[8] = new Array(4001.0,4500.0,1046,0.20,50.0000,0.025,0.212,0.301);
sixinch[9] = new Array(4501.0,5000.0,1146,0.11,50.0000,0.025,0.212,0.301);
sixinch[10] = new Array(5001.0,5500.0,1203,0.16,50.0000,0.025,0.212,0.301);
sixinch[11] = new Array(5501.0,6000.0,1282,0.16,50.0000,0.025,0.212,0.301);
sixinch[12] = new Array(6001.0,6500.0,1360,0.16,50.0000,0.025,0.212,0.301);
sixinch[13] = new Array(6501.0,7000.0,1439,0.16,50.0000,0.025,0.212,0.301);
sixinch[14] = new Array(7001.0,7500.0,1517,0.16,50.0000,0.025,0.212,0.301);
sixinch[15] = new Array(7501.0,8000.0,1596,0.16,50.0000,0.025,0.212,0.301);
sixinch[16] = new Array(8001.0,8500.0,1674,0.16,50.0000,0.025,0.212,0.301);
sixinch[17] = new Array(8501.0,9000.0,1752,0.16,50.0000,0.025,0.212,0.301);
sixinch[18] = new Array(9001.0,9500.0,1831,0.16,50.0000,0.025,0.212,0.301);
sixinch[19] = new Array(9501.0,10000.0,1909,0.16,50.0000,0.025,0.212,0.301);
sixinch[20] = new Array(10001.0,10500.0,1990,0.14,50.0000,0.025,0.212,0.301);
sixinch[21] = new Array(10501.0,11000.0,2060,0.14,50.0000,0.025,0.212,0.301);
sixinch[22] = new Array(11001.0,11500.0,2130,0.14,50.0000,0.025,0.212,0.301);
sixinch[23] = new Array(11501.0,12000.0,2200,0.14,50.0000,0.025,0.212,0.301);
sixinch[24] = new Array(12001.0,12500.0,2270,0.14,50.0000,0.025,0.212,0.301);
sixinch[25] = new Array(12501.0,13000.0,2340,0.14,50.0000,0.025,0.212,0.301);
sixinch[26] = new Array(13001.0,13500.0,2410,0.14,50.0000,0.025,0.212,0.301);
sixinch[27] = new Array(13501.0,14000.0,2480,0.14,50.0000,0.025,0.212,0.301);
sixinch[28] = new Array(14001.0,14500.0,2550,0.14,50.0000,0.025,0.212,0.301);
sixinch[29] = new Array(14501.0,15000.0,2620,0.14,50.0000,0.025,0.212,0.301);
sixinch[30] = new Array(15001.0,15500.0,2690,0.14,50.0000,0.025,0.212,0.301);
sixinch[31] = new Array(15501.0,16000.0,2760,0.14,50.0000,0.025,0.212,0.301);
sixinch[32] = new Array(16001.0,16500.0,2831,0.14,50.0000,0.025,0.212,0.301);
sixinch[33] = new Array(16501.0,17000.0,2901,0.14,50.0000,0.025,0.212,0.301);
sixinch[34] = new Array(17001.0,17500.0,2971,0.14,50.0000,0.025,0.212,0.301);
sixinch[35] = new Array(17501.0,18000.0,3041,0.14,50.0000,0.025,0.212,0.301);
sixinch[36] = new Array(18001.0,18500.0,3111,0.14,50.0000,0.025,0.212,0.301);
sixinch[37] = new Array(18501.0,19000.0,3181,0.14,50.0000,0.025,0.212,0.301);
sixinch[38] = new Array(19001.0,19500.0,3251,0.14,50.0000,0.025,0.212,0.301);
sixinch[39] = new Array(19501.0,20000.0,33211523,0.17,50.0000,0.025,0.212,0.301);

var DesignPrice0 = 0;
var DesignPrice1 = 70;
var DesignPrice2 = 190;

var MailingList_Consumer = 35;
var MailingList_Consumer_Min = 100;
var MailingList_Homeowners = 95;
var MailingList_Homeowners_Min = 150;
var MailingList_Business = 55;
var MailingList_Business_Min = 100;

var Proof0 = 0;
var Proof1 = 20;
var Proof2 = 40;

var Expedite0 = 0;
var Expedite1 = 25;

function Validate(theForm)
{
  calctotal();

}
function uncommafy(n) {
  num = n;
  str = "" + num;

  var int_str_len = str.length;
  var formatted_num = "";

  for (i=0; i<int_str_len; i++)
  {
    if (str.substr(i,1) == '0' || str.substr(i,1) == '1' || str.substr(i,1) == '2' || str.substr(i,1) == '3' || str.substr(i,1) == '4' || str.substr(i,1) == '5' || str.substr(i,1) == '6' || str.substr(i,1) == '7' || str.substr(i,1) == '8' || str.substr(i,1) == '9' || str.substr(i,1) == '.')
    {
      formatted_num += str.substr(i,1);
    }
  }
  return formatted_num;
}
function commafy (n) {
  num = n * 100;
  num = Math.round(num);
  str = "" + num;

  var int_str_len = str.length-2;
  var int_str = str.substr(0,int_str_len);
  var decimal_str = str.substr(str.length - 2,2);
  var comma_ct = Math.floor(int_str_len/ 3);
  var mode_ct = int_str_len% 3;
  var str_pos = 0;
  var formatted_num = "";

  if (comma_ct == 0) 
    formatted_num += int_str;
  else {
    if (mode_ct != 0) {
      formatted_num += int_str.substr(0, mode_ct) + ",";
      str_pos += mode_ct;
    } 
    for (i=1; i<=comma_ct; i++) {
      if (i == comma_ct) {
        formatted_num += int_str.substr(str_pos,3);
        break;
      }
      else {
        formatted_num += int_str.substr(str_pos,3)+ ",";
        str_pos += 3;
      }
    }
  }

  if (num == 0) {
    formatted_num = "$0.00";
  }
  else {
    formatted_num = "$" + formatted_num + "." + decimal_str;
  }

  return formatted_num;
}
function commafyqty (n) {
  num = n * 100;
  num = Math.round(num);
  str = "" + num;

  var int_str_len = str.length-2;
  var int_str = str.substr(0,int_str_len);
  var decimal_str = str.substr(str.length - 2,2);
  var comma_ct = Math.floor(int_str_len/ 3);
  var mode_ct = int_str_len% 3;
  var str_pos = 0;
  var formatted_num = "";

  if (comma_ct == 0) 
    formatted_num += int_str;
  else {
    if (mode_ct != 0) {
      formatted_num += int_str.substr(0, mode_ct) + ",";
      str_pos += mode_ct;
    } 
    for (i=1; i<=comma_ct; i++) {
      if (i == comma_ct) {
        formatted_num += int_str.substr(str_pos,3);
        break;
      }
      else {
        formatted_num += int_str.substr(str_pos,3)+ ",";
        str_pos += 3;
      }
    }
  }
  formatted_num = formatted_num;
  return formatted_num;
}
function commafyeach (n) {
  num = n * 10000;
  num = Math.round(num);
  str = "" + num;
  if (str.length < 4) {
    str = "0" + str;
  }
  if (str.length < 4) {
    str = "0" + str;
  }
  if (str.length < 4) {
    str = "0" + str;
  }
  if (str.length < 4) {
    str = "0" + str;
  }

  var int_str_len = str.length-4;
  var int_str = str.substr(0,int_str_len);
  var decimal_str = str.substr(str.length - 4,4);
  var comma_ct = Math.floor(int_str_len/ 3);
  var mode_ct = int_str_len% 3;
  var str_pos = 0;
  var formatted_num = "";

  if (comma_ct == 0) 
    formatted_num += int_str;
  else {
    if (mode_ct != 0) {
      formatted_num += int_str.substr(0, mode_ct) + ",";
      str_pos += mode_ct;
    } 
    for (i=1; i<=comma_ct; i++) {
      if (i == comma_ct) {
        formatted_num += int_str.substr(str_pos,3);
        break;
      }
      else {
        formatted_num += int_str.substr(str_pos,3)+ ",";
        str_pos += 3;
      }
    }
  }
  formatted_num = "$" + formatted_num + "." + decimal_str;
  return formatted_num;
}

function clickmailing() {
  document.orderform.mailqty.value = document.orderform.qty.value;
  alert("Confirm that Mailing Quantity is correct.");
}

function calctotal() {
	//verify the total quantity ordered is between 250 and 20000
	if (parseInt(document.orderform.pc_qty.value) < 250){
		document.orderform.pc_qty.value = 250;
	}
	else if (parseInt(document.orderform.pc_qty.value) > 20000){
		alert('Please call 1-866-68-GUIDE for discounted pricing on large quantities.');
		document.orderform.pc_qty.value = 20000;
	}


	//verify that the total quantity ordered is greater than or equal to the total postcards to mail
	if (parseInt(document.orderform.pc_mailing_qty.value) > parseInt(document.orderform.pc_qty.value)){
		document.orderform.pc_mailing_qty.value = document.orderform.pc_qty.value;
		//alert('');
	}
	//if the mailing option is selected, make sure a minimum of 200 cards is set
	if (parseInt(document.orderform.pc_mailing_qty.value) > 0 && parseInt(document.orderform.pc_mailing_qty.value) < 200){
		document.orderform.pc_mailing_qty.value = 200;
	}
	//set the field for number of cards shipped directly to customer
	document.orderform.pc_mailing_return.value = parseInt(document.orderform.pc_qty.value) - parseInt(document.orderform.pc_mailing_qty.value);
	//set the minimum mailing list quantity to 250
	if (document.orderform.pc_list_qty.value < 250){
		document.orderform.pc_list_qty.value = 250;
	}
	
	

	//determine size of postcards and which set of pricing to use from the appropriate array
	var Size = -1;
	var Index = -1;
	var TotalQuantity = parseInt(uncommafy(document.orderform.pc_qty.value));
	var TotalMailingQuantity = parseInt(uncommafy(document.orderform.pc_mailing_qty.value));
	
	if (document.orderform.pc_size[0].checked){
		Size = 4;
		for (i=0; i<fourinch.length; i++){
			if (TotalQuantity >= fourinch[i][0] && TotalQuantity <= fourinch[i][1]){
				Index = i;
				break;
			}
		}
	}
	else if (document.orderform.pc_size[1].checked){
		Size = 5;
		for (i=0; i<fiveinch.length; i++){
			if (TotalQuantity >= fiveinch[i][0] && TotalQuantity <= fiveinch[i][1]){
				Index = i;
				break;
			}
		}
	}
	else if (document.orderform.pc_size[2].checked){
		Size = 6;
		for (i=0; i<sixinch.length; i++){
			if (TotalQuantity >= sixinch[i][0] && TotalQuantity <= sixinch[i][1]){
				Index = i;
				break;
			}
		}
	}
	
	//DESIGN ESTIMATE
	var OutputTotalDesign;
	if (document.orderform.pc_design[0].checked){
		OutputTotalDesign = DesignPrice0;
	}
	else if (document.orderform.pc_design[1].checked){
		OutputTotalDesign = DesignPrice1;
	}
	else if (document.orderform.pc_design[2].checked){
		OutputTotalDesign = DesignPrice2;
	}
	document.floatbox.totaldesign.value = commafy(Math.round(OutputTotalDesign));
	document.orderform.totaldesign.value = commafy(Math.round(OutputTotalDesign));
	
	//PRINTING ESTIMATE (Base Price) + ((Total Qty - Min Qty for range) * multiplier price)
	var OutputTotalPrinting = -1;
	if (Size == 4){
		//OutputTotalPrinting = fourinch[Index][2] + (fourinch[Index][3] * TotalQuantity);
		OutputTotalPrinting = fourinch[Index][2] + ((TotalQuantity - fourinch[Index][0]) * fourinch[Index][3])
	}
	else if (Size == 5){
		//OutputTotalPrinting = fiveinch[Index][2] + (fiveinch[Index][3] * TotalQuantity);
		OutputTotalPrinting = fiveinch[Index][2] + ((TotalQuantity - fiveinch[Index][0]) * fiveinch[Index][3])
	}
	else if (Size == 6){
		//OutputTotalPrinting = sixinch[Index][2] + (sixinch[Index][3] * TotalQuantity);
		OutputTotalPrinting = sixinch[Index][2] + ((TotalQuantity - sixinch[Index][0]) * sixinch[Index][3])
	}
	//Proofs
	if (document.orderform.pc_proof[0].checked){
		OutputTotalPrinting += Proof0;
	}
	else if (document.orderform.pc_proof[1].checked){
		OutputTotalPrinting += Proof1;
	}
	else if (document.orderform.pc_proof[2].checked){
		OutputTotalPrinting += Proof2;
	}
	//Expedited shipping costs
	var TempExpediteTotal;
	if (document.orderform.expd[0].checked){
		TempExpediteTotal = Math.ceil(TotalQuantity / 1000) * Expedite0;
	}
	else if (document.orderform.expd[1].checked){
		TempExpediteTotal = Math.ceil(TotalQuantity / 1000) * Expedite1;
	}
	//if the Expedite cost is between $0.01 and $99.99, round up to $100.
	if (TempExpediteTotal != 0){
		if (TempExpediteTotal < 100){
			TempExpediteTotal = 100;
		}
	}
	OutputTotalPrinting += TempExpediteTotal;
	document.floatbox.totalprinting.value = commafy(Math.round(OutputTotalPrinting));
	document.orderform.totalprinting.value = commafy(Math.round(OutputTotalPrinting));
	
	
	//MAILING LIST ESTIMATE
	var MailingListTemp = 0;
	var OutputTotalMailingList;
	if (document.orderform.pc_list_type[0].checked){
		MailingListTemp = 0;
		document.orderform.pc_list_qty.value = "";
	}
	else{
		if (_CF_checknumber(document.orderform.pc_list_qty.value) && document.orderform.pc_list_qty.value != ""){
			if (document.orderform.pc_list_type[1].checked){
				MailingListTemp = Math.ceil(document.orderform.pc_list_qty.value / 1000) * MailingList_Consumer;
				if (MailingListTemp < MailingList_Consumer_Min){
					MailingListTemp = MailingList_Consumer_Min;
				}
			}
			else if (document.orderform.pc_list_type[2].checked){
				MailingListTemp = Math.ceil(document.orderform.pc_list_qty.value / 1000) * MailingList_Homeowners;
				if (MailingListTemp < MailingList_Homeowners_Min){
					MailingListTemp = MailingList_Homeowners_Min;
				}
			}
			else if (document.orderform.pc_list_type[3].checked){
				MailingListTemp = Math.ceil(document.orderform.pc_list_qty.value / 1000) * MailingList_Business;
				if (MailingListTemp < MailingList_Business_Min){
					MailingListTemp = MailingList_Business_Min;
				}
			}
		}
		else{
			alert('Please enter a numercial value into the quantity field.');
			document.orderform.pc_list_qty.focus();
		}
	}
	//Mailing list use (one-time or unlimited use)
	if (document.orderform.pc_mailinglist_extras1[0].checked){
		OutputTotalMailingList = MailingListTemp;
	}
	else if (document.orderform.pc_mailinglist_extras1[1].checked){
		OutputTotalMailingList = MailingListTemp * 2;
	}
	document.floatbox.totalmailinglist.value = commafy(Math.round(OutputTotalMailingList));
	document.orderform.totalmailinglist.value = commafy(Math.round(OutputTotalMailingList));
	
	//MAILING SERVICES ESTIMATE (mailing base) + (mailing multiplier * qty mailed)
	var OutputTotalMailing = 0;
	if (parseInt(document.orderform.pc_mailing_qty.value) != 0){
		if (Size == 4){
			OutputTotalMailing = fourinch[Index][4] + (fourinch[Index][5] * TotalMailingQuantity);
		}
		else if (Size == 5){
			OutputTotalMailing = fiveinch[Index][4] + (fiveinch[Index][5] * TotalMailingQuantity);
		}
		else if (Size == 6){
			OutputTotalMailing = sixinch[Index][4] + (sixinch[Index][5] * TotalMailingQuantity);
		}
	}
	document.floatbox.totalmailing.value = commafy(Math.round(OutputTotalMailing));
	document.orderform.totalmailing.value = commafy(Math.round(OutputTotalMailing));
	
	//POSTAGE ESTIMATE (qty mailed) X (class of postage selected)  STD/FC
	var OutputTotalPostage;
	if (Size == 4 && document.orderform.pc_mailing_rate[0].checked){
		OutputTotalPostage = TotalMailingQuantity * fourinch[Index][6];
	}
	else if (Size == 4 && document.orderform.pc_mailing_rate[1].checked){
		OutputTotalPostage = TotalMailingQuantity * fourinch[Index][7];
	}
	else if (Size == 5 && document.orderform.pc_mailing_rate[0].checked){
		OutputTotalPostage = TotalMailingQuantity * fiveinch[Index][6];
	}
	else if (Size == 5 && document.orderform.pc_mailing_rate[1].checked){
		OutputTotalPostage = TotalMailingQuantity * fiveinch[Index][7];
	}
	else if (Size == 6 && document.orderform.pc_mailing_rate[0].checked){
		OutputTotalPostage = TotalMailingQuantity * sixinch[Index][6];
	}
	else if (Size == 6 && document.orderform.pc_mailing_rate[1].checked){
		OutputTotalPostage = TotalMailingQuantity * sixinch[Index][7];
	}
	document.floatbox.totalpostage.value = commafy(Math.round(OutputTotalPostage));
	document.orderform.totalpostage.value = commafy(Math.round(OutputTotalPostage));

        //SHIPPING ESTIMATE
        var OutputTotalShipping;
        var ShippingIndex;
        var PartialQuantity;
        PartialQuantity = TotalQuantity - TotalMailingQuantity;
        if (PartialQuantity==0) {
                OutputTotalShipping = 0;
        }
        else {
                for (i=0; i<shipping.length; i++){
                        if (PartialQuantity >= shipping[i][0] && PartialQuantity <= shipping[i][1]){
                                ShippingIndex = i;
                                break;
                        }
                }
                if (Size == 4){
                        OutputTotalShipping = shipping[ShippingIndex][2];
                }
                else if (Size == 5){
                        OutputTotalShipping = shipping[ShippingIndex][3];
                }
                else if (Size == 6){
                        OutputTotalShipping = shipping[ShippingIndex][4];
                }
        }
        document.floatbox.totalshipping.value = commafy(Math.round(OutputTotalShipping)); 
        document.orderform.totalshipping.value = commafy(Math.round(OutputTotalShipping)); 

	
	//create temp variable OutputTotal that sums all 6 running totals.
	var OutputTotalEstimate = parseFloat(uncommafy(document.floatbox.totaldesign.value)) + parseFloat(uncommafy(document.floatbox.totalprinting.value)) + parseFloat(uncommafy(document.floatbox.totalmailinglist.value)) + parseFloat(uncommafy(document.floatbox.totalmailing.value)) + parseFloat(uncommafy(document.floatbox.totalpostage.value)) + parseFloat(uncommafy(document.floatbox.totalshipping.value))
	//OutputTotalEstimate = Math.round(OutputTotalEstimate);
	//format and output the total
	document.floatbox.totalestimate.value =  commafy(OutputTotalEstimate);
	document.orderform.totalestimate.value =  commafy(OutputTotalEstimate);
}

window.onerror = null;
var topMargin = 0;
var slideTime = 1200;
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);
function layerObject(id,left) {

  if (ns6) {
    this.obj = document.getElementById(id).style;
    this.obj.left = left;
    return this.obj;
  }
  else if(ie4) {
    this.obj = document.all[id].style;
    this.obj.left = left;
    return this.obj;
  }
  else if(ns4) {
    this.obj = document.layers[id];
    this.obj.left = left;
    return this.obj;
  }
}

function layerSetup() {
  floatLyr = new layerObject('floatLayer', 580);
  window.setInterval("floatmain()", 10)
}
function floatObject() {
  if (ns4 || ns6) {
  findHt = window.innerHeight;
  }
  else if(ie4) {
    findHt = document.body.clientHeight;
  }
} 
function floatmain() {
  if (ns4) {
    this.currentY = document.layers["floatLayer"].top;
    this.scrollTop = window.pageYOffset;
    mainTrigger();
  }
  else if(ns6) {
    this.currentY = parseInt(document.getElementById('floatLayer').style.top);
    this.scrollTop = scrollY;
    mainTrigger();
  }
  else if(ie4) {
    this.currentY = floatLayer.style.pixelTop;
    this.scrollTop = document.body.scrollTop;
    mainTrigger();
  }
}
function mainTrigger() {
  var newTargetY = this.scrollTop + this.topMargin;
  if (this.currentY != newTargetY) {
    if (newTargetY != this.targetY) {
      this.targetY = newTargetY;
      floatStart();
    }
    animator();
  }
}
function floatStart() {
  var now = new Date();
  this.A = this.targetY - this.currentY;
  this.B = Math.PI / ( 2 * this.slideTime );
  this.C = now.getTime();
  if (Math.abs(this.A) > this.findHt) {
    this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
    this.A = this.A > 0 ? this.findHt : -this.findHt;
  }
  else {
    this.D = this.currentY;
  }
}
function animator() {
  var now = new Date();
  var newY = this.A * Math.sin(this.B * (now.getTime() - this.C)) + this.D;
  newY = Math.round(newY);
  if ((this.A > 0 && newY > this.currentY) || (this.A < 0 && newY < this.currentY)) {
  if (ie4) document.all.floatLayer.style.pixelTop = newY;
  if (ns4) document.layers["floatLayer"].top = newY;
  if (ns6) document.getElementById('floatLayer').style.top = newY + "px";
  }
}
function start() {
  if(ns6||ns4) {
    pageWidth = innerWidth;
    pageHeight = innerHeight;
    layerSetup();
    floatObject();
  }
  else if(ie4) {
    pageWidth = document.body.clientWidth;
    pageHeight = document.body.clientHeight;
    layerSetup();
    floatObject();
  }
}

